Commit 5e7a7741 authored by Moritz Lipp's avatar Moritz Lipp
Browse files

Updated coding standard

parent 4c19c798
......@@ -12,7 +12,7 @@
gboolean
cb_destroy(GtkWidget* widget, gpointer data)
{
if(Zathura.UI.session) {
if (Zathura.UI.session) {
girara_session_destroy(Zathura.UI.session);
}
......@@ -28,7 +28,7 @@ buffer_changed(girara_session_t* session)
char* buffer = girara_buffer_get(session);
if(buffer) {
if (buffer) {
girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, buffer);
free(buffer);
} else {
......@@ -39,7 +39,7 @@ buffer_changed(girara_session_t* session)
void
cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
{
if(!Zathura.document || !Zathura.document->pages || !Zathura.UI.page_view) {
if (!Zathura.document || !Zathura.document->pages || !Zathura.UI.page_view) {
return;
}
......@@ -48,19 +48,19 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);
/* find page that fits */
for(unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++)
for (unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++)
{
zathura_page_t* page = Zathura.document->pages[page_id];
/* check for rendered attribute */
if(page->rendered) {
if (page->rendered) {
continue;
}
double begin = page->offset;
double end = page->offset + page->height;
if( ( (begin >= lower) && (end <= upper) ) /* page is in viewport */
if ( ( (begin >= lower) && (end <= upper) ) /* page is in viewport */
|| ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* end of the page is in viewport */
|| ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* begin of the page is in viewport */
) {
......
......@@ -13,7 +13,7 @@ cc_print(girara_session_t* session, char* input)
girara_completion_t* completion = girara_completion_init();
girara_completion_group_t* group = girara_completion_group_create(session, NULL);
if(!session || !input || !completion || !group)
if (!session || !input || !completion || !group)
return NULL;
girara_completion_add_group(completion, group);
......@@ -23,7 +23,7 @@ cc_print(girara_session_t* session, char* input)
};
char* output;
if(!execute_command(list_printers, &output)) {
if (!execute_command(list_printers, &output)) {
girara_completion_free(completion);
return false;
}
......@@ -33,9 +33,8 @@ cc_print(girara_session_t* session, char* input)
char* p = strtok(output, "\n");
char* q;
while(p)
{
if(!(p = strstr(p, "device for ")) || !(q = strchr(p, ':'))) {
while (p) {
if (!(p = strstr(p, "device for ")) || !(q = strchr(p, ':'))) {
p = strtok(NULL, "\n");
continue;
}
......@@ -43,7 +42,7 @@ cc_print(girara_session_t* session, char* input)
unsigned int printer_length = q - p - prefix_length;
char* printer_name = malloc(sizeof(char) * printer_length);
if(!printer_name) {
if (!printer_name) {
p = strtok(NULL, "\n");
continue;
}
......
......@@ -8,7 +8,7 @@
void
config_load_default(void)
{
if(!Zathura.UI.session)
if (!Zathura.UI.session)
return;
/* general settings */
......
......@@ -8,7 +8,7 @@
bool
djvu_document_open(zathura_document_t* document)
{
if(!document) {
if (!document) {
goto error_out;
}
......@@ -24,7 +24,7 @@ djvu_document_open(zathura_document_t* document)
document->functions.page_free = djvu_page_free;
document->data = malloc(sizeof(djvu_document_t));
if(!document->data) {
if (!document->data) {
goto error_out;
}
......@@ -36,7 +36,7 @@ djvu_document_open(zathura_document_t* document)
/* setup format */
djvu_document->format = ddjvu_format_create(DDJVU_FORMAT_RGB24, 0, NULL);
if(!djvu_document->format) {
if (!djvu_document->format) {
goto error_free;
}
......@@ -45,14 +45,14 @@ djvu_document_open(zathura_document_t* document)
/* setup context */
djvu_document->context = ddjvu_context_create("zathura");
if(!djvu_document->context) {
if (!djvu_document->context) {
goto error_free;
}
/* setup document */
djvu_document->document = ddjvu_document_create_by_filename(djvu_document->context, document->file_path, FALSE);
if(!djvu_document->document) {
if (!djvu_document->document) {
goto error_free;
}
......@@ -60,8 +60,8 @@ djvu_document_open(zathura_document_t* document)
ddjvu_message_t* msg;
ddjvu_message_wait(djvu_document->context);
while((msg = ddjvu_message_peek(djvu_document->context)) && (msg->m_any.tag != DDJVU_DOCINFO)) {
if(msg->m_any.tag == DDJVU_ERROR) {
while ((msg = ddjvu_message_peek(djvu_document->context)) && (msg->m_any.tag != DDJVU_DOCINFO)) {
if (msg->m_any.tag == DDJVU_ERROR) {
goto error_free;
}
......@@ -69,7 +69,7 @@ djvu_document_open(zathura_document_t* document)
}
/* decoding error */
if(ddjvu_document_decoding_error(djvu_document->document)) {
if (ddjvu_document_decoding_error(djvu_document->document)) {
goto error_free;
}
......@@ -79,11 +79,11 @@ djvu_document_open(zathura_document_t* document)
error_free:
if(djvu_document->format) {
if (djvu_document->format) {
ddjvu_format_release(djvu_document->format);
}
if(djvu_document->context) {
if (djvu_document->context) {
ddjvu_context_release(djvu_document->context);
}
......@@ -98,11 +98,11 @@ error_out:
bool
djvu_document_free(zathura_document_t* document)
{
if(!document) {
if (!document) {
return false;
}
if(document->data) {
if (document->data) {
djvu_document_t* djvu_document = (djvu_document_t*) document->data;
ddjvu_context_release(djvu_document->context);
ddjvu_document_release(djvu_document->document);
......@@ -122,14 +122,14 @@ djvu_document_index_generate(zathura_document_t* document)
bool
djvu_document_save_as(zathura_document_t* document, const char* path)
{
if(!document || !document->data || !path) {
if (!document || !document->data || !path) {
return false;
}
djvu_document_t* djvu_document = (djvu_document_t*) document->data;
FILE* fp = fopen(path, "w");
if(!fp) {
if (!fp) {
return false;
}
......@@ -148,14 +148,14 @@ djvu_document_attachments_get(zathura_document_t* document)
zathura_page_t*
djvu_page_get(zathura_document_t* document, unsigned int page)
{
if(!document || !document->data) {
if (!document || !document->data) {
return NULL;
}
djvu_document_t* djvu_document = (djvu_document_t*) document->data;
zathura_page_t* document_page = malloc(sizeof(zathura_page_t));
if(!document_page) {
if (!document_page) {
return NULL;
}
......@@ -165,9 +165,9 @@ djvu_page_get(zathura_document_t* document, unsigned int page)
ddjvu_status_t status;
ddjvu_pageinfo_t page_info;
while((status = ddjvu_document_get_pageinfo(djvu_document->document, page, &page_info)) < DDJVU_JOB_OK);
while ((status = ddjvu_document_get_pageinfo(djvu_document->document, page, &page_info)) < DDJVU_JOB_OK);
if(status >= DDJVU_JOB_FAILED) {
if (status >= DDJVU_JOB_FAILED) {
free(document_page);
return NULL;
}
......@@ -181,7 +181,7 @@ djvu_page_get(zathura_document_t* document, unsigned int page)
bool
djvu_page_free(zathura_page_t* page)
{
if(!page) {
if (!page) {
return false;
}
......@@ -211,7 +211,7 @@ djvu_page_form_fields_get(zathura_page_t* page)
GtkWidget*
djvu_page_render(zathura_page_t* page)
{
if(!Zathura.document || !page || !page->document) {
if (!Zathura.document || !page || !page->document) {
return NULL;
}
......@@ -219,7 +219,7 @@ djvu_page_render(zathura_page_t* page)
unsigned int page_width = Zathura.document->scale * page->width;
unsigned int page_height = Zathura.document->scale * page->height;
if(!page_width || !page_height) {
if (!page_width || !page_height) {
goto error_out;
}
......@@ -227,17 +227,17 @@ djvu_page_render(zathura_page_t* page)
djvu_document_t* djvu_document = (djvu_document_t*) page->document->data;
ddjvu_page_t* djvu_page = ddjvu_page_create_by_pageno(djvu_document->document, page->number);
if(!djvu_page) {
if (!djvu_page) {
goto error_out;
}
while(!ddjvu_page_decoding_done(djvu_page));
while (!ddjvu_page_decoding_done(djvu_page));
ddjvu_rect_t rrect = { 0, 0, page_width, page_height };
ddjvu_rect_t prect = { 0, 0, page_width, page_height };
guchar* buffer = malloc(sizeof(char) * (page_width * page_height * 3));
if(!buffer) {
if (!buffer) {
goto error_free;
}
......@@ -274,14 +274,14 @@ djvu_page_render(zathura_page_t* page)
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(buffer, GDK_COLORSPACE_RGB, FALSE, 8,
page_width, page_height, 3 * page_width, NULL, NULL);
if(!pixbuf) {
if (!pixbuf) {
goto error_free;
}
/* rotate page */
if(Zathura.document->rotate != 0) {
if (Zathura.document->rotate != 0) {
GdkPixbuf* pixbuf_temp = gdk_pixbuf_rotate_simple(pixbuf, gdk_angle);
if(!pixbuf_temp) {
if (!pixbuf_temp) {
goto error_free;
}
......@@ -290,7 +290,7 @@ djvu_page_render(zathura_page_t* page)
GtkWidget* image = gtk_image_new();
if(!image) {
if (!image) {
goto error_free;
}
......
......@@ -25,17 +25,17 @@ zathura_document_plugin_t zathura_document_plugins[] = {
zathura_document_t*
zathura_document_open(const char* path, const char* password)
{
if(!path) {
if (!path) {
goto error_out;
}
if(!file_exists(path)) {
if (!file_exists(path)) {
fprintf(stderr, "error: file does not exist\n");
goto error_out;
}
const char* file_extension = file_get_extension(path);
if(!file_extension) {
if (!file_extension) {
fprintf(stderr, "error: could not determine file type\n");
goto error_out;
}
......@@ -46,7 +46,7 @@ zathura_document_open(const char* path, const char* password)
path_max = PATH_MAX;
#else
path_max = pathconf(path,_PC_PATH_MAX);
if(path_max <= 0)
if (path_max <= 0)
path_max = 4096;
#endif
......@@ -54,16 +54,16 @@ zathura_document_open(const char* path, const char* password)
zathura_document_t* document = NULL;
real_path = malloc(sizeof(char) * path_max);
if(!real_path) {
if (!real_path) {
goto error_out;
}
if(!realpath(path, real_path)) {
if (!realpath(path, real_path)) {
goto error_free;
}
document = malloc(sizeof(zathura_document_t));
if(!document) {
if (!document) {
goto error_free;
}
......@@ -88,25 +88,25 @@ zathura_document_open(const char* path, const char* password)
document->functions.page_render = NULL;
/* init plugin with associated file type */
for(unsigned int i = 0; i < LENGTH(zathura_document_plugins); i++)
for (unsigned int i = 0; i < LENGTH(zathura_document_plugins); i++)
{
if(!strcmp(file_extension, zathura_document_plugins[i].file_extension)) {
if(zathura_document_plugins[i].open_function) {
if(zathura_document_plugins[i].open_function(document)) {
if (!strcmp(file_extension, zathura_document_plugins[i].file_extension)) {
if (zathura_document_plugins[i].open_function) {
if (zathura_document_plugins[i].open_function(document)) {
/* update statusbar */
girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, real_path);
/* read all pages */
document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t*));
if(!document->pages) {
if (!document->pages) {
goto error_free;
}
double offset = 0;
for(unsigned int page_id = 0; page_id < document->number_of_pages; page_id++)
for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++)
{
zathura_page_t* page = zathura_page_get(document, page_id);
if(!page) {
if (!page) {
goto error_free;
}
......@@ -131,8 +131,8 @@ error_free:
free(real_path);
if(document && document->pages) {
for(unsigned int page_id = 0; page_id < document->number_of_pages; page_id++)
if (document && document->pages) {
for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++)
{
zathura_page_free(document->pages[page_id]);
}
......@@ -150,12 +150,12 @@ error_out:
bool
zathura_document_free(zathura_document_t* document)
{
if(!document) {
if (!document) {
return false;
}
/* free pages */
for(unsigned int page_id = 0; page_id < document->number_of_pages; page_id++)
for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++)
{
zathura_page_free(document->pages[page_id]);
}
......@@ -163,10 +163,10 @@ zathura_document_free(zathura_document_t* document)
free(document->pages);
/* free document */
if(!document->functions.document_free) {
if (!document->functions.document_free) {
fprintf(stderr, "error: %s not implemented\n", __FUNCTION__);
if(document->file_path) {
if (document->file_path) {
free(document->file_path);
}
......@@ -176,7 +176,7 @@ zathura_document_free(zathura_document_t* document)
bool r = document->functions.document_free(document);
if(document->file_path) {
if (document->file_path) {
free(document->file_path);
}
......@@ -188,11 +188,11 @@ zathura_document_free(zathura_document_t* document)
bool
zathura_document_save_as(zathura_document_t* document, const char* path)
{
if(!document || !path) {
if (!document || !path) {
return false;
}
if(!document->functions.document_save_as) {
if (!document->functions.document_save_as) {
fprintf(stderr, "error: %s not implemented\n", __FUNCTION__);
return false;
}
......@@ -203,11 +203,11 @@ zathura_document_save_as(zathura_document_t* document, const char* path)
girara_tree_node_t*
zathura_document_index_generate(zathura_document_t* document)
{
if(!document) {
if (!document) {
return NULL;
}
if(!document->functions.document_index_generate) {
if (!document->functions.document_index_generate) {
fprintf(stderr, "error: %s not implemented\n", __FUNCTION__);
return NULL;
}
......@@ -224,11 +224,11 @@ zathura_document_index_free(zathura_list_t* list)
zathura_list_t*
zathura_document_attachments_get(zathura_document_t* document)
{
if(!document) {
if (!document) {
return NULL;
}
if(!document->functions.document_attachments_get) {
if (!document->functions.document_attachments_get) {
fprintf(stderr, "error: %s not implemented\n", __FUNCTION__);
return NULL;
}
......@@ -245,18 +245,18 @@ zathura_document_attachments_free(zathura_list_t* list)
zathura_page_t*
zathura_page_get(zathura_document_t* document, unsigned int page_id)
{
if(!document) {
if (!document) {
return NULL;
}
if(!document->functions.page_get) {
if (!document->functions.page_get) {
fprintf(stderr, "error: %s not implemented\n", __FUNCTION__);
return NULL;
}
zathura_page_t* page = document->functions.page_get(document, page_id);
if(page) {
if (page) {
page->number = page_id;
page->rendered = false;
g_static_mutex_init(&(page->lock));
......@@ -268,11 +268,11 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id)
bool
zathura_page_free(zathura_page_t* page)
{
if(!page || !page->document) {
if (!page || !page->document) {
return false;
}
if(!page->document->functions.page_free) {
if (!page->document->functions.page_free) {
fprintf(stderr, "error: %s not implemented\n", __FUNCTION__);
return false;
}
......@@ -283,11 +283,11 @@ zathura_page_free(zathura_page_t* page)
zathura_list_t*
zathura_page_search_text(zathura_page_t* page, const char* text)
{
if(!page || !page->document || !text) {
if (!page || !page->document || !text) {
return NULL;
}
if(!page->document->functions.page_search_text) {
if (!page->document->functions.page_search_text) {
fprintf(stderr, "error: %s not implemented\n", __FUNCTION__);
return NULL;
}
......@@ -298,11 +298,11 @@ zathura_page_search_text(zathura_page_t* page, const char* text)
zathura_list_t*
zathura_page_links_get(zathura_page_t* page)
{
if(!page || !page->document) {
if (!page || !page->document) {
return NULL;
}
if(!page->document->functions.page_links_get) {
if (!page->document->functions.page_links_get) {
fprintf(stderr, "error: %s not implemented\n", __FUNCTION__);
return NULL;
}
......@@ -319,11 +319,11 @@ zathura_page_links_free(zathura_list_t* list)
zathura_list_t*
zathura_page_form_fields_get(zathura_page_t* page)
{
if(!page || !page->document) {
if (!page || !page->document) {
return NULL;
}
if(!page->document->functions.page_form_fields_get) {
if (!page->document->functions.page_form_fields_get) {
fprintf(stderr, "error: %s not implemented\n", __FUNCTION__);
return NULL;
}
......@@ -340,18 +340,18 @@ zathura_page_form_fields_free(zathura_list_t* list)
GtkWidget*
zathura_page_render(zathura_page_t* page)
{
if(!page || !page->document) {
if (!page || !page->document) {
return NULL;
}
if(!page->document->functions.page_render) {
if (!page->document->functions.page_render) {
fprintf(stderr, "error: %s not implemented\n", __FUNCTION__);
return NULL;
}
GtkWidget* widget = page->document->functions.page_render(page);
if(widget) {
if (widget) {
page->rendered = true;
}
......@@ -361,13 +361,13 @@ zathura_page_render(zathura_page_t* page)
zathura_index_element_t*
zathura_index_element_new(const char* title)
{
if(!title) {
if (!title) {
return NULL;
}
zathura_index_element_t* res = g_malloc0(sizeof(zathura_index_element_t));
if(!res) {
if (!res) {
return NULL;
}
......@@ -379,13 +379,13 @@ zathura_index_element_new(const char* title)
void
zathura_index_element_free(zathura_index_element_t* index)
{
if(!index) {
if (!index) {
return;
}
g_free(index->title);
if(index->type == ZATHURA_LINK_EXTERNAL) {
if (index->type == ZATHURA_LINK_EXTERNAL) {
g_free(index->target.uri);
}
......
......@@ -9,7 +9,7 @@
bool
pdf_document_open(zathura_document_t* document)
{
if(!document) {
if (!document) {
goto error_out;
}
......@@ -25,7 +25,7 @@ pdf_document_open(zathura_document_t* document)
document->functions.page_free = pdf_page_free;
document->data = malloc(sizeof(pdf_document_t));
if(!document->data) {
if (!document->data) {
goto error_out;
}
......@@ -33,7 +33,7 @@ pdf_document_open(zathura_document_t* document)
GError* error = NULL;
char* file_uri = g_filename_to_uri(document->file_path, NULL, &error);
if(!file_uri) {
if (!file_uri) {
fprintf(stderr, "error: could not open file: %s\n", error->message);
goto error_free;
}
......@@ -41,7 +41,7 @@ pdf_document_open(zathura_document_t* document)
pdf_document_t* pdf_document = (pdf_document_t*) document->data;
pdf_document->document = poppler_document_new_from_file(file_uri, document->password, &error);
if(!pdf_document->document) {
if (!pdf_document->document) {
fprintf(stderr, "error: could not open file: %s\n", error->message);
goto error_free;
}
......@@ -54,11 +54,11 @@ pdf_document_open(zathura_document_t* document)
error_free: