mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 13:35:59 +01:00
Update coding standard
This commit is contained in:
parent
abc7deadd3
commit
890d6b3299
5 changed files with 47 additions and 36 deletions
|
@ -26,8 +26,7 @@ buffer_changed(girara_session_t* session)
|
||||||
if(buffer) {
|
if(buffer) {
|
||||||
girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, buffer);
|
girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, buffer);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, "");
|
girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,24 +302,33 @@ zathura_page_render(zathura_page_t* page)
|
||||||
zathura_index_element_t*
|
zathura_index_element_t*
|
||||||
zathura_index_element_new(const char* title)
|
zathura_index_element_new(const char* title)
|
||||||
{
|
{
|
||||||
if (!title)
|
if(!title) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
zathura_index_element_t* res = g_malloc0(sizeof(zathura_index_element_t));
|
zathura_index_element_t* res = g_malloc0(sizeof(zathura_index_element_t));
|
||||||
if (!res)
|
|
||||||
|
if(!res) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
res->title = g_strdup(title);
|
res->title = g_strdup(title);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zathura_index_element_free(zathura_index_element_t* index)
|
zathura_index_element_free(zathura_index_element_t* index)
|
||||||
{
|
{
|
||||||
if (!index)
|
if(!index) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
g_free(index->title);
|
g_free(index->title);
|
||||||
if (index->type == ZATHURA_LINK_EXTERNAL)
|
|
||||||
|
if(index->type == ZATHURA_LINK_EXTERNAL) {
|
||||||
g_free(index->target.uri);
|
g_free(index->target.uri);
|
||||||
|
}
|
||||||
|
|
||||||
g_free(index);
|
g_free(index);
|
||||||
}
|
}
|
||||||
|
|
46
ft/pdf/pdf.c
46
ft/pdf/pdf.c
|
@ -89,63 +89,67 @@ pdf_document_free(zathura_document_t* document)
|
||||||
static void
|
static void
|
||||||
build_index(pdf_document_t* pdf, girara_tree_node_t* root, PopplerIndexIter* iter)
|
build_index(pdf_document_t* pdf, girara_tree_node_t* root, PopplerIndexIter* iter)
|
||||||
{
|
{
|
||||||
if (!root || !iter)
|
if(!root || !iter) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
PopplerAction* action = poppler_index_iter_get_action(iter);
|
PopplerAction* action = poppler_index_iter_get_action(iter);
|
||||||
if (!action)
|
|
||||||
|
if(!action) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
gchar* markup = g_markup_escape_text(action->any.title, -1);
|
gchar* markup = g_markup_escape_text(action->any.title, -1);
|
||||||
zathura_index_element_t* indexelement = zathura_index_element_new(markup);
|
zathura_index_element_t* indexelement = zathura_index_element_new(markup);
|
||||||
if (action->type == POPPLER_ACTION_URI)
|
|
||||||
{
|
if(action->type == POPPLER_ACTION_URI) {
|
||||||
indexelement->type = ZATHURA_LINK_EXTERNAL;
|
indexelement->type = ZATHURA_LINK_EXTERNAL;
|
||||||
indexelement->target.uri = g_strdup(action->uri.uri);
|
indexelement->target.uri = g_strdup(action->uri.uri);
|
||||||
}
|
} else if (action->type == POPPLER_ACTION_GOTO_DEST) {
|
||||||
else if (action->type == POPPLER_ACTION_GOTO_DEST)
|
|
||||||
{
|
|
||||||
indexelement->type = ZATHURA_LINK_TO_PAGE;
|
indexelement->type = ZATHURA_LINK_TO_PAGE;
|
||||||
if (action->goto_dest.dest->type == POPPLER_DEST_NAMED)
|
|
||||||
{
|
if(action->goto_dest.dest->type == POPPLER_DEST_NAMED) {
|
||||||
PopplerDest* dest = poppler_document_find_dest(pdf->document, action->goto_dest.dest->named_dest);
|
PopplerDest* dest = poppler_document_find_dest(pdf->document, action->goto_dest.dest->named_dest);
|
||||||
if (dest)
|
if(dest) {
|
||||||
{
|
|
||||||
indexelement->target.page_number = dest->page_num - 1;
|
indexelement->target.page_number = dest->page_num - 1;
|
||||||
poppler_dest_free(dest);
|
poppler_dest_free(dest);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
indexelement->target.page_number = action->goto_dest.dest->page_num - 1;
|
indexelement->target.page_number = action->goto_dest.dest->page_num - 1;
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
poppler_action_free(action);
|
poppler_action_free(action);
|
||||||
zathura_index_element_free(indexelement);
|
zathura_index_element_free(indexelement);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
poppler_action_free(action);
|
poppler_action_free(action);
|
||||||
|
|
||||||
girara_tree_node_t* node = girara_node_append_data(root, indexelement);
|
girara_tree_node_t* node = girara_node_append_data(root, indexelement);
|
||||||
PopplerIndexIter* child = poppler_index_iter_get_child(iter);
|
PopplerIndexIter* child = poppler_index_iter_get_child(iter);
|
||||||
if (child)
|
|
||||||
|
if(child) {
|
||||||
build_index(pdf, node, child);
|
build_index(pdf, node, child);
|
||||||
|
}
|
||||||
|
|
||||||
poppler_index_iter_free(child);
|
poppler_index_iter_free(child);
|
||||||
|
|
||||||
} while (poppler_index_iter_next(iter));
|
} while (poppler_index_iter_next(iter));
|
||||||
}
|
}
|
||||||
|
|
||||||
girara_tree_node_t*
|
girara_tree_node_t*
|
||||||
pdf_document_index_generate(zathura_document_t* document)
|
pdf_document_index_generate(zathura_document_t* document)
|
||||||
{
|
{
|
||||||
if (!document || !document->data) {
|
if(!document || !document->data) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdf_document_t* pdf_document = (pdf_document_t*) document->data;
|
pdf_document_t* pdf_document = (pdf_document_t*) document->data;
|
||||||
PopplerIndexIter* iter = poppler_index_iter_new(pdf_document->document);
|
PopplerIndexIter* iter = poppler_index_iter_new(pdf_document->document);
|
||||||
if (!iter) {
|
|
||||||
|
if(!iter) {
|
||||||
// XXX: error message?
|
// XXX: error message?
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,7 @@ sc_navigate(girara_session_t* session, girara_argument_t* argument)
|
||||||
|
|
||||||
if(argument->n == NEXT) {
|
if(argument->n == NEXT) {
|
||||||
new_page = (new_page + 1) % number_of_pages;
|
new_page = (new_page + 1) % number_of_pages;
|
||||||
}
|
} else if(argument->n == PREVIOUS) {
|
||||||
else if(argument->n == PREVIOUS) {
|
|
||||||
new_page = (new_page + number_of_pages - 1) % number_of_pages;
|
new_page = (new_page + number_of_pages - 1) % number_of_pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
utils.c
14
utils.c
|
@ -31,10 +31,11 @@ file_get_extension(const char* path)
|
||||||
unsigned int i = strlen(path);
|
unsigned int i = strlen(path);
|
||||||
for(; i > 0; i--)
|
for(; i > 0; i--)
|
||||||
{
|
{
|
||||||
if(*(path + i) != '.')
|
if(*(path + i) != '.') {
|
||||||
continue;
|
continue;
|
||||||
else
|
} else {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!i) {
|
if(!i) {
|
||||||
|
@ -52,23 +53,22 @@ execute_command(char* const argv[], char** output)
|
||||||
}
|
}
|
||||||
|
|
||||||
int p[2];
|
int p[2];
|
||||||
if(pipe(p))
|
if(pipe(p)) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
|
|
||||||
if(pid == -1) { // failure
|
if(pid == -1) { // failure
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if(pid == 0) { // child
|
||||||
else if(pid == 0) { // child
|
|
||||||
dup2(p[1], 1);
|
dup2(p[1], 1);
|
||||||
close(p[0]);
|
close(p[0]);
|
||||||
|
|
||||||
if(execvp(argv[0], argv) == -1) {
|
if(execvp(argv[0], argv) == -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else { // parent
|
||||||
else { // parent
|
|
||||||
dup2(p[0], 0);
|
dup2(p[0], 0);
|
||||||
close(p[1]);
|
close(p[1]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue