]> git.mdlowis.com Git - projs/tide.git/commitdiff
switch command execution to use the system shell. Also fixed a bug in cmdwriteread.
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 27 Nov 2016 00:10:56 +0000 (19:10 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 27 Nov 2016 00:10:56 +0000 (19:10 -0500)
Makefile
libedit/exec.c
xedit.c

index 59f1c1ebc239ec68ac3af1fe6b09e011eebb4052..e8e6a50beda74d195482ba2f9ad71d6b3348281a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,8 @@ test: unittests
        ./unittests
 
 xedit: xedit.o libx.a libedit.a
+       $(LD) -o $@ $^ $(LDFLAGS)
+
 #xpick: xpick.o libx.a libedit.a
 
 libedit.a: $(LIBEDIT_OBJS)
index 1bd0c1e510b76c607e4d483adf518c060de7a79e..c6c05a143d92880b093e38b4c1838309e4a214d8 100644 (file)
@@ -91,6 +91,7 @@ char* cmdwriteread(char** cmd, char* text) {
         perror("failed to write");
         return NULL;
     }
+    close(proc.in);
     char* str = fdgets(proc.out);
     detach(&proc);
     waitpid(proc.pid, NULL, 0);
diff --git a/xedit.c b/xedit.c
index 5e7e7a98ccd2823f6452b424f5796c5f3c9c8a87..f56d27a82612353dbf407c219f80c200be9fcb02 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -131,6 +131,8 @@ static char* PasteCmd[] = { "pbpaste", NULL };
 static char* CopyCmd[]  = { "xsel", "-bi", NULL };
 static char* PasteCmd[] = { "xsel", "-bo", NULL };
 #endif
+static char* ShellCmd[] = { "/bin/sh", "-c", NULL, NULL };
+
 
 /* Main Routine
  *****************************************************************************/
@@ -425,7 +427,7 @@ static void find(char* arg) {
 static Tag* tag_lookup(char* cmd) {
     size_t len = 0;
     Tag* tags = Builtins;
-    for (char* tag = cmd; !isspace(*tag); tag++, len++);
+    for (char* tag = cmd; *tag && !isspace(*tag); tag++, len++);
     while (tags->tag) {
         if (!strncmp(tags->tag, cmd, len))
             return tags;
@@ -447,28 +449,19 @@ static void cmd_exec(char* cmd) {
     char op = '\0';
     if (*cmd == '!' || *cmd == '<' || *cmd == '|' || *cmd == '>')
         op = *cmd, cmd++;
-    /* convert the command to an array */
-    size_t len = 0;
-    char **cmdary = NULL, *part = NULL;
-    while (true) {
-        part = strtok((!part ? cmd : NULL), " ");
-        cmdary = realloc(cmdary, len+1 * sizeof(char*));
-        cmdary[len++] = part;
-        if (!part) break;
-    }
     /* execute the command */
     char *input = NULL, *output = NULL;
     enum RegionId dest = EDIT;
     input = view_getstr(getview(EDIT), NULL);
     if (op == '!') {
-        printf("null: '%s' argc: %lu\n", cmd, len);
+        printf("null: '%s'\n", cmd);
     } else if (op == '>') {
-        cmdwrite(cmdary, input);
+        cmdwrite(ShellCmd, input);
     } else if (op == '|') {
-        output = cmdwriteread(cmdary, input);
+        output = cmdwriteread(ShellCmd, input);
     } else {
         if (op != '<') dest = Focused;
-        output = cmdread(cmdary);
+        output = cmdread(ShellCmd);
     }
     if (output) {
         view_putstr(getview(dest), output);
@@ -477,7 +470,6 @@ static void cmd_exec(char* cmd) {
     /* cleanup */
     free(input);
     free(output);
-    free(cmdary);
 }
 
 static void exec(char* cmd) {