From 0c0a5f266c7f341c0aa8cbc51d109f7dd9a2f012 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 27 Apr 2012 12:44:05 +0200 Subject: [PATCH] Open multiple arguments It is now possible to open multiple files by passing them as additional arguments. The password can now be set with the -w/--password parameter instead of the argument after the filename. --- zathura.1.rst | 4 +++- zathura.c | 30 +++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/zathura.1.rst b/zathura.1.rst index e558480..d729a00 100644 --- a/zathura.1.rst +++ b/zathura.1.rst @@ -14,7 +14,6 @@ SYNOPOSIS ========= | zathura [OPTION]... | zathura [OPTION]... FILE -| zathura [OPTION]... FILE PASSWORD DESCRIPTION =========== @@ -37,6 +36,9 @@ OPTIONS -p [path], --plugins-dir [path] Path to the directory containing plugins +-w [password], --password [password] + The documents password + --fork Fork into the background diff --git a/zathura.c b/zathura.c index 5678d5b..bc3001e 100644 --- a/zathura.c +++ b/zathura.c @@ -66,20 +66,21 @@ zathura_init(int argc, char* argv[]) Window embed = 0; #endif - gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL, *loglevel = NULL; + gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL, *loglevel = NULL, *password = NULL; bool forkback = false; GOptionEntry entries[] = { - { "reparent", 'e', 0, G_OPTION_ARG_INT, &embed, _("Reparents to window specified by xid"), "xid" }, - { "config-dir", 'c', 0, G_OPTION_ARG_FILENAME, &config_dir, _("Path to the config directory"), "path" }, - { "data-dir", 'd', 0, G_OPTION_ARG_FILENAME, &data_dir, _("Path to the data directory"), "path" }, - { "plugins-dir", 'p', 0, G_OPTION_ARG_STRING, &plugin_path, _("Path to the directories containing plugins"), "path" }, - { "fork", '\0', 0, G_OPTION_ARG_NONE, &forkback, _("Fork into the background"), NULL }, - { "debug", 'l', 0, G_OPTION_ARG_STRING, &loglevel, _("Log level (debug, info, warning, error)"), "level" }, + { "reparent", 'e', 0, G_OPTION_ARG_INT, &embed, _("Reparents to window specified by xid"), "xid" }, + { "config-dir", 'c', 0, G_OPTION_ARG_FILENAME, &config_dir, _("Path to the config directory"), "path" }, + { "data-dir", 'd', 0, G_OPTION_ARG_FILENAME, &data_dir, _("Path to the data directory"), "path" }, + { "plugins-dir", 'p', 0, G_OPTION_ARG_STRING, &plugin_path, _("Path to the directories containing plugins"), "path" }, + { "fork", '\0', 0, G_OPTION_ARG_NONE, &forkback, _("Fork into the background"), NULL }, + { "password", 'w', 0, G_OPTION_ARG_STRING, &password, _("Document password"), "password" }, + { "debug", 'l', 0, G_OPTION_ARG_STRING, &loglevel, _("Log level (debug, info, warning, error)"), "level" }, { NULL, '\0', 0, 0, NULL, NULL, NULL } }; - GOptionContext* context = g_option_context_new(" [file] [password]"); + GOptionContext* context = g_option_context_new(" [file1] [file2] [...]"); g_option_context_add_main_entries(context, entries, NULL); GError* error = NULL; @@ -291,8 +292,19 @@ zathura_init(int argc, char* argv[]) document_info->zathura = zathura; document_info->path = argv[1]; - document_info->password = (argc >= 2) ? argv[2] : NULL; + document_info->password = password; gdk_threads_add_idle(document_info_open, document_info); + + /* open additional files */ + for (int i = 2; i < argc; i++) { + char* new_argv[] = { + *(zathura->global.arguments), + argv[i], + NULL + }; + + g_spawn_async(NULL, new_argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL); + } } /* add even to purge old pages */