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.
+-------+--------------------+------------------------------------------------+
| Short | Long option | Function |
+=======+====================+================================================+
+| -r | --run | Run the specified filename as javascript |
++-------+--------------------+------------------------------------------------+
| -v | --version | Show version information and exit. |
+-------+--------------------+------------------------------------------------+
main (int argc,
char** argv)
{
+ gboolean run;
gboolean version;
gchar** uris;
MidoriApp* app;
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,
#endif
/* Parse cli options */
+ run = FALSE;
version = FALSE;
uris = NULL;
error = NULL;
}
/* 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 ();