diff options
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/make/arch.c | 8 | ||||
-rw-r--r-- | usr.bin/make/compat.c | 6 | ||||
-rw-r--r-- | usr.bin/make/extern.h | 5 | ||||
-rw-r--r-- | usr.bin/make/for.c | 17 | ||||
-rw-r--r-- | usr.bin/make/job.c | 8 | ||||
-rw-r--r-- | usr.bin/make/main.c | 6 | ||||
-rw-r--r-- | usr.bin/make/parse.c | 14 | ||||
-rw-r--r-- | usr.bin/make/suff.c | 6 | ||||
-rw-r--r-- | usr.bin/make/var.c | 272 |
9 files changed, 180 insertions, 162 deletions
diff --git a/usr.bin/make/arch.c b/usr.bin/make/arch.c index 7504147f54e..21fa1851635 100644 --- a/usr.bin/make/arch.c +++ b/usr.bin/make/arch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arch.c,v 1.17 1999/12/06 22:28:43 espie Exp $ */ +/* $OpenBSD: arch.c,v 1.18 1999/12/16 17:27:18 espie Exp $ */ /* $NetBSD: arch.c,v 1.17 1996/11/06 17:58:59 christos Exp $ */ /* @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94"; #else -static char rcsid[] = "$OpenBSD: arch.c,v 1.17 1999/12/06 22:28:43 espie Exp $"; +static char rcsid[] = "$OpenBSD: arch.c,v 1.18 1999/12/16 17:27:18 espie Exp $"; #endif #endif /* not lint */ @@ -241,7 +241,7 @@ Arch_ParseArchive (linePtr, nodeLst, ctxt) *cp++ = '\0'; if (subLibName) { - libName = Var_Subst(NULL, libName, ctxt, TRUE); + libName = Var_Subst(libName, ctxt, TRUE); } @@ -320,7 +320,7 @@ Arch_ParseArchive (linePtr, nodeLst, ctxt) char *sacrifice; char *oldMemName = memName; - memName = Var_Subst(NULL, memName, ctxt, TRUE); + memName = Var_Subst(memName, ctxt, TRUE); /* * Now form an archive spec and recurse to deal with nested diff --git a/usr.bin/make/compat.c b/usr.bin/make/compat.c index 299cefe3e57..162549c8940 100644 --- a/usr.bin/make/compat.c +++ b/usr.bin/make/compat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: compat.c,v 1.15 1999/12/06 22:28:44 espie Exp $ */ +/* $OpenBSD: compat.c,v 1.16 1999/12/16 17:27:18 espie Exp $ */ /* $NetBSD: compat.c,v 1.14 1996/11/06 17:59:01 christos Exp $ */ /* @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94"; #else -static char rcsid[] = "$OpenBSD: compat.c,v 1.15 1999/12/06 22:28:44 espie Exp $"; +static char rcsid[] = "$OpenBSD: compat.c,v 1.16 1999/12/16 17:27:18 espie Exp $"; #endif #endif /* not lint */ @@ -234,7 +234,7 @@ CompatRunCommand (cmdp, gnp) errCheck = !(gn->type & OP_IGNORE); cmdNode = Lst_Member (gn->commands, (ClientData)cmd); - cmdStart = Var_Subst (NULL, cmd, gn, FALSE); + cmdStart = Var_Subst(cmd, gn, FALSE); /* * brk_string will return an argv with a NULL in av[0], thus causing diff --git a/usr.bin/make/extern.h b/usr.bin/make/extern.h index fb090ac4dc4..264bf01db84 100644 --- a/usr.bin/make/extern.h +++ b/usr.bin/make/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.16 1999/12/16 17:07:20 espie Exp $ */ +/* $OpenBSD: extern.h,v 1.17 1999/12/16 17:27:18 espie Exp $ */ /* $NetBSD: nonints.h,v 1.12 1996/11/06 17:59:19 christos Exp $ */ /*- @@ -147,7 +147,8 @@ void Var_Append __P((char *, char *, GNode *)); Boolean Var_Exists __P((char *, GNode *)); char *Var_Value __P((char *, GNode *)); char *Var_Parse __P((char *, GNode *, Boolean, int *, Boolean *)); -char *Var_Subst __P((char *, char *, GNode *, Boolean)); +char *Var_Subst __P((char *, GNode *, Boolean)); +void Var_SubstVar __P((Buffer, char *, const char *, GNode *)); char *Var_GetTail __P((char *)); char *Var_GetHead __P((char *)); void Var_Init __P((void)); diff --git a/usr.bin/make/for.c b/usr.bin/make/for.c index 751038df5c0..ba4f89459f5 100644 --- a/usr.bin/make/for.c +++ b/usr.bin/make/for.c @@ -1,4 +1,4 @@ -/* $OpenBSD: for.c,v 1.12 1999/12/16 17:24:11 espie Exp $ */ +/* $OpenBSD: for.c,v 1.13 1999/12/16 17:27:18 espie Exp $ */ /* $NetBSD: for.c,v 1.4 1996/11/06 17:59:05 christos Exp $ */ /* @@ -82,7 +82,7 @@ #if 0 static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: for.c,v 1.12 1999/12/16 17:24:11 espie Exp $"; +static char rcsid[] = "$OpenBSD: for.c,v 1.13 1999/12/16 17:27:18 espie Exp $"; #endif #endif /* not lint */ @@ -105,6 +105,7 @@ struct For_ { char *text; /* unexpanded text */ char *var; /* Index name */ Lst lst; /* List of items */ + size_t guess; /* Estimated expansion size */ BUFFER buf; /* Accumulating text */ unsigned long lineno; /* Line number at start of loop */ unsigned long level; /* Nesting level */ @@ -197,7 +198,7 @@ For_Eval(line) arg->var = interval_dup(wrd, endVar); /* Make a list with the remaining words. */ - sub = Var_Subst(NULL, ptr, VAR_GLOBAL, FALSE); + sub = Var_Subst(ptr, VAR_GLOBAL, FALSE); if (DEBUG(FOR)) (void)fprintf(stderr, "For: Iterator %s List %s\n", arg->var, sub); @@ -260,6 +261,7 @@ For_Accumulate(arg, line) } +#define GUESS_EXPANSION 32 /*- *----------------------------------------------------------------------- * ForExec -- @@ -274,11 +276,15 @@ ForExec(namep, argp) char *name = (char *)namep; For *arg = (For *)argp; + Buf_Init(&arg->buf, arg->guess); Var_Set(arg->var, name, VAR_GLOBAL); if (DEBUG(FOR)) (void)fprintf(stderr, "--- %s = %s\n", arg->var, name); - Parse_FromString(Var_Subst(arg->var, arg->text, VAR_GLOBAL, FALSE), - arg->lineno); + Var_SubstVar(&arg->buf, arg->text, arg->var, VAR_GLOBAL); + if (Buf_Size(&arg->buf) >= arg->guess) + arg->guess = Buf_Size(&arg->buf) + GUESS_EXPANSION; + + Parse_FromString(Buf_Retrieve(&arg->buf), arg->lineno); Var_Delete(arg->var, VAR_GLOBAL); return 0; } @@ -296,6 +302,7 @@ For_Run(arg) For *arg; { arg->text = Buf_Retrieve(&arg->buf); + arg->guess = Buf_Size(&arg->buf) + GUESS_EXPANSION; Lst_ForEach(arg->lst, ForExec, (ClientData)arg); free(arg->var); diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index 715cb9a85ce..16fa9528dd1 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -1,4 +1,4 @@ -/* $OpenBSD: job.c,v 1.15 1999/12/06 22:28:44 espie Exp $ */ +/* $OpenBSD: job.c,v 1.16 1999/12/16 17:27:18 espie Exp $ */ /* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */ /* @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94"; #else -static char rcsid[] = "$OpenBSD: job.c,v 1.15 1999/12/06 22:28:44 espie Exp $"; +static char rcsid[] = "$OpenBSD: job.c,v 1.16 1999/12/16 17:27:18 espie Exp $"; #endif #endif /* not lint */ @@ -558,7 +558,7 @@ JobPrintCommand(cmdp, jobp) * the variables in the command. */ cmdNode = Lst_Member(job->node->commands, (ClientData)cmd); - cmdStart = cmd = Var_Subst(NULL, cmd, job->node, FALSE); + cmdStart = cmd = Var_Subst(cmd, job->node, FALSE); Lst_Replace(cmdNode, (ClientData)cmdStart); cmdTemplate = "%s\n"; @@ -678,7 +678,7 @@ JobSaveCommand(cmd, gn) ClientData cmd; ClientData gn; { - cmd = (ClientData) Var_Subst(NULL, (char *) cmd, (GNode *) gn, FALSE); + cmd = (ClientData) Var_Subst((char *) cmd, (GNode *) gn, FALSE); (void) Lst_AtEnd(postCommands->commands, cmd); return(0); } diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index a9da5cc828d..2453d71e9a4 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.22 1999/12/16 17:02:45 espie Exp $ */ +/* $OpenBSD: main.c,v 1.23 1999/12/16 17:27:18 espie Exp $ */ /* $NetBSD: main.c,v 1.34 1997/03/24 20:56:36 gwr Exp $ */ /* @@ -49,7 +49,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.22 1999/12/16 17:02:45 espie Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.23 1999/12/16 17:27:18 espie Exp $"; #endif #endif /* not lint */ @@ -755,7 +755,7 @@ main(argc, argv) */ static char VPATH[] = "${VPATH}"; - vpath = Var_Subst(NULL, VPATH, VAR_CMD, FALSE); + vpath = Var_Subst(VPATH, VAR_CMD, FALSE); path = vpath; do { /* skip to end of directory */ diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c index 9de8d51c818..1eb4d4e51fa 100644 --- a/usr.bin/make/parse.c +++ b/usr.bin/make/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.30 1999/12/16 17:07:21 espie Exp $ */ +/* $OpenBSD: parse.c,v 1.31 1999/12/16 17:27:18 espie Exp $ */ /* $NetBSD: parse.c,v 1.29 1997/03/10 21:20:04 christos Exp $ */ /* @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; #else -static char rcsid[] = "$OpenBSD: parse.c,v 1.30 1999/12/16 17:07:21 espie Exp $"; +static char rcsid[] = "$OpenBSD: parse.c,v 1.31 1999/12/16 17:27:18 espie Exp $"; #endif #endif /* not lint */ @@ -1535,7 +1535,7 @@ Parse_DoVar (line, ctxt) Boolean oldOldVars = oldVars; oldVars = FALSE; - cp = Var_Subst(NULL, cp, ctxt, FALSE); + cp = Var_Subst(cp, ctxt, FALSE); oldVars = oldOldVars; Var_Set(line, cp, ctxt); @@ -1551,7 +1551,7 @@ Parse_DoVar (line, ctxt) * expansion on the whole thing. The resulting string will need * freeing when we're done, so set freeCmd to TRUE. */ - cp = Var_Subst(NULL, cp, VAR_CMD, TRUE); + cp = Var_Subst(cp, VAR_CMD, TRUE); freeCmd = TRUE; } @@ -1715,7 +1715,7 @@ ParseDoInclude (file) * Substitute for any variables in the file name before trying to * find the thing. */ - file = Var_Subst (NULL, file, VAR_CMD, FALSE); + file = Var_Subst(file, VAR_CMD, FALSE); /* * Now we know the file's name and its search path, we attempt to @@ -1915,7 +1915,7 @@ ParseTraditionalInclude (file) * Substitute for any variables in the file name before trying to * find the thing. */ - file = Var_Subst (NULL, file, VAR_CMD, FALSE); + file = Var_Subst(file, VAR_CMD, FALSE); /* * Now we know the file's name, we attempt to find the durn thing. @@ -2586,7 +2586,7 @@ Parse_File(name, stream) #endif ParseFinishLine(); - cp = Var_Subst (NULL, line, VAR_CMD, TRUE); + cp = Var_Subst(line, VAR_CMD, TRUE); free (line); line = cp; diff --git a/usr.bin/make/suff.c b/usr.bin/make/suff.c index c2a070833e5..47572593286 100644 --- a/usr.bin/make/suff.c +++ b/usr.bin/make/suff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: suff.c,v 1.15 1999/12/06 22:28:44 espie Exp $ */ +/* $OpenBSD: suff.c,v 1.16 1999/12/16 17:27:18 espie Exp $ */ /* $NetBSD: suff.c,v 1.13 1996/11/06 17:59:25 christos Exp $ */ /* @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; #else -static char rcsid[] = "$OpenBSD: suff.c,v 1.15 1999/12/06 22:28:44 espie Exp $"; +static char rcsid[] = "$OpenBSD: suff.c,v 1.16 1999/12/16 17:27:18 espie Exp $"; #endif #endif /* not lint */ @@ -1359,7 +1359,7 @@ SuffExpandChildren(cgnp, pgnp) if (DEBUG(SUFF)) { printf("Expanding \"%s\"...", cgn->name); } - cp = Var_Subst(NULL, cgn->name, pgn, TRUE); + cp = Var_Subst(cgn->name, pgn, TRUE); if (cp != (char *)NULL) { Lst members = Lst_Init(FALSE); diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 7e94c74872f..db25dde3544 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -1,4 +1,4 @@ -/* $OpenBSD: var.c,v 1.23 1999/12/16 17:02:45 espie Exp $ */ +/* $OpenBSD: var.c,v 1.24 1999/12/16 17:27:18 espie Exp $ */ /* $NetBSD: var.c,v 1.18 1997/03/18 19:24:46 christos Exp $ */ /* @@ -70,7 +70,7 @@ #if 0 static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94"; #else -static char rcsid[] = "$OpenBSD: var.c,v 1.23 1999/12/16 17:02:45 espie Exp $"; +static char rcsid[] = "$OpenBSD: var.c,v 1.24 1999/12/16 17:27:18 espie Exp $"; #endif #endif /* not lint */ @@ -1672,7 +1672,7 @@ Var_Parse (str, ctxt, err, lengthPtr, freePtr) */ str = VarValue(v); if (strchr (str, '$') != (char *)NULL) { - str = Var_Subst(NULL, str, ctxt, err); + str = Var_Subst(str, ctxt, err); *freePtr = TRUE; } @@ -2091,7 +2091,7 @@ cleanup: /*- *----------------------------------------------------------------------- * Var_Subst -- - * Substitute for all variables in the given string in the given context + * Substitute for all variables in a string in a context * If undefErr is TRUE, Parse_Error will be called when an undefined * variable is encountered. * @@ -2103,16 +2103,12 @@ cleanup: *----------------------------------------------------------------------- */ char * -Var_Subst (var, str, ctxt, undefErr) - char *var; /* Named variable || NULL for all */ +Var_Subst(str, ctxt, undefErr) char *str; /* the string in which to substitute */ GNode *ctxt; /* the context wherein to find variables */ Boolean undefErr; /* TRUE if undefineds are an error */ { - BUFFER buf; /* Buffer for forming things */ - char *val; /* Value to substitute for a variable */ - int length; /* Length of the variable invocation */ - Boolean doFree; /* Set true if val should be freed */ + BUFFER buf; /* Buffer for forming things */ static Boolean errorReported; /* Set true if an error has already * been reported to prevent a plethora * of messages when recursing */ @@ -2120,134 +2116,148 @@ Var_Subst (var, str, ctxt, undefErr) Buf_Init(&buf, MAKE_BSIZE); errorReported = FALSE; - while (*str) { - if (var == NULL && (*str == '$') && (str[1] == '$')) { - /* - * A dollar sign may be escaped either with another dollar sign. - * In such a case, we skip over the escape character and store the - * dollar sign into the buffer directly. - */ - str++; - Buf_AddChar(&buf, *str); - str++; - } else if (*str != '$') { - /* - * Skip as many characters as possible -- either to the end of - * the string or to the next dollar sign (variable invocation). - */ - char *cp; + for (;;) { + char *val; /* Value to substitute for a variable */ + size_t length; /* Length of the variable invocation */ + Boolean doFree; /* Set true if val should be freed */ + const char *cp; + + /* copy uninteresting stuff */ + for (cp = str; *str != '\0' && *str != '$'; str++) + ; + Buf_AddInterval(&buf, cp, str); + if (*str == '\0') + break; + if (str[1] == '$') { + /* A dollar sign may be escaped with another dollar sign. */ + Buf_AddChar(&buf, '$'); + str += 2; + continue; + } + val = Var_Parse(str, ctxt, undefErr, &length, &doFree); + /* When we come down here, val should either point to the + * value of this variable, suitably modified, or be NULL. + * Length should be the total length of the potential + * variable invocation (from $ to end character...) */ + if (val == var_Error || val == varNoError) { + /* If performing old-time variable substitution, skip over + * the variable and continue with the substitution. Otherwise, + * store the dollar sign and advance str so we continue with + * the string... */ + if (oldVars) { + str += length; + } else if (undefErr) { + /* If variable is undefined, complain and skip the + * variable. The complaint will stop us from doing anything + * when the file is parsed. */ + if (!errorReported) { + Parse_Error(PARSE_FATAL, + "Undefined variable \"%.*s\"",length,str); + } + str += length; + errorReported = TRUE; + } else { + Buf_AddChar(&buf, *str); + str += 1; + } + } else { + /* We've now got a variable structure to store in. But first, + * advance the string pointer. */ + str += length; + + /* Copy all the characters from the variable value straight + * into the new string. */ + Buf_AddString(&buf, val); + if (doFree) + free(val); + } + } + return Buf_Retrieve(&buf); +} - for (cp = str++; *str != '$' && *str != '\0'; str++) +/*- + *----------------------------------------------------------------------- + * Var_SubstVar -- + * Substitute for one variable in the given string in the given context + * If undefErr is TRUE, Parse_Error will be called when an undefined + * variable is encountered. + * + * Side Effects: + * Append the result to the buffer + *----------------------------------------------------------------------- + */ +void +Var_SubstVar(buf, str, var, ctxt) + Buffer buf; /* Where to store the result */ + char *str; /* The string in which to substitute */ + const char *var; /* Named variable */ + GNode *ctxt; /* The context wherein to find variables */ +{ + char *val; /* Value substituted for a variable */ + size_t length; /* Length of the variable invocation */ + Boolean doFree; /* Set true if val should be freed */ + + for (;;) { + const char *cp; + /* copy uninteresting stuff */ + for (cp = str; *str != '\0' && *str != '$'; str++) + ; + Buf_AddInterval(buf, cp, str); + if (*str == '\0') + break; + if (str[1] == '$') { + Buf_AddString(buf, "$$"); + str += 2; + continue; + } + if (str[1] != '(' && str[1] != '{') { + if (str[1] != *var || var[1] != '\0') { + Buf_AddChars(buf, 2, str); + str += 2; continue; - Buf_AddInterval(&buf, cp, str); + } } else { - if (var != NULL) { - int expand; - for (;;) { - if (str[1] != '(' && str[1] != '{') { - if (str[1] != *var || var[1] != '\0') { - Buf_AddChars(&buf, 2, str); - str += 2; - expand = FALSE; - } - else - expand = TRUE; - break; - } - else { - char *p; - - /* - * Scan up to the end of the variable name. - */ - for (p = &str[2]; *p && - *p != ':' && *p != ')' && *p != '}'; p++) - if (*p == '$') - break; - /* - * A variable inside the variable. We cannot expand - * the external variable yet, so we try again with - * the nested one - */ - if (*p == '$') { - Buf_AddInterval(&buf, str, p); - str = p; - continue; - } - - 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++) - continue; - Buf_AddInterval(&buf, str, p); - str = p; - expand = FALSE; - } - else - expand = TRUE; - break; - } - } - if (!expand) - continue; + char *p; + char endc; + + if (str[1] == '(') + endc = ')'; + else if (str[1] == '{') + endc = '}'; + + /* Find the end of the variable specification. */ + p = str+2; + while (*p != '\0' && *p != ':' && *p != endc && *p != '$') + p++; + /* A variable inside the variable. We don't know how to + * expand the external variable at this point, so we try + * again with the nested variable. */ + if (*p == '$') { + Buf_AddInterval(buf, str, p); + str = p; + continue; } - val = Var_Parse (str, ctxt, undefErr, &length, &doFree); - - /* - * When we come down here, val should either point to the - * value of this variable, suitably modified, or be NULL. - * Length should be the total length of the potential - * variable invocation (from $ to end character...) - */ - if (val == var_Error || val == varNoError) { - /* - * If performing old-time variable substitution, skip over - * the variable and continue with the substitution. Otherwise, - * store the dollar sign and advance str so we continue with - * the string... - */ - if (oldVars) { - str += length; - } else if (undefErr) { - /* - * If variable is undefined, complain and skip the - * variable. The complaint will stop us from doing anything - * when the file is parsed. - */ - if (!errorReported) { - Parse_Error (PARSE_FATAL, - "Undefined variable \"%.*s\"",length,str); - } - str += length; - errorReported = TRUE; - } else { - Buf_AddChar(&buf, *str); - str += 1; - } - } else { - /* - * We've now got a variable structure to store in. But first, - * advance the string pointer. - */ - str += length; - - /* - * Copy all the characters from the variable value straight - * into the new string. - */ - Buf_AddString(&buf, val); - if (doFree) - free(val); - } + if (strncmp(var, str + 2, p - str - 2) != 0 || + var[p - str - 2] != '\0') { + /* Not the variable we want to expand. */ + Buf_AddInterval(buf, str, p); + str = p; + continue; + } } + /* okay, so we've found the variable we want to expand. */ + val = Var_Parse(str, ctxt, FALSE, &length, &doFree); + /* We've now got a variable structure to store in. But first, + * advance the string pointer. */ + str += length; + + /* Copy all the characters from the variable value straight + * into the new string. */ + Buf_AddString(buf, val); + if (doFree) + free(val); } - - return Buf_Retrieve(&buf); } /*- |