summaryrefslogtreecommitdiff
path: root/usr.bin/make/parse.c
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>1996-11-06 17:58:58 +0000
committerchristos <christos@NetBSD.org>1996-11-06 17:58:58 +0000
commitaa49881371f8fb4d3ea903d9f481fcaddfb869ea (patch)
treebb03e3e2b0608049e1abea489586c7115950cc0d /usr.bin/make/parse.c
parentdce3bea50b3400f3fe3a7978a7a37dd33a6279a1 (diff)
- 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.
Diffstat (limited to 'usr.bin/make/parse.c')
-rw-r--r--usr.bin/make/parse.c219
1 files changed, 100 insertions, 119 deletions
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index e635d9556bd..e58a9513a5e 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,8 +1,8 @@
-/* $NetBSD: parse.c,v 1.26 1996/09/27 02:36:58 thorpej Exp $ */
+/* $NetBSD: parse.c,v 1.27 1996/11/06 17:59:20 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.
*
@@ -40,9 +40,9 @@
#ifndef lint
#if 0
-static char sccsid[] = "@(#)parse.c 5.18 (Berkeley) 2/19/91";
+static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else
-static char rcsid[] = "$NetBSD: parse.c,v 1.26 1996/09/27 02:36:58 thorpej Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.27 1996/11/06 17:59:20 christos Exp $";
#endif
#endif /* not lint */
@@ -275,7 +275,7 @@ ParseFindKeyword (str)
end,
cur;
register int diff;
-
+
start = 0;
end = (sizeof(parseKeywords)/sizeof(parseKeywords[0])) - 1;
@@ -398,7 +398,7 @@ ParseDoOp (gnp, opp)
/*
* If the dependency mask of the operator and the node don't match and
* the node has actually had an operator applied to it before, and
- * the operator actually has some dependency information in it, complain.
+ * the operator actually has some dependency information in it, complain.
*/
if (((op & OP_OPMASK) != (gn->type & OP_OPMASK)) &&
!OP_NOP(gn->type) && !OP_NOP(op))
@@ -418,7 +418,7 @@ ParseDoOp (gnp, opp)
*/
register GNode *cohort;
LstNode ln;
-
+
cohort = Targ_NewGN(gn->name);
/*
* Duplicate links to parents so graph traversal is simple. Perhaps
@@ -442,14 +442,14 @@ ParseDoOp (gnp, opp)
}
/*
* We don't want to nuke any previous flags (whatever they were) so we
- * just OR the new operator into the old
+ * just OR the new operator into the old
*/
gn->type |= op;
return (0);
}
-/*-
+/*-
*---------------------------------------------------------------------
* ParseAddDep --
* Check if the pair of GNodes given needs to be synchronized.
@@ -462,7 +462,7 @@ ParseDoOp (gnp, opp)
*
* Side Effects:
* A dependency can be added between the two nodes.
- *
+ *
*---------------------------------------------------------------------
*/
int
@@ -737,7 +737,7 @@ ParseDoDependency (line)
curTargs = Lst_Init(FALSE);
curSrcs = Lst_Init(FALSE);
-
+
do {
for (cp = line;
*cp && !isspace (*cp) &&
@@ -785,11 +785,11 @@ ParseDoDependency (line)
}
}
savec = *cp;
-
+
if (!*cp) {
/*
* Ending a dependency line without an operator is a Bozo
- * no-no
+ * no-no
*/
Parse_Error (PARSE_FATAL, "Need an operator");
return;
@@ -802,7 +802,7 @@ ParseDoDependency (line)
if (*line == '.' && isupper (line[1])) {
/*
* See if the target is a special target that must have it
- * or its sources handled specially.
+ * or its sources handled specially.
*/
int keywd = ParseFindKeyword(line);
if (keywd != -1) {
@@ -810,7 +810,7 @@ ParseDoDependency (line)
Parse_Error(PARSE_FATAL, "Mismatched special targets");
return;
}
-
+
specType = parseKeywords[keywd].spec;
tOp = parseKeywords[keywd].op;
@@ -870,7 +870,7 @@ ParseDoDependency (line)
case NotParallel:
{
extern int maxJobs;
-
+
maxJobs = 1;
break;
}
@@ -890,7 +890,7 @@ ParseDoDependency (line)
* modify.
*/
Lst path;
-
+
specType = ExPath;
path = Suff_GetPath (&line[5]);
if (path == NILLST) {
@@ -906,10 +906,10 @@ ParseDoDependency (line)
}
}
}
-
+
/*
* Have word in line. Get or create its node and stick it at
- * the end of the targets list
+ * the end of the targets list
*/
if ((specType == Not) && (*line != '\0')) {
if (Dir_HasWildcards(line)) {
@@ -920,9 +920,9 @@ ParseDoDependency (line)
* Dir module could have added a directory to the path...
*/
Lst emptyPath = Lst_Init(FALSE);
-
+
Dir_Expand(line, emptyPath, curTargs);
-
+
Lst_Destroy(emptyPath, Dir_Destroy);
} else {
/*
@@ -931,22 +931,22 @@ ParseDoDependency (line)
*/
(void)Lst_AtEnd(curTargs, (ClientData)line);
}
-
+
while(!Lst_IsEmpty(curTargs)) {
char *targName = (char *)Lst_DeQueue(curTargs);
-
+
if (!Suff_IsTransform (targName)) {
gn = Targ_FindNode (targName, TARG_CREATE);
} else {
gn = Suff_AddTransform (targName);
}
-
+
(void)Lst_AtEnd (targets, (ClientData)gn);
}
} else if (specType == ExPath && *line != '.' && *line != '\0') {
Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", line);
}
-
+
*cp = savec;
/*
* If it is a special type and not .PATH, it's the only target we
@@ -954,7 +954,7 @@ ParseDoDependency (line)
*/
if (specType != Not && specType != ExPath) {
Boolean warn = FALSE;
-
+
while ((*cp != '!') && (*cp != ':') && *cp) {
if (*cp != ' ' && *cp != '\t') {
warn = TRUE;
@@ -1021,7 +1021,7 @@ ParseDoDependency (line)
Lst_ForEach (targets, ParseDoOp, (ClientData)&op);
/*
- * Get to the first source
+ * Get to the first source
*/
while (*cp && isspace (*cp)) {
cp++;
@@ -1074,9 +1074,9 @@ ParseDoDependency (line)
} else if ((specType == NotParallel) || (specType == SingleShell)) {
*line = '\0';
}
-
+
/*
- * NOW GO FOR THE SOURCES
+ * NOW GO FOR THE SOURCES
*/
if ((specType == Suffixes) || (specType == ExPath) ||
(specType == Includes) || (specType == Libs) ||
@@ -1195,7 +1195,7 @@ ParseDoDependency (line)
line = cp;
}
}
-
+
if (mainNode == NILGNODE) {
/*
* If we have yet to decide on a main target to make, in the
@@ -1241,7 +1241,7 @@ Parse_IsVar (line)
/*
* Skip to variable name
*/
- for (;(*line == ' ') || (*line == '\t'); line++)
+ for (;(*line == ' ') || (*line == '\t'); line++)
continue;
for (; *line != '=' || level != 0; line++)
@@ -1256,7 +1256,7 @@ Parse_IsVar (line)
case '\t':
/*
* there can be as much white space as desired so long as there is
- * only one word before the operator
+ * only one word before the operator
*/
wasSpace = TRUE;
break;
@@ -1270,7 +1270,7 @@ Parse_IsVar (line)
case ')':
level--;
break;
-
+
default:
if (wasSpace && haveName) {
if (ISEQOPERATOR(*line)) {
@@ -1301,7 +1301,7 @@ Parse_IsVar (line)
return FALSE;
}
else {
- haveName = TRUE;
+ haveName = TRUE;
wasSpace = FALSE;
}
break;
@@ -1340,9 +1340,9 @@ Parse_DoVar (line, ctxt)
enum {
VAR_SUBST, VAR_APPEND, VAR_SHELL, VAR_NORMAL
} type; /* Type of assignment */
- char *opc; /* ptr to operator character to
+ char *opc; /* ptr to operator character to
* null-terminate the variable name */
- /*
+ /*
* Avoid clobbered variable warnings by forcing the compiler
* to ``unregister'' variables
*/
@@ -1548,7 +1548,7 @@ Parse_AddIncludeDir (dir)
*---------------------------------------------------------------------
* ParseDoInclude --
* Push to another file.
- *
+ *
* The input is the line minus the #include. A file spec is a string
* enclosed in <> or "". The former is looked for only in sysIncPath.
* The latter in . and the directories specified by -I command line
@@ -1640,7 +1640,7 @@ ParseDoInclude (file)
prefEnd = strrchr (Fname, '/');
if (prefEnd != (char *)NULL) {
char *newName;
-
+
*prefEnd = '\0';
if (file[0] == '/')
newName = estrdup(file);
@@ -1730,7 +1730,7 @@ ParseDoInclude (file)
*---------------------------------------------------------------------
* Parse_FromString --
* Start Parsing from the given string
- *
+ *
* Results:
* None
*
@@ -1753,7 +1753,7 @@ Parse_FromString(str)
oldFile->fname = fname;
oldFile->F = curFILE;
oldFile->p = curPTR;
-
+
(void) Lst_AtFront (includes, (ClientData)oldFile);
curFILE = NULL;
@@ -1769,7 +1769,7 @@ Parse_FromString(str)
*---------------------------------------------------------------------
* ParseTraditionalInclude --
* Push to another file.
- *
+ *
* The input is the line minus the "include". The file name is
* the string following the "include".
*
@@ -1832,7 +1832,7 @@ ParseTraditionalInclude (file)
prefEnd = strrchr (fname, '/');
if (prefEnd != (char *)NULL) {
char *newName;
-
+
*prefEnd = '\0';
newName = str_concat (fname, file, STR_ADDSLASH);
fullname = Dir_FindFile (newName, parseIncPath);
@@ -1952,7 +1952,7 @@ ParseEOF (opened)
/*-
*---------------------------------------------------------------------
* ParseReadc --
- * Read a character from the current file
+ * Read a character from the current file
*
* Results:
* The character that was read
@@ -1965,7 +1965,7 @@ ParseReadc()
{
if (curFILE)
return fgetc(curFILE);
-
+
if (curPTR && *curPTR->ptr)
return *curPTR->ptr++;
return EOF;
@@ -1975,7 +1975,7 @@ ParseReadc()
/*-
*---------------------------------------------------------------------
* ParseUnreadc --
- * Put back a character to the current file
+ * Put back a character to the current file
*
* Results:
* None.
@@ -2006,61 +2006,43 @@ ParseSkipLine(skip)
int skip; /* Skip lines that don't start with . */
{
char *line;
- int c, lastc = '\0', lineLength;
+ int c, lastc, lineLength = 0;
Buffer buf;
- c = ParseReadc();
+ buf = Buf_Init(MAKE_BSIZE);
- if (skip) {
- /*
- * Skip lines until get to one that begins with a
- * special char.
- */
- while ((c != '.') && (c != EOF)) {
- while (((c != '\n') || (lastc == '\\')) && (c != EOF)) {
- /*
- * Advance to next unescaped newline
- */
- if ((lastc = c) == '\n') {
- lineno++;
- }
- c = ParseReadc();
- }
- lineno++;
-
- lastc = c;
- c = ParseReadc ();
- }
- }
-
- if (c == EOF) {
- Parse_Error (PARSE_FATAL, "Unclosed conditional/for loop");
- return ((char *)NULL);
- }
-
- /*
- * Read the entire line into buf
- */
- buf = Buf_Init (MAKE_BSIZE);
- if (c != '\n') {
- lastc = '\0';
- do {
- if (lastc != '\0' && lastc != '\n')
- Buf_AddByte (buf, (Byte) lastc);
- if ((lastc = c) == '\n')
- lineno++;
- c = ParseReadc();
- if (c == '\n' && lastc == '\\')
- lastc = '\0';
- } while (((c != '\n') || (lastc == '\0')) && (c != EOF));
- if (lastc != '\0' && lastc != '\n')
- Buf_AddByte (buf, (Byte) lastc);
- }
- lineno++;
-
- Buf_AddByte (buf, (Byte)'\0');
- line = (char *)Buf_GetAll (buf, &lineLength);
- Buf_Destroy (buf, FALSE);
+ do {
+ Buf_Discard(buf, lineLength);
+ lastc = '\0';
+
+ while (((c = ParseReadc()) != '\n' || lastc == '\\')
+ && c != EOF) {
+ if (c == '\n') {
+ Buf_ReplaceLastByte(buf, (Byte)' ');
+ lineno++;
+
+ while ((c = ParseReadc()) == ' ' || c == '\t');
+
+ if (c == EOF)
+ break;
+ }
+
+ Buf_AddByte(buf, (Byte)c);
+ lastc = c;
+ }
+
+ if (c == EOF) {
+ Parse_Error(PARSE_FATAL, "Unclosed conditional/for loop");
+ Buf_Destroy(buf, TRUE);
+ return((char *)NULL);
+ }
+
+ lineno++;
+ Buf_AddByte(buf, (Byte)'\0');
+ line = (char *)Buf_GetAll(buf, &lineLength);
+ } while (skip == 1 && line[0] != '.');
+
+ Buf_Destroy(buf, FALSE);
return line;
}
@@ -2126,11 +2108,11 @@ ParseReadLine ()
break;
}
}
-
+
if (c != EOF) {
lastc = c;
buf = Buf_Init(MAKE_BSIZE);
-
+
while (((c = ParseReadc ()) != '\n' || (lastc == '\\')) &&
(c != EOF))
{
@@ -2178,7 +2160,7 @@ test_char:
*/
ParseUnreadc('\t');
goto line_read;
- }
+ }
break;
case '=':
if (!semiNL) {
@@ -2245,11 +2227,11 @@ test_char:
*/
Buf_AddByte (buf, (Byte)lastc);
lastc = c;
-
+
}
line_read:
lineno++;
-
+
if (lastc != '\0') {
Buf_AddByte (buf, (Byte)lastc);
}
@@ -2265,13 +2247,13 @@ test_char:
ep = line;
while (*ep)
++ep;
- while (ep > line && (ep[-1] == ' ' || ep[-1] == '\t')) {
+ while (ep > line + 1 && (ep[-1] == ' ' || ep[-1] == '\t')) {
if (ep > line + 1 && ep[-2] == '\\')
break;
--ep;
}
*ep = 0;
-
+
if (line[0] == '.') {
/*
* The line might be a conditional. Ask the conditional module
@@ -2303,7 +2285,7 @@ test_char:
*/
line = ParseSkipLine(0);
if (line == NULL) {
- Parse_Error (PARSE_FATAL,
+ Parse_Error (PARSE_FATAL,
"Unexpected end of file in for loop.\n");
break;
}
@@ -2351,7 +2333,7 @@ ParseFinishLine()
inLine = FALSE;
}
}
-
+
/*-
*---------------------------------------------------------------------
@@ -2412,12 +2394,11 @@ Parse_File(name, stream)
goto nextLine;
}
}
- if (*line == '#' || *line == '\0') {
- /* If we're this far, the line must be a comment.
- (Empty lines are ignored as well) */
+ if (*line == '#') {
+ /* If we're this far, the line must be a comment. */
goto nextLine;
}
-
+
if (*line == '\t') {
/*
* If a line starts with a tab, it can only hope to be
@@ -2434,7 +2415,7 @@ Parse_File(name, stream)
/*
* So long as it's not a blank line and we're actually
* in a dependency spec, add the command to the list of
- * commands of all targets in the dependency spec
+ * commands of all targets in the dependency spec
*/
Lst_ForEach (targets, ParseAddCmd, cp);
Lst_AtEnd(targCmds, (ClientData) line);
@@ -2472,7 +2453,7 @@ Parse_File(name, stream)
#ifndef POSIX
Boolean nonSpace = FALSE;
#endif
-
+
cp = line;
if (isspace((unsigned char) line[0])) {
while ((*cp != '\0') && isspace((unsigned char) *cp)) {
@@ -2488,7 +2469,7 @@ Parse_File(name, stream)
}
#endif
}
-
+
#ifndef POSIX
if (*cp == '\0') {
if (inLine) {
@@ -2505,16 +2486,16 @@ Parse_File(name, stream)
cp = Var_Subst (NULL, line, VAR_CMD, TRUE);
free (line);
line = cp;
-
+
/*
- * Need a non-circular list for the target nodes
+ * Need a non-circular list for the target nodes
*/
if (targets)
Lst_Destroy(targets, NOFREE);
targets = Lst_Init (FALSE);
inLine = TRUE;
-
+
ParseDoDependency (line);
#ifndef POSIX
}
@@ -2526,7 +2507,7 @@ Parse_File(name, stream)
free (line);
}
/*
- * Reached EOF, but it may be just EOF of an include file...
+ * Reached EOF, but it may be just EOF of an include file...
*/
} while (ParseEOF(1) == CONTINUE);
@@ -2573,7 +2554,7 @@ Parse_End()
Lst_Destroy(parseIncPath, Dir_Destroy);
Lst_Destroy(includes, NOFREE); /* Should be empty now */
}
-
+
/*-
*-----------------------------------------------------------------------