summaryrefslogtreecommitdiffstats
path: root/usr.bin/make/targ.c
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1995-01-23 21:03:17 +0000
committerjkh <jkh@FreeBSD.org>1995-01-23 21:03:17 +0000
commit2dab142d474fb234edc194c7335fd5a627df77a6 (patch)
tree4fe60a8bd60f90f8461d826b8a6c0cd471c798d3 /usr.bin/make/targ.c
parenta8745a0ec131df320b6a7be781964c129c33644f (diff)
downloadFreeBSD-src-2dab142d474fb234edc194c7335fd5a627df77a6.zip
FreeBSD-src-2dab142d474fb234edc194c7335fd5a627df77a6.tar.gz
Bring in a number of changes from NetBSD's make, fixing quite a few
problems in the process: 1. Quoting should work properly now. In particular, Chet's reported bash make problem has gone away. 2. A lot of memory that just wasn't being free'd after use is now freed. This should cause make to take up a LOT less memory when dealing with archive targets. 3. Give proper credit to Adam de Boor in a number of files. Obtained from: NetBSD (and Adam de Boor)
Diffstat (limited to 'usr.bin/make/targ.c')
-rw-r--r--usr.bin/make/targ.c122
1 files changed, 97 insertions, 25 deletions
diff --git a/usr.bin/make/targ.c b/usr.bin/make/targ.c
index 7e1475a..7d5057d 100644
--- a/usr.bin/make/targ.c
+++ b/usr.bin/make/targ.c
@@ -49,6 +49,8 @@ static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94";
* Interface:
* Targ_Init Initialization procedure.
*
+ * Targ_End Cleanup the module
+ *
* Targ_NewGN Create a new GNode for the passed target
* (string). The node is *not* placed in the
* hash table, though all its fields are
@@ -86,10 +88,16 @@ static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94";
#include "dir.h"
static Lst allTargets; /* the list of all targets found so far */
+static Lst allGNs; /* List of all the GNodes */
static Hash_Table targets; /* a hash table of same */
#define HTSIZE 191 /* initial size of hash table */
+static int TargPrintOnlySrc __P((ClientData, ClientData));
+static int TargPrintName __P((ClientData, ClientData));
+static int TargPrintNode __P((ClientData, ClientData));
+static void TargFreeGN __P((ClientData));
+
/*-
*-----------------------------------------------------------------------
* Targ_Init --
@@ -111,6 +119,27 @@ Targ_Init ()
/*-
*-----------------------------------------------------------------------
+ * Targ_End --
+ * Finalize this module
+ *
+ * Results:
+ * None
+ *
+ * Side Effects:
+ * All lists and gnodes are cleared
+ *-----------------------------------------------------------------------
+ */
+void
+Targ_End ()
+{
+ Lst_Destroy(allTargets, NOFREE);
+ if (allGNs)
+ Lst_Destroy(allGNs, TargFreeGN);
+ Hash_DeleteTable(&targets);
+}
+
+/*-
+ *-----------------------------------------------------------------------
* Targ_NewGN --
* Create and initialize a new graph node
*
@@ -119,7 +148,7 @@ Targ_Init ()
* of the passed name
*
* Side Effects:
- * None.
+ * The gnode is added to the list of all gnodes.
*-----------------------------------------------------------------------
*/
GNode *
@@ -145,17 +174,56 @@ Targ_NewGN (name)
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->successors = Lst_Init (FALSE);
+ gn->preds = Lst_Init (FALSE);
gn->context = Lst_Init (FALSE);
gn->commands = Lst_Init (FALSE);
gn->suffix = NULL;
+ if (allGNs == NULL)
+ allGNs = Lst_Init(FALSE);
+ Lst_AtEnd(allGNs, (ClientData) gn);
+
return (gn);
}
/*-
*-----------------------------------------------------------------------
+ * TargFreeGN --
+ * Destroy a GNode
+ *
+ * Results:
+ * None.
+ *
+ * Side Effects:
+ * None.
+ *-----------------------------------------------------------------------
+ */
+static void
+TargFreeGN (gnp)
+ ClientData gnp;
+{
+ GNode *gn = (GNode *) gnp;
+
+
+ free(gn->name);
+ if (gn->path)
+ free(gn->path);
+
+ Lst_Destroy(gn->iParents, NOFREE);
+ Lst_Destroy(gn->cohorts, NOFREE);
+ Lst_Destroy(gn->parents, NOFREE);
+ Lst_Destroy(gn->children, NOFREE);
+ Lst_Destroy(gn->successors, NOFREE);
+ Lst_Destroy(gn->preds, NOFREE);
+ Lst_Destroy(gn->context, NOFREE);
+ Lst_Destroy(gn->commands, NOFREE);
+ free((Address)gn);
+}
+
+
+/*-
+ *-----------------------------------------------------------------------
* Targ_FindNode --
* Find a node in the list using the given name for matching
*
@@ -343,11 +411,11 @@ Targ_SetMain (gn)
}
static int
-/*ARGSUSED*/
-TargPrintName (gn, ppath)
- GNode *gn;
- int ppath;
+TargPrintName (gnp, ppath)
+ ClientData gnp;
+ ClientData ppath;
{
+ GNode *gn = (GNode *) gnp;
printf ("%s ", gn->name);
#ifdef notdef
if (ppath) {
@@ -359,16 +427,17 @@ TargPrintName (gn, ppath)
}
}
#endif /* notdef */
- return (0);
+ return (ppath ? 0 : 0);
}
int
-Targ_PrintCmd (cmd)
- char *cmd;
+Targ_PrintCmd (cmd, dummy)
+ ClientData cmd;
+ ClientData dummy;
{
- printf ("\t%s\n", cmd);
- return (0);
+ printf ("\t%s\n", (char *) cmd);
+ return (dummy ? 0 : 0);
}
/*-
@@ -462,10 +531,12 @@ Targ_PrintType (type)
*-----------------------------------------------------------------------
*/
static int
-TargPrintNode (gn, pass)
- GNode *gn;
- int pass;
+TargPrintNode (gnp, passp)
+ ClientData gnp;
+ ClientData passp;
{
+ GNode *gn = (GNode *) gnp;
+ int pass = *(int *) passp;
if (!OP_NOP(gn->type)) {
printf("#\n");
if (gn == mainTarg) {
@@ -522,7 +593,7 @@ TargPrintNode (gn, pass)
Lst_ForEach (gn->commands, Targ_PrintCmd, (ClientData)0);
printf("\n\n");
if (gn->type & OP_DOUBLEDEP) {
- Lst_ForEach (gn->cohorts, TargPrintNode, (ClientData)pass);
+ Lst_ForEach (gn->cohorts, TargPrintNode, (ClientData)&pass);
}
}
return (0);
@@ -542,14 +613,15 @@ TargPrintNode (gn, pass)
*-----------------------------------------------------------------------
*/
static int
-TargPrintOnlySrc(gn)
- GNode *gn;
+TargPrintOnlySrc(gnp, dummy)
+ ClientData gnp;
+ ClientData dummy;
{
- if (OP_NOP(gn->type)) {
- printf("#\t%s [%s]\n", gn->name,
- gn->path ? gn->path : gn->name);
- }
- return (0);
+ GNode *gn = (GNode *) gnp;
+ if (OP_NOP(gn->type))
+ printf("#\t%s [%s]\n", gn->name, gn->path ? gn->path : gn->name);
+
+ return (dummy ? 0 : 0);
}
/*-
@@ -570,10 +642,10 @@ Targ_PrintGraph (pass)
* 2 => processing done */
{
printf("#*** Input graph:\n");
- Lst_ForEach (allTargets, TargPrintNode, (ClientData)pass);
+ Lst_ForEach (allTargets, TargPrintNode, (ClientData)&pass);
printf("\n\n");
printf("#\n# Files that are only sources:\n");
- Lst_ForEach (allTargets, TargPrintOnlySrc);
+ Lst_ForEach (allTargets, TargPrintOnlySrc, (ClientData) 0);
printf("#*** Global Variables:\n");
Var_Dump (VAR_GLOBAL);
printf("#*** Command-line Variables:\n");
OpenPOWER on IntegriCloud