summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Bolte <sbolte@lavabit.com>2013-05-18 01:53:46 +0200
committerStefan Bolte <sbolte@lavabit.com>2013-05-18 01:53:46 +0200
commit8ae273486fddbb251a69ec6feff597fa87a9ba7e (patch)
treef48889f454512dc521cf571c3ae33c7e703f919e
parent1bb16eec7a73e891d58da9409d6a5d45c24b7625 (diff)
downloaddwb-8ae273486fddbb251a69ec6feff597fa87a9ba7e.zip
Read archive files in /userscripts
-rw-r--r--exar/exar.c4
-rw-r--r--exar/exar.h3
-rw-r--r--src/dwb.c21
-rw-r--r--src/scripts.c19
-rw-r--r--src/scripts.h1
5 files changed, 36 insertions, 12 deletions
diff --git a/exar/exar.c b/exar/exar.c
index 16735e60..b96d8f42 100644
--- a/exar/exar.c
+++ b/exar/exar.c
@@ -582,12 +582,12 @@ finish:
}
int
-exar_check_version(const char *archive)
+exar_check_version(const char *archive, int verbose)
{
assert(archive != NULL);
int vers_check;
- FILE *f = open_archive(archive, "r", &vers_check, 1);
+ FILE *f = open_archive(archive, "r", &vers_check, verbose);
close_file(f, archive);
return vers_check;
}
diff --git a/exar/exar.h b/exar/exar.h
index 4817e65c..52b9655e 100644
--- a/exar/exar.h
+++ b/exar/exar.h
@@ -116,11 +116,12 @@ exar_delete(const char *archive, const char *file);
* Checks if the file is an archive file with compatible version number
*
* @archive The archive
+ * @verbose Whether to print error messages to stderr
*
* @returns 0 on success and -1 on error
*/
int
-exar_check_version(const char *archive);
+exar_check_version(const char *archive, int verbose);
/*
* Print info about the archive to stdout.
diff --git a/src/dwb.c b/src/dwb.c
index 62a8998e..6ae0327a 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -28,6 +28,8 @@
#ifdef HAS_EXECINFO
#include <execinfo.h>
#endif
+
+#include <exar.h>
#include "dwb.h"
#include "soup.h"
#include "completion.h"
@@ -3407,7 +3409,7 @@ dwb_get_scripts()
GList *gl = NULL;
Navigation *n;
GError *error = NULL;
- FILE *f;
+ FILE *f = NULL;
int l1, l2;
if ( (dir = g_dir_open(dwb.files[FILES_USERSCRIPTS], 0, NULL)) )
@@ -3437,18 +3439,27 @@ dwb_get_scripts()
path = realpath;
}
}
- if (dwb.misc.js_api != JS_API_DISABLED && (f = fopen(path, "r")) != NULL && (l1 = fgetc(f)) && (l2 = fgetc(f)) )
+ if (dwb.misc.js_api != JS_API_DISABLED)
{
- if ( (l1 == '#' && l2 == '!') || (l1 == '/' && l2 == '/' && fgetc(f) == '!') )
+ if (exar_check_version(path, 0) == 0)
+ {
+ content = (char *) exar_search_extract(path, "main.js", NULL);
+ if (content != NULL)
+ scripts_init_archive(path, content);
+ goto loop_end;
+ }
+ else if ( (f = fopen(path, "r")) != NULL)
{
- if (fgets(buf, sizeof(buf), f) != NULL && !g_strcmp0(buf, "javascript"))
+ if ( ( (l1 = fgetc(f)) && (l2 = fgetc(f)) ) &&
+ ( (l1 == '#' && l2 == '!') || (l1 == '/' && l2 == '/' && fgetc(f) == '!') ) &&
+ (fgets(buf, sizeof(buf), f) != NULL && !g_strcmp0(buf, "javascript")) )
{
int next = fgetc(f);
if (g_ascii_isspace(next))
javascript = true;
}
+ fclose(f);
}
- fclose(f);
}
diff --git a/src/scripts.c b/src/scripts.c
index a9660033..860079ce 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -5533,9 +5533,8 @@ scripts_remove_tab(JSObjectRef obj)
CONTEXT_UNLOCK;
}/*}}}*/
-/* scripts_init_script {{{*/
-void
-scripts_init_script(const char *path, const char *script)
+void
+init_script(const char *path, const char *script, const char *templates)
{
char *debug = NULL;
if (s_global_context == NULL)
@@ -5549,11 +5548,23 @@ scripts_init_script(const char *path, const char *script)
if (function != NULL)
s_script_list = g_slist_prepend(s_script_list, function);
}
-
g_free(debug);
+}
+
+/* scripts_init_script {{{*/
+void
+scripts_init_script(const char *path, const char *script)
+{
+ init_script(path, script, SCRIPT_TEMPLATE);
}/*}}}*/
void
+scripts_init_archive(const char *path, const char *script)
+{
+ init_script(path, script, SCRIPT_TEMPLATE_XINCLUDE);
+}
+
+void
evaluate(const char *script)
{
if (!TRY_CONTEXT_LOCK)
diff --git a/src/scripts.h b/src/scripts.h
index f4eccc0a..8ad87f94 100644
--- a/src/scripts.h
+++ b/src/scripts.h
@@ -68,6 +68,7 @@ void scripts_create_tab(GList *gl);
void scripts_remove_tab(JSObjectRef );
void scripts_end(void);
void scripts_init_script(const char *, const char *);
+void scripts_init_archive(const char *, const char *);
gboolean scripts_init(gboolean);
void scripts_reinit();
void scripts_unbind(JSObjectRef);