"#macro mtest\ntest macro with no args\n#endmacro\nmtest");
assert_preproc("", -1, "#macro test\n not terminated\n");
assert_preproc(
- "content macro t1\nt1\nafter\ncontent n1\n", 0,
+ "\ncontent macro t1\nt1\nafter\ncontent n1\n", 0,
"#macro test\nmnested macro $1\n$1\n#macro "
"mnested\ncontent $1\n#endmacro\nafter\nmnested n1\n#endmacro\ntest t1");
}
}
+char *ulas_preprocexpand2(struct ulas_preproc *pp, const char *raw_line,
+ unsigned long *n, int recursive);
void ulas_preprocexpand_rec(struct ulas_preproc *pp) {
// expand macro result again to allow
// defines to appear in the macro
ULASERR("Max macro recursion depth reached\n");
return;
}
- ulas_preprocexpand(pp, pp->line2.buf, &n);
+ ulas_preprocexpand2(pp, pp->line2.buf, &n, 1);
pp->exp_depth--;
}
char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line,
unsigned long *n) {
+ return ulas_preprocexpand2(pp, raw_line, n, 0);
+}
+
+char *ulas_preprocexpand2(struct ulas_preproc *pp, const char *raw_line,
+ unsigned long *n, int recursive) {
const char *praw_line = raw_line;
memset(pp->line.buf, 0, pp->line.maxlen);
const char *tocat = NULL;
unsigned long tocatlen = 0;
+ // always start an expanded macro with a new line
+ // to ensure expansion are separated if we are in a recursive call
+ // this fixes new lines in recursive macros being consumed
+ if (recursive) {
+ int len = strnlen(pp->line.buf, pp->line.maxlen) + 1;
+ ulas_strensr(&pp->line,
+ len + 1);
+ strncat(pp->line.buf, "\n", len);
+ }
+
+
// now tokenize the macro's value and look for $0-$9
// and replace those instances
// eveyrthing else will just be copied as is