From ca59138a2aef96960381f986b8c683634e4d8e63 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Tue, 28 Mar 2023 11:18:54 -0600 Subject: tweak: move things around --- plugins/libre_redirect/README.md | 3 - plugins/libre_redirect/libre_redirect.c | 84 ---------------------- plugins/libre_redirect/libre_redirect.h | 6 -- plugins/libre_redirect/str_replace_start.c | 65 ----------------- plugins/libre_redirect/str_replace_start.h | 4 -- .../str_replace_test/build-example.sh | 11 --- plugins/libre_redirect/str_replace_test/example.c | 19 ----- 7 files changed, 192 deletions(-) delete mode 100644 plugins/libre_redirect/README.md delete mode 100644 plugins/libre_redirect/libre_redirect.c delete mode 100644 plugins/libre_redirect/libre_redirect.h delete mode 100644 plugins/libre_redirect/str_replace_start.c delete mode 100644 plugins/libre_redirect/str_replace_start.h delete mode 100644 plugins/libre_redirect/str_replace_test/build-example.sh delete mode 100644 plugins/libre_redirect/str_replace_test/example.c (limited to 'plugins/libre_redirect') diff --git a/plugins/libre_redirect/README.md b/plugins/libre_redirect/README.md deleted file mode 100644 index f3f58c9..0000000 --- a/plugins/libre_redirect/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## About - -This code automatically redirects webpage to their open-source frontends. It is based on \ No newline at end of file diff --git a/plugins/libre_redirect/libre_redirect.c b/plugins/libre_redirect/libre_redirect.c deleted file mode 100644 index 3794add..0000000 --- a/plugins/libre_redirect/libre_redirect.c +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include -#include - -#include "str_replace_start.h" - -#define LIBRE_N 19 - -/* Uncomment for debug */ -/* #define DEBUG */ - -/* Inspired by https://libredirect.github.io/, but in C. */ - -void str_init(char* str, int n) -{ - for (int i = 0; i < n; i++) - str[i] = ' '; - str[n] = '\0'; -} // could also use - -int libre_redirect(const char* uri, char* output) -{ - int l1 = strlen(uri); - int l2 = strlen(output); - int len; - char tmp_uri[l2++]; - char tmp_output[l2++]; - - if ((l2 - l1) < LIBRE_N) { -#ifdef DEBUG - printf("Not enough memory\n"); -#endif - return 1; // not enough memory. - } else { - strcpy(tmp_uri, uri); // strcpy also copies the terminating '\0' - strcpy(tmp_output, output); - - char* annoying_sites[] = { - "https://www.youtube.com", - "https://www.reddit.com", - "https://medium.com", - "https://translate.google.com", - // "https://forum.effectivealtruism.org", - "https://www.bloomberg.com", - "https://twitter.com" - }; - - char* alternatives[] = { - "https://yt.artemislena.eu", - "https://teddit.nunosempere.com", - "https://scribe.rip", - "https://simplytranslate.org/", - // "https://ea.greaterwrong.com", - "https://archive.is/https://www.bloomberg.com", - "https://nitter.net" - }; - - len = sizeof(annoying_sites) / sizeof(annoying_sites[0]); - - for (int i = 0; i < len; i++) { - int replace_check = str_replace_start(tmp_uri, annoying_sites[i], - alternatives[i], output); - if (replace_check == 2) { -#ifdef DEBUG - printf("tmp_uri: %s\n", tmp_uri); - printf("output: %s\n", output); -#endif - return 2; - } else if (replace_check == 1) { -#ifdef DEBUG - printf("replace_check failed\n"); -#endif - return 1; - } - strcpy(tmp_uri, output); - str_init(output, l2); - } - strcpy(output, tmp_uri); - } -#ifdef DEBUG - printf("No match found\n\n"); -#endif - return 0; -} diff --git a/plugins/libre_redirect/libre_redirect.h b/plugins/libre_redirect/libre_redirect.h deleted file mode 100644 index 150c95e..0000000 --- a/plugins/libre_redirect/libre_redirect.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#define LIBRE_N 19 - -int libre_redirect(const char* uri, char* uri_filtered); -void str_init(char* str, int n); diff --git a/plugins/libre_redirect/str_replace_start.c b/plugins/libre_redirect/str_replace_start.c deleted file mode 100644 index d1fe083..0000000 --- a/plugins/libre_redirect/str_replace_start.c +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include - -#define DEBUG false - -/* -See also: -* -* https://github.com/irl/la-cucina/blob/master/str_replace.c -*/ - -int str_replace_start(const char* string, const char* target, const char* replacement, char* output) -{ - int l1 = strlen(string); - int l2 = strlen(target); - int l3 = strlen(replacement); - int l4 = strlen(output); - if (DEBUG) - printf("%d,%d,%d,%d\n", l1, l2, l3, l4); - // if(DEBUG) printf("%s,%s,%s,%s\n", string, target, replacement, output); - - if ((l4 < (l1 - l2 + l3)) || l4 < l1) { - // Not enough memory in output string. - if (DEBUG) - printf("String not long enough.\n"); - return 1; - } - /* else if(l1 < l2){ - // Not even possible that there is a match. - if(DEBUG) printf("Target larger than string.\n"); - strcpy(output, string); - } */ - else { - if (DEBUG) - printf("Looking for a match for %s in %s.\n", target, string); - int match = true; - for (int i = 0; i < l2; i++) { - if (string[i] != target[i]) { - match = false; - break; - } - } - if (match) { - if (DEBUG) - printf("Found match.\n"); - for (int i = 0; i < l3; i++) { - output[i] = replacement[i]; - } - int counter = l3; - for (int i = l2; i < l1; i++) { - output[counter] = string[i]; - counter++; - } - output[counter] = '\0'; - return 2; // success - } else { - if (DEBUG) - printf("Did not find match.\n"); - strcpy(output, string); - } - } - - return 0; -} diff --git a/plugins/libre_redirect/str_replace_start.h b/plugins/libre_redirect/str_replace_start.h deleted file mode 100644 index 78c79b5..0000000 --- a/plugins/libre_redirect/str_replace_start.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -int str_replace_start(const char* string, const char* target, - const char* replacement, char* output); diff --git a/plugins/libre_redirect/str_replace_test/build-example.sh b/plugins/libre_redirect/str_replace_test/build-example.sh deleted file mode 100644 index a9f8022..0000000 --- a/plugins/libre_redirect/str_replace_test/build-example.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -CC=gcc - -FLAGS="-std=c99 -Wall -lm" - -SRC=example.c -REQS="../str_replace_start.c ../libre_redirect.c" - -echo -e "\n\n\n" -$CC $FLAGS $SRC $REQS -o example - diff --git a/plugins/libre_redirect/str_replace_test/example.c b/plugins/libre_redirect/str_replace_test/example.c deleted file mode 100644 index b93634a..0000000 --- a/plugins/libre_redirect/str_replace_test/example.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "../libre_redirect.h" -#include -#include - -int main() -{ - char uri[] = "https://reddit.com/r/blah"; - - int l = LIBRE_N + strlen(uri) + 1; - char uri_filtered[l]; - str_init(uri_filtered, l); - - if (!libre_redirect(uri, uri_filtered)) { - printf("Filtered uri: %s\n", uri_filtered); - } else { - printf("Uri: %s\n", uri); - // failure; do something with the original uri. - } -} -- cgit v1.2.3