Make needs no circular lists so remove them from the list code.

This commit is contained in:
harti 2004-12-07 10:14:16 +00:00
parent 4a639d6164
commit e65ea2146d
21 changed files with 88 additions and 144 deletions

View File

@ -336,7 +336,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt)
*/
free(buf);
} else if (Dir_HasWildcards(memName)) {
Lst members = Lst_Init(FALSE);
Lst members = Lst_Init();
char *member;
size_t sz = MAXPATHLEN;
size_t nsz;
@ -1193,7 +1193,7 @@ void
Arch_Init(void)
{
archives = Lst_Init(FALSE);
archives = Lst_Init();
}
/*-

View File

@ -209,8 +209,8 @@ void
Dir_Init(void)
{
dirSearchPath = Lst_Init(FALSE);
openDirectories = Lst_Init(FALSE);
dirSearchPath = Lst_Init();
openDirectories = Lst_Init();
Hash_InitTable(&mtimes, 0);
}
@ -621,7 +621,7 @@ Dir_Expand(char *word, Lst path, Lst expansions)
if (*dp == '/')
*dp = '\0';
path = Lst_Init(FALSE);
path = Lst_Init();
Dir_AddDir(path, dirpath);
DirExpandInt(cp + 1, path,
expansions);

View File

@ -168,7 +168,7 @@ For_Eval(char *line)
/*
* Make a list with the remaining words
*/
forLst = Lst_Init(FALSE);
forLst = Lst_Init();
buf = Buf_Init(0);
sub = Var_Subst(NULL, ptr, VAR_CMD, FALSE);

View File

@ -2186,8 +2186,8 @@ Job_Init(int maxproc)
struct sigaction sa;
fifoFd = -1;
jobs = Lst_Init(FALSE);
stoppedJobs = Lst_Init(FALSE);
jobs = Lst_Init();
stoppedJobs = Lst_Init();
env = getenv("MAKE_JOBS_FIFO");
if (env == NULL && maxproc > 1) {

View File

@ -79,8 +79,6 @@ typedef enum {
struct Lst {
LstNode firstPtr; /* first node in list */
LstNode lastPtr; /* last node in list */
Boolean isCirc; /* true if the list should be considered
* circular */
/*
* fields for sequential access
*/
@ -113,7 +111,7 @@ typedef void FreeProc(void *);
* Creation/destruction functions
*/
/* Create a new list */
Lst Lst_Init(Boolean);
Lst Lst_Init(void);
/* Duplicate an existing list */
Lst Lst_Duplicate(Lst, DuplicateProc *);
/* Destroy an old one */

View File

@ -89,11 +89,7 @@ Lst_Append(Lst list, LstNode ln, void *d)
nLNode->useCount = nLNode->flags = 0;
if (ln == NULL) {
if (list->isCirc) {
nLNode->nextPtr = nLNode->prevPtr = nLNode;
} else {
nLNode->nextPtr = nLNode->prevPtr = NULL;
}
nLNode->nextPtr = nLNode->prevPtr = NULL;
list->firstPtr = list->lastPtr = nLNode;
} else {
nLNode->prevPtr = ln;

View File

@ -46,9 +46,8 @@ __FBSDID("$FreeBSD$");
* Close a list for sequential access.
* The sequential functions access the list in a slightly different way.
* CurPtr points to their idea of the current node in the list and they
* access the list based on it. Because the list is circular, Lst_Next
* and Lst_Prev will go around the list forever. Lst_IsAtEnd must be
* used to determine when to stop.
* access the list based on it. Lst_IsAtEnd must be used to determine
* when to stop.
*/
#include "make.h"

View File

@ -87,12 +87,11 @@ Lst_Concat(Lst list1, Lst list2, int flags)
if (flags == LST_CONCLINK) {
if (list2->firstPtr != NULL) {
/*
* We set the nextPtr of the
* last element of list two to be NULL to make the loop easier and
* so we don't need an extra case should the first list turn
* out to be non-circular -- the final element will already point
* to NULL space and the first element will be untouched if it
* existed before and will also point to NULL space if it didn't.
* We set the nextPtr of the last element of list two to be NULL
* to make the loop easier and so we don't need an extra case --
* the final element will already point to NULL space and the first
* element will be untouched if it existed before and will also
* point to NULL space if it didn't.
*/
list2->lastPtr->nextPtr = NULL;
/*
@ -111,15 +110,6 @@ Lst_Concat(Lst list1, Lst list2, int flags)
}
list1->lastPtr = list2->lastPtr;
}
if (list1->isCirc && list1->firstPtr != NULL) {
/*
* If the first list is supposed to be circular and it is (now)
* non-empty, we must make sure it's circular by linking the
* first element to the last and vice versa
*/
list1->firstPtr->prevPtr = list1->lastPtr;
list1->lastPtr->nextPtr = list1->firstPtr;
}
free(list2);
} else if (list2->firstPtr != NULL) {
/*
@ -156,23 +146,7 @@ Lst_Concat(Lst list1, Lst list2, int flags)
* of list one.
*/
list1->lastPtr = last;
/*
* The circularity of both list one and list two must be corrected
* for -- list one because of the new nodes added to it; list two
* because of the alteration of list2->lastPtr's nextPtr to ease the
* above for loop.
*/
if (list1->isCirc) {
list1->lastPtr->nextPtr = list1->firstPtr;
list1->firstPtr->prevPtr = list1->lastPtr;
} else {
last->nextPtr = NULL;
}
if (list2->isCirc) {
list2->lastPtr->nextPtr = list2->firstPtr;
}
last->nextPtr = NULL;
}
return (SUCCESS);

View File

@ -77,7 +77,7 @@ Lst_Duplicate(Lst list, DuplicateProc *copyProc)
return (NULL);
}
nl = Lst_Init(list->isCirc);
nl = Lst_Init();
if (nl == NULL) {
return (NULL);
}
@ -92,11 +92,7 @@ Lst_Duplicate(Lst list, DuplicateProc *copyProc)
return (NULL);
}
if (list->isCirc && ln == list->lastPtr) {
ln = NULL;
} else {
ln = ln->nextPtr;
}
ln = ln->nextPtr;
}
return (nl);

View File

@ -57,16 +57,13 @@ __FBSDID("$FreeBSD$");
* Results:
* The created list.
*
* Arguments:
* circ TRUE if the list should be made circular
*
* Side Effects:
* A list is created, what else?
*
*-----------------------------------------------------------------------
*/
Lst
Lst_Init(Boolean circ)
Lst_Init(void)
{
Lst nList;
@ -75,7 +72,6 @@ Lst_Init(Boolean circ)
nList->firstPtr = NULL;
nList->lastPtr = NULL;
nList->isOpen = FALSE;
nList->isCirc = circ;
nList->atEnd = LstUnknown;
return (nList);

View File

@ -90,11 +90,7 @@ Lst_Insert(Lst list, LstNode ln, void *d)
nLNode->useCount = nLNode->flags = 0;
if (ln == NULL) {
if (list->isCirc) {
nLNode->prevPtr = nLNode->nextPtr = nLNode;
} else {
nLNode->prevPtr = nLNode->nextPtr = NULL;
}
nLNode->prevPtr = nLNode->nextPtr = NULL;
list->firstPtr = list->lastPtr = nLNode;
} else {
nLNode->prevPtr = ln->prevPtr;

View File

@ -46,9 +46,8 @@ __FBSDID("$FreeBSD$");
* Tell if the current node is at the end of the list.
* The sequential functions access the list in a slightly different way.
* CurPtr points to their idea of the current node in the list and they
* access the list based on it. Because the list is circular, Lst_Next
* and Lst_Prev will go around the list forever. Lst_IsAtEnd must be
* used to determine when to stop.
* access the list based on it. Lst_IsAtEnd must be used to determine
* when to stop.
*/
#include "make.h"

View File

@ -46,9 +46,8 @@ __FBSDID("$FreeBSD$");
* Return the next node for a list.
* The sequential functions access the list in a slightly different way.
* CurPtr points to their idea of the current node in the list and they
* access the list based on it. Because the list is circular, Lst_Next
* and Lst_Prev will go around the list forever. Lst_IsAtEnd must be
* used to determine when to stop.
* access the list based on it. Lst_IsAtEnd must be used to determine
* when to stop.
*/
#include "make.h"
@ -60,9 +59,8 @@ __FBSDID("$FreeBSD$");
* Return the next node for the given list.
*
* Results:
* The next node or NULL if the list has yet to be opened. Also
* if the list is non-circular and the end has been reached, NULL
* is returned.
* The next node or NULL if the list has yet to be opened or the end
* has been reached.
*
* Side Effects:
* the curPtr field is updated.
@ -97,15 +95,9 @@ Lst_Next(Lst list)
tln = list->curPtr->nextPtr;
list->curPtr = tln;
if (tln == list->firstPtr || tln == NULL) {
/*
* If back at the front, then we've hit the end...
*/
if (tln == NULL) {
list->atEnd = LstTail;
} else {
/*
* Reset to Middle if gone past first.
*/
list->atEnd = LstMiddle;
}
}

View File

@ -46,8 +46,7 @@ __FBSDID("$FreeBSD$");
* Open a list for sequential access. The sequential functions access the
* list in a slightly different way. CurPtr points to their idea of the
* current node in the list and they access the list based on it.
* If the list is circular, Lst_Next and Lst_Prev will go around
* the list forever. Lst_IsAtEnd must be used to determine when to stop.
* Lst_IsAtEnd must be used to determine when to stop.
*/
#include "make.h"

View File

@ -108,8 +108,7 @@ Lst_Remove(Lst list, LstNode ln)
/*
* the only way firstPtr can still point to ln is if ln is the last
* node on the list (the list is circular, so ln->nextptr == ln in
* this case). The list is, therefore, empty and is marked as such
* node on the list. The list is, therefore, empty and is marked as such
*/
if (list->firstPtr == ln) {
list->firstPtr = NULL;

View File

@ -565,11 +565,11 @@ main(int argc, char **argv)
machine_cpu = "unknown";
}
create = Lst_Init(FALSE);
makefiles = Lst_Init(FALSE);
envFirstVars = Lst_Init(FALSE);
create = Lst_Init();
makefiles = Lst_Init();
envFirstVars = Lst_Init();
expandVars = TRUE;
variables = Lst_Init(FALSE);
variables = Lst_Init();
beSilent = FALSE; /* Print commands as executed */
ignoreErrors = FALSE; /* Pay attention to non-zero returns */
noExecute = FALSE; /* Execute all commands */
@ -746,7 +746,7 @@ main(int argc, char **argv)
if (!noBuiltins) {
LstNode ln;
sysMkPath = Lst_Init(FALSE);
sysMkPath = Lst_Init();
Dir_Expand(_PATH_DEFSYSMK, sysIncPath, sysMkPath);
if (Lst_IsEmpty(sysMkPath))
Fatal("make: no system rules (%s).", _PATH_DEFSYSMK);

View File

@ -783,7 +783,7 @@ Make_Run(Lst targs)
Lst examine; /* List of targets to examine */
int errors; /* Number of errors the Job module reports */
toBeMade = Lst_Init(FALSE);
toBeMade = Lst_Init();
examine = Lst_Duplicate(targs, NOCOPY);
numNodes = 0;

View File

@ -685,8 +685,8 @@ ParseDoDependency (char *line)
waiting = 0;
paths = NULL;
curTargs = Lst_Init(FALSE);
curSrcs = Lst_Init(FALSE);
curTargs = Lst_Init();
curSrcs = Lst_Init();
do {
for (cp = line;
@ -828,7 +828,7 @@ ParseDoDependency (char *line)
switch (specType) {
case ExPath:
if (paths == NULL) {
paths = Lst_Init(FALSE);
paths = Lst_Init();
}
Lst_AtEnd(paths, dirSearchPath);
break;
@ -881,7 +881,7 @@ ParseDoDependency (char *line)
return;
} else {
if (paths == (Lst)NULL) {
paths = Lst_Init(FALSE);
paths = Lst_Init();
}
Lst_AtEnd(paths, path);
}
@ -900,7 +900,7 @@ ParseDoDependency (char *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(FALSE);
Lst emptyPath = Lst_Init();
Dir_Expand(line, emptyPath, curTargs);
@ -1152,7 +1152,7 @@ ParseDoDependency (char *line)
if (*cp == '(') {
GNode *gnp;
sources = Lst_Init(FALSE);
sources = Lst_Init();
if (Arch_ParseArchive(&line, sources, VAR_CMD) != SUCCESS) {
Parse_Error(PARSE_FATAL,
"Error in source archive spec \"%s\"", line);
@ -2499,7 +2499,7 @@ Parse_File(char *name, FILE *stream)
if (targets)
Lst_Destroy(targets, NOFREE);
targets = Lst_Init(FALSE);
targets = Lst_Init();
inLine = TRUE;
ParseDoDependency (line);
@ -2540,10 +2540,10 @@ Parse_Init(void)
{
mainNode = NULL;
parseIncPath = Lst_Init(FALSE);
sysIncPath = Lst_Init(FALSE);
includes = Lst_Init(FALSE);
targCmds = Lst_Init(FALSE);
parseIncPath = Lst_Init();
sysIncPath = Lst_Init();
includes = Lst_Init();
targCmds = Lst_Init();
}
void
@ -2578,7 +2578,7 @@ Parse_MainName(void)
{
Lst listmain; /* result list */
listmain = Lst_Init(FALSE);
listmain = Lst_Init();
if (mainNode == NULL) {
Punt("no target to make.");

View File

@ -444,7 +444,7 @@ Suff_ClearSuffixes(void)
{
Lst_Concat(suffClean, sufflist, LST_CONCLINK);
sufflist = Lst_Init(FALSE);
sufflist = Lst_Init();
sNum = 1;
suffNull = emptySuff;
/*
@ -454,7 +454,7 @@ Suff_ClearSuffixes(void)
* suffNull should not have parents.
*/
Lst_Destroy(suffNull->children, NOFREE);
suffNull->children = Lst_Init(FALSE);
suffNull->children = Lst_Init();
}
/*-
@ -596,8 +596,8 @@ Suff_AddTransform(char *line)
gn = Lst_Datum(ln);
Lst_Destroy(gn->commands, NOFREE);
Lst_Destroy(gn->children, NOFREE);
gn->commands = Lst_Init(FALSE);
gn->children = Lst_Init(FALSE);
gn->commands = Lst_Init();
gn->children = Lst_Init();
}
gn->type = OP_TRANSFORM;
@ -776,10 +776,10 @@ Suff_AddSuffix(char *str)
s->name = estrdup(str);
s->nameLen = strlen (s->name);
s->searchPath = Lst_Init(FALSE);
s->children = Lst_Init(FALSE);
s->parents = Lst_Init(FALSE);
s->ref = Lst_Init(FALSE);
s->searchPath = Lst_Init();
s->children = Lst_Init();
s->parents = Lst_Init();
s->ref = Lst_Init();
s->sNum = sNum++;
s->flags = 0;
s->refCount = 0;
@ -853,8 +853,8 @@ Suff_DoPaths(void)
return;
}
inIncludes = Lst_Init(FALSE);
inLibs = Lst_Init(FALSE);
inIncludes = Lst_Init();
inLibs = Lst_Init();
while ((ln = Lst_Next(sufflist)) != NULL) {
s = Lst_Datum(ln);
@ -987,7 +987,7 @@ SuffAddSrc(void *sp, void *lsp)
targ->children += 1;
Lst_AtEnd(ls->l, s2);
#ifdef DEBUG_SRC
s2->cp = Lst_Init(FALSE);
s2->cp = Lst_Init();
Lst_AtEnd(targ->cp, s2);
printf("1 add %x %x to %x:", targ, s2, ls->l);
Lst_ForEach(ls->l, PrintAddr, (void *)NULL);
@ -1005,7 +1005,7 @@ SuffAddSrc(void *sp, void *lsp)
targ->children += 1;
Lst_AtEnd(ls->l, s2);
#ifdef DEBUG_SRC
s2->cp = Lst_Init(FALSE);
s2->cp = Lst_Init();
Lst_AtEnd(targ->cp, s2);
printf("2 add %x %x to %x:", targ, s2, ls->l);
Lst_ForEach(ls->l, PrintAddr, (void *)NULL);
@ -1235,7 +1235,7 @@ SuffFindCmds (Src *targ, Lst slst)
ret->children = 0;
targ->children += 1;
#ifdef DEBUG_SRC
ret->cp = Lst_Init(FALSE);
ret->cp = Lst_Init();
printf("3 add %x %x\n", targ, ret);
Lst_AtEnd(targ->cp, ret);
#endif
@ -1293,7 +1293,7 @@ SuffExpandChildren(void *cgnp, void *pgnp)
cp = Var_Subst(NULL, cgn->name, pgn, TRUE);
if (cp != NULL) {
Lst members = Lst_Init(FALSE);
Lst members = Lst_Init();
if (cgn->type & OP_ARCHV) {
/*
@ -1432,7 +1432,7 @@ SuffExpandChildren(void *cgnp, void *pgnp)
/*
* Expand the word along the chosen path
*/
exp = Lst_Init(FALSE);
exp = Lst_Init();
Dir_Expand(cgn->name, path, exp);
while (!Lst_IsEmpty(exp)) {
@ -1746,8 +1746,8 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
* Begin at the beginning...
*/
ln = Lst_First(sufflist);
srcs = Lst_Init(FALSE);
targs = Lst_Init(FALSE);
srcs = Lst_Init();
targs = Lst_Init();
/*
* We're caught in a catch-22 here. On the one hand, we want to use any
@ -1789,7 +1789,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
target->parent = NULL;
target->children = 0;
#ifdef DEBUG_SRC
target->cp = Lst_Init(FALSE);
target->cp = Lst_Init();
#endif
/*
@ -1833,7 +1833,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
targ->children = 0;
targ->pref = estrdup(sopref);
#ifdef DEBUG_SRC
targ->cp = Lst_Init(FALSE);
targ->cp = Lst_Init();
#endif
/*
@ -2227,10 +2227,10 @@ void
Suff_Init(void)
{
sufflist = Lst_Init(FALSE);
suffClean = Lst_Init(FALSE);
srclist = Lst_Init(FALSE);
transforms = Lst_Init(FALSE);
sufflist = Lst_Init();
suffClean = Lst_Init();
srclist = Lst_Init();
transforms = Lst_Init();
sNum = 0;
/*
@ -2242,11 +2242,11 @@ Suff_Init(void)
suffNull->name = estrdup("");
suffNull->nameLen = 0;
suffNull->searchPath = Lst_Init(FALSE);
suffNull->searchPath = Lst_Init();
Dir_Concat(suffNull->searchPath, dirSearchPath);
suffNull->children = Lst_Init(FALSE);
suffNull->parents = Lst_Init(FALSE);
suffNull->ref = Lst_Init(FALSE);
suffNull->children = Lst_Init();
suffNull->parents = Lst_Init();
suffNull->ref = Lst_Init();
suffNull->sNum = sNum++;
suffNull->flags = SUFF_NULL;
suffNull->refCount = 1;

View File

@ -115,7 +115,7 @@ void
Targ_Init(void)
{
allTargets = Lst_Init(FALSE);
allTargets = Lst_Init();
Hash_InitTable(&targets, HTSIZE);
}
@ -173,18 +173,18 @@ Targ_NewGN(char *name)
gn->childMade = FALSE;
gn->order = 0;
gn->mtime = gn->cmtime = 0;
gn->iParents = Lst_Init(FALSE);
gn->cohorts = Lst_Init(FALSE);
gn->parents = Lst_Init(FALSE);
gn->children = Lst_Init(FALSE);
gn->successors = Lst_Init(FALSE);
gn->preds = Lst_Init(FALSE);
gn->context = Lst_Init(FALSE);
gn->commands = Lst_Init(FALSE);
gn->iParents = Lst_Init();
gn->cohorts = Lst_Init();
gn->parents = Lst_Init();
gn->children = Lst_Init();
gn->successors = Lst_Init();
gn->preds = Lst_Init();
gn->context = Lst_Init();
gn->commands = Lst_Init();
gn->suffix = NULL;
if (allGNs == NULL)
allGNs = Lst_Init(FALSE);
allGNs = Lst_Init();
Lst_AtEnd(allGNs, (void *)gn);
return (gn);
@ -284,7 +284,7 @@ Targ_FindList(Lst names, int flags)
GNode *gn; /* node in tLn */
char *name;
nodes = Lst_Init(FALSE);
nodes = Lst_Init();
if (Lst_Open(names) == FAILURE) {
return (nodes);

View File

@ -1929,7 +1929,7 @@ Var_Init(void)
VAR_GLOBAL = Targ_NewGN("Global");
VAR_CMD = Targ_NewGN("Command");
allVars = Lst_Init(FALSE);
allVars = Lst_Init();
}