From 848c585c7ff22142e100953a678699d650418d15 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 10 Dec 2018 14:42:35 -0500 Subject: [PATCH] enabled more warnings and fixed them all. Suppressed unused variable warnings in the config file --- bin/c+ | 3 ++- bin/c- | 3 ++- bin/lang | 1 + config.h | 27 +++++++++++++++++---------- config.mk | 2 +- inc/edit.h | 2 +- src/edit.c | 1 + src/fetch.c | 3 ++- src/lib/buf.c | 4 +++- src/lib/view.c | 2 +- src/lib/x11.c | 22 +++++++++++----------- src/pick.c | 6 ++++-- src/registrar.c | 8 +++++--- src/tide.c | 38 +++++++++++++++++++++++++++++++++++++- 14 files changed, 88 insertions(+), 34 deletions(-) diff --git a/bin/c+ b/bin/c+ index fa23571..f50e5d4 100755 --- a/bin/c+ +++ b/bin/c+ @@ -1,5 +1,6 @@ #!/bin/sh case "$(lang "$file")" in - C) sed 's/^/\/\//g' "$@" ;; + C|JavaScript) + sed 's/^/\/\//g' "$@" ;; *) sed 's/^/#/g' "$@" ;; esac diff --git a/bin/c- b/bin/c- index 93107ad..e1f6991 100755 --- a/bin/c- +++ b/bin/c- @@ -1,5 +1,6 @@ #!/bin/sh case "$(lang "$file")" in - C) sed 's/^\/\///g' "$@" ;; + C|JavaScript) + sed 's/^\/\///g' "$@" ;; *) sed 's/^#//g' "$@" ;; esac diff --git a/bin/lang b/bin/lang index 8c1806f..7da0407 100755 --- a/bin/lang +++ b/bin/lang @@ -5,5 +5,6 @@ case "$1" in *.ml) echo "ML" ;; *.py) echo "Python" ;; *.rb) echo "Ruby" ;; + *.js) echo "JavaScript" ;; *) echo "Text" ;; esac diff --git a/config.h b/config.h index 643559c..bb36a1e 100644 --- a/config.h +++ b/config.h @@ -1,3 +1,6 @@ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" + enum { Off = 0, On = 1 }; enum { /* Color Names */ @@ -84,17 +87,9 @@ static int Palette[ClrCount] = { #endif Rule* BuiltinRules[] = { - (Rule[]){ /* Look up .c or .h files in Code/ */ - { ISSET, "EDITOR", NULL }, - { MATCHES, "data", "\\.[ch]$" }, - { ISDIR, "Code", NULL }, - { EXEC, "[[ $(find Code -type f -name '*$data') ]]", NULL }, - { LAUNCH, "find Code -type f -name '*$data' | xargs -r $EDITOR", NULL }, - { COMPLETE, NULL, NULL } - }, (Rule[]){ /* Match URLS and open them with the browser */ { ISSET, "BROWSER", NULL }, - { MATCHES, "data", "^(https?|ftp):/*.*" }, */ + { MATCHES, "data", "^(https?|ftp)://.*" }, { LAUNCH, "$BROWSER $0", NULL }, { COMPLETE, NULL, NULL } }, @@ -116,7 +111,15 @@ Rule* BuiltinRules[] = { { ISSET, "EDITOR", NULL }, { ISFILE, "tags", NULL }, { EXEC, "grep -q '^$data\\s\\+' tags", NULL }, - { LAUNCH, "picktag fetch tags '$data' | xargs -r tide", NULL }, + { LAUNCH, "picktag fetch tags '$data' | xargs -r edit", NULL }, + { COMPLETE, NULL, NULL } + }, + (Rule[]){ /* Look up .c or .h files in Code/ */ + { ISSET, "EDITOR", NULL }, + { MATCHES, "data", "\\.[ch]$" }, + { ISDIR, "Code", NULL }, + { EXEC, "[[ $(find Code -type f -name '*$data') ]]", NULL }, + { LAUNCH, "find Code -type f -name '*$data' | xargs -r $EDITOR", NULL }, { COMPLETE, NULL, NULL } }, (Rule[]){ /* If it's an existing directory, open it with system default */ @@ -125,4 +128,8 @@ Rule* BuiltinRules[] = { { COMPLETE, NULL, NULL } }, }; + #endif + +#pragma GCC diagnostic pop + diff --git a/config.mk b/config.mk index 0d4b9af..835c8f5 100644 --- a/config.mk +++ b/config.mk @@ -19,7 +19,7 @@ INCS += -I/usr/include/freetype2 # Compiler Setup CC = cc CFLAGS = -g --std=c99 -MMD $(INCS) -CFLAGS += -Wall -Werror +CFLAGS += -Wall -Wextra CFLAGS += -Wno-unused-function # Linker Setup diff --git a/inc/edit.h b/inc/edit.h index 8a6121e..027a1ad 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -120,7 +120,7 @@ void view_init(View* view, char* file); void view_reload(View* view); size_t view_limitrows(View* view, size_t maxrows); void view_resize(View* view, size_t width, size_t nrows); -void view_update(View* view, size_t* csrx, size_t* csry); +void view_update(View* view); Row* view_getrow(View* view, size_t row); void view_byrune(View* view, int move, bool extsel); void view_byword(View* view, int move, bool extsel); diff --git a/src/edit.c b/src/edit.c index 52648be..4b776a2 100644 --- a/src/edit.c +++ b/src/edit.c @@ -49,6 +49,7 @@ void edit_file(XConf* x, Window registrar, char* path, char* addr) { } void xclientmsg(XConf* x, XEvent* e) { + (void)x, (void)e; puts("clientmsg"); } diff --git a/src/fetch.c b/src/fetch.c index 37405c0..817dde2 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -124,6 +124,7 @@ bool var_unset(char* var) { } bool find_file(char* file) { + (void)file; return false; } @@ -182,7 +183,7 @@ void usage(char* pname) { int main(int argc, char** argv) { if (argc != 2) usage(argv[0]); setenv("data", argv[1], 1); - for (int i = 0; i < nelem(BuiltinRules); i++) { + for (unsigned int i = 0; i < nelem(BuiltinRules); i++) { Rule* rule = BuiltinRules[i]; for (; rule->type != COMPLETE; rule++) { //printf("%d '%s' '%s'\n", rule->type, rule->arg1, rule->arg2); diff --git a/src/lib/buf.c b/src/lib/buf.c index f5928ed..1bbb7a2 100644 --- a/src/lib/buf.c +++ b/src/lib/buf.c @@ -248,6 +248,8 @@ static void dumplog(Buf* buf) { printf("Redo:\n"); for (Log* log = buf->redo; log; log = log->next) printf(" (%d) %lu-%lu '%s'\n", log->transid, log->beg, log->end, log->data); +#else + (void)buf; #endif } @@ -473,7 +475,7 @@ static void selblock(Buf* buf, Rune first, Rune last) { } static int bytes_match(Buf* buf, size_t mbeg, size_t mend, char* str) { - for (; *str; str++, mbeg++) { + for (; *str && mbeg < mend; str++, mbeg++) { int cmp = *str - getb(buf, mbeg); if (cmp != 0) return cmp; } diff --git a/src/lib/view.c b/src/lib/view.c index 2543875..0348c0a 100644 --- a/src/lib/view.c +++ b/src/lib/view.c @@ -165,7 +165,7 @@ void view_resize(View* view, size_t width, size_t nrows) { resize(view, width, nrows, off); } -void view_update(View* view, size_t* csrx, size_t* csry) { +void view_update(View* view) { /* refill the view contents to make sure updates are visible */ size_t off = view->rows[view->index]->off; clear_rows(view, view->index); diff --git a/src/lib/x11.c b/src/lib/x11.c index c5a20b9..f9f7407 100644 --- a/src/lib/x11.c +++ b/src/lib/x11.c @@ -96,7 +96,7 @@ static void get_position(WinRegion id, int x, int y, size_t* row, size_t* col) { int starty = (id == EDIT ? Divider+3 : 0); int startx = ScrollWidth+3; int maxy = (id == EDIT - ? (Divider + (win_view(EDIT)->nrows * X.font->height)) + ? (Divider + (int)(win_view(EDIT)->nrows * X.font->height)) : Divider - 4 ); x = (x < 0 ? 0 : (x > X.width ? X.width : x)); @@ -106,7 +106,7 @@ static void get_position(WinRegion id, int x, int y, size_t* row, size_t* col) { } static struct XSel* selfetch(Atom atom) { - for (int i = 0; i < (sizeof(Selections) / sizeof(Selections[0])); i++) + for (unsigned int i = 0; i < (sizeof(Selections) / sizeof(Selections[0])); i++) if (atom == Selections[i].atom) return &Selections[i]; return NULL; @@ -308,7 +308,7 @@ static void draw_rect(int color, int x, int y, int width, int height) { XftColorFree(X.display, X.visual, X.colormap, &clr); } -static void draw_statbox(drawcsr* csr) { +static void draw_statbox(void) { draw_rect(VerBdr, ScrollWidth, 0, 1, X.height/4); switch (win_view(EDIT)->buffer.status) { case NORMAL: draw_rect(TagsBg, 0, 0, ScrollWidth, X.height/4); break; @@ -335,11 +335,10 @@ static bool draw_csr(View* view, size_t fheight, int x, int y, bool csrdrawn) { static void draw_view(View* view, XftFont* font, size_t nrows, drawcsr* csr, int bg, int fg, int sel) { size_t fheight = font->height; - size_t csrx = SIZE_MAX, csry = SIZE_MAX; bool csr_drawn = false; /* draw the view to the window */ view_resize(view, (csr->w - csr->x), nrows); - view_update(view, &csrx, &csry); + view_update(view); draw_rect(bg, csr->x, csr->y, csr->w, ((nrows + 1) * fheight) + 9); for (size_t i = 0; i < nrows; i++) { Row* row = view_getrow(view, i + view->index); @@ -359,7 +358,7 @@ static void draw_view(View* view, XftFont* font, size_t nrows, drawcsr* csr, int x += row->cols[i].width; } XftColor fgc; - xftcolor(&fgc, EditFg); + xftcolor(&fgc, fg); XftDrawGlyphSpec(X.xft, &fgc, font, specs, row->len); XftColorFree(X.display, X.visual, X.colormap, &fgc); } @@ -404,7 +403,7 @@ static void xkeypress(XEvent* e) { if (key == RUNE_ERR) return; KeyBtnState = e->xkey.state; int mods = KeyBtnState & (ModCtrl|ModShift|ModAlt); - uint32_t mkey = tolower(key); + int32_t mkey = tolower(key); for (KeyBinding* bind = Keys; bind && bind->key; bind++) { bool match = (mkey == bind->key); bool exact = (bind->mods == mods); @@ -508,7 +507,7 @@ static void xselrequest(XEvent* e) { } static void xclientmsg(XEvent* e) { - if (e->xclient.data.l[0] == XInternAtom(X.display, "WM_DELETE_WINDOW", False)) + if ((Atom)(e->xclient.data.l[0]) == XInternAtom(X.display, "WM_DELETE_WINDOW", False)) win_quit(); else if (e->xclient.message_type == XInternAtom(X.display, "GOTO", False)) view_setln(win_view(EDIT), e->xclient.data.l[0]); @@ -538,6 +537,7 @@ static void (*EventHandlers[LASTEvent])(XEvent*) = { }; static void xupdate(Job* job) { + (void)job; int nevents; /* process events from the queue */ XEventsQueued(X.display, QueuedAfterFlush); @@ -555,7 +555,7 @@ static void xupdate(Job* job) { /* draw the regions to the window */ drawcsr csr = { .w = X.width, .h = X.height }; csr.x += ScrollWidth + 1; - draw_statbox(&csr); + draw_statbox(); draw_view(&Regions[TAGS], X.tagfont, tagrows, &csr, TagsBg, TagsFg, TagsSel); draw_hrule(&csr); draw_view(&Regions[EDIT], X.font, editrows, &csr, EditBg, EditFg, EditSel); @@ -587,7 +587,7 @@ void win_init(KeyBinding* bindings) { X.tagfont = X.font; x11_window("unnamed"); /* initialize selection atoms */ - for (int i = 0; i < (sizeof(Selections) / sizeof(Selections[0])); i++) + for (unsigned int i = 0; i < (sizeof(Selections) / sizeof(Selections[0])); i++) Selections[i].atom = XInternAtom(X.display, Selections[i].name, 0); SelTarget = XInternAtom(X.display, "UTF8_STRING", 0); if (SelTarget == None) @@ -626,7 +626,7 @@ void win_prop_set(char* xname, char* ename, char* value) { } void win_update(int ms) { - job_poll(Timeout); + job_poll(ms); xupdate(NULL); } diff --git a/src/pick.c b/src/pick.c index 44445cd..c7f78e2 100644 --- a/src/pick.c +++ b/src/pick.c @@ -92,7 +92,7 @@ bool match(char *string, size_t offset, size_t *start, size_t *end) { } void score(void) { - for (int i = 0; i < vec_size(&Choices); i++) { + for (unsigned int i = 0; i < vec_size(&Choices); i++) { Choice* choice = (Choice*)vec_at(&Choices, i); float qlen = (float)QueryIdx; if (match(choice->string, 0, &choice->match_start, &choice->match_end)) { @@ -108,9 +108,11 @@ void score(void) { } static void xkeypress(XConf* x, XEvent* e) { + (void)x, (void)e; } static void xbtnpress(XConf* x, XEvent* e) { + (void)x, (void)e; } static void xresize(XConf* x, XEvent* e) { @@ -158,7 +160,7 @@ void filter(void) { } } -int main(int argc, char** argv) { +int main(void) { load_choices(); if (vec_size(&Choices) > 1) filter(); diff --git a/src/registrar.c b/src/registrar.c index c67abca..c74f30e 100644 --- a/src/registrar.c +++ b/src/registrar.c @@ -81,19 +81,21 @@ void win_open(XConf* x, char* wdir, char* path, char* addr) { } void selclear(XConf* x, XEvent* e) { + (void)x, (void)e; exit(0); } void clientmsg(XConf* x, XEvent* e) { if (XA_REGISTRAR != e->xclient.message_type) return; - if (XA_ADD == e->xclient.data.l[0]) + if (XA_ADD == (Atom)(e->xclient.data.l[0])) win_add(x, e->xclient.window); - else if (XA_DEL == e->xclient.data.l[0]) + else if (XA_DEL == (Atom)(e->xclient.data.l[0])) win_del(e->xclient.window); } void propnotify(XConf* x, XEvent* e) { + (void)e; Atom type; int format; unsigned long datalen, nleft; @@ -113,7 +115,7 @@ void propnotify(XConf* x, XEvent* e) { } } -int main(int argc, char** argv) { +int main(void) { XConf x = {0}; x11_init(&x); x11_mkwin(&x, 1, 1, PropertyChangeMask); diff --git a/src/tide.c b/src/tide.c index 1dc6723..ab66529 100644 --- a/src/tide.c +++ b/src/tide.c @@ -87,10 +87,12 @@ void exec(char* cmd) { /* Keyboard and Tag Handlers ******************************************************************************/ static void select_line(char* arg) { + (void)arg; buf_selln(win_buf(FOCUSED)); } static void join_lines(char* arg) { + (void)arg; View* view = win_view(FOCUSED); buf_logstart(win_buf(FOCUSED)); view_eol(view, false); @@ -104,6 +106,7 @@ static void join_lines(char* arg) { } static void delete(char* arg) { + (void)arg; bool byword = win_keymodsset(ModCtrl); view_delete(win_view(FOCUSED), RIGHT, byword); } @@ -124,6 +127,7 @@ void cut(char* arg) { } void paste(char* arg) { + (void)arg; assert(win_sel_get(CLIPBOARD, onpaste)); } @@ -142,10 +146,12 @@ static void del_to(void (*tofn)(View*, bool)) { } static void del_to_bol(char* arg) { + (void)arg; del_to(view_bol); } static void del_to_eol(char* arg) { + (void)arg; del_to(view_eol); } @@ -156,14 +162,17 @@ static void del_to_bow(char* arg) { } static void backspace(char* arg) { + (void)arg; view_delete(win_view(FOCUSED), LEFT, win_keymodsset(ModCtrl)); } static void cursor_bol(char* arg) { + (void)arg; view_bol(win_view(FOCUSED), false); } static void cursor_eol(char* arg) { + (void)arg; view_eol(win_view(FOCUSED), false); } @@ -192,54 +201,67 @@ static void cursor_home_end( } static void cursor_home(char* arg) { + (void)arg; cursor_home_end(view_bof, view_bol); } static void cursor_end(char* arg) { + (void)arg; cursor_home_end(view_eof, view_eol); } static void cursor_up(char* arg) { + (void)arg; cursor_mvupdn(UP); } static void cursor_dn(char* arg) { + (void)arg; cursor_mvupdn(DOWN); } static void cursor_left(char* arg) { + (void)arg; cursor_mvlr(LEFT); } static void cursor_right(char* arg) { + (void)arg; cursor_mvlr(RIGHT); } static void page_up(char* arg) { + (void)arg; view_scrollpage(win_view(FOCUSED), UP); } static void page_dn(char* arg) { + (void)arg; view_scrollpage(win_view(FOCUSED), DOWN); } static void select_prev(char* arg) { + (void)arg; view_selprev(win_view(FOCUSED)); } static void change_focus(char* arg) { + (void)arg; win_togglefocus(); } static void undo(char* arg) { + (void)arg; view_undo(win_view(FOCUSED)); } static void redo(char* arg) { + (void)arg; view_redo(win_view(FOCUSED)); } static void quit(char* arg) { + (void)arg; win_quit(); } @@ -264,14 +286,17 @@ static void get(char* arg) { } static void tag_undo(char* arg) { + (void)arg; view_undo(win_view(EDIT)); } static void tag_redo(char* arg) { + (void)arg; view_redo(win_view(EDIT)); } static void search(char* arg) { + (void)arg; char* str; SearchDir *= (win_keymodsset(ModShift) ? UP : DOWN); if (win_keymodsset(ModAlt) && SearchTerm) @@ -285,6 +310,7 @@ static void search(char* arg) { } static void execute(char* arg) { + (void)arg; char* str = view_getcmd(win_view(FOCUSED)); if (str) exec(str); free(str); @@ -296,6 +322,7 @@ static void find(char* arg) { } static void open_file(char* arg) { + (void)arg; cmd_exec(CMD_PICKFILE); } @@ -304,10 +331,12 @@ static void pick_symbol(char* symbol) { } static void pick_ctag(char* arg) { + (void)arg; pick_symbol(NULL); } static void complete(char* arg) { + (void)arg; View* view = win_view(FOCUSED); view_selectobj(view, risword); cmd_execwitharg(CMD_COMPLETE, view_getstr(view)); @@ -326,22 +355,26 @@ static void jump_to(char* arg) { } static void goto_ctag(char* arg) { + (void)arg; char* str = view_getctx(win_view(FOCUSED)); jump_to(str); free(str); } static void tabs(char* arg) { + (void)arg; ExpandTabs = !ExpandTabs; win_title(NULL); // force an update of title } static void indent(char* arg) { + (void)arg; CopyIndent = !CopyIndent; win_title(NULL); // force an update of title } static void eol_mode(char* arg) { + (void)arg; DosLineFeed = !DosLineFeed; win_title(NULL); View* view = win_view(EDIT); @@ -352,10 +385,12 @@ static void eol_mode(char* arg) { } static void new_win(char* arg) { + (void)arg; cmd_exec(CMD_TIDE); } static void newline(char* arg) { + (void)arg; View* view = win_view(FOCUSED); if (win_keymodsset(ModShift)) { view_byline(view, UP, false); @@ -366,6 +401,7 @@ static void newline(char* arg) { } static void highlight(char* arg) { + (void)arg; view_selctx(win_view(FOCUSED)); } @@ -447,7 +483,7 @@ static KeyBinding Bindings[] = { { .mods = ModOneOrMore, .key = '\n', .fn = newline }, { .mods = ModCtrl, .key = ' ', .fn = complete }, - { 0, 0, 0 } + { 0, 0, 0, 0 } }; static void usage(void) { -- 2.52.0