#include <string.h>
#define ULAS_PATHMAX 4096
+#define ULAS_LINEMAX 4096
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
// 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) { \
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)
#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;
+}
#include "ulas.h"
#include <stdio.h>
#include <assert.h>
+#include "preproc.h"
#define TESTBEGIN(name) printf("[test %s]\n", (name));
#define TESTEND(name) printf("[%s ok]\n", (name));
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;
}