1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-30 03:26:23 -04:00

[console.log] Global variable to store console_log_filename

This commit is contained in:
Witold Filipczyk 2021-02-22 15:55:12 +01:00
parent 4db2b42799
commit bc7a1ae6ad
3 changed files with 12 additions and 8 deletions

View File

@ -71,6 +71,8 @@ static int interpreter_count;
static INIT_LIST_OF(struct string_list_item, allowed_urls); static INIT_LIST_OF(struct string_list_item, allowed_urls);
char *console_log_filename;
static int static int
is_prefix(char *prefix, char *url, int dl) is_prefix(char *prefix, char *url, int dl)
{ {
@ -449,12 +451,17 @@ static void
init_ecmascript_module(struct module *module) init_ecmascript_module(struct module *module)
{ {
read_url_list(); read_url_list();
if (elinks_home) {
console_log_filename = straconcat(elinks_home, "/console.log", NULL);
}
} }
static void static void
done_ecmascript_module(struct module *module) done_ecmascript_module(struct module *module)
{ {
free_string_list(&allowed_urls); free_string_list(&allowed_urls);
mem_free_if(console_log_filename);
} }
static struct module *ecmascript_modules[] = { static struct module *ecmascript_modules[] = {
@ -464,8 +471,6 @@ static struct module *ecmascript_modules[] = {
NULL, NULL,
}; };
struct module ecmascript_module = struct_module( struct module ecmascript_module = struct_module(
/* name: */ N_("ECMAScript"), /* name: */ N_("ECMAScript"),
/* options: */ ecmascript_options, /* options: */ ecmascript_options,

View File

@ -109,6 +109,7 @@ void ecmascript_set_timeout2(struct ecmascript_interpreter *interpreter, JS::Han
int get_ecmascript_enable(struct ecmascript_interpreter *interpreter); int get_ecmascript_enable(struct ecmascript_interpreter *interpreter);
extern char *console_log_filename;
extern struct module ecmascript_module; extern struct module ecmascript_module;
#endif #endif

View File

@ -78,7 +78,7 @@ console_log(JSContext *ctx, unsigned int argc, JS::Value *vp)
struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx); struct ecmascript_interpreter *interpreter = JS_GetContextPrivate(ctx);
JS::CallArgs args = CallArgsFromVp(argc, vp); JS::CallArgs args = CallArgsFromVp(argc, vp);
if (argc != 1) if (argc != 1 || !console_log_filename)
{ {
args.rval().setBoolean(false); args.rval().setBoolean(false);
return(true); return(true);
@ -86,10 +86,8 @@ console_log(JSContext *ctx, unsigned int argc, JS::Value *vp)
unsigned char *key = JS_EncodeString(ctx, args[0].toString()); unsigned char *key = JS_EncodeString(ctx, args[0].toString());
char *log_fname = stracpy(elinks_home); FILE *f = fopen(console_log_filename, "a");
add_to_strn(&log_fname,"console.log");
FILE *f = fopen(log_fname,"a");
if (f) if (f)
{ {
fprintf(f, "%s\n", key); fprintf(f, "%s\n", key);