define preproc directive allows macro replacement for nexted defines
authorLukas Krickl <lukas@krickl.dev>
Wed, 27 Dec 2023 16:40:26 +0000 (17:40 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 27 Dec 2023 16:40:26 +0000 (17:40 +0100)
src/test.c
src/ulas.c

index 8ab2c8d4b49f30e2ff02ea87cd69ffa56c82829f..66091a2690071b72595e48ce25653bafdb1931cf 100644 (file)
@@ -104,6 +104,9 @@ void test_preproc(void) {
   assert_preproc("", -1, "  #define\n");
   assert_preproc("this is a 123 for defs", 0,
                  "  #define test 123\nthis is a test for defs");
+  // define used inside define 
+  assert_preproc("this is a 123 for defs", 0,
+                 "  #define ftest 123\n#define test ftest\nthis is a test for defs");
 
   // undefined
   assert_preproc("123\ntest", 0,
index dffea8920f9fa552ae7abfa6b1150b365c17ebb6..da38d981c95bb45a69ac58f501e154e81c0c8f47 100644 (file)
@@ -714,7 +714,8 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line,
   // otherwise memcpy the read bytes 1:1 into the new string
   while ((read = ulas_tok(&pp->tok, &praw_line, *n))) {
     // if it is the first token, and it begins with a # do not process at all!
-    if (first_tok && pp->tok.buf[0] == ULAS_TOK_PREPROC_BEGIN) {
+    // only apply this to certain preproc types such as #undefine, #ifdef and #ifndef 
+    if (first_tok && pp->tok.buf[0] == ULAS_TOK_PREPROC_BEGIN && strcmp(ULAS_PPSTR_DEF, pp->tok.buf) != 0) {
       ulas_strensr(&pp->line, (*n) + 1);
       strncat(pp->line.buf, raw_line, *n);
       break;