diff options
-rw-r--r-- | action.c | 46 | ||||
-rw-r--r-- | action.h | 10 | ||||
-rw-r--r-- | config.mk | 6 | ||||
-rw-r--r-- | draw.c | 12 | ||||
-rw-r--r-- | dzen.h | 10 | ||||
-rw-r--r-- | main.c | 28 | ||||
-rw-r--r-- | util.c | 2 |
7 files changed, 70 insertions, 44 deletions
@@ -55,7 +55,7 @@ struct action_lookup ac_lookup_table[] = { ev_list *head = NULL; -int +static int new_event(long evid) { ev_list *item, *newitem; @@ -83,22 +83,22 @@ new_event(long evid) { return 0; } -void -add_handler(long evid, int hpos, void* hcb) { +static void +add_handler(long evid, int hpos, handlerf* hcb) { ev_list *item; item = head; while(item) { if(item->id == evid) { item->action[hpos] = emalloc(sizeof(As)); - item->action[hpos]->handler = (handlerf) hcb; + item->action[hpos]->handler = hcb; break; } item = item->next; } } -void +static void add_option(long evid, int hpos, int opos, char* opt) { ev_list *item; @@ -146,7 +146,7 @@ do_action(long evid) { } int -get_ev_id(char *evname) { +get_ev_id(const char *evname) { int i; KeySym ks; @@ -164,15 +164,15 @@ get_ev_id(char *evname) { return -1; } -handlerf -get_action_handler(char *acname) { +handlerf * +get_action_handler(const char *acname) { int i; for(i=0; ac_lookup_table[i].name; i++) { if(strcmp(ac_lookup_table[i].name, acname) == 0) - return (handlerf) ac_lookup_table[i].handler; + return ac_lookup_table[i].handler; } - return (handlerf)NULL; + return NULL; } @@ -196,9 +196,9 @@ fill_ev_table(char *input) { char *saveptr1, *saveptr2, *saveptr3, *saveptr4; int j, i=0, k=0; long eid=0; - void *ah=0; - + handlerf *ah=0; + saveptr1 = NULL; /* wtf, gcc? wtf? */ for (j = 1, str1 = input; ; j++, str1 = NULL) { token = strtok_r(str1, ";", &saveptr1); if (token == NULL) @@ -224,7 +224,7 @@ fill_ev_table(char *input) { break; } if(str4 == kommatoken && str4 != token && eid != -1) { - if((ah = (void *)get_action_handler(dptoken)) != NULL) { + if((ah = get_action_handler(dptoken)) != NULL) { new_event(eid); add_handler(eid, i, ah); i++; @@ -259,6 +259,7 @@ a_exit(char * opt[]) { int a_collapse(char * opt[]){ int i; + (void)opt; if(!dzen.slave_win.ishmenu && dzen.slave_win.max_lines && !dzen.slave_win.issticky) { @@ -272,6 +273,7 @@ a_collapse(char * opt[]){ int a_uncollapse(char * opt[]){ int i; + (void)opt; if(!dzen.slave_win.ishmenu && dzen.slave_win.max_lines && !dzen.slave_win.issticky) { @@ -282,13 +284,17 @@ a_uncollapse(char * opt[]){ return 0; } -int +#if 0 +static int a_togglecollapse(char * opt[]){ + (void)opt; return 0; } +#endif int a_stick(char * opt[]) { + (void)opt; if(!dzen.slave_win.ishmenu && dzen.slave_win.max_lines) dzen.slave_win.issticky = True; @@ -297,6 +303,7 @@ a_stick(char * opt[]) { int a_unstick(char * opt[]) { + (void)opt; if(!dzen.slave_win.ishmenu && dzen.slave_win.max_lines) dzen.slave_win.issticky = False; @@ -305,6 +312,7 @@ a_unstick(char * opt[]) { int a_togglestick(char * opt[]) { + (void)opt; if(!dzen.slave_win.ishmenu && dzen.slave_win.max_lines) dzen.slave_win.issticky = dzen.slave_win.issticky ? False : True; @@ -356,6 +364,7 @@ a_scrolldown(char * opt[]) { int a_hide(char * opt[]) { + (void)opt; if(!dzen.title_win.ishidden) { if(!dzen.slave_win.ishmenu) XResizeWindow(dzen.dpy, dzen.title_win.win, dzen.title_win.width, 1); @@ -369,6 +378,7 @@ a_hide(char * opt[]) { int a_unhide(char * opt[]) { + (void)opt; if(dzen.title_win.ishidden) { if(!dzen.slave_win.ishmenu) XResizeWindow(dzen.dpy, dzen.title_win.win, dzen.title_win.width, dzen.line_height); @@ -403,6 +413,7 @@ a_print(char * opt[]) { int a_menuprint(char * opt[]) { + (void)opt; if(dzen.slave_win.ismenu && dzen.slave_win.sel_line != -1 && (dzen.slave_win.sel_line + dzen.slave_win.first_line_vis) < dzen.slave_win.tcnt) { puts(dzen.slave_win.tbuf[dzen.slave_win.sel_line + dzen.slave_win.first_line_vis].text); @@ -414,6 +425,7 @@ a_menuprint(char * opt[]) { int a_menuexec(char * opt[]) { + (void)opt; if(dzen.slave_win.ismenu && dzen.slave_win.sel_line != -1 && (dzen.slave_win.sel_line + dzen.slave_win.first_line_vis) < dzen.slave_win.tcnt) { spawn(dzen.slave_win.tbuf[dzen.slave_win.sel_line + dzen.slave_win.first_line_vis].text); @@ -424,6 +436,7 @@ a_menuexec(char * opt[]) { int a_raise(char * opt[]) { + (void)opt; XRaiseWindow(dzen.dpy, dzen.title_win.win); if(dzen.slave_win.max_lines) @@ -433,6 +446,7 @@ a_raise(char * opt[]) { int a_lower(char * opt[]) { + (void)opt; XLowerWindow(dzen.dpy, dzen.title_win.win); if(dzen.slave_win.max_lines) @@ -442,6 +456,7 @@ a_lower(char * opt[]) { int a_scrollhome(char * opt[]) { + (void)opt; if(dzen.slave_win.max_lines) { dzen.slave_win.first_line_vis = 0; dzen.slave_win.last_line_vis = dzen.slave_win.max_lines; @@ -453,6 +468,7 @@ a_scrollhome(char * opt[]) { int a_scrollend(char * opt[]) { + (void)opt; if(dzen.slave_win.max_lines) { dzen.slave_win.first_line_vis = dzen.slave_win.tcnt - dzen.slave_win.max_lines ; dzen.slave_win.last_line_vis = dzen.slave_win.tcnt; @@ -464,6 +480,7 @@ a_scrollend(char * opt[]) { int a_grabkeys(char * opt[]) { + (void)opt; XGrabKeyboard(dzen.dpy, RootWindow(dzen.dpy, dzen.screen), True, GrabModeAsync, GrabModeAsync, CurrentTime); return 0; @@ -471,6 +488,7 @@ a_grabkeys(char * opt[]) { int a_ungrabkeys(char * opt[]) { + (void)opt; XUngrabKeyboard(dzen.dpy, CurrentTime); return 0; } @@ -10,7 +10,7 @@ /* Event, Action data structures */ typedef struct AS As; typedef struct _ev_list ev_list; -typedef int (* handlerf)(char **); +typedef int handlerf(char **); enum ev_id { /* startup, exit */ @@ -34,12 +34,12 @@ struct _ev_list { }; struct event_lookup { - char *name; + const char *name; long id; }; struct action_lookup { - char *name; + const char *name; int (*handler)(char **); }; @@ -51,8 +51,8 @@ struct AS { /* utility functions */ void do_action(long); -int get_ev_id(char *); -handlerf get_action_handler(char *); +int get_ev_id(const char *); +handlerf *get_action_handler(const char *); void fill_ev_table(char *); void free_event_list(void); int find_event(long); @@ -4,7 +4,7 @@ VERSION = 0.5.0 # Customize below to fit your system # paths -PREFIX = /usr/local +PREFIX = /home/mauke/usr/local MANPREFIX = ${PREFIX}/share/man X11INC = /usr/X11R6/include @@ -28,9 +28,9 @@ LDFLAGS = ${LIBS} #CFLAGS += -xtarget=ultra # Debugging -#CFLAGS = -g -Wall -O0 ${INCS} -DVERSION=\"${VERSION}\" -DPOSIX_SOURCE +#CFLAGS = ${INCS} -DVERSION=\"${VERSION}\" -std=gnu89 -pedantic -Wall -W -Wno-missing-field-initializers -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -O2 -pipe #LDFLAGS = -g ${LIBS} # compiler and linker -CC = cc +CC = gcc LD = ${CC} @@ -177,10 +177,10 @@ textw(const char *text) { return textnw(text, strlen(text)) + dzen.font.height; } -char * -setlinecolor(char * text, unsigned long * colfg, unsigned long * colbg) { +static const char * +setlinecolor(const char * text, unsigned long * colfg, unsigned long * colbg) { char fgcolor[8], bgcolor[8]; - unsigned long newfg, newbg; + long newfg, newbg; if(text[0] == '^' && text[1] == '#') { strncpy(fgcolor, text+1, 7); @@ -207,8 +207,8 @@ setlinecolor(char * text, unsigned long * colfg, unsigned long * colbg) { } void -drawheader(char * text) { - char *ctext; +drawheader(const char * text) { + const char *ctext; unsigned long colfg, colbg; dzen.x = 0; dzen.y = 0; @@ -233,7 +233,7 @@ drawheader(char * text) { void drawbody(char * text) { - char *ctext; + const char *ctext; unsigned long colfg, colbg; if(dzen.slave_win.tcnt == dzen.slave_win.tsize) @@ -63,7 +63,7 @@ struct SW { Drawable *drawable; /* input buffer */ - //char **tbuf; + /* char **tbuf; */ Sline *tbuf; int tsize; int tcnt; @@ -90,9 +90,9 @@ struct DZEN { TWIN title_win; SWIN slave_win; - char *fnt; - char *bg; - char *fg; + const char *fnt; + const char *bg; + const char *fg; int line_height; Display *dpy; @@ -127,7 +127,7 @@ extern void drawtext(const char *text, extern long getcolor(const char *colstr); /* returns color of colstr */ extern void setfont(const char *fontstr); /* sets global font */ extern unsigned int textw(const char *text); /* returns width of text in px */ -extern void drawheader(char *text); +extern void drawheader(const char *text); extern void drawbody(char *text); /* util.c */ @@ -51,21 +51,25 @@ clean_up(void) { static void catch_sigusr1(int s) { + (void)s; do_action(sigusr1); } static void catch_sigusr2(int s) { + (void)s; do_action(sigusr2); } static void catch_sigterm(int s) { + (void)s; do_action(onexit); } static void catch_alrm(int s) { + (void)s; do_action(onexit); clean_up(); exit(0); @@ -130,7 +134,7 @@ free_buffer(void) { } static int -read_stdin(void *ptr) { +read_stdin(void) { char buf[MAX_LINE_LEN], retbuf[MAX_LINE_LEN]; ssize_t n, n_off=0; @@ -160,14 +164,14 @@ read_stdin(void *ptr) { return 0; } -void +static void x_highlight_line(int line) { drawtext(dzen.slave_win.tbuf[line + dzen.slave_win.first_line_vis].text, 1, line, dzen.slave_win.alignment); XCopyArea(dzen.dpy, dzen.slave_win.drawable[line], dzen.slave_win.line[line], dzen.rgc, 0, 0, dzen.slave_win.width, dzen.line_height, 0, 0); } -void +static void x_unhighlight_line(int line) { drawtext(dzen.slave_win.tbuf[line + dzen.slave_win.first_line_vis].text, 0, line, dzen.slave_win.alignment); XCopyArea(dzen.dpy, dzen.slave_win.drawable[line], dzen.slave_win.line[line], dzen.gc, @@ -176,11 +180,11 @@ x_unhighlight_line(int line) { void x_draw_body(void) { + int i; dzen.x = 0; dzen.y = 0; dzen.w = dzen.slave_win.width; dzen.h = dzen.line_height; - int i; if(!dzen.slave_win.last_line_vis) { if(dzen.slave_win.tcnt < dzen.slave_win.max_lines) { @@ -282,9 +286,9 @@ x_create_windows(void) { root = RootWindow(dzen.dpy, dzen.screen); /* style */ - if((dzen.norm[ColBG] = getcolor(dzen.bg)) == -1) + if((dzen.norm[ColBG] = getcolor(dzen.bg)) == ~0lu) eprint("dzen: error, cannot allocate color '%s'\n", dzen.bg); - if((dzen.norm[ColFG] = getcolor(dzen.fg)) == -1) + if((dzen.norm[ColFG] = getcolor(dzen.fg)) == ~0lu) eprint("dzen: error, cannot allocate color '%s'\n", dzen.fg); setfont(dzen.fnt); @@ -503,7 +507,7 @@ handle_newl(void) { } static void -event_loop(void *ptr) { +event_loop(void) { int xfd, ret, dr=0; fd_set rmask; @@ -523,7 +527,7 @@ event_loop(void *ptr) { ret = select(xfd+1, &rmask, NULL, NULL, NULL); if(ret) { if(dr != -2 && FD_ISSET(STDIN_FILENO, &rmask)) { - if((dr = read_stdin(NULL)) == -1) + if((dr = read_stdin()) == -1) return; handle_newl(); } @@ -623,7 +627,11 @@ main(int argc, char *argv[]) { dzen.ispersistent = True; if (i+1 < argc) { dzen.timeout = strtoul(argv[i+1], &endptr, 10); - *endptr ? dzen.timeout = 0 : i++; + if (*endptr) { + dzen.timeout = 0; + } else { + i++; + } } } else if(!strncmp(argv[i], "-ta", 4)) { @@ -743,7 +751,7 @@ main(int argc, char *argv[]) { do_action(onstart); /* main loop */ - event_loop(NULL); + event_loop(); do_action(onexit); clean_up(); @@ -42,7 +42,7 @@ estrdup(const char *str) { } void spawn(const char *arg) { - static char *shell = NULL; + static const char *shell = NULL; if(!shell && !(shell = getenv("SHELL"))) shell = "/bin/sh"; |