From cf8d5948280ec26ef9173681d657e2b2b4e84eae Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sat, 26 Nov 2016 19:10:56 -0500 Subject: [PATCH] switch command execution to use the system shell. Also fixed a bug in cmdwriteread. --- Makefile | 2 ++ libedit/exec.c | 1 + xedit.c | 22 +++++++--------------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 59f1c1e..e8e6a50 100644 --- 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) diff --git a/libedit/exec.c b/libedit/exec.c index 1bd0c1e..c6c05a1 100644 --- a/libedit/exec.c +++ b/libedit/exec.c @@ -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 5e7e7a9..f56d27a 100644 --- 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) { -- 2.52.0