]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed even more lint
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 14 Oct 2019 01:18:33 +0000 (21:18 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 14 Oct 2019 01:18:33 +0000 (21:18 -0400)
alcc
src/edit.c
src/fetch.c
src/lib/x11_gc.c
src/lib/x11_sel.c

diff --git a/alcc b/alcc
index 92ae8318b48b4ec6853e9d9f64a561a1ab76f556..be0e318660d194d1114ab7759b7f867a75363269 100755 (executable)
--- a/alcc
+++ b/alcc
@@ -275,7 +275,7 @@ script=$(cat <<EOS
         {
             error("reached EOF with open block");
         }
-        exit code
+#        exit code
     }
 EOS
 )
index dde5950a0e5ad94b051a25916671bc82a891f2ca..4f61aefa7f5b614cb1329f06662b77803600c621 100644 (file)
@@ -84,6 +84,7 @@ void edit_file(XConf* x, Window registrar, char* path, char* addr, int force)
 
 int main(int argc, char** argv)
 {
+    int ret = 0;
     int force = 0;
     OPTBEGIN { case 'f': force = 1; break; } OPTEND;
     if (argc == 0)
@@ -99,22 +100,25 @@ int main(int argc, char** argv)
         XA_OPEN = XInternAtom(x.display, "OPEN", 0);
         XA_DONE = XInternAtom(x.display, "DONE", 0);
         Window registrar = start_registrar(&x);
-        if (registrar == None)
+        if (registrar != None)
         {
-            fprintf(stderr, "Failed to contact registrar.\n");
-            return 1;
-        }
-        /* Loop over files and send an OPEN message for each one. */
-        for (int i = 0; i < argc; i++)
-        {
-            char* addr = strrchr(argv[i], ':');
-            if (addr)
+            /* Loop over files and send an OPEN message for each one. */
+            for (int i = 0; i < argc; i++)
             {
-                *addr = '\0', addr++;
+                char* addr = strrchr(argv[i], ':');
+                if (addr)
+                {
+                    *addr = '\0', addr++;
+                }
+                edit_file(&x, registrar, argv[i], (addr ? addr : "0"), force);
             }
-            edit_file(&x, registrar, argv[i], (addr ? addr : "0"), force);
+            XSync(x.display, False);
+        }
+        else
+        {
+            fprintf(stderr, "Failed to contact registrar.\n");
+            ret = 1;
         }
-        XSync(x.display, False);
     }
-    return 0;
+    return ret;
 }
index 1b1021c6f85ee6c655cde63a12da39dc07278711..d217489099bfc2657a64d417056fc816f22145b7 100644 (file)
@@ -39,11 +39,8 @@ char* eval(char* str)
     }
 
     regmatch_t matches[2] = {{0},{0}};
-    if (regexec(&regex, str, nelem(matches), matches, 0) < 0)
-    {
-        return str;
-    }
-    else if (matches[1].rm_so > 0)
+    int result = regexec(&regex, 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(&regex, 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)
index 1ba33538a843f5a05ed39e103d704bf3165b1c63..8d81acadc87258aaf1182588dcc38b19aa2ac8fb 100644 (file)
@@ -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;
 }
 
index 555d10b783a92d5772329d21349930c43deacff0..22296531b8ff888ee375c450c7a311d4d96c6f54 100644 (file)
@@ -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)