Commit da61a695 authored by Moritz Lipp's avatar Moritz Lipp
Browse files

Merge branch 'master' of pwmt.org:zathura

parents d6574f57 ba11e68e
/* See LICENSE file for license and copyright information */
#define _BSD_SOURCE || _XOPEN_SOURCE >= 500
#define _BSD_SOURCE
#define _XOPEN_SOURCE 500
#include <regex.h>
#include <limits.h>
......@@ -18,8 +19,14 @@
#include <gdk/gdkkeysyms.h>
/* macros */
#define LENGTH(x) sizeof(x)/sizeof((x)[0])
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
#define CLEAN(m) (m & ~(GDK_MOD2_MASK) & ~(GDK_BUTTON1_MASK) & ~(GDK_BUTTON2_MASK) & ~(GDK_BUTTON3_MASK) & ~(GDK_BUTTON4_MASK) & ~(GDK_BUTTON5_MASK) & ~(GDK_LEAVE_NOTIFY_MASK))
#if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC) || defined(__clang__)
/* only gcc, clang and Intel's cc seem support this */
#define NORETURN __attribute__((noreturn))
#else
#define NORETURN
#endif
/* enums */
enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT,
......@@ -343,18 +350,18 @@ struct
/* function declarations */
void init_look();
void init_directories();
void init_bookmarks();
void init_keylist();
void init_settings();
void init_zathura();
void init_look(void);
void init_directories(void);
void init_bookmarks(void);
void init_keylist(void);
void init_settings(void);
void init_zathura(void);
void add_marker(int);
void build_index(GtkTreeModel*, GtkTreeIter*, PopplerIndexIter*);
void change_mode(int);
void calculate_offset(GtkWidget*, double*, double*);
void close_file(gboolean);
void enter_password();
void enter_password(void);
void highlight_result(int, PopplerRectangle*);
void draw(int);
void eval_marker(int);
......@@ -362,10 +369,10 @@ void notify(int, const char*);
gboolean open_file(char*, char*);
gboolean open_stdin(gchar*);
void open_uri(char*);
void out_of_memory();
void update_status();
void out_of_memory(void) NORETURN;
void update_status(void);
void read_configuration_file(const char*);
void read_configuration();
void read_configuration(void);
void recalcRectangle(int, PopplerRectangle*);
void setCompletionRowColor(GtkBox*, int, int);
void set_page(int);
......@@ -373,9 +380,9 @@ void switch_view(GtkWidget*);
GtkEventBox* createCompletionRow(GtkBox*, char*, char*, gboolean);
gchar* fix_path(const gchar*);
gchar* path_from_env(const gchar*);
gchar* get_home_dir();
gchar* get_home_dir(void);
Completion* completion_init();
Completion* completion_init(void);
CompletionGroup* completion_group_create(char*);
void completion_add_group(Completion*, CompletionGroup*);
void completion_free(Completion*);
......@@ -466,7 +473,7 @@ gboolean cb_watch_file(GFileMonitor*, GFile*, GFile*, GFileMonitorEvent, gpointe
/* function implementation */
void
init_look()
init_look(void)
{
/* parse */
gdk_color_parse(default_fgcolor, &(Zathura.Style.default_fg));
......@@ -557,14 +564,14 @@ gchar* path_from_env(const gchar* var)
return res;
}
gchar* get_home_dir()
gchar* get_home_dir(void)
{
const gchar* homedir = g_getenv("HOME");
return g_strdup(homedir ? homedir : g_get_home_dir());
}
void
init_directories()
init_directories(void)
{
/* setup directories */
if (!Zathura.Config.config_dir)
......@@ -594,7 +601,7 @@ init_directories()
}
void
init_bookmarks()
init_bookmarks(void)
{
/* create or open existing bookmark file */
Zathura.Bookmarks.data = g_key_file_new();
......@@ -619,7 +626,7 @@ init_bookmarks()
}
void
init_keylist()
init_keylist(void)
{
ShortcutList* e = NULL;
ShortcutList* p = NULL;
......@@ -644,7 +651,7 @@ init_keylist()
}
void
init_settings()
init_settings(void)
{
Zathura.State.filename = g_strdup((char*) default_text);
Zathura.Global.adjust_mode = adjust_open;
......@@ -653,7 +660,7 @@ init_settings()
}
void
init_zathura()
init_zathura(void)
{
/* init mutexes */
g_static_mutex_init(&(Zathura.Lock.pdflib_lock));
......@@ -1126,7 +1133,7 @@ close_file(gboolean keep_monitor)
}
void
enter_password()
enter_password(void)
{
/* replace default inputbar handler */
g_signal_handler_disconnect((gpointer) Zathura.UI.inputbar, Zathura.Handler.inputbar_activate);
......@@ -1418,30 +1425,43 @@ open_stdin(gchar* password)
}
// read from stdin and dump to temporary file
int stdinfno = fileno(stdin);
if (stdinfno == -1)
{
gchar* message = g_strdup_printf("Can not read from stdin.");
notify(ERROR, message);
g_free(message);
close(handle);
g_unlink(file);
g_free(file);
return FALSE;
}
char buffer[BUFSIZ];
ssize_t count = 0;
while ((count = read(0, buffer, BUFSIZ)) > 0)
while ((count = read(stdinfno, buffer, BUFSIZ)) > 0)
{
if (write(handle, buffer, count) != count)
{
gchar* message = g_strdup_printf("Can not write to temporary file: %s", file);
notify(ERROR, message);
g_free(message);
close(handle);
g_unlink(file);
g_free(file);
close(handle);
return FALSE;
}
}
if (count != 0)
{
gchar* message = g_strdup_printf("Can not read from stdin");
gchar* message = g_strdup_printf("Can not read from stdin.");
notify(ERROR, message);
g_free(message);
close(handle);
g_unlink(file);
g_free(file);
close(handle);
return FALSE;
}
......@@ -1463,14 +1483,14 @@ void open_uri(char* uri)
g_free(escaped_uri);
}
void out_of_memory()
void out_of_memory(void)
{
printf("error: out of memory\n");
exit(-1);
}
void
update_status()
update_status(void)
{
/* update text */
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_text, Zathura.State.filename);
......@@ -1530,7 +1550,7 @@ read_configuration_file(const char* rcfile)
}
void
read_configuration()
read_configuration(void)
{
char* zathurarc = g_build_filename(Zathura.Config.config_dir, ZATHURA_RC, NULL);
read_configuration_file(GLOBAL_RC);
......@@ -1702,7 +1722,7 @@ switch_view(GtkWidget* widget)
}
Completion*
completion_init()
completion_init(void)
{
Completion *completion = malloc(sizeof(Completion));
if(!completion)
......@@ -2010,14 +2030,14 @@ sc_follow(Argument* argument)
return;
Page* current_page = Zathura.PDF.pages[Zathura.PDF.page_number];
int number_of_links = 0, link_id = 1;
int link_id = 1;
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
GList *link_list = poppler_page_get_link_mapping(current_page->page);
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
link_list = g_list_reverse(link_list);
if((number_of_links = g_list_length(link_list)) <= 0)
if(g_list_length(link_list) <= 0)
return;
GList *links;
......@@ -2142,7 +2162,6 @@ sc_scroll(Argument* argument)
gdouble view_size = gtk_adjustment_get_page_size(adjustment);
gdouble value = gtk_adjustment_get_value(adjustment);
gdouble max = gtk_adjustment_get_upper(adjustment) - view_size;
gdouble new_value = value;
gboolean static ss = FALSE;
if((argument->n == UP || argument->n == HALF_UP || argument->n == FULL_UP) && value == 0)
......@@ -2163,7 +2182,9 @@ sc_scroll(Argument* argument)
sc_navigate(&arg);
return;
}
else if(argument->n == FULL_UP)
gdouble new_value;
if(argument->n == FULL_UP)
new_value = (value - view_size) < 0 ? 0 : (value - view_size);
else if(argument->n == FULL_DOWN)
new_value = (value + view_size) > max ? max : (value + view_size);
......@@ -2544,14 +2565,12 @@ isc_completion(Argument* argument)
char* current_command;
char* current_parameter;
int current_command_length;
int current_parameter_length;
if(!first_space)
{
current_command = g_strdup(input);
current_command_length = length;
current_parameter = NULL;
current_parameter_length = 0;
}
else
{
......@@ -2559,7 +2578,6 @@ isc_completion(Argument* argument)
current_command = g_strndup(input, offset);
current_command_length = strlen(current_command);
current_parameter = input + offset + 1;
current_parameter_length = strlen(current_parameter);
}
/* if the identifier does not match the command sign and
......@@ -3074,13 +3092,11 @@ cmd_export(int argc, char** argv)
for(images = image_list; images; images = g_list_next(images))
{
PopplerImageMapping *image_mapping;
PopplerRectangle image_field;
gint image_id;
char* file;
char* filename;
image_mapping = (PopplerImageMapping*) images->data;
image_field = image_mapping->area;
image_id = image_mapping->image_id;
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
......
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