allow setting surf adblock file using env - surf-adblock - Surf adblock web ext… | |
git clone git://git.codemadness.org/surf-adblock | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit f34202b8786c190d5935210e0289123943239730 | |
parent 3217c9e3ead5b5cf40df1e624e8475d93574ae1e | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Sat, 16 Jul 2016 12:19:28 +0200 | |
allow setting surf adblock file using env | |
Diffstat: | |
M surf-adblock.c | 19 ++++++++++++------- | |
1 file changed, 12 insertions(+), 7 deletions(-) | |
--- | |
diff --git a/surf-adblock.c b/surf-adblock.c | |
@@ -784,23 +784,28 @@ webpagecreated(WebKitWebExtension *e, WebKitWebPage *p, g… | |
} | |
G_MODULE_EXPORT void | |
-webkit_web_extension_initialize(WebKitWebExtension *e) | |
+webkit_web_extension_initialize(WebKitWebExtension *ext) | |
{ | |
struct filterrule *r; | |
FILE *fp; | |
- char filepath[PATH_MAX], *home; | |
+ char filepath[PATH_MAX], *e; | |
int n; | |
- home = getenv("HOME"); | |
- n = snprintf(filepath, sizeof(filepath), "%s%s.surf/adblockrules", | |
- home ? home : "", home ? "/" : ""); | |
+ if ((e = getenv("SURF_ADBLOCK_FILE"))) { | |
+ n = snprintf(filepath, sizeof(filepath), "%s", e); | |
+ } else { | |
+ if (!(e = getenv("HOME"))) | |
+ e = ""; | |
+ n = snprintf(filepath, sizeof(filepath), "%s%s.surf/adblockrul… | |
+ e, e[0] && e[strlen(e) - 1] != '/' ? "/" : ""); | |
+ } | |
if (n < 0 || (size_t)n >= sizeof(filepath)) { | |
fprintf(stderr, "fatal: path too long, truncated\n"); | |
return; | |
} | |
if (!(fp = fopen(filepath, "r"))) { | |
- fprintf(stderr, "fatal: cannot read rules file: %s: %s\n", | |
+ fprintf(stderr, "fatal: cannot read rules from file: %s: %s\n", | |
filepath, strerror(errno)); | |
return; | |
} | |
@@ -820,6 +825,6 @@ webkit_web_extension_initialize(WebKitWebExtension *e) | |
string_append(&globalcss, STRP("{display:none;}")); | |
} | |
- g_signal_connect(e, "page-created", | |
+ g_signal_connect(ext, "page-created", | |
G_CALLBACK(webpagecreated), NULL); | |
} |