]> git.mdlowis.com Git - projs/tide.git/commitdiff
minor lint cleanup in fetch
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 4 Nov 2019 21:45:01 +0000 (16:45 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 4 Nov 2019 21:45:01 +0000 (16:45 -0500)
src/fetch.c

index 589a17c93168e1e603ae41887f2b3cdde18a7d4b..2f0aa901aace708eb432c0b5e17e6811e4e28160 100644 (file)
@@ -18,9 +18,6 @@ char* Matches[10];
 Rule*** Rulesets = NULL;
 size_t NumRulesets = 0;
 
-#define FETCH_RULES
-#include "config.h"
-
 static Rule*** BuiltinRules = (Rule**[]){
     (Rule*[]){ /* Match URLS and open them with the browser */
         &(Rule){ ISSET, "BROWSER", NULL },
@@ -52,13 +49,6 @@ static Rule*** BuiltinRules = (Rule**[]){
         &(Rule){ LAUNCH, "picktag fetch tags \"$data\"", NULL },
         &(Rule){ COMPLETE, NULL, NULL }
     },
-//    (Rule*[]){ /* Look up .c or .h files in Code/ */
-//        &(Rule){ MATCHES, "data", "\\.[ch]$" },
-//        &(Rule){ ISDIR, "Code", NULL },
-//        &(Rule){ EXEC, "[[ \"$(find Code -type f -name \"*$data\")\" ]]", NULL },
-//        &(Rule){ LAUNCH, "find Code -type f -name \"*$data\" | xargs -r edit", NULL },
-//        &(Rule){ COMPLETE, NULL, NULL }
-//    },
     (Rule*[]){ /* Open man pages in a tide window */
         &(Rule){ ISSET, "BROWSER", NULL },
         &(Rule){ MATCHES, "data", "(.+)\\(([0-9]+)\\)" },
@@ -137,13 +127,7 @@ char* eval(char* str)
 
 /******************************************************************************/
 
-bool complete(void)
-{
-    exit(0);
-    return false;
-}
-
-bool matches(char* var, char* patt)
+static bool matches(char* var, char* patt)
 {
     bool ret = false;
     regex_t regex = {0};
@@ -163,17 +147,17 @@ bool matches(char* var, char* patt)
     return ret;
 }
 
-bool var_is(char* var, char* val)
+static bool var_is(char* var, char* val)
 {
     return (strcmp(getvar(var), eval(val)) == 0);
 }
 
-bool var_isset(char* var)
+static bool var_isset(char* var)
 {
     return (getenv(var) != NULL);
 }
 
-bool var_isdir(char* var)
+static bool var_isdir(char* var)
 {
     bool ret = false;
     struct stat st = {0};
@@ -187,7 +171,7 @@ bool var_isdir(char* var)
     return ret;
 }
 
-bool var_isfile(char* var)
+static bool var_isfile(char* var)
 {
     bool ret = false;
     struct stat st = {0};
@@ -201,24 +185,24 @@ bool var_isfile(char* var)
     return ret;
 }
 
-bool var_set(char* var, char* val)
+static bool var_set(char* var, char* val)
 {
     return (setenv(var, eval(val), 1) == 0);
 }
 
-bool var_unset(char* var)
+static bool var_unset(char* var)
 {
     return (unsetenv(var) == 0);
 }
 
-void runcmd(char* cmd)
+static void runcmd(char* cmd)
 {
     char* shellcmd[] = { getvar("SHELL"), "-c", cmd, NULL };
     if (!shellcmd[0]) shellcmd[0] = "/bin/sh";
     _exit(execvp(shellcmd[0], shellcmd));
 }
 
-bool exec(char* cmd)
+static bool exec(char* cmd)
 {
     bool ret = false;
     int pid, status;
@@ -237,7 +221,7 @@ bool exec(char* cmd)
     return ret;
 }
 
-bool launch(char* cmd)
+static bool launch(char* cmd)
 {
     bool ret = false;
     int pid = fork();
@@ -252,7 +236,7 @@ bool launch(char* cmd)
     return ret;
 }
 
-bool apply_rule(Rule* rule)
+static bool apply_rule(Rule* rule)
 {
     bool ret = false;
     switch (rule->type)
@@ -273,13 +257,13 @@ bool apply_rule(Rule* rule)
 
 /******************************************************************************/
 
-void usage(char* pname)
+static void usage(char* pname)
 {
     fprintf(stderr, "Usage: %s [ITEM]\n", pname);
     exit(1);
 }
 
-char* type2str(int type)
+static char* type2str(int type)
 {
     char* ret = "UNKNOWN";
     switch (type)
@@ -298,7 +282,7 @@ char* type2str(int type)
     return ret;
 }
 
-char* nextline(char** raw)
+static char* nextline(char** raw)
 {
     char* line = NULL;
     char* eol = strchr(*raw, '\n');
@@ -315,7 +299,7 @@ char* nextline(char** raw)
     return line;
 }
 
-char* nextfield(char** raw)
+static char* nextfield(char** raw)
 {
     char* field = *raw;
     /* skip whitespace */
@@ -329,7 +313,7 @@ char* nextfield(char** raw)
     return (field && *field ? field : NULL);
 }
 
-void parse_args1(int type, Rule* rule, char* args)
+static void parse_args1(int type, Rule* rule, char* args)
 {
     rule->type = type;
     rule->arg1 = args;
@@ -340,7 +324,7 @@ void parse_args1(int type, Rule* rule, char* args)
     }
 }
 
-void parse_args2(int type, Rule* rule, char* args)
+static void parse_args2(int type, Rule* rule, char* args)
 {
     rule->type = type;
     rule->arg1 = nextfield(&args);
@@ -352,7 +336,7 @@ void parse_args2(int type, Rule* rule, char* args)
     }
 }
 
-Rule* parse_rule(char* act, char* args)
+static Rule* parse_rule(char* act, char* args)
 {
     Rule* rule = calloc(1, sizeof(Rule));
     if (!strcmp(act, "is"))
@@ -399,7 +383,7 @@ Rule* parse_rule(char* act, char* args)
     return rule;
 }
 
-void add_ruleset(Rule** rules, size_t nrules, Rule* rule)
+static void add_ruleset(Rule** rules, size_t nrules, Rule* rule)
 {
     if (rules)
     {
@@ -410,7 +394,7 @@ void add_ruleset(Rule** rules, size_t nrules, Rule* rule)
     Rulesets[NumRulesets-1] = rules;
 }
 
-void parse_rules(char* path)
+static void parse_rules(char* path)
 {
     char* line = NULL;
     char* raw = readfile(path);
@@ -449,12 +433,10 @@ void parse_rules(char* path)
         {
             add_ruleset(rules, nrules, calloc(1, sizeof(Rule)));
         }
-//        add_ruleset(NULL, 0, NULL);
     }
-    telem_send("DONE\n", path);
 }
 
-void check_ruleset(Rule** rule)
+static void check_ruleset(Rule** rule)
 {
     for (; (*rule)->type != COMPLETE; rule++)
     {
@@ -488,7 +470,7 @@ int main(int argc, char** argv)
         /* load rules from files */
         parse_rules("fetch.rules");
         parse_rules(homedir_path("config/tide/fetch.rules"));
-        add_ruleset(NULL, 0, NULL);
+        add_ruleset(NULL, 0, NULL); // terminate the parsed set of rules
 
         telem_send("FETCH(%s)\n", argv[1]);
         setenv("data", argv[1], 1);