Commit 66b6fa65 authored by Moritz Lipp's avatar Moritz Lipp

Add --version command line argument

parent 97000769
...@@ -527,35 +527,15 @@ cmd_version(girara_session_t* session, girara_list_t* UNUSED(argument_list)) ...@@ -527,35 +527,15 @@ cmd_version(girara_session_t* session, girara_list_t* UNUSED(argument_list))
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
zathura_t* zathura = session->global.data; zathura_t* zathura = session->global.data;
GString* string = g_string_new(NULL); char* string = zathura_get_version_string(zathura, true);
if (string == NULL) {
/* zathura version */ return false;
char* zathura_version = g_strdup_printf("zathura %d.%d.%d", ZATHURA_VERSION_MAJOR, ZATHURA_VERSION_MINOR, ZATHURA_VERSION_REV); }
g_string_append(string, zathura_version);
g_free(zathura_version);
/* plugin information */
girara_list_t* plugins = zathura_plugin_manager_get_plugins(zathura->plugins.manager);
if (plugins != NULL) {
GIRARA_LIST_FOREACH(plugins, zathura_plugin_t*, iter, plugin)
char* name = zathura_plugin_get_name(plugin);
zathura_plugin_version_t version = zathura_plugin_get_version(plugin);
char* text = g_strdup_printf("\n<i>(plugin)</i> %s (%d.%d.%d) <i>(%s)</i>",
(name == NULL) ? "-" : name,
version.major,
version.minor,
version.rev,
zathura_plugin_get_path(plugin)
);
g_string_append(string, text);
g_free(text);
GIRARA_LIST_FOREACH_END(plugins, zathura_plugin_t*, iter, plugin);
}
/* display information */ /* display information */
girara_notify(session, GIRARA_INFO, "%s", string->str); girara_notify(session, GIRARA_INFO, "%s", string);
g_string_free(string, TRUE); g_free(string);
return true; return true;
} }
...@@ -21,7 +21,6 @@ int main(int argc, char* argv[]) ...@@ -21,7 +21,6 @@ int main(int argc, char* argv[])
zathura_t* zathura = zathura_init(argc, argv); zathura_t* zathura = zathura_init(argc, argv);
if (zathura == NULL) { if (zathura == NULL) {
fprintf(stderr, "error: could not initialize zathura\n");
return -1; return -1;
} }
......
...@@ -353,3 +353,43 @@ document_draw_search_results(zathura_t* zathura, bool value) ...@@ -353,3 +353,43 @@ document_draw_search_results(zathura_t* zathura, bool value)
g_object_set(zathura->pages[page_id], "draw-search-results", (value == true) ? TRUE : FALSE, NULL); g_object_set(zathura->pages[page_id], "draw-search-results", (value == true) ? TRUE : FALSE, NULL);
} }
} }
char*
zathura_get_version_string(zathura_t* zathura, bool markup)
{
if (zathura == NULL) {
return NULL;
}
GString* string = g_string_new(NULL);
/* zathura version */
char* zathura_version = g_strdup_printf("zathura %d.%d.%d", ZATHURA_VERSION_MAJOR, ZATHURA_VERSION_MINOR, ZATHURA_VERSION_REV);
g_string_append(string, zathura_version);
g_free(zathura_version);
char* format = (markup == true) ? "\n<i>(plugin)</i> %s (%d.%d.%d) <i>(%s)</i>" : "\n(plugin) %s (%d.%d.%d) (%s)";
/* plugin information */
girara_list_t* plugins = zathura_plugin_manager_get_plugins(zathura->plugins.manager);
if (plugins != NULL) {
GIRARA_LIST_FOREACH(plugins, zathura_plugin_t*, iter, plugin)
char* name = zathura_plugin_get_name(plugin);
zathura_plugin_version_t version = zathura_plugin_get_version(plugin);
char* text = g_strdup_printf(format,
(name == NULL) ? "-" : name,
version.major,
version.minor,
version.rev,
zathura_plugin_get_path(plugin)
);
g_string_append(string, text);
g_free(text);
GIRARA_LIST_FOREACH_END(plugins, zathura_plugin_t*, iter, plugin);
}
char* version = string->str;
g_string_free(string, FALSE);
return version;
}
...@@ -131,4 +131,13 @@ void readjust_view_after_zooming(zathura_t* zathura, float old_zoom, bool delay) ...@@ -131,4 +131,13 @@ void readjust_view_after_zooming(zathura_t* zathura, float old_zoom, bool delay)
*/ */
void document_draw_search_results(zathura_t* zathura, bool value); void document_draw_search_results(zathura_t* zathura, bool value);
/**
* Create zathura version string
*
* @param zathura The zathura instance
* @param markup Enable markup
* @return Version string
*/
char* zathura_get_version_string(zathura_t* zathura, bool markup);
#endif // UTILS_H #endif // UTILS_H
...@@ -67,16 +67,17 @@ zathura_init(int argc, char* argv[]) ...@@ -67,16 +67,17 @@ zathura_init(int argc, char* argv[])
#endif #endif
gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL, *loglevel = NULL, *password = NULL; gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL, *loglevel = NULL, *password = NULL;
bool forkback = false; bool forkback = false, print_version = false;
GOptionEntry entries[] = GOptionEntry entries[] =
{ {
{ "reparent", 'e', 0, G_OPTION_ARG_INT, &embed, _("Reparents to window specified by xid"), "xid" }, { "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" }, { "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" }, { "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" }, { "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 }, { "fork", '\0', 0, G_OPTION_ARG_NONE, &forkback, _("Fork into the background"), NULL },
{ "password", 'w', 0, G_OPTION_ARG_STRING, &password, _("Document password"), "password" }, { "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" }, { "debug", 'l', 0, G_OPTION_ARG_STRING, &loglevel, _("Log level (debug, info, warning, error)"), "level" },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &print_version, _("Print version information"), NULL },
{ NULL, '\0', 0, 0, NULL, NULL, NULL } { NULL, '\0', 0, 0, NULL, NULL, NULL }
}; };
...@@ -117,6 +118,11 @@ zathura_init(int argc, char* argv[]) ...@@ -117,6 +118,11 @@ zathura_init(int argc, char* argv[])
zathura_t* zathura = g_malloc0(sizeof(zathura_t)); zathura_t* zathura = g_malloc0(sizeof(zathura_t));
/* global settings */
zathura->global.recolor = false;
zathura->global.update_page_number = true;
zathura->global.arguments = argv;
/* plugins */ /* plugins */
zathura->plugins.manager = zathura_plugin_manager_new(); zathura->plugins.manager = zathura_plugin_manager_new();
if (zathura->plugins.manager == NULL) { if (zathura->plugins.manager == NULL) {
...@@ -160,6 +166,19 @@ zathura_init(int argc, char* argv[]) ...@@ -160,6 +166,19 @@ zathura_init(int argc, char* argv[])
#endif #endif
} }
/* load plugins */
zathura_plugin_manager_load(zathura->plugins.manager);
/* Print version */
if (print_version == true) {
char* string = zathura_get_version_string(zathura, false);
if (string != NULL) {
fprintf(stdout, "%s\n", string);
}
goto error_free; // FIXME
}
/* UI */ /* UI */
if ((zathura->ui.session = girara_session_create()) == NULL) { if ((zathura->ui.session = girara_session_create()) == NULL) {
goto error_out; goto error_out;
...@@ -167,14 +186,6 @@ zathura_init(int argc, char* argv[]) ...@@ -167,14 +186,6 @@ zathura_init(int argc, char* argv[])
zathura->ui.session->global.data = zathura; zathura->ui.session->global.data = zathura;
/* global settings */
zathura->global.recolor = false;
zathura->global.update_page_number = true;
zathura->global.arguments = argv;
/* load plugins */
zathura_plugin_manager_load(zathura->plugins.manager);
/* configuration */ /* configuration */
config_load_default(zathura); config_load_default(zathura);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment