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 Close document
exec exec
Execute an external command. ``$f`` expands to the current document path, and ``$p`` to the Execute an external command. ``$FILE`` expands to the current document path,
current page number and ``$PAGE`` to the current page number
info info
Show document information Show document information

View file

@ -231,8 +231,8 @@ They can also be combined with modifiers:
* ``exec``: * ``exec``:
Execute an external command. ``$f`` expands to the current document path, Execute an external command. ``$FILE`` expands to the current document path,
and ``$p`` to the current page number. and ``$PAGE`` to the current page number.
* ``focus_inputbar`` * ``focus_inputbar``

View file

@ -535,33 +535,23 @@ cmd_exec(girara_session_t* session, girara_list_t* argument_list)
if (zathura->document != NULL) { if (zathura->document != NULL) {
const char* path = zathura_document_get_path(zathura->document); const char* path = zathura_document_get_path(zathura->document);
unsigned int page = zathura_document_get_current_page_number(zathura->document); unsigned int page = zathura_document_get_current_page_number(zathura->document);
char page_buf[ZATHURA_PAGE_NUMBER_MAX_DIGITS]; char page_buf[G_ASCII_DTOSTR_BUF_SIZE];
snprintf(page_buf, ZATHURA_PAGE_NUMBER_MAX_DIGITS, "%d", page); g_ascii_dtostr(page_buf, G_ASCII_DTOSTR_BUF_SIZE, page);
GIRARA_LIST_FOREACH_BODY_WITH_ITER(argument_list, char*, iter, value, GIRARA_LIST_FOREACH_BODY_WITH_ITER(argument_list, char*, iter, value,
char* r = girara_replace_substring(value, "$FILE", path); char* r = girara_replace_substring(value, "$FILE", path);
char* s = NULL;
if (r != NULL) { if (r != NULL) {
s = girara_replace_substring(r, "%", path); char* s = girara_replace_substring(r, "$PAGE", page_buf);
g_free(r); g_free(r);
r = NULL;
}
if (s != NULL) { if (s != NULL) {
r = girara_replace_substring(s, "$f", path); girara_list_iterator_set(iter, s);
g_free(s);
s = NULL;
} }
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); 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) { if (zathura->document != NULL) {
const char* path = zathura_document_get_path(zathura->document); const char* path = zathura_document_get_path(zathura->document);
unsigned int page = zathura_document_get_current_page_number(zathura->document); unsigned int page = zathura_document_get_current_page_number(zathura->document);
char page_buf[ZATHURA_PAGE_NUMBER_MAX_DIGITS]; char page_buf[G_ASCII_DTOSTR_BUF_SIZE];
snprintf(page_buf, ZATHURA_PAGE_NUMBER_MAX_DIGITS, "%d", page + 1); g_ascii_dtostr(page_buf, G_ASCII_DTOSTR_BUF_SIZE, page);
girara_argument_t new_argument = *argument; 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; return false;
} }
char* s = girara_replace_substring(r, "%", path); char* s = girara_replace_substring(r, "$PAGE", page_buf);
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);
g_free(r); g_free(r);
if (s == NULL) { if (s == NULL) {

View file

@ -70,11 +70,8 @@ enum {
ZOOM_SMOOTH ZOOM_SMOOTH
}; };
/* on page numbers */ /* unspecified page number */
enum { 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 ZATHURA_PAGE_NUMBER_UNSPECIFIED = INT_MIN
}; };