From ef68f9c37818bd685cf363f67f5c08feb5e21ab0 Mon Sep 17 00:00:00 2001 From: Shav Kinderlehrer Date: Thu, 4 May 2023 09:59:52 -0400 Subject: [PATCH] Revert extension --- include/arg.h | 2 +- src/lib/arg.c | 2 +- src/lib/exec.c | 63 ++------------------------------------------------ src/main.c | 6 ++--- 4 files changed, 7 insertions(+), 66 deletions(-) diff --git a/include/arg.h b/include/arg.h index a1864c7..a5d63a6 100644 --- a/include/arg.h +++ b/include/arg.h @@ -2,7 +2,7 @@ #define ARG_H #include -#define LAT_VERSION "0.12.2" +#define LAT_VERSION "0.12.3" struct config { bool isstdin; diff --git a/src/lib/arg.c b/src/lib/arg.c index 030d453..191198d 100644 --- a/src/lib/arg.c +++ b/src/lib/arg.c @@ -26,7 +26,7 @@ void help(void) { "stdout (or equivalent)\n" "\t-p print file with the pager (uses less)\n" "\t-n manually set the name of the file shown in the title\n" - "\t-e link extension to lat\n" + "\t-e NONFUNCTIONAL (will be added soon) link extension to lat\n" "\t-V show program version\n" "\t-h display this help text\n\n"); printf("environment:\n" diff --git a/src/lib/exec.c b/src/lib/exec.c index eb0aebc..4fa98df 100644 --- a/src/lib/exec.c +++ b/src/lib/exec.c @@ -9,65 +9,6 @@ #include "util.h" struct line runextension(struct line *data, char *filename, size_t n) { - struct line line; - - int in[2]; - int out[2]; - if (pipe(out) == -1 || pipe(in) == -1) - die("pipe"); - - pid_t pid = fork(); - if (pid == -1) - die("fork"); - - if (pid == 0) { - // child - dup2(out[1], STDOUT_FILENO); - close(out[0]); - close(out[1]); - - dup2(in[1], STDIN_FILENO); - close(in[0]); - close(in[1]); - - char *eargv[4]; - eargv[0] = conf.extension; - eargv[1] = filename; - eargv[2] = malloc((intlen(n) + 1) * sizeof(char)); - if (eargv[2] == NULL) - die("malloc"); - sprintf(eargv[2], "%zu", n); - eargv[3] = NULL; - - if (execvp(conf.extension, eargv) == -1) - die("exec"); - } else { - // parent - close(out[1]); - close(in[1]); - - write(in[0], "test\0", 4); - - char *buf = malloc(256); - memset(buf, '\0', 256); - - size_t len = read(out[0], buf, 256); - - line.buf = buf; - line.len = len; - - int status; - waitpid(pid, &status, 0); - - if (WEXITSTATUS(status) != EXIT_SUCCESS) { - die("exec fail"); - } - } - - close(out[0]); - close(out[1]); - close(in[0]); - close(in[1]); - - return line; + // TODO: Implement as unix socket + return *data; } diff --git a/src/main.c b/src/main.c index 66cedbd..19f4a9c 100644 --- a/src/main.c +++ b/src/main.c @@ -91,7 +91,9 @@ void run(FILE *fp, char *filename, bool tty) { free(padding); } - f.lines[i] = runextension(&f.lines[i], filename, i + 1); + if (conf.extension != NULL) { + f.lines[i] = runextension(&f.lines[i], filename, i + 1); + } fwrite(f.lines[i].buf, 1, f.lines[i].len, st); fprintf(st, "\n"); linecount++; @@ -162,8 +164,6 @@ int main(int argc, char *argv[]) { conf.headers = conf.headers && tty; - printf("set extension to '%s'\n", conf.extension); - if (argc > 1) { tty = tty || conf.literal;