]> git.mdlowis.com Git - projs/tide.git/commitdiff
had to keep the eval function for rule actions that do not utilize the shell but...
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 17 Dec 2018 16:07:12 +0000 (11:07 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 17 Dec 2018 16:07:12 +0000 (11:07 -0500)
TODO.md
config.h
src/fetch.c

diff --git a/TODO.md b/TODO.md
index 4f72d7ee33bb906bc646cd7539024d52cbe357cb..3183fedb42e94eeaf34449aed2972cc5f8d7a21b 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -3,7 +3,6 @@
 ## STAGING
 
 * registrar doesnt match open windows when new file created and is then opened for edit or line number
-* fetch should stuff match strings in environment variables instead of evaling
 * implement a mini-sed command to standardize scripts across platforms without relying on sed
 * registrar should remove invalid windows from registry when detected
 * tide should re-register with the registrar when a new registrar is launched
index 65c73f28b3ccf227e83cf295b6251c8e08f84bfe..543597d9e4cdf311fc57a495dce9f48089066b59 100644 (file)
--- a/config.h
+++ b/config.h
@@ -75,7 +75,6 @@ static int Palette[ClrCount] = {
     [ScrollFg] = 0xF0F0E5, /* Scroll region foreground */
     [VerBdr]   = 0x909047, /* Vertical border */
     [HorBdr]   = 0x000000, /* Horizontal border */
-
 };
 
 #ifdef FETCH_RULES
@@ -90,13 +89,13 @@ Rule* BuiltinRules[] = {
     (Rule[]){ /* Match URLS and open them with the browser */
         { ISSET, "BROWSER", NULL },
         { MATCHES, "data", "^(https?|ftp)://.*" },
-        { LAUNCH, "$BROWSER \"$0\"", NULL },
+        { LAUNCH, "$BROWSER \"$M0\"", NULL },
         { COMPLETE, NULL, NULL }
     },
     (Rule[]){ /* Open files with addresses in the editor */
         { MATCHES, "data", "^([^:]+):([0-9]+)" },
-        { ISFILE, "$1", NULL },
-        { LAUNCH, "edit \"$0\"", NULL },
+        { ISFILE, "$M1", NULL },
+        { LAUNCH, "edit \"$M0\"", NULL },
         { COMPLETE, NULL, NULL }
     },
     (Rule[]){ /* If it's an existing text file, open it with editor */
index 817dde21f2df47f7a306e3c41c381201925f352d..19e21cc09d6eeb1417f1bbb9ccc825d5244d816c 100644 (file)
@@ -25,10 +25,7 @@ char* Matches[10];
 /******************************************************************************/
 
 char* getvar(char* val) {
-    if (strlen(val) == 1 && isdigit(*val))
-        val = Matches[*val - '0'];
-    else
-        val = getenv(val);
+    val = getenv(val);
     return (val ? val : "");
 }
 
@@ -71,10 +68,11 @@ bool matches(char* var, char* patt) {
     regmatch_t matches[10] = {{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}};
     if (regcomp(&regex, patt, REG_EXTENDED) == 0) {
         var = getvar(var);
-        memset(Matches, 0, sizeof(Matches));
         int err = regexec(&regex, var, nelem(matches), matches, 0);
         for (int i = 0; i < 10 && matches[i].rm_so >= 0; i++) {
-            Matches[i] = strndup(var+matches[i].rm_so, matches[i].rm_eo-matches[i].rm_so);
+            char* matchval = strndup(var+matches[i].rm_so, matches[i].rm_eo-matches[i].rm_so);
+            setenv((char[]){ 'M', ('0' + i), 0 }, matchval, 1);
+            free(matchval);
         }
         return (err == 0);
     }
@@ -129,9 +127,8 @@ bool find_file(char* file) {
 }
 
 void runcmd(char* cmd) {
-    char* shellcmd[] = { getvar("SHELL"), "-c", NULL, NULL };
+    char* shellcmd[] = { getvar("SHELL"), "-c", cmd, NULL };
     if (!shellcmd[0]) shellcmd[0] = "/bin/sh";
-    shellcmd[2] = eval(cmd);
     _exit(execvp(shellcmd[0], shellcmd));
 }