Commit 426159d4 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Imported Upstream version 0.0.8.5

parent 231e63ad
......@@ -2,6 +2,7 @@
# zathura - user interface
include config.mk
include common.mk
PROJECT = zathura
SOURCE = zathura.c
......@@ -19,12 +20,12 @@ options:
@echo "CC = ${CC}"
%.o: %.c
@echo CC $<
@${CC} -c ${CFLAGS} -o $@ $<
$(ECHO) CC $<
$(QUIET)${CC} -c ${CFLAGS} -o $@ $<
%.do: %.c
@echo CC $<
@${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $<
$(ECHO) CC $<
$(QUIET)${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $<
${OBJECTS}: config.h config.mk
${DOBJECTS}: config.h config.mk
......@@ -38,19 +39,19 @@ config.h: config.def.h
fi
${PROJECT}: ${OBJECTS}
@echo CC -o $@
@${CC} ${SFLAGS} ${LDFLAGS} -o $@ ${OBJECTS} ${LIBS}
$(ECHO) CC -o $@
$(QUIET)${CC} ${SFLAGS} ${LDFLAGS} -o $@ ${OBJECTS} ${LIBS}
clean:
@rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \
$(QUIET)rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \
${DOBJECTS} ${PROJECT}-debug
distclean: clean
@rm -rf config.h
$(QUIET)rm -rf config.h
${PROJECT}-debug: ${DOBJECTS}
@echo CC -o ${PROJECT}-debug
@${CC} ${LDFLAGS} -o ${PROJECT}-debug ${DOBJECTS} ${LIBS}
$(ECHO) CC -o ${PROJECT}-debug
$(QUIET)${CC} ${LDFLAGS} -o ${PROJECT}-debug ${DOBJECTS} ${LIBS}
debug: ${PROJECT}-debug
......@@ -62,36 +63,35 @@ gdb: debug
cgdb ${PROJECT}-debug
dist: clean
@mkdir -p ${PROJECT}-${VERSION}
@cp -R LICENSE Makefile config.mk config.def.h README \
$(QUIET)mkdir -p ${PROJECT}-${VERSION}
$(QUIET)cp -R LICENSE Makefile config.mk common.mk config.def.h README \
${PROJECT}.desktop ${PROJECT}rc.5.rst \
${PROJECT}.1 ${SOURCE} ${PROJECT}-${VERSION}
@tar -cf ${PROJECT}-${VERSION}.tar ${PROJECT}-${VERSION}
@gzip ${PROJECT}-${VERSION}.tar
@rm -rf ${PROJECT}-${VERSION}
$(QUIET)tar -cf ${PROJECT}-${VERSION}.tar ${PROJECT}-${VERSION}
$(QUIET)gzip ${PROJECT}-${VERSION}.tar
$(QUIET)rm -rf ${PROJECT}-${VERSION}
install: all
@echo installing executable file
@mkdir -p ${DESTDIR}${PREFIX}/bin
@cp -f ${PROJECT} ${DESTDIR}${PREFIX}/bin
@chmod 755 ${PROJECT} ${DESTDIR}${PREFIX}/bin/${PROJECT}
@echo installing manual page
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
@sed "s/VERSION/${VERSION}/g" < ${PROJECT}.1 > ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
@if which rst2man > /dev/null ; then \
$(ECHO) installing executable file
$(QUIET)mkdir -p ${DESTDIR}${PREFIX}/bin
$(QUIET)install -m 755 ${PROJECT} ${DESTDIR}${PREFIX}/bin
$(ECHO) installing manual page
$(QUIET)mkdir -p ${DESTDIR}${MANPREFIX}/man1
$(QUIET)sed "s/VERSION/${VERSION}/g" < ${PROJECT}.1 > ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
$(QUIET)if which rst2man > /dev/null ; then \
mkdir -p ${DESTDIR}${MANPREFIX}/man5 ; \
rst2man ${PROJECT}rc.5.rst > ${DESTDIR}${MANPREFIX}/man5/${PROJECT}rc.5 ; \
fi
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
@mkdir -p ${DESTDIR}${DESKTOPPREFIX}
@echo installing desktop file
@install -m 644 ${PROJECT}.desktop ${DESTDIR}${DESKTOPPREFIX}
$(QUIET)chmod 644 ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
$(QUIET)mkdir -p ${DESTDIR}${DESKTOPPREFIX}
$(ECHO) installing desktop file
$(QUIET)install -m 644 ${PROJECT}.desktop ${DESTDIR}${DESKTOPPREFIX}
uninstall:
@echo removing executable file
@rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT}
@echo removing manual page
@rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
@rm -f ${DESTDIR}${MANPREFIX}/man5/${PROJECT}rc.5
@echo removing desktop file
@rm -f ${DESTDIR}${DESKTOPPREFIX}/${PROJECT}.desktop
$(ECHO) removing executable file
$(QUIET)rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT}
$(ECHO) removing manual page
$(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
$(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man5/${PROJECT}rc.5
$(ECHO) removing desktop file
$(QUIET)rm -f ${DESTDIR}${DESKTOPPREFIX}/${PROJECT}.desktop
# See LICENSE file for license and copyright information
ifeq "$(VERBOSE)" "0"
ECHO=@echo
QUIET=@
else
ECHO=@\#
QUIET=
endif
# See LICENSE file for license and copyright information
# zathura make config
VERSION = 0.0.8.4
VERSION = 0.0.8.5
# paths
PREFIX ?= /usr
......@@ -29,3 +29,6 @@ CC ?= gcc
# strip
SFLAGS ?= -s
# set to something != 0 to enable verbose build output
VERBOSE ?= 0
......@@ -20,7 +20,7 @@
/* macros */
#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))
#define CLEAN(m) (m & ~(GDK_MOD5_MASK) & ~(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))
......@@ -377,6 +377,7 @@ gboolean open_file(char*, char*);
gboolean open_stdin(gchar*);
void open_uri(char*);
void out_of_memory(void) NORETURN;
void* safe_realloc(void** ptr, size_t nmemb, size_t size);
void update_status(void);
void read_bookmarks_file(void);
void write_bookmarks_file(void);
......@@ -825,8 +826,10 @@ add_marker(int id)
/* add new marker */
int marker_index = Zathura.Marker.number_of_markers++;
Zathura.Marker.markers = realloc(Zathura.Marker.markers, sizeof(Marker) *
(Zathura.Marker.number_of_markers));
Zathura.Marker.markers = safe_realloc((void**)&Zathura.Marker.markers,
Zathura.Marker.number_of_markers, sizeof(Marker));
if(!Zathura.Marker.markers)
out_of_memory();
Zathura.Marker.markers[marker_index].id = id;
Zathura.Marker.markers[marker_index].page = page_number;
......@@ -1234,7 +1237,7 @@ open_file(char* path, char* password)
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
/* specify path max */
size_t pm;
long pm;
#ifdef PATH_MAX
pm = PATH_MAX;
#else
......@@ -1429,8 +1432,10 @@ open_file(char* path, char* password)
{
if(!is_reserved_bm_name(keys[i]))
{
Zathura.Bookmarks.bookmarks = realloc(Zathura.Bookmarks.bookmarks,
(Zathura.Bookmarks.number_of_bookmarks + 1) * sizeof(Bookmark));
Zathura.Bookmarks.bookmarks = safe_realloc((void**)&Zathura.Bookmarks.bookmarks,
Zathura.Bookmarks.number_of_bookmarks + 1, sizeof(Bookmark));
if(!Zathura.Bookmarks.bookmarks)
out_of_memory();
Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks].id = g_strdup(keys[i]);
Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks].page =
......@@ -1535,6 +1540,31 @@ void out_of_memory(void)
exit(-1);
}
void*
safe_realloc(void** ptr, size_t nmemb, size_t size)
{
static const size_t limit = ~((size_t)0u);
void* tmp = NULL;
/* Check for overflow. */
if(nmemb > limit / size)
goto failure;
tmp = realloc(*ptr, nmemb * size);
/* Check for out of memory. */
if(!tmp)
goto failure;
*ptr = tmp;
return *ptr;
/* Error handling. */
failure:
free(*ptr);
*ptr = NULL;
return NULL;
}
void
update_status(void)
{
......@@ -2312,7 +2342,7 @@ 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;
gboolean static ss = FALSE;
static gboolean ss = FALSE;
if((argument->n == UP || argument->n == HALF_UP || argument->n == FULL_UP) && value == 0)
{
......@@ -2320,7 +2350,7 @@ sc_scroll(Argument* argument)
Argument arg;
arg.n = PREVIOUS;
sc_navigate(&arg);
if (!scroll_wrap || (Zathura.PDF.page_number < old_page))
if (scroll_wrap || (Zathura.PDF.page_number < old_page))
{
arg.n = BOTTOM;
ss = TRUE;
......@@ -2901,7 +2931,9 @@ isc_completion(Argument* argument)
{
if(group->value && !group_elements)
{
rows = realloc(rows, (n_items + 1) * sizeof(CompletionRow));
rows = safe_realloc((void**)&rows, n_items + 1, sizeof(CompletionRow));
if(!rows)
out_of_memory();
rows[n_items].command = g_strdup(group->value);
rows[n_items].description = NULL;
rows[n_items].command_id = -1;
......@@ -2909,7 +2941,9 @@ isc_completion(Argument* argument)
rows[n_items++].row = GTK_WIDGET(create_completion_row(results, group->value, NULL, TRUE));
}
rows = realloc(rows, (n_items + 1) * sizeof(CompletionRow));
rows = safe_realloc((void**)&rows, n_items + 1, sizeof(CompletionRow));
if(!rows)
out_of_memory();
rows[n_items].command = g_strdup(element->value);
rows[n_items].description = element->description ? g_strdup(element->description) : NULL;
rows[n_items].command_id = previous_id;
......@@ -2942,8 +2976,8 @@ isc_completion(Argument* argument)
* the current command would match the command
* the current command would match the abbreviation
*/
if( ((current_command_length <= cmd_length) && !strncmp(current_command, commands[i].command, current_command_length)) ||
((current_command_length <= abbr_length) && !strncmp(current_command, commands[i].abbr, current_command_length))
if( ((current_command_length <= cmd_length) && commands[i].command && !strncmp(current_command, commands[i].command, current_command_length)) ||
((current_command_length <= abbr_length) && commands[i].abbr && !strncmp(current_command, commands[i].abbr, current_command_length))
)
{
rows[n_items].command = g_strdup(commands[i].command);
......@@ -2954,7 +2988,9 @@ isc_completion(Argument* argument)
}
}
rows = realloc(rows, n_items * sizeof(CompletionRow));
rows = safe_realloc((void**)&rows, n_items, sizeof(CompletionRow));
if(!rows)
out_of_memory();
}
gtk_box_pack_start(Zathura.UI.box, GTK_WIDGET(results), FALSE, FALSE, 0);
......@@ -3127,8 +3163,10 @@ cmd_bookmark(int argc, char** argv)
}
/* add new bookmark */
Zathura.Bookmarks.bookmarks = realloc(Zathura.Bookmarks.bookmarks,
(Zathura.Bookmarks.number_of_bookmarks + 1) * sizeof(Bookmark));
Zathura.Bookmarks.bookmarks = safe_realloc((void**)&Zathura.Bookmarks.bookmarks,
Zathura.Bookmarks.number_of_bookmarks + 1, sizeof(Bookmark));
if(!Zathura.Bookmarks.bookmarks)
out_of_memory();
Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks].id = g_strdup(id->str);
Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks].page = Zathura.PDF.page_number;
......@@ -3234,8 +3272,10 @@ cmd_delete_bookmark(int argc, char** argv)
/* update bookmarks */
Zathura.Bookmarks.bookmarks[i].id = Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks - 1].id;
Zathura.Bookmarks.bookmarks[i].page = Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks - 1].page;
Zathura.Bookmarks.bookmarks = realloc(Zathura.Bookmarks.bookmarks,
Zathura.Bookmarks.number_of_bookmarks * sizeof(Bookmark));
Zathura.Bookmarks.bookmarks = safe_realloc((void**)&Zathura.Bookmarks.bookmarks,
Zathura.Bookmarks.number_of_bookmarks, sizeof(Bookmark));
if(!Zathura.Bookmarks.bookmarks)
out_of_memory();
Zathura.Bookmarks.number_of_bookmarks--;
g_string_free(id, TRUE);
......@@ -3702,7 +3742,7 @@ cmd_set(int argc, char** argv)
int arg_c;
for(arg_c = 0; arg_c < LENGTH(argument_names); arg_c++)
{
if(!strcmp(argv[1], argument_names[arg_c].name))
if(argv[1] && !strcmp(argv[1], argument_names[arg_c].name))
{
id = argument_names[arg_c].argument;
break;
......@@ -3862,7 +3902,7 @@ cc_bookmark(char* input)
for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++)
{
if( (input_length <= strlen(Zathura.Bookmarks.bookmarks[i].id)) &&
!strncmp(input, Zathura.Bookmarks.bookmarks[i].id, input_length) )
input && !strncmp(input, Zathura.Bookmarks.bookmarks[i].id, input_length) )
{
completion_group_add_element(group, Zathura.Bookmarks.bookmarks[i].id, g_strdup_printf("Page %d", Zathura.Bookmarks.bookmarks[i].page));
}
......@@ -4025,7 +4065,9 @@ cc_print(char* input)
if(!current_line)
out_of_memory();
current_line = realloc(current_line, (count + 1) * sizeof(char));
current_line = safe_realloc((void**)&current_line, count + 1, sizeof(char));
if(!current_line)
out_of_memory();
if(current_char != '\n')
current_line[count++] = current_char;
......@@ -4046,6 +4088,8 @@ cc_print(char* input)
}
}
free(current_line);
pclose(fp);
return completion;
......@@ -4064,8 +4108,8 @@ cc_set(char* input)
for(i = 0; i < LENGTH(settings); i++)
{
if( (input_length <= strlen(settings[i].name)) &&
!strncmp(input, settings[i].name, input_length) )
if(settings[i].name && (input_length <= strlen(settings[i].name)) &&
input && !strncmp(input, settings[i].name, input_length) )
{
completion_group_add_element(group, settings[i].name, settings[i].description);
}
......@@ -4133,10 +4177,17 @@ void
bcmd_scroll(char* buffer, Argument* argument)
{
int b_length = strlen(buffer);
if(b_length < 1)
if(b_length < 1) {
return;
}
char* tmp = g_strndup(buffer, b_length - 1);
if (tmp == NULL) {
return;
}
int percentage = atoi(g_strndup(buffer, b_length - 1));
int percentage = atoi(tmp);
g_free(tmp);
percentage = (percentage < 0) ? 0 : ((percentage > 100) ? 100 : percentage);
GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment(Zathura.UI.view);
......@@ -4175,7 +4226,12 @@ bcmd_zoom(char* buffer, Argument* argument)
if(b_length < 1)
return;
int value = atoi(g_strndup(buffer, b_length - 1));
char* tmp = g_strndup(buffer, b_length - 1);
if (tmp == NULL) {
return;
}
int value = atoi(tmp);
g_free(tmp);
if(value <= zoom_min)
Zathura.PDF.scale = zoom_min;
else if(value >= zoom_max)
......@@ -4752,9 +4808,11 @@ cb_view_button_release(GtkWidget* widget, GdkEventButton* event, gpointer data)
rectangle.y2 = d;
}
#if !POPPLER_CHECK_VERSION(0,15,0)
/* adapt y coordinates */
rectangle.y1 = page_height - rectangle.y1;
rectangle.y2 = page_height - rectangle.y2;
#endif
/* get selected text */
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
......
......@@ -104,7 +104,7 @@ set
show_inputbar [bool] -
show statusbar, inputbar and scrollbars.
* smooth_scolling [float] - smooth scrolling.
* smooth_scrolling [float] - smooth scrolling.
* transparency [float] - transparency of rectangles.
......
Markdown is supported
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