From 0545c0551346f74ba2c763ed1aa3b5eeb700338c Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 5 Nov 2023 20:18:22 +0100 Subject: [PATCH] WIP: preproc --- include/ulas.h | 4 ++++ makefile | 2 +- src/preproc.c | 15 ++++++++++++++- src/test.c | 26 ++++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/include/ulas.h b/include/ulas.h index b7ff99b..ba8c24c 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -7,6 +7,7 @@ #include #define ULAS_PATHMAX 4096 +#define ULAS_LINEMAX 4096 #define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MIN(x, y) (((x) < (y)) ? (x) : (y)) @@ -27,6 +28,9 @@ // start of preprocessor directives such as #define or #include #define ULAS_TOK_PREPROC_BEGIN '#' +#define ULASERR(...) fprintf(ulaserr, __VA_ARGS__); +#define ULASWARN(...) fprintf(ulaserr, __VA_ARGS__); + // format macros #define ULAS_FMT(f, fmt) \ if (isatty(fileno(f)) && ulascfg.color) { \ diff --git a/makefile b/makefile index 3465ca5..aa03e42 100644 --- a/makefile +++ b/makefile @@ -4,7 +4,7 @@ SDIR=./src CC=gcc DBGCFLAGS=-g -fsanitize=address DBGLDFLAGS=-fsanitize=address -CFLAGS=-I$(IDIR) -Wall -pedantic $(DBGCFLAGS) -std=c99 +CFLAGS=-I$(IDIR) -Wall -pedantic $(DBGCFLAGS) -std=gnu99 LIBS= TEST_LIBS= LDFLAGS=$(DBGLDFLAGS) $(LIBS) diff --git a/src/preproc.c b/src/preproc.c index 5ddacfe..a469713 100644 --- a/src/preproc.c +++ b/src/preproc.c @@ -1,4 +1,17 @@ #include "preproc.h" +#include "ulas.h" +int ulas_preproc(FILE *dst, FILE *src) { + char buf[ULAS_LINEMAX]; + memset(buf, 0, ULAS_LINEMAX); -int ulas_preproc(FILE *dst, FILE *src) { return 0; } + if (!dst || !src) { + ULASERR("[preproc] Unable to read from dst or write to src!\n"); + return -1; + } + + while (fgets(buf, ULAS_LINEMAX, src) == NULL) { + } + + return 0; +} diff --git a/src/test.c b/src/test.c index da84d42..e17777c 100644 --- a/src/test.c +++ b/src/test.c @@ -1,6 +1,7 @@ #include "ulas.h" #include #include +#include "preproc.h" #define TESTBEGIN(name) printf("[test %s]\n", (name)); #define TESTEND(name) printf("[%s ok]\n", (name)); @@ -25,14 +26,35 @@ void test_tok(void) { TESTEND("tok"); } +#define assert_preproc(expect_dst, expect_ret, input) \ + { \ + char dstbuf[ULAS_LINEMAX]; \ + memset(dstbuf, 0, ULAS_LINEMAX); \ + FILE *src = fmemopen((input), strlen((input)), "r"); \ + FILE *dst = fmemopen(dstbuf, ULAS_LINEMAX, "w"); \ + assert(ulas_preproc(dst, src) == (expect_ret)); \ + assert(strcmp(dstbuf, (expect_dst)) == 0); \ + fclose(src); \ + fclose(dst); \ + } + +void test_preproc(void) { + TESTBEGIN("preproc"); + + assert_preproc("", 0, "test"); + + TESTEND("preproc"); +} + int main(int arc, char **argv) { ulas_init(ulas_cfg_from_env()); - if (!ulascfg.verbose) { + /*if (!ulascfg.verbose) { fclose(stderr); - } + }*/ test_tok(); + test_preproc(); return 0; } -- 2.30.2