scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 176113dda664e739a5f9fbaf79a2a74cf0fb2374
parent 125f52205831b30937916de4eaaaf86a99844169
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 30 Oct 2024 12:39:56 +0100

make: Split expandmacro()

The semantic of expandmacro() was weird because it was doing
two different things, expanding a macro and applying a replace
so it is better to split it in two different functions.

Diffstat:
Msrc/cmd/scc-make/parser.c | 24++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/cmd/scc-make/parser.c b/src/cmd/scc-make/parser.c @@ -394,13 +394,18 @@ validchar(int c) return c == '.' || c == '/' || c == '_' || c == '-' || isalnum(c); } +static char * +expandmacro(char *name) +{ + return expandstring(getmacro(name), NULL); +} + + static void -expandmacro(char *name, char *repl, char *to) +replace(char *s, char *repl, char *to) { int pos, siz, replsiz, tosiz; - char *s, *t, *p, *buf; - - s = expandstring(getmacro(name), NULL); + char *t, *p, *buf; pos = 0; buf = NULL; @@ -428,7 +433,6 @@ expandmacro(char *name, char *repl, char *to) push(FTEXPAN, buf); free(buf); } - free(s); } static void @@ -484,7 +488,9 @@ expandsimple(Target *tp) default: token[0] = c; token[1] = '\0'; - expandmacro(token, "", ""); + s = expandmacro(token); + push(FTEXPAN, s); + free(s); break; } } @@ -493,7 +499,7 @@ static void expansion(Target *tp) { int delim, c, repli, toi, namei, st; - char name[MAXTOKEN], repl[MAXREPL], to[MAXREPL]; + char *s, name[MAXTOKEN], repl[MAXREPL], to[MAXREPL]; c = nextc(); if (c == '(') @@ -549,7 +555,9 @@ expansion(Target *tp) name[namei] = '\0'; repl[repli] = '\0'; to[toi] = '\0'; - expandmacro(name, repl, to); + s = expandmacro(name); + replace(s, repl, to); + free(s); } }