diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1996-11-30 21:09:23 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1996-11-30 21:09:23 +0000 |
commit | 67e9b81bf2c3acfeba94fdb222f197904c16cfef (patch) | |
tree | d3c86e29fa60fc56eb72f9263478434f9b2f3607 /usr.bin/make/var.c | |
parent | 66030e0876e2f9722b759c1df2901e526a7be102 (diff) |
Sync with NetBSD:
- Merge in FreeBSD and Lite2 changes.
- Fix bug where a non-archive target with a .a suffix would always
be considered to be out of date, since it does not have a TOC.
- Fix NetBSD PR #2930: declare missing variable.
Diffstat (limited to 'usr.bin/make/var.c')
-rw-r--r-- | usr.bin/make/var.c | 118 |
1 files changed, 54 insertions, 64 deletions
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 06cc5ae0690..642c07c0be2 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -1,9 +1,9 @@ -/* $OpenBSD: var.c,v 1.4 1996/09/02 16:04:22 briggs Exp $ */ -/* $NetBSD: var.c,v 1.14 1996/08/13 16:42:25 christos Exp $ */ +/* $OpenBSD: var.c,v 1.5 1996/11/30 21:09:07 millert Exp $ */ +/* $NetBSD: var.c,v 1.15 1996/11/06 17:59:29 christos Exp $ */ /* - * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. - * Copyright (c) 1988, 1989 by Adam de Boor + * Copyright (c) 1988, 1989, 1990, 1993 + * The Regents of the University of California. All rights reserved. * Copyright (c) 1989 by Berkeley Softworks * All rights reserved. * @@ -41,9 +41,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)var.c 5.7 (Berkeley) 6/1/90"; +static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; #else -static char rcsid[] = "$OpenBSD: var.c,v 1.4 1996/09/02 16:04:22 briggs Exp $"; +static char rcsid[] = "$OpenBSD: var.c,v 1.5 1996/11/30 21:09:07 millert Exp $"; #endif #endif /* not lint */ @@ -154,7 +154,6 @@ typedef struct { #define VAR_SUB_GLOBAL 1 /* Apply substitution globally */ #define VAR_MATCH_START 2 /* Match at start of word */ #define VAR_MATCH_END 4 /* Match at end of word */ -#define VAR_NO_SUB 8 /* Substitution is non-global and already done */ } VarPattern; static int VarCmp __P((ClientData, ClientData)); @@ -280,15 +279,15 @@ VarFind (name, ctxt, flags) if ((env = getenv (name)) != NULL) { int len; - + v = (Var *) emalloc(sizeof(Var)); v->name = estrdup(name); len = strlen(env); - + v->val = Buf_Init(len); Buf_AddBytes(v->val, len, (Byte *)env); - + v->flags = VAR_FROM_ENV; return (v); } else if (checkEnvFirst && (flags & FIND_GLOBAL) && @@ -756,7 +755,7 @@ VarRoot (word, addSpace, buf, dummy) * VarMatch -- * Place the word in the buffer if it matches the given pattern. * Callback function for VarModify to implement the :M modifier. - * + * * Results: * TRUE if a space should be placed in the buffer before the next * word. @@ -792,7 +791,7 @@ VarMatch (word, addSpace, buf, pattern) * Place the word in the buffer if it matches the given pattern. * Callback function for VarModify to implement the System V % * modifiers. - * + * * Results: * TRUE if a space should be placed in the buffer before the next * word. @@ -835,7 +834,7 @@ VarSYSVMatch (word, addSpace, buf, patp) * VarNoMatch -- * Place the word in the buffer if it doesn't match the given pattern. * Callback function for VarModify to implement the :N modifier. - * + * * Results: * TRUE if a space should be placed in the buffer before the next * word. @@ -892,9 +891,9 @@ VarSubstitute (word, addSpace, buf, patternp) VarPattern *pattern = (VarPattern *) patternp; wordLen = strlen(word); - if ((pattern->flags & VAR_NO_SUB) == 0) { + if (1) { /* substitute in each word of the variable */ /* - * Still substituting -- break it down into simple anchored cases + * Break substitution down into simple anchored cases * and if none of them fits, perform the general substitution case. */ if ((pattern->flags & VAR_MATCH_START) && @@ -976,7 +975,7 @@ VarSubstitute (word, addSpace, buf, patternp) * Pattern is unanchored: search for the pattern in the word using * String_FindSubstring, copying unmatched portions and the * right-hand-side for each match found, handling non-global - * subsititutions correctly, etc. When the loop is done, any + * substitutions correctly, etc. When the loop is done, any * remaining part of the word (word and wordLen are adjusted * accordingly through the loop) is copied straight into the * buffer. @@ -999,12 +998,8 @@ VarSubstitute (word, addSpace, buf, patternp) Buf_AddBytes(buf, pattern->rightLen, (Byte *)pattern->rhs); wordLen -= (cp - word) + pattern->leftLen; word = cp + pattern->leftLen; - if (wordLen == 0) { - done = TRUE; - } - if ((pattern->flags & VAR_SUB_GLOBAL) == 0) { + if (wordLen == 0 || (pattern->flags & VAR_SUB_GLOBAL) == 0){ done = TRUE; - pattern->flags |= VAR_NO_SUB; } } else { done = TRUE; @@ -1024,14 +1019,9 @@ VarSubstitute (word, addSpace, buf, patternp) return ((Buf_Size(buf) != origSize) || addSpace); } /* - * Common code for anchored substitutions: if performed a substitution - * and it's not supposed to be global, mark the pattern as requiring - * no more substitutions. addSpace was set TRUE if characters were - * added to the buffer. + * Common code for anchored substitutions: + * addSpace was set TRUE if characters were added to the buffer. */ - if ((pattern->flags & VAR_SUB_GLOBAL) == 0) { - pattern->flags |= VAR_NO_SUB; - } return (addSpace); } nosub: @@ -1077,7 +1067,7 @@ VarModify (str, modProc, datum) for (i = 1; i < ac; i++) addSpace = (*modProc)(av[i], addSpace, buf, datum); - + Buf_AddByte (buf, '\0'); str = (char *)Buf_GetAll (buf, (int *)NULL); Buf_Destroy (buf, FALSE); @@ -1128,11 +1118,11 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) * expanding it in a non-local context. This * is done to support dynamic sources. The * result is just the invocation, unaltered */ - + *freePtr = FALSE; dynamic = FALSE; start = str; - + if (str[1] != '(' && str[1] != '{') { /* * If it's not bounded by braces of some sort, life is much simpler. @@ -1147,7 +1137,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) v = VarFind (name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); if (v == (Var *)NIL) { *lengthPtr = 2; - + if ((ctxt == VAR_CMD) || (ctxt == VAR_GLOBAL)) { /* * If substituting a local variable in a non-local context, @@ -1205,7 +1195,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) return (var_Error); } *tstr = '\0'; - + v = VarFind (str + 2, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD); if ((v == (Var *)NIL) && (ctxt != VAR_CMD) && (ctxt != VAR_GLOBAL) && ((tstr-str) == 4) && (str[3] == 'F' || str[3] == 'D')) @@ -1231,7 +1221,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) vname[0] = str[2]; vname[1] = '\0'; v = VarFind(vname, ctxt, 0); - + if (v != (Var *)NIL) { /* * No need for nested expansion or anything, as we're @@ -1239,7 +1229,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) * but nested invocations in them... */ val = (char *)Buf_GetAll(v->val, (int *)NULL); - + if (str[3] == 'D') { val = VarModify(val, VarHead, (ClientData)0); } else { @@ -1258,7 +1248,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) } } } - + if (v == (Var *)NIL) { if ((((tstr-str) == 3) || ((((tstr-str) == 4) && (str[3] == 'F' || @@ -1287,7 +1277,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) ((ctxt == VAR_CMD) || (ctxt == VAR_GLOBAL))) { int len; - + len = (tstr-str) - 3; if ((strncmp(str+2, ".TARGET", len) == 0) || (strncmp(str+2, ".ARCHIVE", len) == 0) || @@ -1297,7 +1287,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) dynamic = TRUE; } } - + if (!haveModifier) { /* * No modifiers -- have specification length so we can return @@ -1347,9 +1337,9 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) str = Var_Subst(NULL, str, ctxt, err); *freePtr = TRUE; } - + v->flags &= ~VAR_IN_USE; - + /* * Now we need to apply any modifiers the user wants applied. * These are: @@ -1375,7 +1365,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) while (*tstr != endc) { char *newStr; /* New value to return */ char termc; /* Character which terminated scan */ - + if (DEBUG(VAR)) { printf("Applying :%c to \"%s\"\n", *tstr, str); } @@ -1452,7 +1442,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) } buf = Buf_Init(0); - + /* * Pass through the lhs looking for 1) escaped delimiters, * '$'s and backslashes (place the escaped character in @@ -1478,7 +1468,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) char *cp2; int len; Boolean freeIt; - + cp2 = Var_Parse(cp, ctxt, err, &len, &freeIt); Buf_AddBytes(buf, strlen(cp2), (Byte *)cp2); if (freeIt) { @@ -1498,7 +1488,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) } Buf_AddByte(buf, (Byte)'\0'); - + /* * If lhs didn't end with the delimiter, complain and * return NULL @@ -1533,7 +1523,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) * it right here) and 3) expand any variable substitutions. */ buf = Buf_Init(0); - + tstr = cp + 1; for (cp = tstr; *cp != '\0' && *cp != delim; cp++) { if ((*cp == '\\') && @@ -1564,7 +1554,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) } Buf_AddByte(buf, (Byte)'\0'); - + /* * If didn't end in delimiter character, complain */ @@ -1658,7 +1648,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) */ VarPattern pattern; Boolean eqFound; - + pattern.flags = 0; eqFound = FALSE; /* @@ -1681,7 +1671,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) cp++; } if (*cp == endc && eqFound) { - + /* * Now we break this sucker into the lhs and * rhs. We must null terminate them of course. @@ -1691,7 +1681,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) pattern.lhs = tstr; pattern.leftLen = cp - tstr; *cp++ = '\0'; - + pattern.rhs = cp; cnt = 1; while (cnt) { @@ -1704,7 +1694,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) } pattern.rightLen = cp - pattern.rhs; *cp = '\0'; - + /* * SYSV modifications happen through the whole * string. Note the pattern is anchored at the end. @@ -1724,7 +1714,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) Error ("Unknown modifier '%c'\n", *tstr); for (cp = tstr+1; *cp != ':' && *cp != endc && *cp != '\0'; - cp++) + cp++) continue; termc = *cp; newStr = var_Error; @@ -1734,7 +1724,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) if (DEBUG(VAR)) { printf("Result is \"%s\"\n", newStr); } - + if (*freePtr) { free (str); } @@ -1758,10 +1748,10 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) *lengthPtr = tstr - start + 1; *tstr = endc; } - + if (v->flags & VAR_FROM_ENV) { Boolean destroy = FALSE; - + if (str != (char *)Buf_GetAll(v->val, (int *)NULL)) { destroy = TRUE; } else { @@ -1868,9 +1858,9 @@ Var_Subst (var, str, ctxt, undefErr) /* * Scan up to the end of the variable name. */ - for (p = &str[2]; *p && + for (p = &str[2]; *p && *p != ':' && *p != ')' && *p != '}'; p++) - if (*p == '$') + if (*p == '$') break; /* * A variable inside the variable. We cannot expand @@ -1882,14 +1872,14 @@ Var_Subst (var, str, ctxt, undefErr) str = p; continue; } - - if (strncmp(var, str + 2, p - str - 2) != 0 || + + if (strncmp(var, str + 2, p - str - 2) != 0 || var[p - str - 2] != '\0') { /* * Not the variable we want to expand, scan * until the next variable */ - for (;*p != '$' && *p != '\0'; p++) + for (;*p != '$' && *p != '\0'; p++) continue; Buf_AddBytes(buf, p - str, (Byte *) str); str = p; @@ -1903,7 +1893,7 @@ Var_Subst (var, str, ctxt, undefErr) if (!expand) continue; } - + val = Var_Parse (str, ctxt, undefErr, &length, &doFree); /* @@ -1943,7 +1933,7 @@ Var_Subst (var, str, ctxt, undefErr) * advance the string pointer. */ str += length; - + /* * Copy all the characters from the variable value straight * into the new string. @@ -1955,7 +1945,7 @@ Var_Subst (var, str, ctxt, undefErr) } } } - + Buf_AddByte (buf, '\0'); str = (char *)Buf_GetAll (buf, (int *)NULL); Buf_Destroy (buf, FALSE); @@ -2014,7 +2004,7 @@ Var_GetHead(file) * None * * Side Effects: - * The VAR_CMD and VAR_GLOBAL contexts are created + * The VAR_CMD and VAR_GLOBAL contexts are created *----------------------------------------------------------------------- */ void @@ -2032,7 +2022,7 @@ Var_End () { Lst_Destroy(allVars, VarDelete); } - + /****************** PRINT DEBUGGING INFO *****************/ static int |