diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 86 | 
1 files changed, 53 insertions, 33 deletions
| @@ -1,19 +1,19 @@ -/* sxiv: main.c - * Copyright (c) 2012 Bert Muennich <be.muennich at googlemail.com> +/* Copyright 2011-2013 Bert Muennich   * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. + * This file is part of sxiv.   * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU - * General Public License for more details. + * sxiv is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version.   * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * sxiv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with sxiv.  If not, see <http://www.gnu.org/licenses/>.   */  #define _POSIX_C_SOURCE 200112L @@ -84,7 +84,8 @@ timeout_t timeouts[] = {  	{ { 0, 0 }, false, clear_resize },  }; -void cleanup(void) { +void cleanup(void) +{  	static bool in = false;  	if (!in) { @@ -95,7 +96,8 @@ void cleanup(void) {  	}  } -void check_add_file(char *filename) { +void check_add_file(char *filename) +{  	const char *bn;  	if (filename == NULL || *filename == '\0') @@ -128,7 +130,8 @@ void check_add_file(char *filename) {  	fileidx++;  } -void remove_file(int n, bool manual) { +void remove_file(int n, bool manual) +{  	if (n < 0 || n >= filecnt)  		return; @@ -156,7 +159,8 @@ void remove_file(int n, bool manual) {  		tns.cnt--;  } -void set_timeout(timeout_f handler, int time, bool overwrite) { +void set_timeout(timeout_f handler, int time, bool overwrite) +{  	int i;  	for (i = 0; i < ARRLEN(timeouts); i++) { @@ -171,7 +175,8 @@ void set_timeout(timeout_f handler, int time, bool overwrite) {  	}  } -void reset_timeout(timeout_f handler) { +void reset_timeout(timeout_f handler) +{  	int i;  	for (i = 0; i < ARRLEN(timeouts); i++) { @@ -182,7 +187,8 @@ void reset_timeout(timeout_f handler) {  	}  } -bool check_timeouts(struct timeval *t) { +bool check_timeouts(struct timeval *t) +{  	int i = 0, tdiff, tmin = -1;  	struct timeval now; @@ -206,7 +212,8 @@ bool check_timeouts(struct timeval *t) {  	return tmin > 0;  } -void read_info(void) { +void read_info(void) +{  	char cmd[4096];  	FILE *outp;  	int c, i = 0, n = sizeof(bar.l) - 1; @@ -236,7 +243,8 @@ end:  	bar.l[i] = '\0';  } -void load_image(int new) { +void load_image(int new) +{  	if (new < 0 || new >= filecnt)  		return; @@ -261,7 +269,8 @@ void load_image(int new) {  		reset_timeout(animate);  } -void update_info(void) { +void update_info(void) +{  	unsigned int i, fn, fw, n, len = sizeof(bar.r);  	int sel;  	char *t = bar.r, title[TITLE_LEN]; @@ -309,7 +318,8 @@ void update_info(void) {  	win_set_bar_info(&win, bar.l, bar.r);  } -void redraw(void) { +void redraw(void) +{  	if (mode == MODE_IMAGE)  		img_render(&img);  	else @@ -320,7 +330,8 @@ void redraw(void) {  	reset_cursor();  } -void reset_cursor(void) { +void reset_cursor(void) +{  	int i;  	cursor_t cursor = CURSOR_NONE; @@ -341,27 +352,32 @@ void reset_cursor(void) {  	win_set_cursor(&win, cursor);  } -void animate(void) { +void animate(void) +{  	if (img_frame_animate(&img, false)) {  		redraw();  		set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);  	}  } -void clear_resize(void) { +void clear_resize(void) +{  	resized = false;  } -bool keymask(const keymap_t *k, unsigned int state) { +bool keymask(const keymap_t *k, unsigned int state) +{  	return (k->ctrl ? ControlMask : 0) == (state & ControlMask);  } -bool buttonmask(const button_t *b, unsigned int state) { +bool buttonmask(const button_t *b, unsigned int state) +{  	return ((b->ctrl ? ControlMask : 0) | (b->shift ? ShiftMask : 0)) ==  	       (state & (ControlMask | ShiftMask));  } -void on_keypress(XKeyEvent *kev) { +void on_keypress(XKeyEvent *kev) +{  	int i;  	KeySym ksym;  	char key; @@ -389,7 +405,8 @@ void on_keypress(XKeyEvent *kev) {  	}  } -void on_buttonpress(XButtonEvent *bev) { +void on_buttonpress(XButtonEvent *bev) +{  	int i, sel;  	if (bev == NULL) @@ -436,7 +453,8 @@ void on_buttonpress(XButtonEvent *bev) {  	}  } -void run(void) { +void run(void) +{  	int xfd;  	fd_set fds;  	struct timeval timeout; @@ -531,11 +549,13 @@ void run(void) {  	}  } -int fncmp(const void *a, const void *b) { +int fncmp(const void *a, const void *b) +{  	return strcoll(((fileinfo_t*) a)->name, ((fileinfo_t*) b)->name);  } -int main(int argc, char **argv) { +int main(int argc, char **argv) +{  	int i, start;  	size_t n;  	ssize_t len; | 
