Revert extension
This commit is contained in:
parent
4618e66f55
commit
ef68f9c378
@ -2,7 +2,7 @@
|
|||||||
#define ARG_H
|
#define ARG_H
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define LAT_VERSION "0.12.2"
|
#define LAT_VERSION "0.12.3"
|
||||||
|
|
||||||
struct config {
|
struct config {
|
||||||
bool isstdin;
|
bool isstdin;
|
||||||
|
@ -26,7 +26,7 @@ void help(void) {
|
|||||||
"stdout (or equivalent)\n"
|
"stdout (or equivalent)\n"
|
||||||
"\t-p print file with the pager (uses less)\n"
|
"\t-p print file with the pager (uses less)\n"
|
||||||
"\t-n <name> manually set the name of the file shown in the title\n"
|
"\t-n <name> manually set the name of the file shown in the title\n"
|
||||||
"\t-e <program> link extension to lat\n"
|
"\t-e <program> NONFUNCTIONAL (will be added soon) link extension to lat\n"
|
||||||
"\t-V show program version\n"
|
"\t-V show program version\n"
|
||||||
"\t-h display this help text\n\n");
|
"\t-h display this help text\n\n");
|
||||||
printf("environment:\n"
|
printf("environment:\n"
|
||||||
|
@ -9,65 +9,6 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
struct line runextension(struct line *data, char *filename, size_t n) {
|
struct line runextension(struct line *data, char *filename, size_t n) {
|
||||||
struct line line;
|
// TODO: Implement as unix socket
|
||||||
|
return *data;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,9 @@ void run(FILE *fp, char *filename, bool tty) {
|
|||||||
free(padding);
|
free(padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (conf.extension != NULL) {
|
||||||
f.lines[i] = runextension(&f.lines[i], filename, i + 1);
|
f.lines[i] = runextension(&f.lines[i], filename, i + 1);
|
||||||
|
}
|
||||||
fwrite(f.lines[i].buf, 1, f.lines[i].len, st);
|
fwrite(f.lines[i].buf, 1, f.lines[i].len, st);
|
||||||
fprintf(st, "\n");
|
fprintf(st, "\n");
|
||||||
linecount++;
|
linecount++;
|
||||||
@ -162,8 +164,6 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
conf.headers = conf.headers && tty;
|
conf.headers = conf.headers && tty;
|
||||||
|
|
||||||
printf("set extension to '%s'\n", conf.extension);
|
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
|
|
||||||
tty = tty || conf.literal;
|
tty = tty || conf.literal;
|
||||||
|
Loading…
Reference in New Issue
Block a user