From: Christian Dywan Date: Thu, 16 Oct 2008 18:54:26 +0000 (+0200) Subject: Speficy -r or --run to run a file as javascript X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6cd7e61c6152babcab22cf495ddedb592f6012bd;p=midori Speficy -r or --run to run a file as javascript --- diff --git a/docs/user/midori.txt b/docs/user/midori.txt index 3e38ddfc..26e41383 100644 --- a/docs/user/midori.txt +++ b/docs/user/midori.txt @@ -111,9 +111,9 @@ Running Midori normally works as follows: You can separate URIS by a pipe (|) as well. They are handled as if you provided all URIs as separate arguments. -* $ midori [JAVASCRIPT] +* $ midori --run [JAVASCRIPT] - If you pass a filename ending with ".js" Midori will attempt to run + If you pass the filename of a javascript Midori will attempt to run the contents of the file as javascript code. @@ -127,6 +127,8 @@ The following arguments are supported if you call Midori from a command line. +-------+--------------------+------------------------------------------------+ | Short | Long option | Function | +=======+====================+================================================+ +| -r | --run | Run the specified filename as javascript | ++-------+--------------------+------------------------------------------------+ | -v | --version | Show version information and exit. | +-------+--------------------+------------------------------------------------+ diff --git a/midori/main.c b/midori/main.c index 1c6e5410..20d3d748 100644 --- a/midori/main.c +++ b/midori/main.c @@ -1049,6 +1049,7 @@ int main (int argc, char** argv) { + gboolean run; gboolean version; gchar** uris; MidoriApp* app; @@ -1056,6 +1057,8 @@ main (int argc, GError* error; GOptionEntry entries[] = { + { "run", 'r', 0, G_OPTION_ARG_NONE, &run, + N_("Run the specified filename as javascript"), NULL }, { "version", 'v', 0, G_OPTION_ARG_NONE, &version, N_("Display program version"), NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &uris, @@ -1089,6 +1092,7 @@ main (int argc, #endif /* Parse cli options */ + run = FALSE; version = FALSE; uris = NULL; error = NULL; @@ -1121,16 +1125,24 @@ main (int argc, } /* Standalone gjs support */ - if (uris && uris[0] && g_str_has_suffix (uris[0], ".js")) + if (run) { - js_context = gjs_global_context_new (); - exception = NULL; - gjs_script_from_file (js_context, uris[0], &exception); - JSGlobalContextRelease (js_context); - if (!exception) - return 0; - printf ("%s - Exception: %s\n", uris[0], exception); - return 1; + if (uris && *uris) + { + js_context = gjs_global_context_new (); + exception = NULL; + gjs_script_from_file (js_context, *uris, &exception); + JSGlobalContextRelease (js_context); + if (!exception) + return 0; + g_print ("%s - Exception: %s\n", *uris, exception); + return 1; + } + else + { + g_print ("%s - %s\n", _("Midori"), _("No filename specified")); + return 1; + } } app = midori_app_new ();