diff --git a/LICENSE b/LICENSE index ccbeea4..2244d16 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009-2015 pwmt.org +Copyright (c) 2009-2016 pwmt.org This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/README b/README index c7bdc22..55f43aa 100644 --- a/README +++ b/README @@ -12,7 +12,7 @@ sqlite3 (optional, >= 3.5.9) check (for tests) intltool libmagic from file(1) (optional, for mime-type detection) -libsynctex from TeXLive (option, for SyncTeX support) +libsynctex from TeXLive (optional, for SyncTeX support) Sphinx (optional, for manpages and HTML documentation) doxygen (optional, for HTML documentation) breathe (optional, for HTML documentation) diff --git a/config.mk b/config.mk index 96c4009..d529e79 100644 --- a/config.mk +++ b/config.mk @@ -6,7 +6,7 @@ PROJECT = zathura ZATHURA_VERSION_MAJOR = 0 ZATHURA_VERSION_MINOR = 3 -ZATHURA_VERSION_REV = 4 +ZATHURA_VERSION_REV = 5 # If the API changes, the API version and the ABI version have to be bumped. ZATHURA_API_VERSION = 2 # If the ABI breaks for any reason, this has to be bumped. diff --git a/doc/Makefile b/doc/Makefile index 28b8f2d..7e36b9d 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -6,7 +6,7 @@ include ../colors.mk include config.mk MAN_SOURCES=$(wildcard man/*.rst) $(wildcard man/*.txt) man/conf.py -DOXYGEN_SOURCES=$(wildcard ../*.h) Doxyfile +DOXYGEN_SOURCES=$(wildcard ../zathura/*.h) Doxyfile HTML_SOURCES=$(wildcard *.rst api/*.rst configuration/*.rst installation/*.rst usage/*.rst) conf.py SPHINX_OPTS+=-d $(SPHINX_BUILDDIR)/doctrees @@ -18,15 +18,17 @@ clean: $(QUIET)rm -rf $(SPHINX_BUILDDIR)/ $(SPHINX_BUILDDIR)/html/index.html: $(HTML_SOURCES) $(SPHINX_BUILDDIR)/doxygen/xml/index.xml + $(QUIET)mkdir -p $(SPHINX_BUILDDIR)/html $(call colorecho,DOC,"Build HTML documentation") $(QUIET)$(SPHINX_BIN) -b html $(SPHINX_OPTS) . $(SPHINX_BUILDDIR)/html $(SPHINX_BUILDDIR)/zathura.1 $(SPHINX_BUILDDIR)/zathurarc.5: $(MAN_SOURCES) + $(QUIET)mkdir -p $(SPHINX_BUILDDIR) $(call colorecho,DOC,"Build man pages") $(QUIET)$(SPHINX_BIN) -b man $(SPHINX_OPTS) man $(SPHINX_BUILDDIR) $(SPHINX_BUILDDIR)/doxygen/xml/index.xml: $(DOXYGEN_SOURCES) - $(QUIET)mkdir -p $(SPHINX_BUILDDIR) + $(QUIET)mkdir -p $(SPHINX_BUILDDIR)/doxygen/xml $(call colorecho,DOC,"Run doxygen") $(QUIET)$(DOXYGEN_BIN) Doxyfile diff --git a/doc/man/_commands.txt b/doc/man/_commands.txt index b7acbd4..114ef2a 100644 --- a/doc/man/_commands.txt +++ b/doc/man/_commands.txt @@ -16,9 +16,6 @@ exec info Show document information -help - Show help page - open Open a document diff --git a/doc/man/_options.txt b/doc/man/_options.txt index 89a6be6..0ebbf14 100644 --- a/doc/man/_options.txt +++ b/doc/man/_options.txt @@ -28,7 +28,13 @@ --synctex-forward=input Jump to the given position. The switch expects the same format as specified - for synctex's view -i. + for synctex's view -i. If no instance is running for the specified document, + a new instance will be launched (only if --synctex-pid is not specified). + +--synctex-pid=pid + Instead of looking for an instance having the correct file opened, try only + the instance with the given PID. Note that if the given PID does not have the + correct file open or does not exist, no new instance will be spanned. --fork Fork into background diff --git a/doc/man/_synctex.txt b/doc/man/_synctex.txt index 70db6ad..dfa5dc8 100644 --- a/doc/man/_synctex.txt +++ b/doc/man/_synctex.txt @@ -1,6 +1,6 @@ Both synctex forward and backwards synchronization are supported by zathura, To -enable synctex forward synchronization, please look at the *--syntex* and -*--synctex-editor* options. zathura will also emit a signal via the D-Bus +enable synctex forward synchronization, please look at the *--synctex-forward* +and *--synctex-editor* options. zathura will also emit a signal via the D-Bus interface. To support synctex backwards synchronization, zathura provides a D-Bus interface that can be called by the editor. For convince zathura also knows how to parse the output of the *synctex view* command. It is enough to diff --git a/doc/man/_synopsis.txt b/doc/man/_synopsis.txt index c4e918d..9311e9d 100644 --- a/doc/man/_synopsis.txt +++ b/doc/man/_synopsis.txt @@ -1,2 +1,3 @@ zathura [-e XID] [-c PATH] [-d PATH] [-p PATH] [-w PASSWORD] [-P NUMBER] -[--fork] [-l LEVEL] [-s] [-x CMD] [--synctex-forward INPUT] +[--fork] [-l LEVEL] [-s] [-x CMD] [--synctex-forward INPUT] [--synctex-pid PID] + diff --git a/doc/man/zathurarc.5.rst b/doc/man/zathurarc.5.rst index 45a9bbb..c70f524 100644 --- a/doc/man/zathurarc.5.rst +++ b/doc/man/zathurarc.5.rst @@ -307,6 +307,13 @@ The following shortcut functions can be mapped: Zoom in or out. +* ``mark_add`` + Set a quickmark. + +* ``mark_evaluate`` + Go to a quickmark. + + Pass arguments ^^^^^^^^^^^^^^ Some shortcut function require or have optional arguments which influence the @@ -454,8 +461,8 @@ guioptions Shows or hides GUI elements. If it contains 'c', the command line is displayed. If it contains 's', the statusbar is displayed. -If it contains 'h', the vertical scrollbar is displayed. -If it contains 'v', the horizontal scrollbar is displayed. +If it contains 'h', the horizontal scrollbar is displayed. +If it contains 'v', the vertical scrollbar is displayed. * Value type: String * Default value: s diff --git a/doc/usage/index.rst b/doc/usage/index.rst index d24096f..a1e1e64 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -5,4 +5,4 @@ Usage :maxdepth: 2 :numbered: - commands + commands diff --git a/po/Makefile b/po/Makefile index cebea0e..2d60065 100644 --- a/po/Makefile +++ b/po/Makefile @@ -19,10 +19,10 @@ all: ${MOS} clean: $(QUIET)rm -rf POTFILES.in POTFILES.in.tmp $(patsubst %.po, %, $(CATALOGS)) ${PROJECT}.pot -POTFILES.in: $(sort $(wildcard ../girara/*.c)) +POTFILES.in: $(sort $(wildcard ../zathura/*.c)) $(QUIET) set -e && rm -f $@.tmp && touch $@.tmp && \ for f in $(^F) ; do \ - echo girara/$$f >> $@.tmp ; \ + echo zathura/$$f >> $@.tmp ; \ done && \ mv $@.tmp $@ diff --git a/tests/test_document.c b/tests/test_document.c index c5aea4a..75b401d 100644 --- a/tests/test_document.c +++ b/tests/test_document.c @@ -5,9 +5,10 @@ #include "document.h" START_TEST(test_open) { - fail_unless(zathura_document_open(NULL, NULL, NULL, NULL) == NULL, "Could create document", NULL); - fail_unless(zathura_document_open(NULL, "fl", NULL, NULL) == NULL, "Could create document", NULL); - fail_unless(zathura_document_open(NULL, "fl", "pw", NULL) == NULL, "Could create document", NULL); + fail_unless(zathura_document_open(NULL, NULL, NULL, NULL, NULL) == NULL, "Could create document", NULL); + fail_unless(zathura_document_open(NULL, "fl", NULL, NULL, NULL) == NULL, "Could create document", NULL); + fail_unless(zathura_document_open(NULL, "fl", "ur", NULL, NULL) == NULL, "Could create document", NULL); + fail_unless(zathura_document_open(NULL, "fl", NULL, "pw", NULL) == NULL, "Could create document", NULL); } END_TEST Suite* suite_document() diff --git a/zathura/callbacks.h b/zathura/callbacks.h index 148ed71..eb41db9 100644 --- a/zathura/callbacks.h +++ b/zathura/callbacks.h @@ -16,7 +16,7 @@ * * @param widget The gtk window of zathura * @param zathura Correspondending zathura session - * @return true if no error occured and the event has been handled + * @return true if no error occurred and the event has been handled */ gboolean cb_destroy(GtkWidget* widget, zathura_t* zathura); @@ -108,7 +108,7 @@ void cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path, * * @param entry The dialog inputbar * @param session The girara session - * @return true if no error occured and the event has been handled + * @return true if no error occurred and the event has been handled */ bool cb_sc_follow(GtkEntry* entry, girara_session_t* session); @@ -117,7 +117,7 @@ bool cb_sc_follow(GtkEntry* entry, girara_session_t* session); * * @param entry The dialog inputbar * @param session The girara session - * @return true if no error occured and the event has been handled + * @return true if no error occurred and the event has been handled */ bool cb_sc_display_link(GtkEntry* entry, girara_session_t* session); diff --git a/zathura/commands.h b/zathura/commands.h index 1327068..6d65f06 100644 --- a/zathura/commands.h +++ b/zathura/commands.h @@ -11,7 +11,7 @@ * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list); @@ -20,7 +20,7 @@ bool cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_bookmark_delete(girara_session_t* session, girara_list_t* argument_list); @@ -29,7 +29,7 @@ bool cmd_bookmark_delete(girara_session_t* session, girara_list_t* argument_list * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list); @@ -38,7 +38,7 @@ bool cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list); * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_close(girara_session_t* session, girara_list_t* argument_list); @@ -47,7 +47,7 @@ bool cmd_close(girara_session_t* session, girara_list_t* argument_list); * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_info(girara_session_t* session, girara_list_t* argument_list); @@ -56,7 +56,7 @@ bool cmd_info(girara_session_t* session, girara_list_t* argument_list); * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_help(girara_session_t* session, girara_list_t* argument_list); @@ -65,7 +65,7 @@ bool cmd_help(girara_session_t* session, girara_list_t* argument_list); * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_hlsearch(girara_session_t* session, girara_list_t* argument_list); @@ -74,7 +74,7 @@ bool cmd_hlsearch(girara_session_t* session, girara_list_t* argument_list); * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_open(girara_session_t* session, girara_list_t* argument_list); @@ -83,7 +83,7 @@ bool cmd_open(girara_session_t* session, girara_list_t* argument_list); * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_print(girara_session_t* session, girara_list_t* argument_list); @@ -92,7 +92,7 @@ bool cmd_print(girara_session_t* session, girara_list_t* argument_list); * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_nohlsearch(girara_session_t* session, girara_list_t* argument_list); @@ -101,7 +101,7 @@ bool cmd_nohlsearch(girara_session_t* session, girara_list_t* argument_list); * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_quit(girara_session_t* session, girara_list_t* argument_list); @@ -110,7 +110,7 @@ bool cmd_quit(girara_session_t* session, girara_list_t* argument_list); * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_save(girara_session_t* session, girara_list_t* argument_list); @@ -119,7 +119,7 @@ bool cmd_save(girara_session_t* session, girara_list_t* argument_list); * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_savef(girara_session_t* session, girara_list_t* argument_list); @@ -129,7 +129,7 @@ bool cmd_savef(girara_session_t* session, girara_list_t* argument_list); * @param session The used girara session * @param input The current input * @param argument Passed argument - * @return true if no error occured + * @return true if no error occurred */ bool cmd_search(girara_session_t* session, const char* input, girara_argument_t* argument); @@ -138,7 +138,7 @@ bool cmd_search(girara_session_t* session, const char* input, girara_argument_t* * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_export(girara_session_t* session, girara_list_t* argument_list); @@ -147,7 +147,7 @@ bool cmd_export(girara_session_t* session, girara_list_t* argument_list); * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_exec(girara_session_t* session, girara_list_t* argument_list); @@ -156,7 +156,7 @@ bool cmd_exec(girara_session_t* session, girara_list_t* argument_list); * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_offset(girara_session_t* session, girara_list_t* argument_list); @@ -165,7 +165,7 @@ bool cmd_offset(girara_session_t* session, girara_list_t* argument_list); * * @param session The used girara session * @param argument_list List of passed arguments - * @return true if no error occured + * @return true if no error occurred */ bool cmd_version(girara_session_t* session, girara_list_t* argument_list); diff --git a/zathura/completion.h b/zathura/completion.h index 6d17868..14e8460 100644 --- a/zathura/completion.h +++ b/zathura/completion.h @@ -11,7 +11,7 @@ * * @param session The used girara session * @param input The current input - * @return The completion object or NULL if an error occured + * @return The completion object or NULL if an error occurred */ girara_completion_t* cc_open(girara_session_t* session, const char* input); @@ -21,7 +21,7 @@ girara_completion_t* cc_open(girara_session_t* session, const char* input); * * @param session The used girara session * @param input The current input - * @return The completion object or NULL if an error occured + * @return The completion object or NULL if an error occurred */ girara_completion_t* cc_write(girara_session_t* session, const char* input); @@ -30,7 +30,7 @@ girara_completion_t* cc_write(girara_session_t* session, const char* input); * * @param session The used girara session * @param input The current input - * @return The completion object or NULL if an error occured + * @return The completion object or NULL if an error occurred */ girara_completion_t* cc_bookmarks(girara_session_t* session, const char* input); diff --git a/zathura/config.c b/zathura/config.c index 626f495..f0037ec 100644 --- a/zathura/config.c +++ b/zathura/config.c @@ -466,6 +466,8 @@ config_load_default(zathura_t* zathura) girara_shortcut_mapping_add(gsession, "goto", sc_goto); girara_shortcut_mapping_add(gsession, "jumplist", sc_jumplist); girara_shortcut_mapping_add(gsession, "bisect", sc_bisect); + girara_shortcut_mapping_add(gsession, "mark_add", sc_mark_add); + girara_shortcut_mapping_add(gsession, "mark_evaluate", sc_mark_evaluate); girara_shortcut_mapping_add(gsession, "navigate", sc_navigate); girara_shortcut_mapping_add(gsession, "navigate_index", sc_navigate_index); girara_shortcut_mapping_add(gsession, "print", sc_print); diff --git a/zathura/content-type.c b/zathura/content-type.c index 5edcf10..3440973 100644 --- a/zathura/content-type.c +++ b/zathura/content-type.c @@ -17,14 +17,23 @@ #include #include -/** Read a most GT_MAX_READ bytes before falling back to file. */ -static const size_t GT_MAX_READ = 1 << 16; +struct zathura_content_type_context_s +{ +#ifdef WITH_MAGIC + magic_t magic; +#endif +}; + +zathura_content_type_context_t* +zathura_content_type_new(void) +{ + zathura_content_type_context_t* context = + g_try_malloc0(sizeof(zathura_content_type_context_t)); + if (context == NULL) { + return NULL; + } #ifdef WITH_MAGIC -static const char* -guess_type_magic(const char* path) { - const char* mime_type = NULL; - /* creat magic cookie */ const int flags = MAGIC_MIME_TYPE | @@ -36,46 +45,78 @@ guess_type_magic(const char* path) { magic_t magic = magic_open(flags); if (magic == NULL) { girara_debug("failed creating the magic cookie"); - goto cleanup; + return context; } /* ... and load mime database */ if (magic_load(magic, NULL) < 0) { girara_debug("failed loading the magic database: %s", magic_error(magic)); - goto cleanup; - } - - /* get the mime type */ - mime_type = magic_file(magic, path); - if (mime_type == NULL) { - girara_debug("failed guessing filetype: %s", magic_error(magic)); - goto cleanup; - } - /* dup so we own the memory */ - mime_type = g_strdup(mime_type); - - girara_debug("magic detected filetype: %s", mime_type); - -cleanup: - if (magic != NULL) { magic_close(magic); + return context; } - return mime_type; + context->magic = magic; +#endif + + return context; } -static const char* +void +zathura_content_type_free(zathura_content_type_context_t* context) +{ + if (context == NULL) { + return; + } + +#ifdef WITH_MAGIC + if (context->magic != NULL) { + magic_close(context->magic); + } +#endif + + g_free(context); +} + + +/** Read a most GT_MAX_READ bytes before falling back to file. */ +static const size_t GT_MAX_READ = 1 << 16; + +#ifdef WITH_MAGIC +static char* +guess_type_magic(zathura_content_type_context_t* context, const char* path) +{ + if (context == NULL || context->magic == NULL) { + return NULL; + } + + const char* mime_type = NULL; + + /* get the mime type */ + mime_type = magic_file(context->magic, path); + if (mime_type == NULL) { + girara_debug("failed guessing filetype: %s", magic_error(context->magic)); + return NULL; + } + girara_debug("magic detected filetype: %s", mime_type); + + /* dup so we own the memory */ + return g_strdup(mime_type);; +} + +static char* guess_type_file(const char* UNUSED(path)) { return NULL; } #else static const char* -guess_type_magic(const char* UNUSED(path)) { +guess_type_magic(zathura_content_type_context_t* UNUSED(context), + const char* UNUSED(path)) +{ return NULL; } -static const char* +static char* guess_type_file(const char* path) { GString* command = g_string_new("file -b --mime-type "); @@ -106,11 +147,11 @@ guess_type_file(const char* path) } #endif -static const char* +static char* guess_type_glib(const char* path) { gboolean uncertain = FALSE; - const char* content_type = g_content_type_guess(path, NULL, 0, &uncertain); + char* content_type = g_content_type_guess(path, NULL, 0, &uncertain); if (content_type == NULL) { girara_debug("g_content_type failed\n"); } else { @@ -160,11 +201,12 @@ guess_type_glib(const char* path) return NULL; } -const char* -guess_content_type(const char* path) +char* +zathura_content_type_guess(zathura_content_type_context_t* context, + const char* path) { /* try libmagic first */ - const char* content_type = guess_type_magic(path); + char* content_type = guess_type_magic(context, path); if (content_type != NULL) { return content_type; } diff --git a/zathura/content-type.h b/zathura/content-type.h index fca53d1..9bd367d 100644 --- a/zathura/content-type.h +++ b/zathura/content-type.h @@ -3,13 +3,30 @@ #ifndef ZATHURA_CONTENT_TYPE_H #define ZATHURA_CONTENT_TYPE_H +#include "types.h" + +/** + * Create new context for MIME type detection. + * + * @return new context + */ +zathura_content_type_context_t* zathura_content_type_new(void); + +/** + * Free MIME type detection context. + * + * @param context The context. + */ +void zathura_content_type_free(zathura_content_type_context_t* context); + /** * "Guess" the content type of a file. Various methods are tried depending on * the available libraries. * * @param path file name - * @return content type of path + * @return content type of path, needs to freeed with g_free. */ -const char* guess_content_type(const char* path); +char* zathura_content_type_guess(zathura_content_type_context_t* context, + const char* path); #endif diff --git a/zathura/dbus-interface.c b/zathura/dbus-interface.c index e2560f6..1a89261 100644 --- a/zathura/dbus-interface.c +++ b/zathura/dbus-interface.c @@ -469,7 +469,7 @@ iterate_instances_call_synctex_view(const char* filename, const bool ret = call_synctex_view(connection, filename, well_known_name, input_file, line, column); g_free(well_known_name); - return ret ? 1 : 0; + return ret ? 1 : -1; } GVariant* vnames = g_dbus_connection_call_sync( diff --git a/zathura/document.c b/zathura/document.c index fb03f65..7ed9acb 100644 --- a/zathura/document.c +++ b/zathura/document.c @@ -61,16 +61,16 @@ check_set_error(zathura_error_t* error, zathura_error_t code) { } zathura_document_t* -zathura_document_open(zathura_plugin_manager_t* plugin_manager, const char* - path, const char *uri, const char* password, zathura_error_t* error) +zathura_document_open(zathura_t* zathura, const char* path, const char* uri, + const char* password, zathura_error_t* error) { - if (path == NULL) { + if (zathura == NULL || path == NULL) { return NULL; } GFile* file = g_file_new_for_path(path); char* real_path = NULL; - const char* content_type = NULL; + char* content_type = NULL; zathura_plugin_t* plugin = NULL; zathura_document_t* document = NULL; @@ -87,14 +87,14 @@ zathura_document_open(zathura_plugin_manager_t* plugin_manager, const char* goto error_free; } - content_type = guess_content_type(real_path); + content_type = zathura_content_type_guess(zathura->content_type_context, real_path); if (content_type == NULL) { girara_error("Could not determine file type."); check_set_error(error, ZATHURA_ERROR_UNKNOWN); goto error_free; } - plugin = zathura_plugin_manager_get_plugin(plugin_manager, content_type); + plugin = zathura_plugin_manager_get_plugin(zathura->plugins.manager, content_type); if (plugin == NULL) { girara_error("Unknown file type: '%s'", content_type); @@ -106,7 +106,7 @@ zathura_document_open(zathura_plugin_manager_t* plugin_manager, const char* goto error_free; } - g_free((void*)content_type); + g_free(content_type); content_type = NULL; document = g_try_malloc0(sizeof(zathura_document_t)); diff --git a/zathura/document.h b/zathura/document.h index 6880d07..3118f30 100644 --- a/zathura/document.h +++ b/zathura/document.h @@ -11,21 +11,21 @@ /** * Open the document * - * @param plugin_manager The plugin manager + * @param plugin_manager The zathura instance * @param path Path to the document * @param password Password of the document or NULL * @param error Optional error parameter * @return The document object and NULL if an error occurs */ -zathura_document_t* zathura_document_open(zathura_plugin_manager_t* - plugin_manager, const char* path, const char *uri, const char* password, zathura_error_t* +zathura_document_t* zathura_document_open(zathura_t* zathura, + const char* path, const char *uri, const char* password, zathura_error_t* error); /** * Free the document * * @param document - * @return ZATHURA_ERROR_OK when no error occured, otherwise see + * @return ZATHURA_ERROR_OK when no error occurred, otherwise see * zathura_error_t */ zathura_error_t zathura_document_free(zathura_document_t* document); @@ -67,7 +67,7 @@ const char* zathura_document_get_password(zathura_document_t* document); * * @param document The document * @param index The index of the page - * @return The page or NULL if an error occured + * @return The page or NULL if an error occurred */ zathura_page_t* zathura_document_get_page(zathura_document_t* document, unsigned int index); @@ -283,7 +283,7 @@ void zathura_document_set_page_layout(zathura_document_t* document, unsigned int unsigned int pages_per_row, unsigned int first_page_column); /** - * Returns the padding in pixels betwen pages + * Returns the padding in pixels between pages * * @param document The document * @return The padding in pixels between pages @@ -311,7 +311,7 @@ unsigned int zathura_document_get_first_page_column(zathura_document_t* document * * @param document The document object * @param path Path for the saved file - * @return ZATHURA_ERROR_OK when no error occured, otherwise see + * @return ZATHURA_ERROR_OK when no error occurred, otherwise see * zathura_error_t */ zathura_error_t zathura_document_save_as(zathura_document_t* document, const char* path); @@ -321,7 +321,7 @@ zathura_error_t zathura_document_save_as(zathura_document_t* document, const cha * * @param document The document object * @param error Set to an error value (see \ref zathura_error_t) if an - * error occured + * error occurred * @return Generated index */ @@ -332,7 +332,7 @@ girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document * * @param document The document object * @param error Set to an error value (see \ref zathura_error_t) if an - * error occured + * error occurred * @return List of attachments */ girara_list_t* zathura_document_attachments_get(zathura_document_t* document, zathura_error_t* error); @@ -343,7 +343,7 @@ girara_list_t* zathura_document_attachments_get(zathura_document_t* document, za * @param document The document objects * @param attachment name of the attachment * @param file the target filename - * @return ZATHURA_ERROR_OK when no error occured, otherwise see + * @return ZATHURA_ERROR_OK when no error occurred, otherwise see * zathura_error_t */ zathura_error_t zathura_document_attachment_save(zathura_document_t* document, const char* attachment, const char* file); @@ -353,8 +353,8 @@ zathura_error_t zathura_document_attachment_save(zathura_document_t* document, c * * @param document The zathura document * @param error Set to an error value (see \ref zathura_error_t) if an - * error occured - * @return List of document information entries or NULL if information could not be retreived + * error occurred + * @return List of document information entries or NULL if information could not be retrieved */ girara_list_t* zathura_document_get_information(zathura_document_t* document, zathura_error_t* error); diff --git a/zathura/main.c b/zathura/main.c index 060382a..2671e4c 100644 --- a/zathura/main.c +++ b/zathura/main.c @@ -18,6 +18,10 @@ #include "synctex.h" #endif +#ifndef GDK_WINDOWING_X11 +typedef int Window; +#endif + /* Init locale */ static void init_locale(void) @@ -45,7 +49,7 @@ set_log_level(const char* loglevel) #ifdef WITH_SYNCTEX static int run_synctex_forward(const char* synctex_fwd, const char* filename, - int synctex_pid) + int synctex_pid) { GFile* file = g_file_new_for_commandline_arg(filename); if (file == NULL) { @@ -60,8 +64,8 @@ run_synctex_forward(const char* synctex_fwd, const char* filename, return -1; } - int line = 0; - int column = 0; + int line = 0; + int column = 0; char* input_file = NULL; if (synctex_parse_input(synctex_fwd, &input_file, &line, &column) == false) { girara_error("Failed to parse argument to --synctex-forward."); @@ -69,13 +73,15 @@ run_synctex_forward(const char* synctex_fwd, const char* filename, return -1; } - const int ret = zathura_dbus_synctex_position(real_path, input_file, line, column, synctex_pid); + const int ret = zathura_dbus_synctex_position(real_path, input_file, line, + column, synctex_pid); g_free(input_file); g_free(real_path); if (ret == -1) { /* D-Bus or SyncTeX failed */ - girara_error("Got no usable data from SyncTeX or D-Bus failed in some way."); + girara_error( + "Got no usable data from SyncTeX or D-Bus failed in some way."); } return ret; @@ -84,12 +90,8 @@ run_synctex_forward(const char* synctex_fwd, const char* filename, static zathura_t* init_zathura(const char* config_dir, const char* data_dir, - const char* cache_dir, const char* plugin_path, char** argv, -#ifdef GDK_WINDOWING_X11 - char* synctex_editor, Window embed) -#else - char* synctex_editor) -#endif + const char* cache_dir, const char* plugin_path, char** argv, + char* synctex_editor, Window embed) { /* create zathura session */ zathura_t* zathura = zathura_create(); @@ -112,11 +114,10 @@ init_zathura(const char* config_dir, const char* data_dir, return NULL; } -#ifdef WITH_SYNCTEX if (synctex_editor != NULL) { - girara_setting_set(zathura->ui.session, "synctex-editor-command", synctex_editor); + girara_setting_set(zathura->ui.session, "synctex-editor-command", + synctex_editor); } -#endif return zathura; } @@ -135,20 +136,16 @@ main(int argc, char* argv[]) gchar* plugin_path = NULL; gchar* loglevel = NULL; gchar* password = NULL; -#ifdef WITH_SYNCTEX gchar* synctex_editor = NULL; gchar* synctex_fwd = NULL; -#endif gchar* mode = NULL; - bool forkback = false; - bool print_version = false; - int page_number = ZATHURA_PAGE_NUMBER_UNSPECIFIED; + bool forkback = false; + bool print_version = false; + int page_number = ZATHURA_PAGE_NUMBER_UNSPECIFIED; #ifdef WITH_SYNCTEX - int synctex_pid = -1; + int synctex_pid = -1; #endif -#ifdef GDK_WINDOWING_X11 Window embed = 0; -#endif GOptionEntry entries[] = { #ifdef GDK_WINDOWING_X11 @@ -185,20 +182,29 @@ main(int argc, char* argv[]) } g_option_context_free(context); + int ret = 0; set_log_level(loglevel); #ifdef WITH_SYNCTEX /* handle synctex forward synchronization */ if (synctex_fwd != NULL) { if (argc != 2) { - girara_error("Too many arguments or missing filename while running with --synctex-forward"); - return -1; + girara_error("Too many arguments or missing filename while running with " + "--synctex-forward"); + ret = -1; + goto free_and_ret; } - const int ret = run_synctex_forward(synctex_fwd, argv[1], synctex_pid); - if (ret != 0) { - /* Error or instance found */ - return ret; + ret = run_synctex_forward(synctex_fwd, argv[1], synctex_pid); + if (ret > 0) { + /* Instance found. */ + ret = 0; + goto free_and_ret; + } + else if (ret < 0) { + /* Error occurred. */ + ret = -1; + goto free_and_ret; } girara_debug("No instance found. Starting new one."); @@ -206,42 +212,62 @@ main(int argc, char* argv[]) #endif /* check mode */ - if (mode != NULL && g_strcmp0(mode, "presentation") != 0 && g_strcmp0(mode, "fullscreen") != 0) { + if (mode != NULL && g_strcmp0(mode, "presentation") != 0 && + g_strcmp0(mode, "fullscreen") != 0) { girara_error("Invalid argument for --mode: %s", mode); - return -1; + ret = -1; + goto free_and_ret; } - size_t file_idx = argc > 1 ? 1 : 0; + /* g_option_context_parse has some funny (documented) behavior: + * * for "-- a b c" you get no -- in argv + * * for "-- --" you get -- in argv twice + * * for "-- -a" you get -- in argv + * + * So if there is one -- in argv, we need to ignore it. */ + const bool has_double_dash = argc > 1 && g_strcmp0(argv[1], "--") == 0; + const int file_idx_base = has_double_dash ? 2 : 1; + + int file_idx = argc > file_idx_base ? file_idx_base : 0; /* Fork instances for other files. */ - if (print_version == false && argc > 2) { - for (int idx = 2; idx < argc; ++idx) { + if (print_version == false && argc > file_idx_base + 1) { + for (int idx = file_idx_base + 1; idx < argc; ++idx) { const pid_t pid = fork(); if (pid == 0) { /* child */ file_idx = idx; if (setsid() == -1) { - girara_error("Could not start new process group: %s", strerror(errno)); - return -1; + girara_error("Could not start new process group: %s", + strerror(errno)); + ret = -1; + goto free_and_ret; } - } else if (pid < 0) { /* error */ + break; + } + else if (pid < 0) { /* error */ girara_error("Could not fork: %s", strerror(errno)); - return -1; + ret = -1; + goto free_and_ret; } } } /* Fork into the background if the user really wants to ... */ - if (print_version == false && forkback == true && file_idx < 2) { + if (print_version == false && forkback == true && + file_idx < file_idx_base + 1) { const pid_t pid = fork(); if (pid > 0) { /* parent */ - return 0; - } else if (pid < 0) { /* error */ + goto free_and_ret; + } + else if (pid < 0) { /* error */ girara_error("Could not fork: %s", strerror(errno)); - return -1; + ret = -1; + goto free_and_ret; } if (setsid() == -1) { girara_error("Could not start new process group: %s", strerror(errno)); - return -1; + ret = -1; + goto free_and_ret; } } @@ -250,14 +276,11 @@ main(int argc, char* argv[]) /* Create zathura session */ zathura_t* zathura = init_zathura(config_dir, data_dir, cache_dir, -#ifdef GDK_WINDOWING_X11 - plugin_path, argv, synctex_editor, embed); -#else - plugin_path, argv, synctex_editor); -#endif + plugin_path, argv, synctex_editor, embed); if (zathura == NULL) { girara_error("Could not initialize zathura."); - return -1; + ret = -1; + goto free_and_ret; } /* Print version */ @@ -269,7 +292,7 @@ main(int argc, char* argv[]) } zathura_free(zathura); - return 0; + goto free_and_ret; } /* open document if passed */ @@ -277,11 +300,8 @@ main(int argc, char* argv[]) if (page_number > 0) { --page_number; } -#ifdef WITH_SYNCTEX - document_open_idle(zathura, argv[file_idx], password, page_number, mode, synctex_fwd); -#else - document_open_idle(zathura, argv[file_idx], password, page_number, mode, NULL); -#endif + document_open_idle(zathura, argv[file_idx], password, page_number, mode, + synctex_fwd); } /* run zathura */ @@ -290,5 +310,16 @@ main(int argc, char* argv[]) /* free zathura */ zathura_free(zathura); - return 0; +free_and_ret: + g_free(config_dir); + g_free(data_dir); + g_free(cache_dir); + g_free(plugin_path); + g_free(loglevel); + g_free(password); + g_free(synctex_editor); + g_free(synctex_fwd); + g_free(mode); + + return ret; } diff --git a/zathura/marks.h b/zathura/marks.h index b821f52..64d3329 100644 --- a/zathura/marks.h +++ b/zathura/marks.h @@ -16,7 +16,7 @@ typedef struct zathura_mark_s zathura_mark_t; * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_mark_add(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -28,7 +28,7 @@ bool sc_mark_add(girara_session_t* session, girara_argument_t* argument, * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_mark_evaluate(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -38,7 +38,7 @@ bool sc_mark_evaluate(girara_session_t* session, girara_argument_t* argument, * * @param session The girara session * @param argument_list Argument list - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool cmd_marks_add(girara_session_t* session, girara_list_t* argument_list); @@ -47,7 +47,7 @@ bool cmd_marks_add(girara_session_t* session, girara_list_t* argument_list); * * @param session The girara session * @param argument_list Argument list - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool cmd_marks_delete(girara_session_t* session, girara_list_t* argument_list); diff --git a/zathura/page-widget.h b/zathura/page-widget.h index 30e99c7..d18c63f 100644 --- a/zathura/page-widget.h +++ b/zathura/page-widget.h @@ -75,7 +75,7 @@ void zathura_page_widget_clear_rectangles(ZathuraPage* widget); * * @param widget the widget * @param index Index of the link - * @return Link object or NULL if an error occured + * @return Link object or NULL if an error occurred */ zathura_link_t* zathura_page_widget_link_get(ZathuraPage* widget, unsigned int index); /** diff --git a/zathura/page.h b/zathura/page.h index dbac902..d8f260e 100644 --- a/zathura/page.h +++ b/zathura/page.h @@ -14,7 +14,7 @@ * @param document The document * @param index Page number * @param error Optional error - * @return Page object or NULL if an error occured + * @return Page object or NULL if an error occurred */ zathura_page_t* zathura_page_new(zathura_document_t* document, unsigned int index, zathura_error_t* error); @@ -23,7 +23,7 @@ zathura_page_t* zathura_page_new(zathura_document_t* document, unsigned int * Frees the page object * * @param page The page object - * @return ZATHURA_ERROR_OK when no error occured, otherwise see + * @return ZATHURA_ERROR_OK when no error occurred, otherwise see * zathura_error_t */ zathura_error_t zathura_page_free(zathura_page_t* page); @@ -33,7 +33,7 @@ zathura_error_t zathura_page_free(zathura_page_t* page); * * @param page The page object * @return The associated document - * @return NULL if an error occured + * @return NULL if an error occurred */ zathura_document_t* zathura_page_get_document(zathura_page_t* page); @@ -50,7 +50,7 @@ unsigned int zathura_page_get_index(zathura_page_t* page); * * @param page The page object * @return Width of the page - * @return -1 If an error occured + * @return -1 If an error occurred */ double zathura_page_get_width(zathura_page_t* page); @@ -67,7 +67,7 @@ void zathura_page_set_width(zathura_page_t* page, double width); * * @param page The page object * @return Height of the page - * @return -1 If an error occured + * @return -1 If an error occurred */ double zathura_page_get_height(zathura_page_t* page); @@ -118,7 +118,7 @@ void zathura_page_set_data(zathura_page_t* page, void* data); * @param page The page object * @param text Search item * @param error Set to an error value (see \ref zathura_error_t) if an - * error occured + * error occurred * @return List of results */ girara_list_t* zathura_page_search_text(zathura_page_t* page, const char* text, zathura_error_t* error); @@ -128,7 +128,7 @@ girara_list_t* zathura_page_search_text(zathura_page_t* page, const char* text, * * @param page The page object * @param error Set to an error value (see \ref zathura_error_t) if an - * error occured + * error occurred * @return List of links */ girara_list_t* zathura_page_links_get(zathura_page_t* page, zathura_error_t* error); @@ -137,7 +137,7 @@ girara_list_t* zathura_page_links_get(zathura_page_t* page, zathura_error_t* err * Free page links * * @param list List of links - * @return ZATHURA_ERROR_OK when no error occured, otherwise see + * @return ZATHURA_ERROR_OK when no error occurred, otherwise see * zathura_error_t */ zathura_error_t zathura_page_links_free(girara_list_t* list); @@ -147,7 +147,7 @@ zathura_error_t zathura_page_links_free(girara_list_t* list); * * @param page The page object * @param error Set to an error value (see \ref zathura_error_t) if an - * error occured + * error occurred * @return List of form fields */ girara_list_t* zathura_page_form_fields_get(zathura_page_t* page, zathura_error_t* error); @@ -156,7 +156,7 @@ girara_list_t* zathura_page_form_fields_get(zathura_page_t* page, zathura_error_ * Free list of form fields * * @param list List of form fields - * @return ZATHURA_ERROR_OK when no error occured, otherwise see + * @return ZATHURA_ERROR_OK when no error occurred, otherwise see * zathura_error_t */ zathura_error_t zathura_page_form_fields_free(girara_list_t* list); @@ -166,8 +166,8 @@ zathura_error_t zathura_page_form_fields_free(girara_list_t* list); * * @param page Page * @param error Set to an error value (see \ref zathura_error_t) if an - * error occured - * @return List of images or NULL if an error occured + * error occurred + * @return List of images or NULL if an error occurred */ girara_list_t* zathura_page_images_get(zathura_page_t* page, zathura_error_t* error); @@ -177,8 +177,8 @@ girara_list_t* zathura_page_images_get(zathura_page_t* page, zathura_error_t* er * @param page Page * @param image Image identifier * @param error Set to an error value (see \ref zathura_error_t) if an - * error occured - * @return The cairo image surface or NULL if an error occured + * error occurred + * @return The cairo image surface or NULL if an error occurred */ cairo_surface_t* zathura_page_image_get_cairo(zathura_page_t* page, zathura_image_t* image, zathura_error_t* error); @@ -187,7 +187,7 @@ cairo_surface_t* zathura_page_image_get_cairo(zathura_page_t* page, zathura_imag * @param page Page * @param rectangle Selection * @param error Set to an error value (see \ref zathura_error_t) if an error - * occured + * occurred * @return The selected text (needs to be deallocated with g_free) */ char* zathura_page_get_text(zathura_page_t* page, zathura_rectangle_t rectangle, zathura_error_t* error); @@ -198,7 +198,7 @@ char* zathura_page_get_text(zathura_page_t* page, zathura_rectangle_t rectangle, * @param page The page object * @param cairo Cairo object * @param printing render for printing - * @return ZATHURA_ERROR_OK when no error occured, otherwise see + * @return ZATHURA_ERROR_OK when no error occurred, otherwise see * zathura_error_t */ zathura_error_t zathura_page_render(zathura_page_t* page, cairo_t* cairo, bool printing); diff --git a/zathura/plugin.h b/zathura/plugin.h index 799159f..5578ee1 100644 --- a/zathura/plugin.h +++ b/zathura/plugin.h @@ -27,7 +27,7 @@ typedef struct zathura_plugin_version_s { /** * Creates a new instance of the plugin manager * - * @return A plugin manager object or NULL if an error occured + * @return A plugin manager object or NULL if an error occurred */ zathura_plugin_manager_t* zathura_plugin_manager_new(void); diff --git a/zathura/render.h b/zathura/render.h index f832cf9..c250e27 100644 --- a/zathura/render.h +++ b/zathura/render.h @@ -55,7 +55,7 @@ bool zathura_renderer_recolor_enabled(ZathuraRenderer* renderer); /** * Enable/disable recoloring. * @param renderer a renderer object - * @param enable wheter to enable or disable recoloring + * @param enable whether to enable or disable recoloring */ void zathura_renderer_enable_recolor(ZathuraRenderer* renderer, bool enable); /** @@ -67,7 +67,7 @@ bool zathura_renderer_recolor_hue_enabled(ZathuraRenderer* renderer); /** * Enable/disable preservation of hue while recoloring. * @param renderer a renderer object - * @param enable wheter to enable or disable hue preservation + * @param enable whether to enable or disable hue preservation */ void zathura_renderer_enable_recolor_hue(ZathuraRenderer* renderer, bool enable); diff --git a/zathura/shortcuts.h b/zathura/shortcuts.h index 7fce02f..dc3c30f 100644 --- a/zathura/shortcuts.h +++ b/zathura/shortcuts.h @@ -12,7 +12,7 @@ * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_abort(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -23,7 +23,7 @@ bool sc_abort(girara_session_t* session, girara_argument_t* argument, girara_eve * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -34,7 +34,7 @@ bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, gi * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_change_mode(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -45,7 +45,7 @@ bool sc_change_mode(girara_session_t* session, girara_argument_t* argument, gira * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_display_link(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -56,8 +56,8 @@ bool sc_display_link(girara_session_t* session, girara_argument_t* argument, gir * @param argument The argument * @param event Girara event * @param t Number of executions - * @return true No error occured - * @return false An error occured (abort execution) + * @return true No error occurred + * @return false An error occurred (abort execution) */ bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -68,7 +68,7 @@ bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, g * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_follow(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -79,7 +79,7 @@ bool sc_follow(girara_session_t* session, girara_argument_t* argument, girara_ev * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_goto(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -90,7 +90,7 @@ bool sc_goto(girara_session_t* session, girara_argument_t* argument, girara_even * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_mouse_scroll(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -101,7 +101,7 @@ bool sc_mouse_scroll(girara_session_t* session, girara_argument_t* argument, gir * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_mouse_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -112,7 +112,7 @@ bool sc_mouse_zoom(girara_session_t* session, girara_argument_t* argument, girar * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_navigate(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -123,7 +123,7 @@ bool sc_navigate(girara_session_t* session, girara_argument_t* argument, girara_ * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_print(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -134,7 +134,7 @@ bool sc_print(girara_session_t* session, girara_argument_t* argument, girara_eve * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_recolor(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -145,7 +145,7 @@ bool sc_recolor(girara_session_t* session, girara_argument_t* argument, girara_e * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_reload(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -156,7 +156,7 @@ bool sc_reload(girara_session_t* session, girara_argument_t* argument, girara_ev * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_rotate(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -167,7 +167,7 @@ bool sc_rotate(girara_session_t* session, girara_argument_t* argument, girara_ev * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_scroll(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -178,7 +178,7 @@ bool sc_scroll(girara_session_t* session, girara_argument_t* argument, girara_ev * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_jumplist(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -189,7 +189,7 @@ bool sc_jumplist(girara_session_t* session, girara_argument_t* argument, girara_ * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_bisect(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -200,7 +200,7 @@ bool sc_bisect(girara_session_t* session, girara_argument_t* argument, girara_ev * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_search(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -211,7 +211,7 @@ bool sc_search(girara_session_t* session, girara_argument_t* argument, girara_ev * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -222,7 +222,7 @@ bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument, g * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_toggle_index(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -233,7 +233,7 @@ bool sc_toggle_index(girara_session_t* session, girara_argument_t* argument, gir * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_toggle_page_mode(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -244,7 +244,7 @@ bool sc_toggle_page_mode(girara_session_t* session, girara_argument_t* argument, * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -255,7 +255,7 @@ bool sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_toggle_presentation(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -266,7 +266,7 @@ bool sc_toggle_presentation(girara_session_t* session, girara_argument_t* argume * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_quit(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); @@ -277,7 +277,7 @@ bool sc_quit(girara_session_t* session, girara_argument_t* argument, girara_even * @param argument The used argument * @param event Girara event * @param t Number of executions - * @return true if no error occured otherwise false + * @return true if no error occurred otherwise false */ bool sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); diff --git a/zathura/types.h b/zathura/types.h index 380e4f7..de87eaa 100644 --- a/zathura/types.h +++ b/zathura/types.h @@ -45,8 +45,8 @@ typedef struct zathura_dbus_s ZathuraDbus; */ typedef enum zathura_plugin_error_e { - ZATHURA_ERROR_OK, /**< No error occured */ - ZATHURA_ERROR_UNKNOWN, /**< An unknown error occured */ + ZATHURA_ERROR_OK, /**< No error occurred */ + ZATHURA_ERROR_UNKNOWN, /**< An unknown error occurred */ ZATHURA_ERROR_OUT_OF_MEMORY, /**< Out of memory */ ZATHURA_ERROR_NOT_IMPLEMENTED, /**< The called function has not been implemented */ ZATHURA_ERROR_INVALID_ARGUMENTS, /**< Invalid arguments have been passed */ @@ -109,7 +109,7 @@ typedef enum zathura_adjust_mode_e * * @param width Width of the image stored in the buffer * @param height Height of the image stored in the buffer - * @return Image buffer or NULL if an error occured + * @return Image buffer or NULL if an error occurred */ zathura_image_buffer_t* zathura_image_buffer_create(unsigned int width, unsigned int height); @@ -148,7 +148,7 @@ typedef struct zathura_image_s typedef enum zathura_link_type_e { ZATHURA_LINK_INVALID, /**< Invalid type */ - ZATHURA_LINK_NONE, /**< No action */ + ZATHURA_LINK_NONE, /**< No action */ ZATHURA_LINK_GOTO_DEST, /**< Links to a page */ ZATHURA_LINK_GOTO_REMOTE, /**< Links to a page */ ZATHURA_LINK_URI, /**< Links to an external source */ @@ -158,15 +158,15 @@ typedef enum zathura_link_type_e typedef enum zathura_link_destination_type_e { - ZATHURA_LINK_DESTINATION_UNKNOWN, - ZATHURA_LINK_DESTINATION_XYZ, - ZATHURA_LINK_DESTINATION_FIT, - ZATHURA_LINK_DESTINATION_FITH, - ZATHURA_LINK_DESTINATION_FITV, - ZATHURA_LINK_DESTINATION_FITR, - ZATHURA_LINK_DESTINATION_FITB, - ZATHURA_LINK_DESTINATION_FITBH, - ZATHURA_LINK_DESTINATION_FITBV + ZATHURA_LINK_DESTINATION_UNKNOWN, + ZATHURA_LINK_DESTINATION_XYZ, + ZATHURA_LINK_DESTINATION_FIT, + ZATHURA_LINK_DESTINATION_FITH, + ZATHURA_LINK_DESTINATION_FITV, + ZATHURA_LINK_DESTINATION_FITR, + ZATHURA_LINK_DESTINATION_FITB, + ZATHURA_LINK_DESTINATION_FITBH, + ZATHURA_LINK_DESTINATION_FITBV } zathura_link_destination_type_t; typedef struct zathura_link_target_s @@ -232,7 +232,7 @@ void zathura_index_element_free(zathura_index_element_t* index); * Creates a list that should be used to store \ref * zathura_document_information_entry_t entries * - * @return A list or NULL if an error occured + * @return A list or NULL if an error occurred */ girara_list_t* zathura_document_information_entry_list_new(); @@ -242,7 +242,7 @@ girara_list_t* zathura_document_information_entry_list_new(); * @param type The type * @param value The value * - * @return A new entry or NULL if an error occured + * @return A new entry or NULL if an error occurred */ zathura_document_information_entry_t* zathura_document_information_entry_new(zathura_document_information_type_t @@ -255,4 +255,9 @@ zathura_document_information_entry_new(zathura_document_information_type_t */ void zathura_document_information_entry_free(zathura_document_information_entry_t* entry); +/** + * Context for MIME type detection + */ +typedef struct zathura_content_type_context_s zathura_content_type_context_t; + #endif // TYPES_H diff --git a/zathura/utils.c b/zathura/utils.c index 531196c..d99a461 100644 --- a/zathura/utils.c +++ b/zathura/utils.c @@ -52,13 +52,13 @@ file_valid_extension(zathura_t* zathura, const char* path) return false; } - const gchar* content_type = guess_content_type(path); + char* content_type = zathura_content_type_guess(zathura->content_type_context, path); if (content_type == NULL) { return false; } zathura_plugin_t* plugin = zathura_plugin_manager_get_plugin(zathura->plugins.manager, content_type); - g_free((void*)content_type); + g_free(content_type); return (plugin == NULL) ? false : true; } diff --git a/zathura/utils.h b/zathura/utils.h index a1902f0..c30d3f9 100644 --- a/zathura/utils.h +++ b/zathura/utils.h @@ -28,7 +28,7 @@ typedef struct page_offset_s bool file_valid_extension(zathura_t* zathura, const char* path); /** - * Generates the document index based upon the list retreived from the document + * Generates the document index based upon the list retrieved from the document * object. * * @param model The tree model @@ -64,7 +64,7 @@ zathura_rectangle_t recalc_rectangle(zathura_page_t* page, zathura_rectangle_t r * @param zathura The zathura instance * @param page The page object * @return The page widget of the page - * @return NULL if an error occured + * @return NULL if an error occurred */ GtkWidget* zathura_page_get_widget(zathura_t* zathura, zathura_page_t* page); diff --git a/zathura/zathura.c b/zathura/zathura.c index c9ec071..163063b 100644 --- a/zathura/zathura.c +++ b/zathura/zathura.c @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -21,6 +20,7 @@ #ifdef G_OS_UNIX #include +#include #endif #include "bookmarks.h" @@ -43,6 +43,7 @@ #include "dbus-interface.h" #include "css-definitions.h" #include "synctex.h" +#include "content-type.h" typedef struct zathura_document_info_s { zathura_t* zathura; @@ -93,7 +94,8 @@ zathura_create(void) } /* UI */ - if ((zathura->ui.session = girara_session_create()) == NULL) { + zathura->ui.session = girara_session_create(); + if (zathura->ui.session == NULL) { goto error_out; } @@ -102,6 +104,9 @@ zathura_create(void) zathura->signals.sigterm = g_unix_signal_add(SIGTERM, zathura_signal_sigterm, zathura); #endif + /* MIME type detection */ + zathura->content_type_context = zathura_content_type_new(); + zathura->ui.session->global.data = zathura; return zathura; @@ -113,32 +118,27 @@ error_out: return NULL; } -bool -zathura_init(zathura_t* zathura) +static void +create_directories(zathura_t* zathura) { - if (zathura == NULL) { - return false; + static const unsigned int mode = 0711; + + if (g_mkdir_with_parents(zathura->config.config_dir, mode) == -1) { + girara_error("Could not create '%s': %s", zathura->config.config_dir, + strerror(errno)); } - /* create zathura (config/data) directory */ - if (g_mkdir_with_parents(zathura->config.config_dir, 0771) == -1) { - girara_error("Could not create '%s': %s", zathura->config.config_dir, strerror(errno)); + if (g_mkdir_with_parents(zathura->config.data_dir, mode) == -1) { + girara_error("Could not create '%s': %s", zathura->config.data_dir, + strerror(errno)); } +} - if (g_mkdir_with_parents(zathura->config.data_dir, 0771) == -1) { - girara_error("Could not create '%s': %s", zathura->config.data_dir, strerror(errno)); - } - - /* load plugins */ - zathura_plugin_manager_load(zathura->plugins.manager); - - /* configuration */ - config_load_default(zathura); - config_load_files(zathura); - - /* UI */ +static bool +init_ui(zathura_t* zathura) +{ if (girara_session_init(zathura->ui.session, "zathura") == false) { - goto error_free; + return false; } /* girara events */ @@ -146,16 +146,9 @@ zathura_init(zathura_t* zathura) zathura->ui.session->events.unknown_command = cb_unknown_command; /* zathura signals */ - zathura->signals.refresh_view = g_signal_new("refresh-view", - GTK_TYPE_WIDGET, - G_SIGNAL_RUN_LAST, - 0, - NULL, - NULL, - g_cclosure_marshal_generic, - G_TYPE_NONE, - 1, - G_TYPE_POINTER); + zathura->signals.refresh_view = g_signal_new( + "refresh-view", GTK_TYPE_WIDGET, G_SIGNAL_RUN_LAST, 0, NULL, NULL, + g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_POINTER); g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), "refresh-view", G_CALLBACK(cb_refresh_view), zathura); @@ -165,28 +158,29 @@ zathura_init(zathura_t* zathura) gtk_grid_set_row_homogeneous(GTK_GRID(zathura->ui.page_widget), TRUE); gtk_grid_set_column_homogeneous(GTK_GRID(zathura->ui.page_widget), TRUE); if (zathura->ui.page_widget == NULL) { - goto error_free; + return false; } - g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "size-allocate", G_CALLBACK(cb_view_resized), zathura); + g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "size-allocate", + G_CALLBACK(cb_view_resized), zathura); GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment( GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); /* Connect hadjustment signals */ g_signal_connect(G_OBJECT(hadjustment), "value-changed", - G_CALLBACK(cb_view_hadjustment_value_changed), zathura); + G_CALLBACK(cb_view_hadjustment_value_changed), zathura); g_signal_connect(G_OBJECT(hadjustment), "changed", - G_CALLBACK(cb_view_hadjustment_changed), zathura); + G_CALLBACK(cb_view_hadjustment_changed), zathura); GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); /* Connect vadjustment signals */ g_signal_connect(G_OBJECT(vadjustment), "value-changed", - G_CALLBACK(cb_view_vadjustment_value_changed), zathura); + G_CALLBACK(cb_view_vadjustment_value_changed), zathura); g_signal_connect(G_OBJECT(vadjustment), "changed", - G_CALLBACK(cb_view_vadjustment_changed), zathura); + G_CALLBACK(cb_view_vadjustment_changed), zathura); /* page view alignment */ gtk_widget_set_halign(zathura->ui.page_widget, GTK_ALIGN_CENTER); @@ -200,66 +194,39 @@ zathura_init(zathura_t* zathura) gtk_widget_show(zathura->ui.page_widget); /* statusbar */ - zathura->ui.statusbar.file = girara_statusbar_item_add(zathura->ui.session, TRUE, TRUE, TRUE, NULL); + zathura->ui.statusbar.file = + girara_statusbar_item_add(zathura->ui.session, TRUE, TRUE, TRUE, NULL); if (zathura->ui.statusbar.file == NULL) { - goto error_free; + return false; } - zathura->ui.statusbar.buffer = girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL); + zathura->ui.statusbar.buffer = + girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL); if (zathura->ui.statusbar.buffer == NULL) { - goto error_free; + return false; } - zathura->ui.statusbar.page_number = girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL); + zathura->ui.statusbar.page_number = + girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL); if (zathura->ui.statusbar.page_number == NULL) { - goto error_free; + return false; } - girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, _("[No name]")); + girara_statusbar_item_set_text(zathura->ui.session, + zathura->ui.statusbar.file, _("[No name]")); /* signals */ - g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), zathura); + g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy", + G_CALLBACK(cb_destroy), zathura); - /* database */ - char* database = NULL; - girara_setting_get(zathura->ui.session, "database", &database); + return true; +} - if (g_strcmp0(database, "plain") == 0) { - girara_debug("Using plain database backend."); - zathura->database = zathura_plaindatabase_new(zathura->config.data_dir); -#ifdef WITH_SQLITE - } else if (g_strcmp0(database, "sqlite") == 0) { - girara_debug("Using sqlite database backend."); - char* tmp = g_build_filename(zathura->config.data_dir, "bookmarks.sqlite", NULL); - zathura->database = zathura_sqldatabase_new(tmp); - g_free(tmp); -#endif - } else if (g_strcmp0(database, "null") != 0) { - girara_error("Database backend '%s' is not supported.", database); - } - - if (zathura->database == NULL && g_strcmp0(database, "null") != 0) { - girara_error("Unable to initialize database. Bookmarks won't be available."); - } else { - g_object_set(G_OBJECT(zathura->ui.session->command_history), "io", zathura->database, NULL); - } - g_free(database); - - /* bookmarks */ - zathura->bookmarks.bookmarks = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare, - (girara_free_function_t) zathura_bookmark_free); - - /* jumplist */ - int jumplist_size = 20; - girara_setting_get(zathura->ui.session, "jumplist-size", &jumplist_size); - - zathura->jumplist.max_size = jumplist_size < 0 ? 0 : jumplist_size; - zathura->jumplist.list = NULL; - zathura->jumplist.size = 0; - zathura->jumplist.cur = NULL; - - /* CSS for index mode */ - GiraraTemplate* csstemplate = girara_session_get_template(zathura->ui.session); +static void +init_css(zathura_t* zathura) +{ + GiraraTemplate* csstemplate = + girara_session_get_template(zathura->ui.session); static const char* index_settings[] = { "index-fg", @@ -271,8 +238,8 @@ zathura_init(zathura_t* zathura) for (size_t s = 0; s < LENGTH(index_settings); ++s) { girara_template_add_variable(csstemplate, index_settings[s]); - char* tmp_value = NULL; - GdkRGBA rgba = { 0, 0, 0, 0 }; + char* tmp_value = NULL; + GdkRGBA rgba = {0, 0, 0, 0}; girara_setting_get(zathura->ui.session, index_settings[s], &tmp_value); if (tmp_value != NULL) { gdk_rgba_parse(&rgba, tmp_value); @@ -280,24 +247,111 @@ zathura_init(zathura_t* zathura) } char* color = gdk_rgba_to_string(&rgba); - girara_template_set_variable_value(csstemplate, - index_settings[s], color); + girara_template_set_variable_value(csstemplate, index_settings[s], color); g_free(color); } - char* css = g_strdup_printf("%s\n%s", girara_template_get_base(csstemplate), CSS_TEMPLATE_INDEX); + char* css = g_strdup_printf("%s\n%s", girara_template_get_base(csstemplate), + CSS_TEMPLATE_INDEX); girara_template_set_base(csstemplate, css); g_free(css); +} - /* Shortcut helpers */ +static void +init_database(zathura_t* zathura) +{ + char* database = NULL; + girara_setting_get(zathura->ui.session, "database", &database); + + if (g_strcmp0(database, "plain") == 0) { + girara_debug("Using plain database backend."); + zathura->database = zathura_plaindatabase_new(zathura->config.data_dir); +#ifdef WITH_SQLITE + } else if (g_strcmp0(database, "sqlite") == 0) { + girara_debug("Using sqlite database backend."); + char* tmp = + g_build_filename(zathura->config.data_dir, "bookmarks.sqlite", NULL); + zathura->database = zathura_sqldatabase_new(tmp); + g_free(tmp); +#endif + } else if (g_strcmp0(database, "null") != 0) { + girara_error("Database backend '%s' is not supported.", database); + } + + if (zathura->database == NULL && g_strcmp0(database, "null") != 0) { + girara_error( + "Unable to initialize database. Bookmarks won't be available."); + } + else { + g_object_set(G_OBJECT(zathura->ui.session->command_history), "io", + zathura->database, NULL); + } + g_free(database); +} + +static void +init_jumplist(zathura_t* zathura) +{ + int jumplist_size = 20; + girara_setting_get(zathura->ui.session, "jumplist-size", &jumplist_size); + + zathura->jumplist.max_size = jumplist_size < 0 ? 0 : jumplist_size; + zathura->jumplist.list = NULL; + zathura->jumplist.size = 0; + zathura->jumplist.cur = NULL; +} + +static void +init_shortcut_helpers(zathura_t* zathura) +{ zathura->shortcut.mouse.x = 0; zathura->shortcut.mouse.y = 0; zathura->shortcut.toggle_page_mode.pages = 2; - zathura->shortcut.toggle_presentation_mode.pages = 1; + zathura->shortcut.toggle_presentation_mode.pages = 1; zathura->shortcut.toggle_presentation_mode.first_page_column_list = NULL; - zathura->shortcut.toggle_presentation_mode.zoom = 1.0; + zathura->shortcut.toggle_presentation_mode.zoom = 1.0; +} + +bool +zathura_init(zathura_t* zathura) +{ + if (zathura == NULL) { + return false; + } + + /* create zathura (config/data) directory */ + create_directories(zathura); + + /* load plugins */ + zathura_plugin_manager_load(zathura->plugins.manager); + + /* configuration */ + config_load_default(zathura); + config_load_files(zathura); + + /* UI */ + if (!init_ui(zathura)) { + goto error_free; + } + + /* database */ + init_database(zathura); + + /* bookmarks */ + zathura->bookmarks.bookmarks = girara_sorted_list_new2( + (girara_compare_function_t)zathura_bookmarks_compare, + (girara_free_function_t)zathura_bookmark_free); + + /* jumplist */ + init_jumplist(zathura); + + /* CSS for index mode */ + init_css(zathura); + + /* Shortcut helpers */ + init_shortcut_helpers(zathura); /* Start D-Bus service */ bool dbus = true; @@ -326,6 +380,16 @@ zathura_free(zathura_t* zathura) document_close(zathura, false); + /* MIME type detection */ + zathura_content_type_free(zathura->content_type_context); + +#ifdef G_OS_UNIX + if (zathura->signals.sigterm > 0) { + g_source_remove(zathura->signals.sigterm); + zathura->signals.sigterm = 0; + } +#endif + /* stop D-Bus */ if (zathura->dbus != NULL) { g_object_unref(zathura->dbus); @@ -337,7 +401,9 @@ zathura_free(zathura_t* zathura) } /* shortcut */ - g_free(zathura->shortcut.toggle_presentation_mode.first_page_column_list); + if (zathura->shortcut.toggle_presentation_mode.first_page_column_list != NULL) { + g_free(zathura->shortcut.toggle_presentation_mode.first_page_column_list); + } /* stdin support */ if (zathura->stdin_support.file != NULL) { @@ -466,6 +532,7 @@ zathura_set_argv(zathura_t* zathura, char** argv) zathura->global.arguments = argv; } +#ifdef G_OS_UNIX static gchar* prepare_document_open_from_stdin(const char* path) { @@ -483,58 +550,60 @@ prepare_document_open_from_stdin(const char* path) return NULL; } - GError* error = NULL; - gchar* file = NULL; - gint handle = g_file_open_tmp("zathura.stdin.XXXXXX", &file, &error); - if (handle == -1) { + if (infileno == -1) { + girara_error("Can not read from file descriptor."); + return NULL; + } + + GInputStream* input_stream = g_unix_input_stream_new(infileno, false); + if (input_stream == NULL) { + girara_error("Can not read from file descriptor."); + return NULL; + + } + + GFileIOStream* iostream = NULL; + GError* error = NULL; + GFile* tmpfile = g_file_new_tmp("zathura.stdin.XXXXXX", &iostream, &error); + if (tmpfile == NULL) { if (error != NULL) { girara_error("Can not create temporary file: %s", error->message); g_error_free(error); } + g_object_unref(input_stream); return NULL; } - // read and dump to temporary file - if (infileno == -1) { - girara_error("Can not read from file descriptor."); - close(handle); - g_unlink(file); - g_free(file); - return NULL; - } - - char buffer[BUFSIZ]; - ssize_t count = 0; - while ((count = read(infileno, buffer, BUFSIZ)) > 0) { - if (write(handle, buffer, count) != count) { - girara_error("Can not write to temporary file: %s", file); - close(handle); - g_unlink(file); - g_free(file); - return NULL; + const ssize_t count = g_output_stream_splice( + g_io_stream_get_output_stream(G_IO_STREAM(iostream)), input_stream, + G_OUTPUT_STREAM_SPLICE_NONE, NULL, &error); + g_object_unref(input_stream); + g_object_unref(iostream); + if (count == -1) { + if (error != NULL) { + girara_error("Can not write to temporary file: %s", error->message); + g_error_free(error); } - } - - close(handle); - - if (count != 0) { - girara_error("Can not read from file descriptor."); - g_unlink(file); - g_free(file); + g_file_delete(tmpfile, NULL, NULL); + g_object_unref(tmpfile); return NULL; } + char* file = g_file_get_path(tmpfile); + g_object_unref(tmpfile); + return file; } +#endif static gchar* prepare_document_open_from_gfile(GFile* source) { - gchar* file = NULL; + gchar* file = NULL; GFileIOStream* iostream = NULL; - GError* error = NULL; + GError* error = NULL; - GFile *tmpfile = g_file_new_tmp("zathura.gio.XXXXXX", &iostream, &error); + GFile* tmpfile = g_file_new_tmp("zathura.gio.XXXXXX", &iostream, &error); if (tmpfile == NULL) { if (error != NULL) { girara_error("Can not create temporary file: %s", error->message); @@ -543,7 +612,8 @@ prepare_document_open_from_gfile(GFile* source) return NULL; } - gboolean rc = g_file_copy(source, tmpfile, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error); + gboolean rc = g_file_copy(source, tmpfile, G_FILE_COPY_OVERWRITE, NULL, NULL, + NULL, &error); if (rc == FALSE) { if (error != NULL) { girara_error("Can not copy to temporary file: %s", error->message); @@ -572,7 +642,9 @@ document_info_open(gpointer data) char* file = NULL; if (g_strcmp0(document_info->path, "-") == 0 || g_str_has_prefix(document_info->path, "/proc/self/fd/") == true) { +#ifdef G_OS_UNIX file = prepare_document_open_from_stdin(document_info->path); +#endif if (file == NULL) { girara_notify(document_info->zathura->ui.session, GIRARA_ERROR, _("Could not read file from stdin and write it to a temporary file.")); @@ -695,7 +767,7 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* gchar* file_uri = NULL; zathura_error_t error = ZATHURA_ERROR_OK; - zathura_document_t* document = zathura_document_open(zathura->plugins.manager, path, uri, password, &error); + zathura_document_t* document = zathura_document_open(zathura, path, uri, password, &error); if (document == NULL) { if (error == ZATHURA_ERROR_INVALID_PASSWORD) { @@ -870,7 +942,7 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char* } /* set up recolor info in ZathuraRenderer */ - char* recolor_dark = NULL; + char* recolor_dark = NULL; char* recolor_light = NULL; girara_setting_get(zathura->ui.session, "recolor-darkcolor", &recolor_dark); girara_setting_get(zathura->ui.session, "recolor-lightcolor", &recolor_light); @@ -1413,10 +1485,10 @@ adjust_view(zathura_t* zathura) if (adjust_mode == ZATHURA_ADJUST_WIDTH || (adjust_mode == ZATHURA_ADJUST_BESTFIT && page_ratio < view_ratio)) { - newscale = scale * (double)view_width / (double)document_width; + newscale *= (double)view_width / (double)document_width; } else if (adjust_mode == ZATHURA_ADJUST_BESTFIT) { - newscale = scale * (double)view_height / (double)cell_height; + newscale *= (double)view_height / (double)cell_height; } else { goto error_ret; @@ -1428,8 +1500,8 @@ adjust_view(zathura_t* zathura) zathura_document_get_cell_size(zathura->document, &new_cell_height, &new_cell_width); /* if the change in scale changes page cell dimensions by at least one pixel, render */ - if (abs(new_cell_width - cell_width) > 1 || - abs(new_cell_height - cell_height) > 1) { + if (abs((int)new_cell_width - (int)cell_width) > 1 || + abs((int)new_cell_height - (int)cell_height) > 1) { render_all(zathura); refresh_view(zathura); diff --git a/zathura/zathura.h b/zathura/zathura.h index e536b56..904b938 100644 --- a/zathura/zathura.h +++ b/zathura/zathura.h @@ -6,7 +6,9 @@ #include #include #include +#ifdef GDK_WINDOWING_X11 #include +#endif #include "macros.h" #include "types.h" @@ -222,6 +224,11 @@ struct zathura_s double zoom; } toggle_presentation_mode; } shortcut; + + /** + * Context for MIME type detection + */ + zathura_content_type_context_t* content_type_context; }; /** @@ -304,7 +311,7 @@ void zathura_set_argv(zathura_t* zathura, char** argv); * @param password The password of the file * @param page_number Open given page number * - * @return If no error occured true, otherwise false, is returned. + * @return If no error occurred true, otherwise false, is returned. */ bool document_open(zathura_t* zathura, const char* path, const char* uri, const char* password, int page_number); @@ -317,7 +324,7 @@ bool document_open(zathura_t* zathura, const char* path, const char* uri, const * @param password The password of the file * @param synctex Open at the given SyncTeX string * - * @return If no error occured true, otherwise false, is returned. + * @return If no error occurred true, otherwise false, is returned. */ bool document_open_synctex(zathura_t* zathura, const char* path, const char* uri, const char* password, const char* synctex); @@ -343,7 +350,7 @@ void document_open_idle(zathura_t* zathura, const char* path, * @param path The path * @param overwrite Overwrite existing file * - * @return If no error occured true, otherwise false, is returned. + * @return If no error occurred true, otherwise false, is returned. */ bool document_save(zathura_t* zathura, const char* path, bool overwrite); @@ -352,7 +359,7 @@ bool document_save(zathura_t* zathura, const char* path, bool overwrite); * * @param zathura The zathura session * @param keep_monitor Set to true if monitor should be kept (sc_reload) - * @return If no error occured true, otherwise false, is returned. + * @return If no error occurred true, otherwise false, is returned. */ bool document_close(zathura_t* zathura, bool keep_monitor); @@ -361,7 +368,7 @@ bool document_close(zathura_t* zathura, bool keep_monitor); * * @param zathura The zathura session * @param page_id The id of the page that should be set - * @return If no error occured true, otherwise false, is returned. + * @return If no error occurred true, otherwise false, is returned. */ bool page_set(zathura_t* zathura, unsigned int page_id); @@ -371,7 +378,7 @@ bool page_set(zathura_t* zathura, unsigned int page_id); * @param zathura Zathura session * @param position_x X coordinate * @param position_y Y coordinate - * @return If no error occured true, otherwise false, is returned. + * @return If no error occurred true, otherwise false, is returned. */ bool position_set(zathura_t* zathura, double position_x, double position_y);