Prep for new extension system

This commit is contained in:
Shav Kinderlehrer 2023-05-18 08:51:12 -04:00
parent e5398d744f
commit 08abee1958
6 changed files with 22 additions and 24 deletions

View File

@ -1,6 +0,0 @@
#ifndef EXEC_H
#define exec_h
#include "types.h"
struct line runextension(struct line *data, char *filename, size_t n);
#endif

8
include/extension.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef EXTENSION_H
#define EXTENSION_H
#include "types.h"
struct filedata runfilter(struct filedata *f);
#endif // EXTENSION_H

4
include/server.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef SERVER_H
#define SERVER_H
#endif // SERVER_H

5
src/extension/filter.c Normal file
View File

@ -0,0 +1,5 @@
#include "extension.h"
#include "types.h"
#include "util.h"
struct filedata runfilter(struct filedata *f) { return *f; }

View File

@ -1,14 +0,0 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "arg.h"
#include "types.h"
#include "util.h"
struct line runextension(struct line *data, char *filename, size_t n) {
// TODO: Implement as unix socket
return *data;
}

View File

@ -3,7 +3,7 @@
#include <unistd.h> #include <unistd.h>
#include "arg.h" #include "arg.h"
#include "exec.h" #include "extension.h"
#include "file.h" #include "file.h"
#include "process.h" #include "process.h"
#include "types.h" #include "types.h"
@ -53,6 +53,10 @@ void run(FILE *fp, char *filename, bool tty) {
struct filedata f; struct filedata f;
f = readfile(fp, conf.isstdin); f = readfile(fp, conf.isstdin);
if (conf.extension != NULL) {
f = runfilter(&f);
}
if (conf.pager) { if (conf.pager) {
st = popen("less", "w"); st = popen("less", "w");
err = st; err = st;
@ -91,9 +95,6 @@ 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);
}
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++;