Compare commits
5 Commits
8707adb983
...
c8ff246cc2
Author | SHA1 | Date | |
---|---|---|---|
c8ff246cc2 | |||
43cac7f3f1 | |||
8f4b4b9abf | |||
f2e06785f9 | |||
b4c3e3a0e3 |
2
TODO.md
2
TODO.md
|
@ -1,5 +1,7 @@
|
||||||
# To do
|
# To do
|
||||||
|
|
||||||
|
- [ ] Settle on a C standard (C11?), and use safer string handling functions provided by it.
|
||||||
|
- See make lint for purported insecurities
|
||||||
- [ ] Document creating new applications, e.g., as in [Asana for Linux](https://git.nunosempere.com/NunoSempere/asana-for-linux)
|
- [ ] Document creating new applications, e.g., as in [Asana for Linux](https://git.nunosempere.com/NunoSempere/asana-for-linux)
|
||||||
- [ ] This time, use something other than Whatsapp as an example syslink.
|
- [ ] This time, use something other than Whatsapp as an example syslink.
|
||||||
- [ ] Fix bug about distorted audio. Maybe related to [this pipewire issue](<https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1547>)?
|
- [ ] Fix bug about distorted audio. Maybe related to [this pipewire issue](<https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/1547>)?
|
||||||
|
|
|
@ -7,28 +7,17 @@
|
||||||
|
|
||||||
#define LIBRE_N 50
|
#define LIBRE_N 50
|
||||||
|
|
||||||
/* Uncomment for debug */
|
|
||||||
/* #define DEBUG */
|
|
||||||
|
|
||||||
/* Inspired by https://libredirect.github.io/, but in C. */
|
/* Inspired by https://libredirect.github.io/, but in C. */
|
||||||
|
|
||||||
int libre_redirect(const char* uri, char* output)
|
int libre_redirect(const char* uri, char* output)
|
||||||
{
|
{
|
||||||
int l1 = strlen(uri);
|
int len_uri = strlen(uri);
|
||||||
int l2 = strlen(output);
|
int len_output = strlen(output);
|
||||||
int len;
|
|
||||||
char tmp_uri[l2++];
|
|
||||||
char tmp_output[l2++];
|
|
||||||
|
|
||||||
if ((l2 - l1) < LIBRE_N) {
|
if ((len_output - len_uri) < LIBRE_N) {
|
||||||
#ifdef DEBUG
|
|
||||||
printf("Not enough memory\n");
|
printf("Not enough memory\n");
|
||||||
#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_output, output);
|
|
||||||
|
|
||||||
char* annoying_sites[] = {
|
char* annoying_sites[] = {
|
||||||
"https://www.reddit.com",
|
"https://www.reddit.com",
|
||||||
"https://www.youtube.com",
|
"https://www.youtube.com",
|
||||||
|
@ -55,30 +44,26 @@ int libre_redirect(const char* uri, char* output)
|
||||||
// "https://nitter.net"
|
// "https://nitter.net"
|
||||||
};
|
};
|
||||||
|
|
||||||
len = sizeof(annoying_sites) / sizeof(annoying_sites[0]);
|
int 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],
|
str_init(output, len_output);
|
||||||
|
int replace_check = str_replace_start(uri, annoying_sites[i],
|
||||||
alternatives[i], output);
|
alternatives[i], output);
|
||||||
if (replace_check == 2) {
|
switch(replace_check){
|
||||||
#ifdef DEBUG
|
case 0: // no match found
|
||||||
printf("tmp_uri: %s\n", tmp_uri);
|
break;
|
||||||
printf("output: %s\n", output);
|
case 1: // str_replace_start somehow failed
|
||||||
#endif
|
printf("str_replace_start failed\n");
|
||||||
return 2;
|
|
||||||
} else if (replace_check == 1) {
|
|
||||||
#ifdef DEBUG
|
|
||||||
printf("replace_check failed\n");
|
|
||||||
#endif
|
|
||||||
return 1;
|
return 1;
|
||||||
|
break;
|
||||||
|
case 2: // match succeeded
|
||||||
|
return 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("Unreachable state");
|
||||||
}
|
}
|
||||||
strcpy(tmp_uri, output);
|
|
||||||
str_init(output, l2);
|
|
||||||
}
|
}
|
||||||
strcpy(output, tmp_uri);
|
strcpy(output, uri);
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
|
||||||
printf("No match found\n\n");
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,21 +31,23 @@ int shortcut_expand(const char* uri, char* output)
|
||||||
strcpy(tmp_output, output);
|
strcpy(tmp_output, output);
|
||||||
|
|
||||||
char* shortcuts[] = {
|
char* shortcuts[] = {
|
||||||
"!x",
|
"!aa",
|
||||||
"!blog",
|
"!blog",
|
||||||
"!fnf",
|
"!fnf",
|
||||||
"!fnc",
|
"!fnc",
|
||||||
"!hn",
|
"!hn",
|
||||||
"!hnb"
|
"!hnb"
|
||||||
|
"!x",
|
||||||
};
|
};
|
||||||
|
|
||||||
char* expansions[] = {
|
char* expansions[] = {
|
||||||
"https://twitter.com",
|
"https://annas-archive.org",
|
||||||
"https://nunosempere.com/blog",
|
"https://nunosempere.com/blog",
|
||||||
"https://forum.nunosempere.com/frontpage",
|
"https://forum.nunosempere.com/frontpage",
|
||||||
"https://forum.nunosempere.com/comments",
|
"https://forum.nunosempere.com/comments",
|
||||||
"https://news.ycombinator.com",
|
"https://news.ycombinator.com",
|
||||||
"https://news.ycombinator.com/best",
|
"https://news.ycombinator.com/best",
|
||||||
|
"https://twitter.com",
|
||||||
};
|
};
|
||||||
|
|
||||||
// len = sizeof(shortcuts) / sizeof(shortcuts[0]);
|
// len = sizeof(shortcuts) / sizeof(shortcuts[0]);
|
||||||
|
|
11
rosenrot.c
11
rosenrot.c
|
@ -37,6 +37,11 @@ void load_uri(WebKitWebView* view, const char* uri)
|
||||||
toggle_bar(notebook);
|
toggle_bar(notebook);
|
||||||
} else if (g_str_has_prefix(uri, "http://") || g_str_has_prefix(uri, "https://") || g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) {
|
} else if (g_str_has_prefix(uri, "http://") || g_str_has_prefix(uri, "https://") || g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) {
|
||||||
webkit_web_view_load_uri(view, uri);
|
webkit_web_view_load_uri(view, uri);
|
||||||
|
} else if (strstr(uri, ".com") || strstr(uri, ".org")) {
|
||||||
|
char tmp[strlen("https://") + strlen(uri)];
|
||||||
|
snprintf(tmp, sizeof(tmp), "https://%s", uri);
|
||||||
|
webkit_web_view_load_uri(view, tmp);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Check for shortcuts
|
// Check for shortcuts
|
||||||
int l = SHORTCUT_N + strlen(uri) + 1;
|
int l = SHORTCUT_N + strlen(uri) + 1;
|
||||||
|
@ -212,14 +217,15 @@ void notebook_create_new_tab(GtkNotebook* notebook, const char* uri)
|
||||||
void toggle_bar(GtkNotebook* notebook)
|
void toggle_bar(GtkNotebook* notebook)
|
||||||
{
|
{
|
||||||
switch (bar.entry_mode) {
|
switch (bar.entry_mode) {
|
||||||
case _SEARCH:
|
case _SEARCH: {
|
||||||
const char* url = webkit_web_view_get_uri(notebook_get_webview(notebook));
|
const char* url = webkit_web_view_get_uri(notebook_get_webview(notebook));
|
||||||
gtk_entry_set_placeholder_text(bar.line, "Search");
|
gtk_entry_set_placeholder_text(bar.line, "Search");
|
||||||
gtk_entry_buffer_set_text(bar.line_text, url, strlen(url));
|
gtk_entry_buffer_set_text(bar.line_text, url, strlen(url));
|
||||||
gtk_widget_show(GTK_WIDGET(bar.widget));
|
gtk_widget_show(GTK_WIDGET(bar.widget));
|
||||||
gtk_window_set_focus(window, GTK_WIDGET(bar.line));
|
gtk_window_set_focus(window, GTK_WIDGET(bar.line));
|
||||||
break;
|
break;
|
||||||
case _FIND:
|
}
|
||||||
|
case _FIND: {
|
||||||
const char* search_text = webkit_find_controller_get_search_text(
|
const char* search_text = webkit_find_controller_get_search_text(
|
||||||
webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
|
webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
|
||||||
|
|
||||||
|
@ -230,6 +236,7 @@ void toggle_bar(GtkNotebook* notebook)
|
||||||
gtk_widget_show(GTK_WIDGET(bar.widget));
|
gtk_widget_show(GTK_WIDGET(bar.widget));
|
||||||
gtk_window_set_focus(window, GTK_WIDGET(bar.line));
|
gtk_window_set_focus(window, GTK_WIDGET(bar.line));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
// fallthrough
|
// fallthrough
|
||||||
case _HIDDEN:
|
case _HIDDEN:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user