summaryrefslogtreecommitdiff
path: root/usr.bin/make/parse.c
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2000-06-17 14:38:23 +0000
committerMarc Espie <espie@cvs.openbsd.org>2000-06-17 14:38:23 +0000
commitecbebb6e3cb3428095eb28e7e03e6872e5d24a68 (patch)
tree25a3cb92a8ac766285ba464991f3a7d4d6f10cf4 /usr.bin/make/parse.c
parent93fa2e228c8792a5468e8d398b5bb6c290eecb73 (diff)
This patch introduces a distinction between
Lst_Init (constructor) and Lst_New (allocation + construction) Lst_Destroy (destructor) and Lst_Delete (deallocation + destruction), and uses that to turn most dynamic allocation of lists (Lst pointers) into static structures (LIST). Most of this is mundane, except for allGNs in targ.c, where the code must be checked to verify that Targ_Init is called soon enough. Lst_New is a temporary addition. All lists will soon be static. Reviewed by millert@, like the previous patch.
Diffstat (limited to 'usr.bin/make/parse.c')
-rw-r--r--usr.bin/make/parse.c190
1 files changed, 90 insertions, 100 deletions
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index e471f28574a..339bb4ea157 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.42 2000/06/10 01:41:06 espie Exp $ */
+/* $OpenBSD: parse.c,v 1.43 2000/06/17 14:38: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.42 2000/06/10 01:41:06 espie Exp $";
+static char rcsid[] = "$OpenBSD: parse.c,v 1.43 2000/06/17 14:38:18 espie Exp $";
#endif
#endif /* not lint */
@@ -105,7 +105,7 @@ static char rcsid[] = "$OpenBSD: parse.c,v 1.42 2000/06/10 01:41:06 espie Exp $"
#include "pathnames.h"
#ifdef CLEANUP
-static Lst fileNames; /* file names to free at end */
+static LIST fileNames; /* file names to free at end */
#endif
/*
@@ -117,7 +117,7 @@ static Lst fileNames; /* file names to free at end */
#define DONE 0
static Lst targets; /* targets we're working on */
#ifdef CLEANUP
-static Lst targCmds; /* command lines for targets */
+static LIST targCmds; /* command lines for targets */
#endif
static Boolean inLine; /* true if currently in a dependency
* line or its commands */
@@ -147,10 +147,10 @@ typedef struct IFile {
PTR *p; /* the char pointer */
} IFile;
-static Lst includes; /* stack of IFiles generated by
+static LIST includes; /* stack of IFiles generated by
* #includes */
-Lst parseIncPath; /* list of directories for "..." includes */
-Lst sysIncPath; /* list of directories for <...> includes */
+LIST parseIncPath; /* list of directories for "..." includes */
+LIST sysIncPath; /* list of directories for <...> includes */
/*-
* specType contains the SPECial TYPE of the current target. It is
@@ -435,10 +435,10 @@ ParseLinkSrc(pgnp, cgnp)
{
GNode *pgn = (GNode *)pgnp;
GNode *cgn = (GNode *)cgnp;
- if (Lst_Member(pgn->children, cgn) == NULL) {
- Lst_AtEnd(pgn->children, cgn);
+ if (Lst_Member(&pgn->children, cgn) == NULL) {
+ Lst_AtEnd(&pgn->children, cgn);
if (specType == Not)
- Lst_AtEnd(cgn->parents, pgn);
+ Lst_AtEnd(&cgn->parents, pgn);
pgn->unmade += 1;
}
}
@@ -500,9 +500,9 @@ ParseDoOp (gnp, opp)
* anything with their local variables, but better safe than
* sorry.
*/
- Lst_ForEach(gn->parents, ParseLinkSrc, cohort);
+ Lst_ForEach(&gn->parents, ParseLinkSrc, cohort);
cohort->type = OP_DOUBLEDEP|OP_INVISIBLE;
- Lst_AtEnd(gn->cohorts, cohort);
+ Lst_AtEnd(&gn->cohorts, cohort);
/*
* Replace the node in the targets list with the new copy
@@ -550,8 +550,8 @@ ParseAddDep(pp, sp)
* but checking is tedious, and the debugging output can show the
* problem
*/
- Lst_AtEnd(p->successors, s);
- Lst_AtEnd(s->preds, p);
+ Lst_AtEnd(&p->successors, s);
+ Lst_AtEnd(&s->preds, p);
return 1;
}
else
@@ -610,7 +610,7 @@ ParseDoSrc (tOp, src, allsrc)
* invoked if the user didn't specify a target on the command
* line. This is to allow #ifmake's to succeed, or something...
*/
- Lst_AtEnd(create, estrdup(src));
+ Lst_AtEnd(&create, estrdup(src));
/*
* Add the name to the .TARGETS variable as well, so the user cna
* employ that, if desired.
@@ -625,8 +625,8 @@ ParseDoSrc (tOp, src, allsrc)
*/
gn = Targ_FindNode(src, TARG_CREATE);
if (predecessor != NULL) {
- Lst_AtEnd(predecessor->successors, gn);
- Lst_AtEnd(gn->preds, predecessor);
+ Lst_AtEnd(&predecessor->successors, gn);
+ Lst_AtEnd(&gn->preds, predecessor);
}
/*
* The current source now becomes the predecessor for the next one.
@@ -656,7 +656,7 @@ ParseDoSrc (tOp, src, allsrc)
register GNode *cohort;
register LstNode ln;
- for (ln=Lst_First(gn->cohorts); ln != NULL; ln = Lst_Succ(ln)){
+ for (ln=Lst_First(&gn->cohorts); ln != NULL; ln = Lst_Succ(ln)){
cohort = (GNode *)Lst_Datum(ln);
if (tOp) {
cohort->type |= tOp;
@@ -784,11 +784,9 @@ ParseDoDependency (line)
Lst paths; /* List of search paths to alter when parsing
* a list of .PATH targets */
int tOp; /* operator from special target */
- Lst sources; /* list of archive source names after
- * expansion */
- Lst curTargs; /* list of target names to be found and added
+ LIST curTargs; /* list of target names to be found and added
* to the targets list */
- Lst curSrcs; /* list of sources in order */
+ LIST curSrcs; /* list of sources in order */
tOp = 0;
@@ -796,8 +794,8 @@ ParseDoDependency (line)
waiting = 0;
paths = (Lst)NULL;
- curTargs = Lst_Init();
- curSrcs = Lst_Init();
+ Lst_Init(&curTargs);
+ Lst_Init(&curSrcs);
do {
for (cp = line;
@@ -929,13 +927,12 @@ ParseDoDependency (line)
*/
switch (specType) {
case ExPath:
- if (paths == NULL) {
- paths = Lst_Init();
- }
- Lst_AtEnd(paths, dirSearchPath);
+ if (paths == NULL)
+ paths = Lst_New();
+ Lst_AtEnd(paths, &dirSearchPath);
break;
case Main:
- if (!Lst_IsEmpty(create)) {
+ if (!Lst_IsEmpty(&create)) {
specType = Not;
}
break;
@@ -984,9 +981,8 @@ ParseDoDependency (line)
&line[5]);
return;
} else {
- if (paths == NULL) {
- paths = Lst_Init();
- }
+ if (paths == NULL)
+ paths = Lst_New();
Lst_AtEnd(paths, path);
}
}
@@ -1006,20 +1002,22 @@ ParseDoDependency (line)
* use Dir_Destroy in the destruction of the path as the
* Dir module could have added a directory to the path...
*/
- Lst emptyPath = Lst_Init();
+ LIST emptyPath;
+
+ Lst_Init(&emptyPath);
- Dir_Expand(line, emptyPath, curTargs);
+ Dir_Expand(line, &emptyPath, &curTargs);
- Lst_Destroy(emptyPath, Dir_Destroy);
+ Lst_Destroy(&emptyPath, Dir_Destroy);
} else {
/*
* No wildcards, but we want to avoid code duplication,
* so create a list with the word on it.
*/
- Lst_AtEnd(curTargs, line);
+ Lst_AtEnd(&curTargs, line);
}
- while((targName = (char *)Lst_DeQueue(curTargs)) != NULL) {
+ while((targName = (char *)Lst_DeQueue(&curTargs)) != NULL) {
if (!Suff_IsTransform (targName)) {
gn = Targ_FindNode (targName, TARG_CREATE);
} else {
@@ -1058,10 +1056,8 @@ ParseDoDependency (line)
line = cp;
} while ((*line != '!') && (*line != ':') && *line);
- /*
- * Don't need the list of target names anymore...
- */
- Lst_Destroy(curTargs, NOFREE);
+ /* Don't need the list of target names any more */
+ Lst_Destroy(&curTargs, NOFREE);
if (!Lst_IsEmpty(targets)) {
switch(specType) {
@@ -1227,9 +1223,8 @@ ParseDoDependency (line)
}
line = cp;
}
- if (paths) {
- Lst_Destroy(paths, NOFREE);
- }
+ if (paths)
+ Lst_Delete(paths, NOFREE);
} else {
while (*line) {
/*
@@ -1253,17 +1248,19 @@ ParseDoDependency (line)
if (*cp == '(') {
GNode *gn;
+ LIST sources; /* list of archive source names after
+ * expansion */
- sources = Lst_Init();
- if (Arch_ParseArchive (&line, sources, VAR_CMD) != SUCCESS) {
+ Lst_Init(&sources);
+ if (Arch_ParseArchive(&line, &sources, VAR_CMD) != SUCCESS) {
Parse_Error (PARSE_FATAL,
"Error in source archive spec \"%s\"", line);
return;
}
- while ((gn = (GNode *)Lst_DeQueue(sources)) != NULL)
- ParseDoSrc(tOp, gn->name, curSrcs);
- Lst_Destroy(sources, NOFREE);
+ while ((gn = (GNode *)Lst_DeQueue(&sources)) != NULL)
+ ParseDoSrc(tOp, gn->name, &curSrcs);
+ Lst_Destroy(&sources, NOFREE);
cp = line;
} else {
if (*cp) {
@@ -1271,7 +1268,7 @@ ParseDoDependency (line)
cp += 1;
}
- ParseDoSrc (tOp, line, curSrcs);
+ ParseDoSrc(tOp, line, &curSrcs);
}
while (*cp && isspace (*cp)) {
cp++;
@@ -1290,10 +1287,8 @@ ParseDoDependency (line)
Lst_Find(targets, ParseFindMain, NULL);
}
- /*
- * Finally, destroy the list of sources
- */
- Lst_Destroy(curSrcs, NOFREE);
+ /* Finally, destroy the list of sources. */
+ Lst_Destroy(&curSrcs, NOFREE);
}
/*-
@@ -1574,7 +1569,7 @@ ParseAddCmd(gnp, cmd)
GNode *gn = (GNode *)gnp;
/* if target already supplied, ignore commands */
if (!(gn->type & OP_HAS_COMMANDS)) {
- Lst_AtEnd(gn->commands, cmd);
+ Lst_AtEnd(&gn->commands, cmd);
if (!gn->lineno) {
gn->lineno = Parse_Getlineno();
gn->fname = Parse_Getfilename();
@@ -1603,7 +1598,7 @@ ParseHasCommands(gnp)
void *gnp; /* Node to examine */
{
GNode *gn = (GNode *) gnp;
- if (!Lst_IsEmpty(gn->commands)) {
+ if (!Lst_IsEmpty(&gn->commands)) {
gn->type |= OP_HAS_COMMANDS;
}
}
@@ -1623,10 +1618,10 @@ ParseHasCommands(gnp)
*-----------------------------------------------------------------------
*/
void
-Parse_AddIncludeDir (dir)
+Parse_AddIncludeDir(dir)
char *dir; /* The name of the directory to add */
{
- Dir_AddDir (parseIncPath, dir);
+ Dir_AddDir(&parseIncPath, dir);
}
/*-
@@ -1731,9 +1726,9 @@ ParseDoInclude (file)
newName = estrdup(file);
else
newName = str_concat (Fname, file, STR_ADDSLASH);
- fullname = Dir_FindFile (newName, parseIncPath);
+ fullname = Dir_FindFile(newName, &parseIncPath);
if (fullname == (char *)NULL) {
- fullname = Dir_FindFile(newName, dirSearchPath);
+ fullname = Dir_FindFile(newName, &dirSearchPath);
}
free (newName);
*prefEnd = '/';
@@ -1752,9 +1747,9 @@ ParseDoInclude (file)
* then on the .PATH search path, if not found in a -I directory.
* XXX: Suffix specific?
*/
- fullname = Dir_FindFile (file, parseIncPath);
+ fullname = Dir_FindFile(file, &parseIncPath);
if (fullname == (char *)NULL) {
- fullname = Dir_FindFile(file, dirSearchPath);
+ fullname = Dir_FindFile(file, &dirSearchPath);
}
}
@@ -1763,7 +1758,7 @@ ParseDoInclude (file)
* Still haven't found the makefile. Look for it on the system
* path as a last resort.
*/
- fullname = Dir_FindFile(file, sysIncPath);
+ fullname = Dir_FindFile(file, &sysIncPath);
}
if (fullname == (char *) NULL) {
@@ -1788,7 +1783,7 @@ ParseDoInclude (file)
oldFile->p = curPTR;
oldFile->lineno = lineno;
- Lst_AtFront(includes, oldFile);
+ Lst_AtFront(&includes, oldFile);
/*
* Once the previous state has been saved, we can get down to reading
@@ -1798,7 +1793,7 @@ ParseDoInclude (file)
*/
fname = fullname;
#ifdef CLEANUP
- Lst_AtEnd(fileNames, fname);
+ Lst_AtEnd(&fileNames, fname);
#endif
lineno = 0;
@@ -1843,7 +1838,7 @@ Parse_FromString(str, newlineno)
oldFile->F = curFILE;
oldFile->p = curPTR;
- Lst_AtFront(includes, oldFile);
+ Lst_AtFront(&includes, oldFile);
curFILE = NULL;
curPTR = (PTR *) emalloc (sizeof (PTR));
@@ -1923,10 +1918,9 @@ ParseTraditionalInclude (file)
*prefEnd = '\0';
newName = str_concat (fname, file, STR_ADDSLASH);
- fullname = Dir_FindFile (newName, parseIncPath);
- if (fullname == (char *)NULL) {
- fullname = Dir_FindFile(newName, dirSearchPath);
- }
+ fullname = Dir_FindFile(newName, &parseIncPath);
+ if (fullname == NULL)
+ fullname = Dir_FindFile(newName, &dirSearchPath);
free (newName);
*prefEnd = '/';
} else {
@@ -1940,10 +1934,9 @@ ParseTraditionalInclude (file)
* then on the .PATH search path, if not found in a -I directory.
* XXX: Suffix specific?
*/
- fullname = Dir_FindFile (file, parseIncPath);
- if (fullname == (char *)NULL) {
- fullname = Dir_FindFile(file, dirSearchPath);
- }
+ fullname = Dir_FindFile(file, &parseIncPath);
+ if (fullname == NULL)
+ fullname = Dir_FindFile(file, &dirSearchPath);
}
if (fullname == (char *)NULL) {
@@ -1951,7 +1944,7 @@ ParseTraditionalInclude (file)
* Still haven't found the makefile. Look for it on the system
* path as a last resort.
*/
- fullname = Dir_FindFile(file, sysIncPath);
+ fullname = Dir_FindFile(file, &sysIncPath);
}
if (fullname == (char *) NULL) {
@@ -1973,7 +1966,7 @@ ParseTraditionalInclude (file)
oldFile->p = curPTR;
oldFile->lineno = lineno;
- Lst_AtFront(includes, oldFile);
+ Lst_AtFront(&includes, oldFile);
/*
* Once the previous state has been saved, we can get down to reading
@@ -1983,7 +1976,7 @@ ParseTraditionalInclude (file)
*/
fname = fullname;
#ifdef CLEANUP
- lst_AtEnd(fileNames, fname);
+ Lst_AtEnd(&fileNames, fname);
#endif
lineno = 0;
@@ -2020,7 +2013,7 @@ ParseEOF (opened)
{
IFile *ifile; /* the state on the top of the includes stack */
- if ((ifile = (IFile *)Lst_DeQueue(includes)) == NULL)
+ if ((ifile = (IFile *)Lst_DeQueue(&includes)) == NULL)
return DONE;
fname = ifile->fname;
lineno = ifile->lineno;
@@ -2414,7 +2407,7 @@ ParseFinishLine()
{
if (inLine) {
Lst_Every(targets, Suff_EndTransform);
- Lst_Destroy(targets, ParseHasCommands);
+ Lst_Delete(targets, ParseHasCommands);
targets = NULL;
inLine = FALSE;
}
@@ -2447,7 +2440,7 @@ Parse_File(name, stream)
inLine = FALSE;
fname = estrdup(name);
#ifdef CLEANUP
- Lst_AtEnd(fileNames, fname);
+ Lst_AtEnd(&fileNames, fname);
#endif
curFILE = stream;
lineno = 0;
@@ -2508,7 +2501,7 @@ Parse_File(name, stream)
*/
Lst_ForEach(targets, ParseAddCmd, cp);
#ifdef CLEANUP
- Lst_AtEnd(targCmds, line);
+ Lst_AtEnd(&targCmds, line);
#endif
continue;
} else {
@@ -2582,9 +2575,9 @@ Parse_File(name, stream)
* Need a non-circular list for the target nodes
*/
if (targets)
- Lst_Destroy(targets, NOFREE);
+ Lst_Delete(targets, NOFREE);
- targets = Lst_Init();
+ targets = Lst_New();
inLine = TRUE;
ParseDoDependency (line);
@@ -2618,23 +2611,20 @@ Parse_File(name, stream)
* Parse_Init --
* initialize the parsing module
*
- * Results:
- * none
- *
* Side Effects:
* the parseIncPath list is initialized...
*---------------------------------------------------------------------
*/
void
-Parse_Init ()
+Parse_Init()
{
mainNode = NULL;
- parseIncPath = Lst_Init();
- sysIncPath = Lst_Init();
- includes = Lst_Init();
+ Lst_Init(&parseIncPath);
+ Lst_Init(&sysIncPath);
+ Lst_Init(&includes);
#ifdef CLEANUP
- targCmds = Lst_Init();
- fileNames = Lst_Init();
+ Lst_Init(&targCmds);
+ Lst_Init(&fileNames);
#endif
}
@@ -2642,13 +2632,13 @@ void
Parse_End()
{
#ifdef CLEANUP
- Lst_Destroy(targCmds, (SimpleProc)free);
- Lst_Destroy(fileNames, (void (*) __P((ClientData))) free);
+ Lst_Destroy(&targCmds, (SimpleProc)free);
+ Lst_Destroy(&fileNames, (void (*) __P((ClientData))) free);
if (targets)
- Lst_Destroy(targets, NOFREE);
- Lst_Destroy(sysIncPath, Dir_Destroy);
- Lst_Destroy(parseIncPath, Dir_Destroy);
- Lst_Destroy(includes, NOFREE); /* Should be empty now */
+ Lst_Delete(targets, NOFREE);
+ Lst_Destroy(&sysIncPath, Dir_Destroy);
+ Lst_Destroy(&parseIncPath, Dir_Destroy);
+ Lst_Destroy(&includes, NOFREE); /* Should be empty now */
#endif
}
@@ -2672,14 +2662,14 @@ Parse_MainName()
{
Lst listmain; /* result list */
- listmain = Lst_Init();
+ listmain = Lst_New();
if (mainNode == NULL) {
Punt ("no target to make.");
/*NOTREACHED*/
} else if (mainNode->type & OP_DOUBLEDEP) {
Lst_AtEnd(listmain, mainNode);
- Lst_Concat(listmain, mainNode->cohorts, LST_CONCNEW);
+ Lst_Concat(listmain, &mainNode->cohorts, LST_CONCNEW);
}
else
Lst_AtEnd(listmain, mainNode);