diff options
author | harti <harti@FreeBSD.org> | 2005-05-10 08:06:13 +0000 |
---|---|---|
committer | harti <harti@FreeBSD.org> | 2005-05-10 08:06:13 +0000 |
commit | 35798a61f5bc26fc5367c82049406055d1e71604 (patch) | |
tree | 848bbd774031d41facff25de4a70857f9eb8b2c1 /usr.bin/make/var.c | |
parent | 6352eca8c58c516b39b9fcfe237e2b4736fa66c1 (diff) | |
download | FreeBSD-src-35798a61f5bc26fc5367c82049406055d1e71604.zip FreeBSD-src-35798a61f5bc26fc5367c82049406055d1e71604.tar.gz |
Make make a little bit more POSIXish with regard to option parsing:
take everything after -- as either a macro assignment or a target.
Note that make still reorders arguments before --: anything starting
with a dash is considered an option, anything which contains an equal
sign is considered a macro assignment and everything else a target.
This still is not POSIX with regard to the options, but it will probably
not change because it has been make's behaviour for ages.
Add a new function Var_Match() that correctly skips a macro call by just
doing the same as Var_Subst() but without producing output. This will help
making the parser more robust.
Patches: 7.190,7.191
Submitted by: Max Okumoto <okumoto@ucsd.edu>
Diffstat (limited to 'usr.bin/make/var.c')
-rw-r--r-- | usr.bin/make/var.c | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index cb62da7..1ca3e4c 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -108,6 +108,7 @@ typedef struct VarParser { const char *ptr; /* current parser pos in input str */ GNode *ctxt; Boolean err; + Boolean execute; } VarParser; static char *VarParse(VarParser *, Boolean *); @@ -764,7 +765,8 @@ VarGetPattern(VarParser *vp, int delim, int *flags, VarPattern *patt) vp->ptr, vp->ptr, vp->ctxt, - vp->err + vp->err, + vp->execute }; char *rval; Boolean rfree; @@ -1229,10 +1231,13 @@ ParseModifier(VarParser *vp, char startc, Var *v, Boolean *freeResult) (vp->ptr[1] == 'h') && (vp->ptr[2] == endc || vp->ptr[2] == ':')) { const char *error; - Buffer *buf; - buf = Cmd_Exec(value, &error); - newStr = Buf_Peel(buf); + if (vp->execute) { + newStr = Buf_Peel( + Cmd_Exec(value, &error)); + } else { + newStr = estrdup(""); + } if (error) Error(error, value); @@ -1560,7 +1565,8 @@ VarParseLong(VarParser *vp, Boolean *freeResult) vp->ptr, vp->ptr, vp->ctxt, - vp->err + vp->err, + vp->execute }; char *rval; Boolean rfree; @@ -1691,7 +1697,8 @@ Var_Parse(const char input[], GNode *ctxt, Boolean err, input, input, ctxt, - err + err, + TRUE }; char *value; @@ -1700,6 +1707,34 @@ Var_Parse(const char input[], GNode *ctxt, Boolean err, return (value); } +/* + * + * Results: + * The number of characters in the specification. For invalid + * specifications, this is just 2 to skip the '$' and the + * following letter, or 1 if '$' was the last character in the + * string. + */ +size_t +Var_Match(const char input[], GNode *ctxt) +{ + VarParser vp = { + input, + input, + ctxt, + FALSE, + FALSE + }; + char *value; + Boolean freeResult; + + value = VarParse(&vp, &freeResult); + if (freeResult) { + free(value); + } + return (vp.ptr - vp.input); +} + /*- *----------------------------------------------------------------------- * Var_Subst -- @@ -1746,7 +1781,8 @@ Var_Subst(const char *str, GNode *ctxt, Boolean err) str, str, ctxt, - err + err, + TRUE }; char *rval; Boolean rfree; @@ -1883,7 +1919,8 @@ Var_SubstOnly(const char *var, const char *str, GNode *ctxt, Boolean err) str, str, ctxt, - err + err, + TRUE }; char *rval; Boolean rfree; |