commit b872ae604c8b5614d27ebb5701bb12d319fdb1a3
parent fbbce21c354959755db3a34342679040491bd83a
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Wed, 23 Dec 2020 16:54:14 -0800
Move configuration options to a config file
Diffstat:
3 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/Makefile b/Makefile
@@ -11,12 +11,15 @@ CFLAGS = -std=c99 -Wall -pedantic -O2
all: ${TARGET}
-.PHONY: clean
-
.c.o:
${CC} ${LDFLAGS} -c ${CFLAGS} $<
-${TARGET}: ${OBJS}
+${OBJS}: Makefile config.def.h
+
+config.h:
+ cp config.def.h $@
+
+${TARGET}: config.h ${OBJS}
${CC} -o $@ ${OBJS} ${LDLIBS}
clean:
@@ -29,3 +32,5 @@ install: ${TARGET}
uninstall:
rm -f ${PREFIX}/bin/${TARGET}
rm -f ${MANPREFIX}/man1/${TARGET}.1
+
+.PHONY: clean install uninstall
diff --git a/config.def.h b/config.def.h
@@ -0,0 +1,16 @@
+/* gawk config.h */
+
+/* default gopher hole (path, host, port): */
+static const char *default_address[] = { "/", "localhost", "70" };
+
+#define IFS ":\t " /* input field seporator */
+#define ISS ";\n" /* input statement seporator */
+
+/* arbitrary limits */
+#define CHUNK_SIZE 256 /* for slurping data */
+#define MY_ARGV_MAX 12
+#define MY_FILTER_MAX 4
+#define MY_INPUT_MAX 128
+#define MY_LINE_MAX 128
+#define MY_PATH_MAX 128
+#define MY_URL_MAX 72
diff --git a/main.c b/main.c
@@ -17,7 +17,6 @@
#include <sys/socket.h>
#include <sys/stat.h>
-
#include <ctype.h>
#include <err.h>
#include <errno.h>
@@ -30,22 +29,13 @@
#include <string.h>
#include <unistd.h>
-#define LEN(X) (sizeof(X) / sizeof(*X))
-
-#define BUFSIZE 128
-#define ARG_SEP ":\t "
-#define CMD_SEP ";\n"
+#include "config.h"
-#define MY_ARGV_MAX 12
-#define MY_INPUT_MAX 128 /* MAX_INPUT */
-#define MY_LINE_MAX 128
-#define MY_PATH_MAX 128 /* NOTE: PATH_MAX should be used with realpath(1), etc. */
-#define MY_URL_MAX 72
-#define MY_FILTER_MAX 4
+#define LEN(X) (sizeof(X) / sizeof(*X))
enum address { AR_PATH, AR_HOST, AR_PORT, AR_NULL }; /* NOTE: see reqtoaddr() */
enum gphitem { GI_INFO, GI_PATH, GI_HOST, GI_PORT, GI_PLUS, GI_NULL };
-enum status { ERROR = -1, OK, UNWIND };
+enum status { ERROR = -1, OK, UNWIND };
typedef int (item_command)(int, const char **, int, const char **);
typedef int (filter)(int, const char **, unsigned int, const char **);
@@ -53,10 +43,9 @@ typedef int (command)(int, const char **, int, const char **);
int gawk(const char **);
-static int timeout = 5 * 1000;
static char tmpdir[] = "/tmp/gawk-XXXXXXXXXXX";
-static const char *default_address[] = { "/", "localhost", "70" };
static int fatal;
+static int timeout = 5 * 1000;
/* This exists to make it easy to track down later */
const char **
@@ -263,7 +252,7 @@ int
gph_write_resp(int sock, const char *path)
{
FILE *fp;
- char buf[BUFSIZE];
+ char buf[CHUNK_SIZE];
ssize_t bytes;
struct pollfd pfd;
@@ -655,8 +644,8 @@ gawk(const char **addr)
done = 0;
snprintf(prompt, sizeof(prompt), "(%d) [%s] %s ", depth, addr[AR_HOST], addr[AR_PATH]);
- while (!done && input(inbuf, sizeof(inbuf), CMD_SEP, prompt, stdin) == 0) {
- argc = argsplit(argv, LEN(argv), inbuf, ARG_SEP);
+ while (!done && input(inbuf, sizeof(inbuf), ISS, prompt, stdin) == 0) {
+ argc = argsplit(argv, LEN(argv), inbuf, IFS);
if (argc < 0) {
warnx("Too many arguments.");
} else if (argc > 0) {