diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2000-06-17 14:40:31 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2000-06-17 14:40:31 +0000 |
commit | ba25a00b79070aa39d76e92f0c729f0e2a3f39a4 (patch) | |
tree | d1ef8181245e1d581e2993fd9be0d05be19ed799 /usr.bin | |
parent | ecbebb6e3cb3428095eb28e7e03e6872e5d24a68 (diff) |
A few assorted changes, to remove more dynamic lists.
- in Dir_Expand, path is a misnomer. Use a temp variable instead...
Reformat code for readability.
- Change Parse_MainName/Targ_FindList so that they fill arguments instead
of allocating new lists.
- nuke Targ_FindList(TG_NOCREATE), as this is never used.
- close a small memory hole (forgot to free sysMkPath if CLEANUP).
Reviewed by millert@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/make/dir.c | 49 | ||||
-rw-r--r-- | usr.bin/make/extern.h | 6 | ||||
-rw-r--r-- | usr.bin/make/main.c | 22 | ||||
-rw-r--r-- | usr.bin/make/make.h | 14 | ||||
-rw-r--r-- | usr.bin/make/parse.c | 22 | ||||
-rw-r--r-- | usr.bin/make/targ.c | 69 |
6 files changed, 74 insertions, 108 deletions
diff --git a/usr.bin/make/dir.c b/usr.bin/make/dir.c index a401fe4a5ad..02ecf0002b4 100644 --- a/usr.bin/make/dir.c +++ b/usr.bin/make/dir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dir.c,v 1.20 2000/06/17 14:38:14 espie Exp $ */ +/* $OpenBSD: dir.c,v 1.21 2000/06/17 14:40:27 espie Exp $ */ /* $NetBSD: dir.c,v 1.14 1997/03/29 16:51:26 christos Exp $ */ /* @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94"; #else -static char rcsid[] = "$OpenBSD: dir.c,v 1.20 2000/06/17 14:38:14 espie Exp $"; +static char rcsid[] = "$OpenBSD: dir.c,v 1.21 2000/06/17 14:40:27 espie Exp $"; #endif #endif /* not lint */ @@ -588,20 +588,15 @@ Dir_Expand (word, path, expansions) } } if (*cp == '{') { - /* - * This one will be fun. - */ + /* This one will be fun. */ DirExpandCurly(word, cp, path, expansions); return; } else if (*cp != '\0') { - /* - * Back up to the start of the component - */ + /* Back up to the start of the component. */ char *dirpath; - while (cp > word && *cp != '/') { + while (cp > word && *cp != '/') cp--; - } if (cp != word) { char sc; /* @@ -619,36 +614,28 @@ Dir_Expand (word, path, expansions) * looking for Etc, it won't be found. Ah well. * Probably not important. */ - if (dirpath != (char *)NULL) { + if (dirpath != NULL) { + LIST temp; + char *dp = &dirpath[strlen(dirpath) - 1]; if (*dp == '/') *dp = '\0'; - path = Lst_New(); - Dir_AddDir(path, dirpath); - DirExpandInt(cp+1, path, expansions); - Lst_Delete(path, NOFREE); + Lst_Init(&temp); + Dir_AddDir(&temp, dirpath); + DirExpandInt(cp+1, &temp, expansions); + Lst_Destroy(&temp, NOFREE); } - } else { - /* - * Start the search from the local directory - */ + } else + /* Start the search from the local directory. */ DirExpandInt(word, path, expansions); - } - } else { - /* - * Return the file -- this should never happen. - */ + } else + /* Return the file -- this should never happen. */ DirExpandInt(word, path, expansions); - } } else { - /* - * First the files in dot - */ + /* First the files in dot. */ DirMatchFiles(word, dot, expansions); - /* - * Then the files in every other directory on the path. - */ + /* Then the files in every other directory on the path. */ DirExpandInt(word, path, expansions); } } diff --git a/usr.bin/make/extern.h b/usr.bin/make/extern.h index c45a9c871c5..685194f94c9 100644 --- a/usr.bin/make/extern.h +++ b/usr.bin/make/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.22 2000/06/10 01:41:05 espie Exp $ */ +/* $OpenBSD: extern.h,v 1.23 2000/06/17 14:40:28 espie Exp $ */ /* $NetBSD: nonints.h,v 1.12 1996/11/06 17:59:19 christos Exp $ */ /*- @@ -96,7 +96,7 @@ void Parse_File __P((char *, FILE *)); void Parse_Init __P((void)); void Parse_End __P((void)); void Parse_FromString __P((char *, unsigned long)); -Lst Parse_MainName __P((void)); +void Parse_MainName __P((Lst)); unsigned long Parse_Getlineno __P((void)); const char *Parse_Getfilename __P((void)); @@ -131,7 +131,7 @@ void Targ_Init __P((void)); void Targ_End __P((void)); GNode *Targ_NewGN __P((char *)); GNode *Targ_FindNode __P((char *, int)); -Lst Targ_FindList __P((Lst, int)); +void Targ_FindList __P((Lst, Lst)); Boolean Targ_Ignore __P((GNode *)); Boolean Targ_Silent __P((GNode *)); Boolean Targ_Precious __P((GNode *)); diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 6ef4c6da020..af6b567d040 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.33 2000/06/17 14:38:18 espie Exp $ */ +/* $OpenBSD: main.c,v 1.34 2000/06/17 14:40:29 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.33 2000/06/17 14:38:18 espie Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.34 2000/06/17 14:40:29 espie Exp $"; #endif #endif /* not lint */ @@ -468,7 +468,7 @@ main(argc, argv) int argc; char **argv; { - Lst targs; /* target nodes to create -- passed to Make_Init */ + LIST targs; /* target nodes to create -- passed to Make_Init */ Boolean outOfDate = TRUE; /* FALSE if all targets up to date */ struct stat sb, sa; char *p, *path, *pathp, *pwd; @@ -718,6 +718,9 @@ main(argc, argv) ln = Lst_Find(&sysMkPath, ReadMakefile, NULL); if (ln != NULL) Fatal("make: cannot open %s.", (char *)Lst_Datum(ln)); +#ifdef CLEANUP + Lst_Destroy(&sysMkPath, (SimpleProc)free); +#endif } if (!Lst_IsEmpty(&makefiles)) { @@ -802,10 +805,11 @@ main(argc, argv) * to create. If none was given on the command line, we consult the * parsing module to find the main target(s) to create. */ - if (Lst_IsEmpty(&create)) - targs = Parse_MainName(); + Lst_Init(&targs); + if (!Lst_IsEmpty(&create)) + Targ_FindList(&targs, &create); else - targs = Targ_FindList(&create, TARG_CREATE); + Parse_MainName(&targs); if (!compatMake && !printVars) { /* @@ -822,16 +826,16 @@ main(argc, argv) } /* Traverse the graph, checking on all the targets */ - outOfDate = Make_Run(targs); + outOfDate = Make_Run(&targs); } else if (!printVars) { /* * Compat_Init will take care of creating all the targets as * well as initializing the module. */ - Compat_Run(targs); + Compat_Run(&targs); } - Lst_Delete(targs, NOFREE); + Lst_Destroy(&targs, NOFREE); Lst_Destroy(&variables, NOFREE); Lst_Destroy(&makefiles, NOFREE); Lst_Destroy(&create, (SimpleProc)free); diff --git a/usr.bin/make/make.h b/usr.bin/make/make.h index 097ebbf5f37..2512405aaee 100644 --- a/usr.bin/make/make.h +++ b/usr.bin/make/make.h @@ -1,4 +1,4 @@ -/* $OpenBSD: make.h,v 1.19 2000/06/17 14:38:18 espie Exp $ */ +/* $OpenBSD: make.h,v 1.20 2000/06/17 14:40:29 espie Exp $ */ /* $NetBSD: make.h,v 1.15 1997/03/10 21:20:00 christos Exp $ */ /* @@ -236,12 +236,12 @@ typedef struct GNode { #define OP_NOTARGET (OP_NOTMAIN|OP_USE|OP_EXEC|OP_TRANSFORM) /* - * The TARG_ constants are used when calling the Targ_FindNode and - * Targ_FindList functions in targ.c. They simply tell the functions what to - * do if the desired node(s) is (are) not found. If the TARG_CREATE constant - * is given, a new, empty node will be created for the target, placed in the - * table of all targets and its address returned. If TARG_NOCREATE is given, - * a NULL pointer will be returned. + * The TARG_ constants are used when calling the Targ_FindNode function in + * targ.c. They simply tell the function what to do if the desired node(s) + * is (are) not found. + * If the TARG_CREATE constant is given, a new, empty node will be created + * for the target, placed in the table of all targets and its address returned. + * If TARG_NOCREATE is given, a NULL pointer will be returned. */ #define TARG_CREATE 0x01 /* create node if not found */ #define TARG_NOCREATE 0x00 /* don't create it */ diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c index 339bb4ea157..35267238c32 100644 --- a/usr.bin/make/parse.c +++ b/usr.bin/make/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.43 2000/06/17 14:38:18 espie Exp $ */ +/* $OpenBSD: parse.c,v 1.44 2000/06/17 14:40:29 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.43 2000/06/17 14:38:18 espie Exp $"; +static char rcsid[] = "$OpenBSD: parse.c,v 1.44 2000/06/17 14:40:29 espie Exp $"; #endif #endif /* not lint */ @@ -2649,31 +2649,25 @@ Parse_End() * Return a Lst of the main target to create for main()'s sake. If * no such target exists, we Punt with an obnoxious error message. * - * Results: - * A Lst of the single node to create. - * * Side Effects: - * None. + * Add the node to create to the list. * *----------------------------------------------------------------------- */ -Lst -Parse_MainName() -{ +void +Parse_MainName(listmain) Lst listmain; /* result list */ +{ - listmain = Lst_New(); - - if (mainNode == NULL) { + if (mainNode == NULL) Punt ("no target to make."); /*NOTREACHED*/ - } else if (mainNode->type & OP_DOUBLEDEP) { + else if (mainNode->type & OP_DOUBLEDEP) { Lst_AtEnd(listmain, mainNode); Lst_Concat(listmain, &mainNode->cohorts, LST_CONCNEW); } else Lst_AtEnd(listmain, mainNode); - return (listmain); } unsigned long diff --git a/usr.bin/make/targ.c b/usr.bin/make/targ.c index 9b1c24d79d7..0e1420752be 100644 --- a/usr.bin/make/targ.c +++ b/usr.bin/make/targ.c @@ -1,4 +1,4 @@ -/* $OpenBSD: targ.c,v 1.19 2000/06/17 14:38:20 espie Exp $ */ +/* $OpenBSD: targ.c,v 1.20 2000/06/17 14:40:30 espie Exp $ */ /* $NetBSD: targ.c,v 1.11 1997/02/20 16:51:50 christos Exp $ */ /* @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94"; #else -static char *rcsid = "$OpenBSD: targ.c,v 1.19 2000/06/17 14:38:20 espie Exp $"; +static char *rcsid = "$OpenBSD: targ.c,v 1.20 2000/06/17 14:40:30 espie Exp $"; #endif #endif /* not lint */ @@ -68,10 +68,7 @@ static char *rcsid = "$OpenBSD: targ.c,v 1.19 2000/06/17 14:38:20 espie Exp $"; * flags are right (TARG_CREATE) * * Targ_FindList Given a list of names, find nodes for all - * of them. If a name doesn't exist and the - * TARG_NOCREATE flag was given, an error message - * is printed. Else, if a name doesn't exist, - * its node is created. + * of them, creating nodes if needed. * * Targ_Ignore Return TRUE if errors should be ignored when * creating the given target. @@ -289,51 +286,35 @@ Targ_FindNode (name, flags) * Targ_FindList -- * Make a complete list of GNodes from the given list of names * - * Results: - * A complete list of graph nodes corresponding to all instances of all - * the names in names. - * * Side Effects: - * If flags is TARG_CREATE, nodes will be created for all names in - * names which do not yet have graph nodes. If flags is TARG_NOCREATE, - * an error message will be printed for each name which can't be found. + * Nodes will be created for all names which do not yet have graph + * nodes. + * + * A complete list of graph nodes corresponding to all instances of + * all names is added to nodes. * ----------------------------------------------------------------------- */ -Lst -Targ_FindList(names, flags) - Lst names; /* list of names to find */ - int flags; /* flags used if no node is found for a given - * name */ +void +Targ_FindList(nodes, names) + Lst nodes; /* result list */ + Lst names; /* list of names to find */ { - Lst nodes; /* result list */ - register LstNode ln; /* name list element */ - register GNode *gn; /* node in tLn */ - char *name; - - nodes = Lst_New(); + LstNode ln; /* name list element */ + GNode *gn; /* node in tLn */ + char *name; - if (Lst_Open (names) == FAILURE) { - return (nodes); - } - while ((ln = Lst_Next (names)) != NULL) { + for (ln = Lst_First(names); ln != NULL; ln = Lst_Succ(ln)) { name = (char *)Lst_Datum(ln); - gn = Targ_FindNode (name, flags); - if (gn != NULL) { - /* - * Note: Lst_AtEnd must come before the Lst_Concat so the nodes - * are added to the list in the order in which they were - * encountered in the makefile. - */ - Lst_AtEnd(nodes, gn); - if (gn->type & OP_DOUBLEDEP) { - Lst_Concat(nodes, &gn->cohorts, LST_CONCNEW); - } - } else if (flags == TARG_NOCREATE) { - Error ("\"%s\" -- target unknown.", name); - } + gn = Targ_FindNode(name, TARG_CREATE); + /* + * Note: Lst_AtEnd must come before the Lst_Concat so the nodes + * are added to the list in the order in which they were + * encountered in the makefile. + */ + Lst_AtEnd(nodes, gn); + if (gn->type & OP_DOUBLEDEP) + Lst_Concat(nodes, &gn->cohorts, LST_CONCNEW); } - Lst_Close (names); - return (nodes); } /*- |