Commit 6d470893 authored by Jonathan Teran's avatar Jonathan Teran Committed by Sebastian Ramacher
Browse files

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

parent 83a33482
......@@ -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
......
......@@ -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``
......
......@@ -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 (r != NULL) {
s = girara_replace_substring(r, "$p", page_buf);
g_free(r);
r = NULL;
if (s != NULL) {
girara_list_iterator_set(iter, s);
}
}
girara_list_iterator_set(iter, s ? s : r);
);
g_free(page_buf);
}
return girara_exec_with_argument_list(session, argument_list);
......
......@@ -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) {
......
......@@ -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
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment