style: enforce webkit style for plugins
$ clang-format -style=webkit -i */.c $ clang-format -style=webkit -i */*/.c
This commit is contained in:
parent
ec97a8f3f3
commit
3483af0f0f
|
@ -1,6 +1,6 @@
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "str_replace_start.h"
|
#include "str_replace_start.h"
|
||||||
|
|
||||||
|
@ -13,72 +13,72 @@
|
||||||
|
|
||||||
void str_init(char* str, int n)
|
void str_init(char* str, int n)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
str[i] = ' ';
|
str[i] = ' ';
|
||||||
str[n] = '\0';
|
str[n] = '\0';
|
||||||
} // could also use <https://manpages.ubuntu.com/manpages/impish/man3/strinit.3pub.html>
|
} // could also use <https://manpages.ubuntu.com/manpages/impish/man3/strinit.3pub.html>
|
||||||
|
|
||||||
int libre_redirect(const char* uri, char* output)
|
int libre_redirect(const char* uri, char* output)
|
||||||
{
|
{
|
||||||
int l1 = strlen(uri);
|
int l1 = strlen(uri);
|
||||||
int l2 = strlen(output);
|
int l2 = strlen(output);
|
||||||
int len;
|
int len;
|
||||||
char tmp_uri[l2++];
|
char tmp_uri[l2++];
|
||||||
char tmp_output[l2++];
|
char tmp_output[l2++];
|
||||||
|
|
||||||
if ((l2 - l1) < LIBRE_N) {
|
if ((l2 - l1) < LIBRE_N) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Not enough memory\n");
|
printf("Not enough memory\n");
|
||||||
#endif
|
#endif
|
||||||
return 1; // not enough memory.
|
return 1; // not enough memory.
|
||||||
} else {
|
} else {
|
||||||
strcpy(tmp_uri, uri); // strcpy also copies the terminating '\0'
|
strcpy(tmp_uri, uri); // strcpy also copies the terminating '\0'
|
||||||
strcpy(tmp_output, output);
|
strcpy(tmp_output, output);
|
||||||
|
|
||||||
char* annoying_sites[] = {
|
char* annoying_sites[] = {
|
||||||
"https://www.youtube.com",
|
"https://www.youtube.com",
|
||||||
"https://www.reddit.com",
|
"https://www.reddit.com",
|
||||||
"https://medium.com",
|
"https://medium.com",
|
||||||
"https://translate.google.com",
|
"https://translate.google.com",
|
||||||
// "https://forum.effectivealtruism.org",
|
// "https://forum.effectivealtruism.org",
|
||||||
"https://www.bloomberg.com",
|
"https://www.bloomberg.com",
|
||||||
"https://twitter.com"
|
"https://twitter.com"
|
||||||
};
|
};
|
||||||
|
|
||||||
char* alternatives[] = {
|
char* alternatives[] = {
|
||||||
"https://yt.artemislena.eu",
|
"https://yt.artemislena.eu",
|
||||||
"https://teddit.nunosempere.com",
|
"https://teddit.nunosempere.com",
|
||||||
"https://scribe.rip",
|
"https://scribe.rip",
|
||||||
"https://simplytranslate.org/",
|
"https://simplytranslate.org/",
|
||||||
// "https://ea.greaterwrong.com",
|
// "https://ea.greaterwrong.com",
|
||||||
"https://archive.is/https://www.bloomberg.com",
|
"https://archive.is/https://www.bloomberg.com",
|
||||||
"https://nitter.net"
|
"https://nitter.net"
|
||||||
};
|
};
|
||||||
|
|
||||||
len = sizeof(annoying_sites) / sizeof(annoying_sites[0]);
|
len = sizeof(annoying_sites) / sizeof(annoying_sites[0]);
|
||||||
|
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
int replace_check = str_replace_start(tmp_uri, annoying_sites[i],
|
int replace_check = str_replace_start(tmp_uri, annoying_sites[i],
|
||||||
alternatives[i], output);
|
alternatives[i], output);
|
||||||
if (replace_check == 2) {
|
if (replace_check == 2) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("tmp_uri: %s\n", tmp_uri);
|
printf("tmp_uri: %s\n", tmp_uri);
|
||||||
printf("output: %s\n", output);
|
printf("output: %s\n", output);
|
||||||
#endif
|
#endif
|
||||||
return 2;
|
return 2;
|
||||||
} else if (replace_check == 1) {
|
} else if (replace_check == 1) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("replace_check failed\n");
|
printf("replace_check failed\n");
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
strcpy(tmp_uri, output);
|
strcpy(tmp_uri, output);
|
||||||
str_init(output, l2);
|
str_init(output, l2);
|
||||||
}
|
}
|
||||||
strcpy(output, tmp_uri);
|
strcpy(output, tmp_uri);
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("No match found\n\n");
|
printf("No match found\n\n");
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <string.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define DEBUG false
|
#define DEBUG false
|
||||||
|
|
||||||
|
@ -12,50 +12,54 @@ See also:
|
||||||
|
|
||||||
int str_replace_start(const char* string, const char* target, const char* replacement, char* output)
|
int str_replace_start(const char* string, const char* target, const char* replacement, char* output)
|
||||||
{
|
{
|
||||||
int l1 = strlen(string);
|
int l1 = strlen(string);
|
||||||
int l2 = strlen(target);
|
int l2 = strlen(target);
|
||||||
int l3 = strlen(replacement);
|
int l3 = strlen(replacement);
|
||||||
int l4 = strlen(output);
|
int l4 = strlen(output);
|
||||||
if(DEBUG) printf("%d,%d,%d,%d\n", l1, l2, l3, l4);
|
if (DEBUG)
|
||||||
// if(DEBUG) printf("%s,%s,%s,%s\n", string, target, replacement, output);
|
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 ){
|
if ((l4 < (l1 - l2 + l3)) || l4 < l1) {
|
||||||
// Not enough memory in output string.
|
// Not enough memory in output string.
|
||||||
if(DEBUG) printf("String not long enough.\n");
|
if (DEBUG)
|
||||||
return 1;
|
printf("String not long enough.\n");
|
||||||
}
|
return 1;
|
||||||
/* else if(l1 < l2){
|
}
|
||||||
|
/* else if(l1 < l2){
|
||||||
// Not even possible that there is a match.
|
// Not even possible that there is a match.
|
||||||
if(DEBUG) printf("Target larger than string.\n");
|
if(DEBUG) printf("Target larger than string.\n");
|
||||||
strcpy(output, string);
|
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 {
|
else {
|
||||||
if(DEBUG) printf("Did not find match.\n");
|
if (DEBUG)
|
||||||
strcpy(output, string);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
#include "../libre_redirect.h"
|
#include "../libre_redirect.h"
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
int main(){
|
int main()
|
||||||
char uri[] = "https://reddit.com/r/blah";
|
{
|
||||||
|
char uri[] = "https://reddit.com/r/blah";
|
||||||
|
|
||||||
int l = LIBRE_N + strlen(uri) + 1;
|
int l = LIBRE_N + strlen(uri) + 1;
|
||||||
char uri_filtered[l];
|
char uri_filtered[l];
|
||||||
str_init(uri_filtered, l);
|
str_init(uri_filtered, l);
|
||||||
|
|
||||||
if (!libre_redirect(uri, uri_filtered)) {
|
if (!libre_redirect(uri, uri_filtered)) {
|
||||||
printf("Filtered uri: %s\n", uri_filtered);
|
printf("Filtered uri: %s\n", uri_filtered);
|
||||||
} else {
|
} else {
|
||||||
printf("Uri: %s\n", uri);
|
printf("Uri: %s\n", uri);
|
||||||
// failure; do something with the original uri.
|
// failure; do something with the original uri.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,23 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#define READABILITY_N 85133 + 1000
|
#define READABILITY_N 85133 + 1000
|
||||||
|
|
||||||
void read_readability_js(char* string){
|
void read_readability_js(char* string)
|
||||||
FILE *fp=fopen("/home/loki/Documents/core/software/fresh/C/rose-browser/rosenrot/plugins/readability/readability.js", "r");
|
{
|
||||||
if (!fp) { // fp is NULL, fopen failed
|
FILE* fp = fopen("/home/loki/Documents/core/software/fresh/C/rose-browser/rosenrot/plugins/readability/readability.js", "r");
|
||||||
fprintf(stderr, "Failed to open file\n");
|
if (!fp) { // fp is NULL, fopen failed
|
||||||
string=NULL;
|
fprintf(stderr, "Failed to open file\n");
|
||||||
return;
|
string = NULL;
|
||||||
}
|
return;
|
||||||
int i=0;
|
}
|
||||||
int c;
|
int i = 0;
|
||||||
while ((c = fgetc(fp)) != EOF){
|
int c;
|
||||||
string[i++] = c;
|
while ((c = fgetc(fp)) != EOF) {
|
||||||
}
|
string[i++] = c;
|
||||||
string[i]='\0';
|
}
|
||||||
fclose(fp);
|
string[i] = '\0';
|
||||||
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1,22 +1,23 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#define STYLE_N 1393 + 1
|
#define STYLE_N 1393 + 1
|
||||||
|
|
||||||
void read_style_js(char* string){
|
void read_style_js(char* string)
|
||||||
FILE *fp=fopen("/home/loki/Documents/core/software/fresh/C/rose-browser/rosenrot/plugins/style/style.js", "r");
|
{
|
||||||
if (!fp) { // fp is NULL, fopen failed
|
FILE* fp = fopen("/home/loki/Documents/core/software/fresh/C/rose-browser/rosenrot/plugins/style/style.js", "r");
|
||||||
fprintf(stderr, "Failed to open file\n");
|
if (!fp) { // fp is NULL, fopen failed
|
||||||
string=NULL;
|
fprintf(stderr, "Failed to open file\n");
|
||||||
return;
|
string = NULL;
|
||||||
}
|
return;
|
||||||
int i=0;
|
}
|
||||||
int c;
|
int i = 0;
|
||||||
while ((c = fgetc(fp)) != EOF){
|
int c;
|
||||||
string[i++] = c;
|
while ((c = fgetc(fp)) != EOF) {
|
||||||
}
|
string[i++] = c;
|
||||||
string[i]='\0';
|
}
|
||||||
fclose(fp);
|
string[i] = '\0';
|
||||||
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user