tweak: conciseness tweaks.
This commit is contained in:
parent
304b4b274c
commit
76ab73e38c
Binary file not shown.
|
@ -4,20 +4,16 @@
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
char uri[] = "https://reddit.com/r/blah";
|
char uri[] = "https://reddit.com/r/blah";
|
||||||
|
|
||||||
int uri_length = strlen(uri);
|
int l = LIBRE_N + strlen(uri) + 1;
|
||||||
int l = LIBRE_N+uri_length;
|
char uri_filtered[l];
|
||||||
char uri_filtered[l++];
|
str_init(uri_filtered, l);
|
||||||
for(int i=0; i<l; i++){
|
|
||||||
uri_filtered[i] = ' ';
|
|
||||||
}
|
|
||||||
uri_filtered[l] = '\0';
|
|
||||||
|
|
||||||
int libre_check = libre_redirect(uri, uri_filtered);
|
int libre_check = libre_redirect(uri, uri_filtered);
|
||||||
if(!libre_check){
|
if(!libre_check){
|
||||||
printf("Filtered url: %s", uri_filtered);
|
printf("Filtered url: %s\n", uri_filtered);
|
||||||
}else{
|
}else{
|
||||||
printf("Uri: %s", uri);
|
printf("Uri: %s\n", uri);
|
||||||
// failure; do something with the original uri.
|
// failure; do something with the original uri.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,13 @@
|
||||||
|
|
||||||
// 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){
|
||||||
|
|
||||||
|
void str_init(char* str, int n){
|
||||||
|
for(int i=0; i<n; i++){
|
||||||
|
str[i] = ' ';
|
||||||
|
}
|
||||||
|
str[n] = '\0';
|
||||||
|
} // 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){
|
||||||
/* inv.riverside.rocks */
|
/* inv.riverside.rocks */
|
||||||
// max length
|
// max length
|
||||||
|
@ -16,7 +23,7 @@ int libre_redirect(const char* uri, char* output){
|
||||||
return 1; // not enough memory.
|
return 1; // not enough memory.
|
||||||
}else{
|
}else{
|
||||||
char tmp_uri[l2++];
|
char tmp_uri[l2++];
|
||||||
strcpy(tmp_uri, uri);
|
strcpy(tmp_uri, uri); // includes terminating '\0'
|
||||||
|
|
||||||
char* sites[] = {
|
char* sites[] = {
|
||||||
"https://youtube.com",
|
"https://youtube.com",
|
||||||
|
@ -39,7 +46,6 @@ int libre_redirect(const char* uri, char* output){
|
||||||
strcpy(tmp_uri, output);
|
strcpy(tmp_uri, output);
|
||||||
}
|
}
|
||||||
strcpy(output, tmp_uri);
|
strcpy(output, tmp_uri);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -4,5 +4,6 @@
|
||||||
#define LIBRE_N 12
|
#define LIBRE_N 12
|
||||||
|
|
||||||
int libre_redirect(const char* uri, char* uri_filtered);
|
int libre_redirect(const char* uri, char* uri_filtered);
|
||||||
|
void str_init(char* str, int n);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user