Add --version command line argument

This commit is contained in:
Moritz Lipp 2012-07-12 10:37:58 +02:00
parent 97000769e4
commit 66b6fa65a1
5 changed files with 82 additions and 43 deletions

View file

@ -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);
zathura_t* zathura = session->global.data;
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);
/* 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);
char* string = zathura_get_version_string(zathura, true);
if (string == NULL) {
return false;
}
/* 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;
}

1
main.c
View file

@ -21,7 +21,6 @@ int main(int argc, char* argv[])
zathura_t* zathura = zathura_init(argc, argv);
if (zathura == NULL) {
fprintf(stderr, "error: could not initialize zathura\n");
return -1;
}

40
utils.c
View file

@ -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);
}
}
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;
}

View file

@ -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);
/**
* 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

View file

@ -67,7 +67,7 @@ zathura_init(int argc, char* argv[])
#endif
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[] =
{
{ "reparent", 'e', 0, G_OPTION_ARG_INT, &embed, _("Reparents to window specified by xid"), "xid" },
@ -77,6 +77,7 @@ zathura_init(int argc, char* argv[])
{ "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" },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &print_version, _("Print version information"), NULL },
{ NULL, '\0', 0, 0, NULL, NULL, NULL }
};
@ -117,6 +118,11 @@ zathura_init(int argc, char* argv[])
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 */
zathura->plugins.manager = zathura_plugin_manager_new();
if (zathura->plugins.manager == NULL) {
@ -160,6 +166,19 @@ zathura_init(int argc, char* argv[])
#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 */
if ((zathura->ui.session = girara_session_create()) == NULL) {
goto error_out;
@ -167,14 +186,6 @@ zathura_init(int argc, char* argv[])
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 */
config_load_default(zathura);