From 0c9a77c269c4264127a04231d9a730441010c314 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 13 Oct 2019 21:18:33 -0400 Subject: [PATCH] fixed even more lint --- alcc | 2 +- src/edit.c | 30 ++++++----- src/fetch.c | 124 +++++++++++++++++++++------------------------- src/lib/x11_gc.c | 31 ++++++------ src/lib/x11_sel.c | 36 ++++++++------ 5 files changed, 110 insertions(+), 113 deletions(-) diff --git a/alcc b/alcc index 92ae831..be0e318 100755 --- a/alcc +++ b/alcc @@ -275,7 +275,7 @@ script=$(cat < 0) + int result = regexec(®ex, str, nelem(matches), matches, 0); + if ((result == 0) && (matches[1].rm_so > 0)) { char* var = strndup(str+matches[1].rm_so, matches[1].rm_eo-matches[1].rm_so); char* val = getvar(var); @@ -52,10 +49,9 @@ char* eval(char* str) strncat(exp, str, matches[0].rm_so); strcat(exp, val); strcat(exp, str + matches[0].rm_eo); - return eval(exp); - } else { - return str; + str = eval(exp); } + return str; } /******************************************************************************/ @@ -68,6 +64,7 @@ bool complete(void) bool matches(char* var, char* patt) { + bool ret = false; regex_t regex = {0}; regmatch_t matches[10] = {{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}}; if (regcomp(®ex, patt, REG_EXTENDED) == 0) @@ -80,9 +77,9 @@ bool matches(char* var, char* patt) setenv((char[]){ 'M', ('0' + i), 0 }, matchval, 1); free(matchval); } - return (err == 0); + ret = (err == 0); } - return false; + return ret; } bool var_is(char* var, char* val) @@ -97,40 +94,28 @@ bool var_isset(char* var) bool var_isdir(char* var) { + bool ret = false; struct stat st = {0}; char* path = eval(var); - if ((stat(path, &st) < 0) && (errno == ENOENT)) - { - return false; - } - else if (S_ISDIR(st.st_mode)) + if (!stat(path, &st) && !errno && S_ISDIR(st.st_mode)) { setenv("dir", var, 1); - return true; - } - else - { - return false; + ret = true; } + return ret; } bool var_isfile(char* var) { + bool ret = false; struct stat st = {0}; char* path = eval(var); - if ((stat(eval(var), &st) < 0) && (errno == ENOENT)) - { - return false; - } - else if (!S_ISDIR(st.st_mode)) + if (!stat(eval(var), &st) && !errno && !S_ISDIR(st.st_mode)) { setenv("file", path, 1); - return true; - } - else - { - return false; + ret = true; } + return ret; } bool var_set(char* var, char* val) @@ -158,54 +143,56 @@ void runcmd(char* cmd) bool exec(char* cmd) { + bool ret = false; int pid, status; - if ((pid = fork()) < 0) + if ((pid = fork()) >= 0) { - return false; - } - if (pid == 0) - { - runcmd(cmd); - } - else - { - waitpid(pid, &status, 0); - return (status == 0); + if (pid == 0) + { + runcmd(cmd); + } + else + { + waitpid(pid, &status, 0); + ret = (status == 0); + } } - return false; + return ret; } bool launch(char* cmd) { + bool ret = false; int pid = fork(); if (pid > 0) { - return true; + ret = true; } else if (pid == 0) { runcmd(cmd); } - return false; + return ret; } bool apply_rule(Rule* rule) { + bool ret = false; switch (rule->type) { - case COMPLETE: exit(0); - case MATCHES: return matches(rule->arg1, rule->arg2); - case IS: return var_is(rule->arg1, rule->arg2); - case ISSET: return var_isset(rule->arg1); - case ISDIR: return var_isdir(rule->arg1); - case ISFILE: return var_isfile(rule->arg1); - case SET: return var_set(rule->arg1, rule->arg2); - case UNSET: return var_unset(rule->arg1); - case FINDFILE: return find_file(rule->arg1); - case EXEC: return exec(rule->arg1); - case LAUNCH: return launch(rule->arg1); + case COMPLETE: exit(0); break; + case MATCHES: ret = matches(rule->arg1, rule->arg2); break; + case IS: ret = var_is(rule->arg1, rule->arg2); break; + case ISSET: ret = var_isset(rule->arg1); break; + case ISDIR: ret = var_isdir(rule->arg1); break; + case ISFILE: ret = var_isfile(rule->arg1); break; + case SET: ret = var_set(rule->arg1, rule->arg2); break; + case UNSET: ret = var_unset(rule->arg1); break; + case FINDFILE: ret = find_file(rule->arg1); break; + case EXEC: ret = exec(rule->arg1); break; + case LAUNCH: ret = launch(rule->arg1); break; } - return false; + return ret; } /******************************************************************************/ @@ -218,21 +205,22 @@ void usage(char* pname) char* type2str(int type) { + char* ret = "UNKNOWN"; switch (type) { - case COMPLETE: return "COMPLETE"; - case MATCHES: return "MATCHES"; - case IS: return "IS"; - case ISSET: return "ISSET"; - case ISDIR: return "ISDIR"; - case ISFILE: return "ISFILE"; - case SET: return "SET"; - case UNSET: return "UNSET"; - case FINDFILE: return "FINDFILE"; - case EXEC: return "EXEC"; - case LAUNCH: return "LAUNCH"; + case COMPLETE: ret = "COMPLETE"; break; + case MATCHES: ret = "MATCHES"; break; + case IS: ret = "IS"; break; + case ISSET: ret = "ISSET"; break; + case ISDIR: ret = "ISDIR"; break; + case ISFILE: ret = "ISFILE"; break; + case SET: ret = "SET"; break; + case UNSET: ret = "UNSET"; break; + case FINDFILE: ret = "FINDFILE"; break; + case EXEC: ret = "EXEC"; break; + case LAUNCH: ret = "LAUNCH"; break; } - return "UNKNOWN"; + return ret; } int main(int argc, char** argv) diff --git a/src/lib/x11_gc.c b/src/lib/x11_gc.c index 1ba3353..8d81aca 100644 --- a/src/lib/x11_gc.c +++ b/src/lib/x11_gc.c @@ -103,26 +103,23 @@ void x11_show(XConf* x) XftFont* x11_font_load(XConf* x, char* name) { - /* init the library and the base font pattern */ - if (!FcInit()) - { - return NULL; - } - FcPattern* pattern = FcNameParse((FcChar8 *)name); - if (!pattern) - { - return NULL; - } - /* load the base font */ - FcResult result; - FcPattern* match = XftFontMatch(x->display, x->screen, pattern, &result); XftFont* font = NULL; - if (match) + if (FcInit()) { - font = XftFontOpenPattern(x->display, match); + FcPattern* pattern = FcNameParse((FcChar8 *)name); + if (pattern) + { + /* load the base font */ + FcResult result; + FcPattern* match = XftFontMatch(x->display, x->screen, pattern, &result); + if (match) + { + font = XftFontOpenPattern(x->display, match); + } + FcPatternDestroy(pattern); + FcPatternDestroy(match); + } } - FcPatternDestroy(pattern); - FcPatternDestroy(match); return font; } diff --git a/src/lib/x11_sel.c b/src/lib/x11_sel.c index 555d10b..2229653 100644 --- a/src/lib/x11_sel.c +++ b/src/lib/x11_sel.c @@ -15,14 +15,16 @@ static struct XSel Selections[] = { static struct XSel* selfetch(Atom atom) { + struct XSel* ret = NULL; for (unsigned int i = 0; i < (sizeof(Selections) / sizeof(Selections[0])); i++) { if (atom == Selections[i].atom) { - return &Selections[i]; + ret = &Selections[i]; + break; } } - return NULL; + return ret; } static void xselclear(XConf* x, XEvent* e) @@ -110,35 +112,41 @@ void x11_sel_init(XConf* x) int x11_sel_get(XConf* x, int selid, void(*cbfn)(char*)) { + int ret = 0; struct XSel* sel = &(Selections[selid]); - if (sel->callback) return 0; - Window owner = XGetSelectionOwner(x->display, sel->atom); - if (owner == x->self) + if (!sel->callback) { - cbfn(sel->text); - } - else if (owner != None) - { - sel->callback = cbfn; - XConvertSelection(x->display, sel->atom, SelTarget, sel->atom, x->self, CurrentTime); + Window owner = XGetSelectionOwner(x->display, sel->atom); + if (owner == x->self) + { + cbfn(sel->text); + } + else if (owner != None) + { + sel->callback = cbfn; + XConvertSelection(x->display, sel->atom, SelTarget, sel->atom, x->self, CurrentTime); + } + ret = 1; } - return 1; + return ret; } int x11_sel_set(XConf* x, int selid, char* str) { + int ret; struct XSel* sel = &(Selections[selid]); if (!sel || !str || !*str) { free(str); - return 0; + ret = 0; } else { sel->text = str; XSetSelectionOwner(x->display, sel->atom, x->self, CurrentTime); - return 1; + ret = 1; } + return ret; } void x11_sel_quit(XConf* x, XEvent* e) -- 2.49.0