fix some issues, use g_ascii_dtostr to do int to str convertions

This commit is contained in:
Jonathan Teran 2021-07-28 00:27:24 -03:00 committed by Sebastian Ramacher
parent 83a334820b
commit 6d4708937e
5 changed files with 16 additions and 43 deletions

View file

@ -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

View file

@ -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``

View file

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

View file

@ -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) {

View file

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