WIP: preproc directive detection
authorLukas Krickl <lukas@krickl.dev>
Mon, 6 Nov 2023 19:16:51 +0000 (20:16 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 6 Nov 2023 19:16:51 +0000 (20:16 +0100)
src/preproc.c
src/test.c

index 8dbde7aa881be1779281c475c048b4a186fdf64d..7fe00dbcc2d1f3dd9ee92326f8d021e7bd9573cf 100644 (file)
@@ -5,7 +5,7 @@
 #include <stdio.h>
 #include <assert.h>
 
-bool ulas_tokpreproc(char c) { return !isalnum(c); }
+bool ulas_tokpreproc(char c) { return !isalnum(c) && c != '#'; }
 
 char *ulas_preprocexpand(char *line, size_t linemax, const char *raw_line,
                          size_t *n) {
@@ -61,6 +61,8 @@ found:
 
   if (found_dir) {
     // TODO: process directive
+    printf("%s preproc directive!\n", tok);
+    fputc('\0', dst);
   } else {
     assert(fwrite(line, 1, n, dst) == n);
   }
index 32d804d1e08eca3bbede590bc81d3bad0b364a2b..a9f39ef58a792b06fcc15ed98494422027bfc34b 100644 (file)
@@ -61,6 +61,7 @@ void test_preproc(void) {
 
   // should just echo back line as is
   assert_preproc("  test line", 0, "  test line");
+  assert_preproc("", 0, "  #define test");
 
   TESTEND("preproc");
 }