diff --git a/doc/man/zathura.1.rst b/doc/man/zathura.1.rst index b63b429..089dbf7 100644 --- a/doc/man/zathura.1.rst +++ b/doc/man/zathura.1.rst @@ -225,8 +225,8 @@ close Close document exec - Execute an external command. ``$f`` expands to the current document path, and ``$p`` to the - current page number + Execute an external command. ``$FILE`` expands to the current document path, + and ``$PAGE`` to the current page number info Show document information diff --git a/doc/man/zathurarc.5.rst b/doc/man/zathurarc.5.rst index 9d6692a..bf519ae 100644 --- a/doc/man/zathurarc.5.rst +++ b/doc/man/zathurarc.5.rst @@ -231,8 +231,8 @@ They can also be combined with modifiers: * ``exec``: - Execute an external command. ``$f`` expands to the current document path, - and ``$p`` to the current page number. + Execute an external command. ``$FILE`` expands to the current document path, + and ``$PAGE`` to the current page number. * ``focus_inputbar`` diff --git a/zathura/commands.c b/zathura/commands.c index 7684a60..29ae852 100644 --- a/zathura/commands.c +++ b/zathura/commands.c @@ -535,33 +535,23 @@ cmd_exec(girara_session_t* session, girara_list_t* argument_list) if (zathura->document != NULL) { const char* path = zathura_document_get_path(zathura->document); unsigned int page = zathura_document_get_current_page_number(zathura->document); - char page_buf[ZATHURA_PAGE_NUMBER_MAX_DIGITS]; - snprintf(page_buf, ZATHURA_PAGE_NUMBER_MAX_DIGITS, "%d", page); + char page_buf[G_ASCII_DTOSTR_BUF_SIZE]; + g_ascii_dtostr(page_buf, G_ASCII_DTOSTR_BUF_SIZE, page); GIRARA_LIST_FOREACH_BODY_WITH_ITER(argument_list, char*, iter, value, char* r = girara_replace_substring(value, "$FILE", path); - char* s = NULL; if (r != NULL) { - s = girara_replace_substring(r, "%", path); + char* s = girara_replace_substring(r, "$PAGE", page_buf); g_free(r); - r = NULL; - } - if (s != NULL) { - r = girara_replace_substring(s, "$f", path); - g_free(s); - s = NULL; + if (s != NULL) { + girara_list_iterator_set(iter, s); + } } - - if (r != NULL) { - s = girara_replace_substring(r, "$p", page_buf); - g_free(r); - r = NULL; - } - - girara_list_iterator_set(iter, s ? s : r); ); + + g_free(page_buf); } return girara_exec_with_argument_list(session, argument_list); diff --git a/zathura/shortcuts.c b/zathura/shortcuts.c index 77731cc..745e8a6 100644 --- a/zathura/shortcuts.c +++ b/zathura/shortcuts.c @@ -1470,8 +1470,8 @@ sc_exec(girara_session_t* session, girara_argument_t* argument, girara_event_t* if (zathura->document != NULL) { const char* path = zathura_document_get_path(zathura->document); unsigned int page = zathura_document_get_current_page_number(zathura->document); - char page_buf[ZATHURA_PAGE_NUMBER_MAX_DIGITS]; - snprintf(page_buf, ZATHURA_PAGE_NUMBER_MAX_DIGITS, "%d", page + 1); + char page_buf[G_ASCII_DTOSTR_BUF_SIZE]; + g_ascii_dtostr(page_buf, G_ASCII_DTOSTR_BUF_SIZE, page); girara_argument_t new_argument = *argument; @@ -1480,21 +1480,7 @@ sc_exec(girara_session_t* session, girara_argument_t* argument, girara_event_t* return false; } - char* s = girara_replace_substring(r, "%", path); - g_free(r); - - if (s == NULL) { - return false; - } - - r = girara_replace_substring(s, "$f", path); - g_free(s); - - if (r == NULL) { - return false; - } - - s = girara_replace_substring(r, "$p", page_buf); + char* s = girara_replace_substring(r, "$PAGE", page_buf); g_free(r); if (s == NULL) { diff --git a/zathura/zathura.h b/zathura/zathura.h index 3891ce7..ea0f038 100644 --- a/zathura/zathura.h +++ b/zathura/zathura.h @@ -70,11 +70,8 @@ enum { ZOOM_SMOOTH }; -/* on page numbers */ +/* unspecified page number */ enum { - /* We should never open a pdf with more that 99.999 pages... right? */ - ZATHURA_PAGE_NUMBER_MAX_DIGITS = 5, - /* unspecified page numbers */ ZATHURA_PAGE_NUMBER_UNSPECIFIED = INT_MIN };