aboutsummaryrefslogtreecommitdiff
path: root/suff.c
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2020-09-05 16:11:04 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2020-09-05 16:11:04 +0000
commit6bbc783f48498b808e19db4441299dc7d85a278b (patch)
treebe201219a56594c76537191ee91fdd3ef8cfb348 /suff.c
parent367d32e2b15fe0397ddecccaa04cf9ed0164c969 (diff)
Import bmake-20200902vendor/NetBSD/bmake/20200902
Lots of code refactoring, simplification and cleanup. Lots of new unit-tests providing much higher code coverage. All courtesy of rillig at netbsd. Other significant changes: o new read-only variable .SHELL which provides the path of the shell used to run scripts (as defined by the .SHELL target). o new debug option -dl: LINT mode, does the equivalent of := for all variable assignments so that file and line number are reported for variable parse errors.
Notes
Notes: svn path=/vendor/NetBSD/bmake/dist/; revision=365361 svn path=/vendor/NetBSD/bmake/20200902/; revision=365363; tag=vendor/NetBSD/bmake/20200902
Diffstat (limited to 'suff.c')
-rw-r--r--suff.c1235
1 files changed, 406 insertions, 829 deletions
diff --git a/suff.c b/suff.c
index 5a40b73d788d..bcab3027e6dd 100644
--- a/suff.c
+++ b/suff.c
@@ -1,4 +1,4 @@
-/* $NetBSD: suff.c,v 1.88 2020/07/03 08:02:55 rillig Exp $ */
+/* $NetBSD: suff.c,v 1.142 2020/08/31 16:44:25 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.88 2020/07/03 08:02:55 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.142 2020/08/31 16:44:25 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
#else
-__RCSID("$NetBSD: suff.c,v 1.88 2020/07/03 08:02:55 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.142 2020/08/31 16:44:25 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -135,12 +135,21 @@ __RCSID("$NetBSD: suff.c,v 1.88 2020/07/03 08:02:55 rillig Exp $");
* order to find the node.
*/
-#include <assert.h>
-#include <stdio.h>
#include "make.h"
-#include "hash.h"
#include "dir.h"
+#define SUFF_DEBUG0(fmt) \
+ if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt)
+
+#define SUFF_DEBUG1(fmt, arg1) \
+ if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt, arg1)
+
+#define SUFF_DEBUG2(fmt, arg1, arg2) \
+ if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt, arg1, arg2)
+
+#define SUFF_DEBUG3(fmt, arg1, arg2, arg3) \
+ if (!DEBUG(SUFF)) (void) 0; else fprintf(debug_file, fmt, arg1, arg2, arg3)
+
static Lst sufflist; /* Lst of suffixes */
#ifdef CLEANUP
static Lst suffClean; /* Lst of suffixes to be cleaned */
@@ -150,16 +159,23 @@ static Lst transforms; /* Lst of transformation rules */
static int sNum = 0; /* Counter for assigning suffix numbers */
+typedef enum {
+ SUFF_INCLUDE = 0x01, /* One which is #include'd */
+ SUFF_LIBRARY = 0x02, /* One which contains a library */
+ SUFF_NULL = 0x04 /* The empty suffix */
+ /* XXX: Why is SUFF_NULL needed? Wouldn't nameLen == 0 mean the same? */
+} SuffFlags;
+
+ENUM_FLAGS_RTTI_3(SuffFlags,
+ SUFF_INCLUDE, SUFF_LIBRARY, SUFF_NULL);
+
/*
* Structure describing an individual suffix.
*/
-typedef struct _Suff {
- char *name; /* The suffix itself */
- int nameLen; /* Length of the suffix */
- short flags; /* Type of suffix */
-#define SUFF_INCLUDE 0x01 /* One which is #include'd */
-#define SUFF_LIBRARY 0x02 /* One which contains a library */
-#define SUFF_NULL 0x04 /* The empty suffix */
+typedef struct Suff {
+ char *name; /* The suffix itself, such as ".c" */
+ int nameLen; /* Length of the name, to avoid strlen calls */
+ SuffFlags flags; /* Type of suffix */
Lst searchPath; /* The path along which files of this suffix
* may be found */
int sNum; /* The suffix number */
@@ -170,14 +186,6 @@ typedef struct _Suff {
} Suff;
/*
- * for SuffSuffIsSuffix
- */
-typedef struct {
- char *ename; /* The end of the name */
- int len; /* Length of the name */
-} SuffixCmpData;
-
-/*
* Structure used in the search for implied sources.
*/
typedef struct _Src {
@@ -213,12 +221,6 @@ static Suff *emptySuff; /* The empty suffix required for POSIX
* single-suffix transformation rules */
-static const char *SuffStrIsPrefix(const char *, const char *);
-static char *SuffSuffIsSuffix(const Suff *, const SuffixCmpData *);
-static int SuffSuffIsSuffixP(const void *, const void *);
-static int SuffSuffHasNameP(const void *, const void *);
-static int SuffSuffIsPrefix(const void *, const void *);
-static int SuffGNHasNameP(const void *, const void *);
static void SuffUnRef(void *, void *);
static void SuffFree(void *);
static void SuffInsert(Lst, Suff *);
@@ -227,10 +229,7 @@ static Boolean SuffParseTransform(char *, Suff **, Suff **);
static int SuffRebuildGraph(void *, void *);
static int SuffScanTargets(void *, void *);
static int SuffAddSrc(void *, void *);
-static int SuffRemoveSrc(Lst);
static void SuffAddLevel(Lst, Src *);
-static Src *SuffFindThem(Lst, Lst);
-static Src *SuffFindCmds(Src *, Lst);
static void SuffExpandChildren(LstNode, GNode *);
static void SuffExpandWildcards(LstNode, GNode *);
static Boolean SuffApplyTransform(GNode *, GNode *, Suff *, Suff *);
@@ -269,35 +268,33 @@ SuffStrIsPrefix(const char *pref, const char *str)
return *pref ? NULL : str;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffSuffIsSuffix --
- * See if suff is a suffix of str. sd->ename should point to THE END
- * of the string to check. (THE END == the null byte)
+typedef struct {
+ char *ename; /* The end of the name */
+ int len; /* Length of the name */
+} SuffSuffGetSuffixArgs;
+
+/* See if suff is a suffix of str. str->ename should point to THE END
+ * of the string to check. (THE END == the null byte)
*
* Input:
* s possible suffix
- * sd string to examine
+ * str string to examine
*
* Results:
* NULL if it ain't, pointer to character in str before suffix if
* it is.
- *
- * Side Effects:
- * None
- *-----------------------------------------------------------------------
*/
static char *
-SuffSuffIsSuffix(const Suff *s, const SuffixCmpData *sd)
+SuffSuffGetSuffix(const Suff *s, const SuffSuffGetSuffixArgs *str)
{
char *p1; /* Pointer into suffix name */
char *p2; /* Pointer into string being examined */
- if (sd->len < s->nameLen)
+ if (str->len < s->nameLen)
return NULL; /* this string is shorter than the suffix */
p1 = s->name + s->nameLen;
- p2 = sd->ename;
+ p2 = str->ename;
while (p1 >= s->name && *p1 == *p2) {
p1--;
@@ -307,126 +304,55 @@ SuffSuffIsSuffix(const Suff *s, const SuffixCmpData *sd)
return p1 == s->name - 1 ? p2 : NULL;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffSuffIsSuffixP --
- * Predicate form of SuffSuffIsSuffix. Passed as the callback function
- * to Lst_Find.
- *
- * Results:
- * 0 if the suffix is the one desired, non-zero if not.
- *
- * Side Effects:
- * None.
- *
- *-----------------------------------------------------------------------
- */
-static int
-SuffSuffIsSuffixP(const void *s, const void *sd)
+/* Predicate form of SuffSuffGetSuffix, for Lst_Find. */
+static Boolean
+SuffSuffIsSuffix(const void *s, const void *sd)
{
- return !SuffSuffIsSuffix(s, sd);
+ return SuffSuffGetSuffix(s, sd) != NULL;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffSuffHasNameP --
- * Callback procedure for finding a suffix based on its name. Used by
- * Suff_GetPath.
- *
- * Input:
- * s Suffix to check
- * sd Desired name
- *
- * Results:
- * 0 if the suffix is of the given name. non-zero otherwise.
- *
- * Side Effects:
- * None
- *-----------------------------------------------------------------------
- */
-static int
-SuffSuffHasNameP(const void *s, const void *sname)
+/* See if the suffix has the desired name. */
+static Boolean
+SuffSuffHasName(const void *s, const void *desiredName)
{
- return strcmp(sname, ((const Suff *)s)->name);
+ return strcmp(((const Suff *)s)->name, desiredName) == 0;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffSuffIsPrefix --
- * See if the suffix described by s is a prefix of the string. Care
- * must be taken when using this to search for transformations and
- * what-not, since there could well be two suffixes, one of which
- * is a prefix of the other...
- *
- * Input:
- * s suffix to compare
- * str string to examine
- *
- * Results:
- * 0 if s is a prefix of str. non-zero otherwise
- *
- * Side Effects:
- * None
- *-----------------------------------------------------------------------
- */
-static int
+/* See if the suffix name is a prefix of the string. Care must be taken when
+ * using this to search for transformations and what-not, since there could
+ * well be two suffixes, one of which is a prefix of the other... */
+static Boolean
SuffSuffIsPrefix(const void *s, const void *str)
{
- return SuffStrIsPrefix(((const Suff *)s)->name, str) == NULL;
+ return SuffStrIsPrefix(((const Suff *)s)->name, str) != NULL;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffGNHasNameP --
- * See if the graph node has the desired name
- *
- * Input:
- * gn current node we're looking at
- * name name we're looking for
- *
- * Results:
- * 0 if it does. non-zero if it doesn't
- *
- * Side Effects:
- * None
- *-----------------------------------------------------------------------
- */
-static int
-SuffGNHasNameP(const void *gn, const void *name)
+/* See if the graph node has the desired name. */
+static Boolean
+SuffGNHasName(const void *gn, const void *desiredName)
{
- return strcmp(name, ((const GNode *)gn)->name);
+ return strcmp(((const GNode *)gn)->name, desiredName) == 0;
}
- /*********** Maintenance Functions ************/
+ /*********** Maintenance Functions ************/
static void
SuffUnRef(void *lp, void *sp)
{
Lst l = (Lst) lp;
- LstNode ln = Lst_Member(l, sp);
+ LstNode ln = Lst_FindDatum(l, sp);
if (ln != NULL) {
Lst_Remove(l, ln);
((Suff *)sp)->refCount--;
}
}
-/*-
- *-----------------------------------------------------------------------
- * SuffFree --
- * Free up all memory associated with the given suffix structure.
- *
- * Results:
- * none
- *
- * Side Effects:
- * the suffix entry is detroyed
- *-----------------------------------------------------------------------
- */
+/* Free up all memory associated with the given suffix structure. */
static void
SuffFree(void *sp)
{
- Suff *s = (Suff *)sp;
+ Suff *s = (Suff *)sp;
if (s == suffNull)
suffNull = NULL;
@@ -441,28 +367,16 @@ SuffFree(void *sp)
s->refCount);
#endif
- Lst_Destroy(s->ref, NULL);
- Lst_Destroy(s->children, NULL);
- Lst_Destroy(s->parents, NULL);
+ Lst_Free(s->ref);
+ Lst_Free(s->children);
+ Lst_Free(s->parents);
Lst_Destroy(s->searchPath, Dir_Destroy);
free(s->name);
free(s);
}
-/*-
- *-----------------------------------------------------------------------
- * SuffRemove --
- * Remove the suffix into the list
- *
- * Results:
- * None
- *
- * Side Effects:
- * The reference count for the suffix is decremented and the
- * suffix is possibly freed
- *-----------------------------------------------------------------------
- */
+/* Remove the suffix from the list, and free if it is otherwise unused. */
static void
SuffRemove(Lst l, Suff *s)
{
@@ -472,23 +386,12 @@ SuffRemove(Lst l, Suff *s)
SuffFree(s);
}
}
-
-/*-
- *-----------------------------------------------------------------------
- * SuffInsert --
- * Insert the suffix into the list keeping the list ordered by suffix
- * numbers.
+
+/* Insert the suffix into the list keeping the list ordered by suffix numbers.
*
* Input:
* l the list where in s should be inserted
* s the suffix to insert
- *
- * Results:
- * None
- *
- * Side Effects:
- * The reference count of the suffix is incremented
- *-----------------------------------------------------------------------
*/
static void
SuffInsert(Lst l, Suff *s)
@@ -496,100 +399,83 @@ SuffInsert(Lst l, Suff *s)
LstNode ln; /* current element in l we're examining */
Suff *s2 = NULL; /* the suffix descriptor in this element */
- if (Lst_Open(l) == FAILURE) {
- return;
- }
+ Lst_Open(l);
while ((ln = Lst_Next(l)) != NULL) {
- s2 = (Suff *)Lst_Datum(ln);
+ s2 = LstNode_Datum(ln);
if (s2->sNum >= s->sNum) {
break;
}
}
-
Lst_Close(l);
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "inserting %s(%d)...", s->name, s->sNum);
- }
+
+ SUFF_DEBUG2("inserting %s(%d)...", s->name, s->sNum);
+
if (ln == NULL) {
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "at end of list\n");
- }
- (void)Lst_AtEnd(l, s);
+ SUFF_DEBUG0("at end of list\n");
+ Lst_Append(l, s);
s->refCount++;
- (void)Lst_AtEnd(s->ref, l);
+ Lst_Append(s->ref, l);
} else if (s2->sNum != s->sNum) {
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "before %s(%d)\n", s2->name, s2->sNum);
- }
- (void)Lst_InsertBefore(l, ln, s);
+ SUFF_DEBUG2("before %s(%d)\n", s2->name, s2->sNum);
+ Lst_InsertBefore(l, ln, s);
s->refCount++;
- (void)Lst_AtEnd(s->ref, l);
- } else if (DEBUG(SUFF)) {
- fprintf(debug_file, "already there\n");
+ Lst_Append(s->ref, l);
+ } else {
+ SUFF_DEBUG0("already there\n");
}
}
-/*-
- *-----------------------------------------------------------------------
- * Suff_ClearSuffixes --
- * This is gross. Nuke the list of suffixes but keep all transformation
- * rules around. The transformation graph is destroyed in this process,
- * but we leave the list of rules so when a new graph is formed the rules
- * will remain.
- * This function is called from the parse module when a
- * .SUFFIXES:\n line is encountered.
- *
- * Results:
- * none
- *
- * Side Effects:
- * the sufflist and its graph nodes are destroyed
- *-----------------------------------------------------------------------
- */
+static Suff *
+SuffNew(const char *name)
+{
+ Suff *s = bmake_malloc(sizeof(Suff));
+
+ s->name = bmake_strdup(name);
+ s->nameLen = strlen(s->name);
+ s->searchPath = Lst_Init();
+ s->children = Lst_Init();
+ s->parents = Lst_Init();
+ s->ref = Lst_Init();
+ s->sNum = sNum++;
+ s->flags = 0;
+ s->refCount = 1;
+
+ return s;
+}
+
+/* This is gross. Nuke the list of suffixes but keep all transformation
+ * rules around. The transformation graph is destroyed in this process, but
+ * we leave the list of rules so when a new graph is formed the rules will
+ * remain. This function is called from the parse module when a .SUFFIXES:\n
+ * line is encountered. */
void
Suff_ClearSuffixes(void)
{
#ifdef CLEANUP
- Lst_Concat(suffClean, sufflist, LST_CONCLINK);
+ Lst_MoveAll(suffClean, sufflist);
#endif
- sufflist = Lst_Init(FALSE);
+ sufflist = Lst_Init();
sNum = 0;
if (suffNull)
SuffFree(suffNull);
- emptySuff = suffNull = bmake_malloc(sizeof(Suff));
+ emptySuff = suffNull = SuffNew("");
- suffNull->name = bmake_strdup("");
- suffNull->nameLen = 0;
- suffNull->searchPath = Lst_Init(FALSE);
Dir_Concat(suffNull->searchPath, dirSearchPath);
- suffNull->children = Lst_Init(FALSE);
- suffNull->parents = Lst_Init(FALSE);
- suffNull->ref = Lst_Init(FALSE);
- suffNull->sNum = sNum++;
suffNull->flags = SUFF_NULL;
- suffNull->refCount = 1;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffParseTransform --
- * Parse a transformation string to find its two component suffixes.
+/* Parse a transformation string to find its two component suffixes.
*
* Input:
* str String being parsed
- * srcPtr Place to store source of trans.
- * targPtr Place to store target of trans.
+ * out_src Place to store source of trans.
+ * out_targ Place to store target of trans.
*
* Results:
- * TRUE if the string is a valid transformation and FALSE otherwise.
- *
- * Side Effects:
- * The passed pointers are overwritten.
- *
- *-----------------------------------------------------------------------
+ * TRUE if the string is a valid transformation, FALSE otherwise.
*/
static Boolean
-SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr)
+SuffParseTransform(char *str, Suff **out_src, Suff **out_targ)
{
LstNode srcLn; /* element in suffix list of trans source*/
Suff *src; /* Source of transformation */
@@ -611,10 +497,10 @@ SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr)
*/
for (;;) {
if (srcLn == NULL) {
- srcLn = Lst_Find(sufflist, str, SuffSuffIsPrefix);
+ srcLn = Lst_Find(sufflist, SuffSuffIsPrefix, str);
} else {
- srcLn = Lst_FindFrom(sufflist, Lst_Succ(srcLn), str,
- SuffSuffIsPrefix);
+ srcLn = Lst_FindFrom(sufflist, LstNode_Next(srcLn),
+ SuffSuffIsPrefix, str);
}
if (srcLn == NULL) {
/*
@@ -630,45 +516,30 @@ SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr)
*
* XXX: Use emptySuff over suffNull?
*/
- *srcPtr = single;
- *targPtr = suffNull;
+ *out_src = single;
+ *out_targ = suffNull;
return TRUE;
}
return FALSE;
}
- src = (Suff *)Lst_Datum(srcLn);
+ src = LstNode_Datum(srcLn);
str2 = str + src->nameLen;
if (*str2 == '\0') {
single = src;
singleLn = srcLn;
} else {
- targLn = Lst_Find(sufflist, str2, SuffSuffHasNameP);
+ targLn = Lst_Find(sufflist, SuffSuffHasName, str2);
if (targLn != NULL) {
- *srcPtr = src;
- *targPtr = (Suff *)Lst_Datum(targLn);
+ *out_src = src;
+ *out_targ = LstNode_Datum(targLn);
return TRUE;
}
}
}
}
-/*-
- *-----------------------------------------------------------------------
- * Suff_IsTransform --
- * Return TRUE if the given string is a transformation rule
- *
- *
- * Input:
- * str string to check
- *
- * Results:
- * TRUE if the string is a concatenation of two known suffixes.
- * FALSE otherwise
- *
- * Side Effects:
- * None
- *-----------------------------------------------------------------------
- */
+/* Return TRUE if the given string is a transformation rule, that is, a
+ * concatenation of two known suffixes. */
Boolean
Suff_IsTransform(char *str)
{
@@ -677,39 +548,35 @@ Suff_IsTransform(char *str)
return SuffParseTransform(str, &src, &targ);
}
-/*-
- *-----------------------------------------------------------------------
- * Suff_AddTransform --
- * Add the transformation rule described by the line to the
- * list of rules and place the transformation itself in the graph
+/* Add the transformation rule described by the line to the list of rules
+ * and place the transformation itself in the graph.
*
+ * The node is placed on the end of the transforms Lst and links are made
+ * between the two suffixes mentioned in the target name.
+
* Input:
* line name of transformation to add
*
* Results:
* The node created for the transformation in the transforms list
- *
- * Side Effects:
- * The node is placed on the end of the transforms Lst and links are
- * made between the two suffixes mentioned in the target name
- *-----------------------------------------------------------------------
*/
GNode *
Suff_AddTransform(char *line)
{
GNode *gn; /* GNode of transformation rule */
Suff *s, /* source suffix */
- *t; /* target suffix */
+ *t; /* target suffix */
LstNode ln; /* Node for existing transformation */
+ Boolean ok;
- ln = Lst_Find(transforms, line, SuffGNHasNameP);
+ ln = Lst_Find(transforms, SuffGNHasName, line);
if (ln == NULL) {
/*
* Make a new graph node for the transformation. It will be filled in
* by the Parse module.
*/
gn = Targ_NewGN(line);
- (void)Lst_AtEnd(transforms, gn);
+ Lst_Append(transforms, gn);
} else {
/*
* New specification for transformation rule. Just nuke the old list
@@ -717,58 +584,50 @@ Suff_AddTransform(char *line)
* free the commands themselves, because a given command can be
* attached to several different transformations.
*/
- gn = (GNode *)Lst_Datum(ln);
- Lst_Destroy(gn->commands, NULL);
- Lst_Destroy(gn->children, NULL);
- gn->commands = Lst_Init(FALSE);
- gn->children = Lst_Init(FALSE);
+ gn = LstNode_Datum(ln);
+ Lst_Free(gn->commands);
+ Lst_Free(gn->children);
+ gn->commands = Lst_Init();
+ gn->children = Lst_Init();
}
gn->type = OP_TRANSFORM;
- (void)SuffParseTransform(line, &s, &t);
+ ok = SuffParseTransform(line, &s, &t);
+ assert(ok);
+ (void)ok;
/*
* link the two together in the proper relationship and order
*/
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "defining transformation from `%s' to `%s'\n",
+ SUFF_DEBUG2("defining transformation from `%s' to `%s'\n",
s->name, t->name);
- }
SuffInsert(t->children, s);
SuffInsert(s->parents, t);
return gn;
}
-/*-
- *-----------------------------------------------------------------------
- * Suff_EndTransform --
- * Handle the finish of a transformation definition, removing the
- * transformation from the graph if it has neither commands nor
- * sources. This is a callback procedure for the Parse module via
- * Lst_ForEach
+/* Handle the finish of a transformation definition, removing the
+ * transformation from the graph if it has neither commands nor sources.
+ * This is a callback procedure for the Parse module via Lst_ForEach.
+ *
+ * If the node has no commands or children, the children and parents lists
+ * of the affected suffixes are altered.
*
* Input:
* gnp Node for transformation
- * dummy Node for transformation
*
* Results:
- * === 0
- *
- * Side Effects:
- * If the node has no commands or children, the children and parents
- * lists of the affected suffixes are altered.
- *
- *-----------------------------------------------------------------------
+ * 0, so that Lst_ForEach continues
*/
int
Suff_EndTransform(void *gnp, void *dummy MAKE_ATTR_UNUSED)
{
GNode *gn = (GNode *)gnp;
- if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty (gn->cohorts))
- gn = (GNode *)Lst_Datum(Lst_Last(gn->cohorts));
+ if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(gn->cohorts))
+ gn = LstNode_Datum(Lst_Last(gn->cohorts));
if ((gn->type & OP_TRANSFORM) && Lst_IsEmpty(gn->commands) &&
Lst_IsEmpty(gn->children))
{
@@ -781,10 +640,8 @@ Suff_EndTransform(void *gnp, void *dummy MAKE_ATTR_UNUSED)
if (SuffParseTransform(gn->name, &s, &t)) {
Lst p;
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "deleting transformation from `%s' to `%s'\n",
- s->name, t->name);
- }
+ SUFF_DEBUG2("deleting transformation from `%s' to `%s'\n",
+ s->name, t->name);
/*
* Store s->parents because s could be deleted in SuffRemove
@@ -806,35 +663,28 @@ Suff_EndTransform(void *gnp, void *dummy MAKE_ATTR_UNUSED)
*/
SuffRemove(p, t);
}
- } else if ((gn->type & OP_TRANSFORM) && DEBUG(SUFF)) {
- fprintf(debug_file, "transformation %s complete\n", gn->name);
+ } else if (gn->type & OP_TRANSFORM) {
+ SUFF_DEBUG1("transformation %s complete\n", gn->name);
}
return 0;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffRebuildGraph --
- * Called from Suff_AddSuffix via Lst_ForEach to search through the
- * list of existing transformation rules and rebuild the transformation
- * graph when it has been destroyed by Suff_ClearSuffixes. If the
- * given rule is a transformation involving this suffix and another,
- * existing suffix, the proper relationship is established between
- * the two.
+/* Called from Suff_AddSuffix via Lst_ForEach to search through the list of
+ * existing transformation rules and rebuild the transformation graph when
+ * it has been destroyed by Suff_ClearSuffixes. If the given rule is a
+ * transformation involving this suffix and another, existing suffix, the
+ * proper relationship is established between the two.
+ *
+ * The appropriate links will be made between this suffix and others if
+ * transformation rules exist for it.
*
* Input:
* transformp Transformation to test
* sp Suffix to rebuild
*
* Results:
- * Always 0.
- *
- * Side Effects:
- * The appropriate links will be made between this suffix and
- * others if transformation rules exist for it.
- *
- *-----------------------------------------------------------------------
+ * 0, so that Lst_ForEach continues
*/
static int
SuffRebuildGraph(void *transformp, void *sp)
@@ -844,20 +694,20 @@ SuffRebuildGraph(void *transformp, void *sp)
char *cp;
LstNode ln;
Suff *s2;
- SuffixCmpData sd;
+ SuffSuffGetSuffixArgs sd;
/*
* First see if it is a transformation from this suffix.
*/
cp = UNCONST(SuffStrIsPrefix(s->name, transform->name));
if (cp != NULL) {
- ln = Lst_Find(sufflist, cp, SuffSuffHasNameP);
+ ln = Lst_Find(sufflist, SuffSuffHasName, cp);
if (ln != NULL) {
/*
* Found target. Link in and return, since it can't be anything
* else.
*/
- s2 = (Suff *)Lst_Datum(ln);
+ s2 = LstNode_Datum(ln);
SuffInsert(s2->children, s);
SuffInsert(s->parents, s2);
return 0;
@@ -869,13 +719,13 @@ SuffRebuildGraph(void *transformp, void *sp)
*/
sd.len = strlen(transform->name);
sd.ename = transform->name + sd.len;
- cp = SuffSuffIsSuffix(s, &sd);
+ cp = SuffSuffGetSuffix(s, &sd);
if (cp != NULL) {
/*
* Null-terminate the source suffix in order to find it.
*/
cp[1] = '\0';
- ln = Lst_Find(sufflist, transform->name, SuffSuffHasNameP);
+ ln = Lst_Find(sufflist, SuffSuffHasName, transform->name);
/*
* Replace the start of the target suffix
*/
@@ -884,7 +734,7 @@ SuffRebuildGraph(void *transformp, void *sp)
/*
* Found it -- establish the proper relationship
*/
- s2 = (Suff *)Lst_Datum(ln);
+ s2 = LstNode_Datum(ln);
SuffInsert(s->children, s2);
SuffInsert(s2->parents, s);
}
@@ -892,22 +742,16 @@ SuffRebuildGraph(void *transformp, void *sp)
return 0;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffScanTargets --
- * Called from Suff_AddSuffix via Lst_ForEach to search through the
- * list of existing targets and find if any of the existing targets
- * can be turned into a transformation rule.
+/* Called from Suff_AddSuffix via Lst_ForEach to search through the list of
+ * existing targets and find if any of the existing targets can be turned
+ * into a transformation rule.
+ *
+ * If such a target is found and the target is the current main target, the
+ * main target is set to NULL and the next target examined (if that exists)
+ * becomes the main target.
*
* Results:
* 1 if a new main target has been selected, 0 otherwise.
- *
- * Side Effects:
- * If such a target is found and the target is the current main
- * target, the main target is set to NULL and the next target
- * examined (if that exists) becomes the main target.
- *
- *-----------------------------------------------------------------------
*/
static int
SuffScanTargets(void *targetp, void *gsp)
@@ -923,7 +767,7 @@ SuffScanTargets(void *targetp, void *gsp)
return 1;
}
- if ((unsigned int)target->type == OP_TRANSFORM)
+ if (target->type == OP_TRANSFORM)
return 0;
if ((ptr = strstr(target->name, gs->s->name)) == NULL ||
@@ -936,63 +780,43 @@ SuffScanTargets(void *targetp, void *gsp)
*gs->gn = NULL;
Targ_SetMain(NULL);
}
- Lst_Destroy(target->children, NULL);
- target->children = Lst_Init(FALSE);
+ Lst_Free(target->children);
+ target->children = Lst_Init();
target->type = OP_TRANSFORM;
/*
* link the two together in the proper relationship and order
*/
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "defining transformation from `%s' to `%s'\n",
- s->name, t->name);
- }
+ SUFF_DEBUG2("defining transformation from `%s' to `%s'\n",
+ s->name, t->name);
SuffInsert(t->children, s);
SuffInsert(s->parents, t);
}
return 0;
}
-/*-
- *-----------------------------------------------------------------------
- * Suff_AddSuffix --
- * Add the suffix in string to the end of the list of known suffixes.
- * Should we restructure the suffix graph? Make doesn't...
+/* Add the suffix to the end of the list of known suffixes.
+ * Should we restructure the suffix graph? Make doesn't...
*
- * Input:
- * str the name of the suffix to add
+ * A GNode is created for the suffix and a Suff structure is created and
+ * added to the suffixes list unless the suffix was already known.
+ * The mainNode passed can be modified if a target mutated into a
+ * transform and that target happened to be the main target.
*
- * Results:
- * None
- *
- * Side Effects:
- * A GNode is created for the suffix and a Suff structure is created and
- * added to the suffixes list unless the suffix was already known.
- * The mainNode passed can be modified if a target mutated into a
- * transform and that target happened to be the main target.
- *-----------------------------------------------------------------------
+ * Input:
+ * name the name of the suffix to add
*/
void
-Suff_AddSuffix(char *str, GNode **gn)
+Suff_AddSuffix(const char *name, GNode **gn)
{
Suff *s; /* new suffix descriptor */
LstNode ln;
GNodeSuff gs;
- ln = Lst_Find(sufflist, str, SuffSuffHasNameP);
+ ln = Lst_Find(sufflist, SuffSuffHasName, name);
if (ln == NULL) {
- s = bmake_malloc(sizeof(Suff));
-
- s->name = bmake_strdup(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->sNum = sNum++;
- s->flags = 0;
- s->refCount = 1;
-
- (void)Lst_AtEnd(sufflist, s);
+ s = SuffNew(name);
+
+ Lst_Append(sufflist, s);
/*
* We also look at our existing targets list to see if adding
* this suffix will make one of our current targets mutate into
@@ -1011,51 +835,30 @@ Suff_AddSuffix(char *str, GNode **gn)
}
}
-/*-
- *-----------------------------------------------------------------------
- * Suff_GetPath --
- * Return the search path for the given suffix, if it's defined.
- *
- * Results:
- * The searchPath for the desired suffix or NULL if the suffix isn't
- * defined.
- *
- * Side Effects:
- * None
- *-----------------------------------------------------------------------
- */
+/* Return the search path for the given suffix, or NULL. */
Lst
Suff_GetPath(char *sname)
{
LstNode ln;
Suff *s;
- ln = Lst_Find(sufflist, sname, SuffSuffHasNameP);
+ ln = Lst_Find(sufflist, SuffSuffHasName, sname);
if (ln == NULL) {
return NULL;
} else {
- s = (Suff *)Lst_Datum(ln);
+ s = LstNode_Datum(ln);
return s->searchPath;
}
}
-/*-
- *-----------------------------------------------------------------------
- * Suff_DoPaths --
- * Extend the search paths for all suffixes to include the default
- * search path.
+/* Extend the search paths for all suffixes to include the default search
+ * path.
*
- * Results:
- * None.
- *
- * Side Effects:
- * The searchPath field of all the suffixes is extended by the
- * directories in dirSearchPath. If paths were specified for the
- * ".h" suffix, the directories are stuffed into a global variable
- * called ".INCLUDES" with each directory preceded by a -I. The same
- * is done for the ".a" suffix, except the variable is called
- * ".LIBS" and the flag is -L.
- *-----------------------------------------------------------------------
+ * The searchPath field of all the suffixes is extended by the directories
+ * in dirSearchPath. If paths were specified for the ".h" suffix, the
+ * directories are stuffed into a global variable called ".INCLUDES" with
+ * each directory preceded by a -I. The same is done for the ".a" suffix,
+ * except the variable is called ".LIBS" and the flag is -L.
*/
void
Suff_DoPaths(void)
@@ -1066,16 +869,14 @@ Suff_DoPaths(void)
Lst inIncludes; /* Cumulative .INCLUDES path */
Lst inLibs; /* Cumulative .LIBS path */
- if (Lst_Open(sufflist) == FAILURE) {
- return;
- }
- inIncludes = Lst_Init(FALSE);
- inLibs = Lst_Init(FALSE);
+ inIncludes = Lst_Init();
+ inLibs = Lst_Init();
+ Lst_Open(sufflist);
while ((ln = Lst_Next(sufflist)) != NULL) {
- s = (Suff *)Lst_Datum(ln);
- if (!Lst_IsEmpty (s->searchPath)) {
+ s = LstNode_Datum(ln);
+ if (!Lst_IsEmpty(s->searchPath)) {
#ifdef INCLUDES
if (s->flags & SUFF_INCLUDE) {
Dir_Concat(inIncludes, s->searchPath);
@@ -1089,9 +890,10 @@ Suff_DoPaths(void)
Dir_Concat(s->searchPath, dirSearchPath);
} else {
Lst_Destroy(s->searchPath, Dir_Destroy);
- s->searchPath = Lst_Duplicate(dirSearchPath, Dir_CopyDir);
+ s->searchPath = Lst_Copy(dirSearchPath, Dir_CopyDir);
}
}
+ Lst_Close(sufflist);
Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", inIncludes), VAR_GLOBAL);
free(ptr);
@@ -1100,27 +902,15 @@ Suff_DoPaths(void)
Lst_Destroy(inIncludes, Dir_Destroy);
Lst_Destroy(inLibs, Dir_Destroy);
-
- Lst_Close(sufflist);
}
-/*-
- *-----------------------------------------------------------------------
- * Suff_AddInclude --
- * Add the given suffix as a type of file which gets included.
- * Called from the parse module when a .INCLUDES line is parsed.
- * The suffix must have already been defined.
+/* Add the given suffix as a type of file which gets included.
+ * Called from the parse module when a .INCLUDES line is parsed.
+ * The suffix must have already been defined.
+ * The SUFF_INCLUDE bit is set in the suffix's flags field.
*
* Input:
* sname Name of the suffix to mark
- *
- * Results:
- * None.
- *
- * Side Effects:
- * The SUFF_INCLUDE bit is set in the suffix's flags field
- *
- *-----------------------------------------------------------------------
*/
void
Suff_AddInclude(char *sname)
@@ -1128,64 +918,46 @@ Suff_AddInclude(char *sname)
LstNode ln;
Suff *s;
- ln = Lst_Find(sufflist, sname, SuffSuffHasNameP);
+ ln = Lst_Find(sufflist, SuffSuffHasName, sname);
if (ln != NULL) {
- s = (Suff *)Lst_Datum(ln);
+ s = LstNode_Datum(ln);
s->flags |= SUFF_INCLUDE;
}
}
-/*-
- *-----------------------------------------------------------------------
- * Suff_AddLib --
- * Add the given suffix as a type of file which is a library.
- * Called from the parse module when parsing a .LIBS line. The
- * suffix must have been defined via .SUFFIXES before this is
- * called.
+/* Add the given suffix as a type of file which is a library.
+ * Called from the parse module when parsing a .LIBS line.
+ * The suffix must have been defined via .SUFFIXES before this is called.
+ * The SUFF_LIBRARY bit is set in the suffix's flags field.
*
* Input:
* sname Name of the suffix to mark
- *
- * Results:
- * None.
- *
- * Side Effects:
- * The SUFF_LIBRARY bit is set in the suffix's flags field
- *
- *-----------------------------------------------------------------------
*/
void
-Suff_AddLib(char *sname)
+Suff_AddLib(const char *sname)
{
LstNode ln;
Suff *s;
- ln = Lst_Find(sufflist, sname, SuffSuffHasNameP);
+ ln = Lst_Find(sufflist, SuffSuffHasName, sname);
if (ln != NULL) {
- s = (Suff *)Lst_Datum(ln);
+ s = LstNode_Datum(ln);
s->flags |= SUFF_LIBRARY;
}
}
- /********** Implicit Source Search Functions *********/
+ /********** Implicit Source Search Functions *********/
-/*-
- *-----------------------------------------------------------------------
- * SuffAddSrc --
- * Add a suffix as a Src structure to the given list with its parent
- * being the given Src structure. If the suffix is the null suffix,
- * the prefix is used unaltered as the file name in the Src structure.
+/* Add a suffix as a Src structure to the given list with its parent
+ * being the given Src structure. If the suffix is the null suffix,
+ * the prefix is used unaltered as the file name in the Src structure.
*
* Input:
* sp suffix for which to create a Src structure
* lsp list and parent for the new Src
*
* Results:
- * always returns 0
- *
- * Side Effects:
- * A Src structure is created and tacked onto the end of the list
- *-----------------------------------------------------------------------
+ * 0, so that Lst_ForEach continues
*/
static int
SuffAddSrc(void *sp, void *lsp)
@@ -1212,17 +984,17 @@ SuffAddSrc(void *sp, void *lsp)
s->refCount++;
s2->children = 0;
targ->children += 1;
- (void)Lst_AtEnd(ls->l, s2);
+ Lst_Append(ls->l, s2);
#ifdef DEBUG_SRC
- s2->cp = Lst_Init(FALSE);
- Lst_AtEnd(targ->cp, s2);
+ s2->cp = Lst_Init();
+ Lst_Append(targ->cp, s2);
fprintf(debug_file, "1 add %p %p to %p:", targ, s2, ls->l);
Lst_ForEach(ls->l, PrintAddr, NULL);
fprintf(debug_file, "\n");
#endif
}
s2 = bmake_malloc(sizeof(Src));
- s2->file = str_concat(targ->pref, s->name, 0);
+ s2->file = str_concat2(targ->pref, s->name);
s2->pref = targ->pref;
s2->parent = targ;
s2->node = NULL;
@@ -1230,10 +1002,10 @@ SuffAddSrc(void *sp, void *lsp)
s->refCount++;
s2->children = 0;
targ->children += 1;
- (void)Lst_AtEnd(ls->l, s2);
+ Lst_Append(ls->l, s2);
#ifdef DEBUG_SRC
- s2->cp = Lst_Init(FALSE);
- Lst_AtEnd(targ->cp, s2);
+ s2->cp = Lst_Init();
+ Lst_Append(targ->cp, s2);
fprintf(debug_file, "2 add %p %p to %p:", targ, s2, ls->l);
Lst_ForEach(ls->l, PrintAddr, NULL);
fprintf(debug_file, "\n");
@@ -1242,21 +1014,11 @@ SuffAddSrc(void *sp, void *lsp)
return 0;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffAddLevel --
- * Add all the children of targ as Src structures to the given list
+/* Add all the children of targ as Src structures to the given list.
*
* Input:
* l list to which to add the new level
* targ Src structure to use as the parent
- *
- * Results:
- * None
- *
- * Side Effects:
- * Lots of structures are created and added to the list
- *-----------------------------------------------------------------------
*/
static void
SuffAddLevel(Lst l, Src *targ)
@@ -1269,44 +1031,31 @@ SuffAddLevel(Lst l, Src *targ)
Lst_ForEach(targ->suff->children, SuffAddSrc, &ls);
}
-/*-
- *----------------------------------------------------------------------
- * SuffRemoveSrc --
- * Free all src structures in list that don't have a reference count
- *
- * Results:
- * Ture if an src was removed
- *
- * Side Effects:
- * The memory is free'd.
- *----------------------------------------------------------------------
- */
-static int
+/* Free the first Src in the list that doesn't have a reference count.
+ * Return whether a Src was removed. */
+static Boolean
SuffRemoveSrc(Lst l)
{
LstNode ln;
Src *s;
- int t = 0;
- if (Lst_Open(l) == FAILURE) {
- return 0;
- }
+ Lst_Open(l);
+
#ifdef DEBUG_SRC
fprintf(debug_file, "cleaning %lx: ", (unsigned long) l);
Lst_ForEach(l, PrintAddr, NULL);
fprintf(debug_file, "\n");
#endif
-
while ((ln = Lst_Next(l)) != NULL) {
- s = (Src *)Lst_Datum(ln);
+ s = LstNode_Datum(ln);
if (s->children == 0) {
free(s->file);
if (!s->parent)
free(s->pref);
else {
#ifdef DEBUG_SRC
- LstNode ln2 = Lst_Member(s->parent->cp, s);
+ LstNode ln2 = Lst_FindDatum(s->parent->cp, s);
if (ln2 != NULL)
Lst_Remove(s->parent->cp, ln2);
#endif
@@ -1314,11 +1063,10 @@ SuffRemoveSrc(Lst l)
}
#ifdef DEBUG_SRC
fprintf(debug_file, "free: [l=%p] p=%p %d\n", l, s, s->children);
- Lst_Destroy(s->cp, NULL);
+ Lst_Free(s->cp);
#endif
Lst_Remove(l, ln);
free(s);
- t |= 1;
Lst_Close(l);
return TRUE;
}
@@ -1333,23 +1081,16 @@ SuffRemoveSrc(Lst l)
Lst_Close(l);
- return t;
+ return FALSE;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffFindThem --
- * Find the first existing file/target in the list srcs
+/* Find the first existing file/target in the list srcs.
*
* Input:
* srcs list of Src structures to search through
*
* Results:
- * The lowest structure in the chain of transformations
- *
- * Side Effects:
- * None
- *-----------------------------------------------------------------------
+ * The lowest structure in the chain of transformations, or NULL.
*/
static Src *
SuffFindThem(Lst srcs, Lst slst)
@@ -1360,12 +1101,10 @@ SuffFindThem(Lst srcs, Lst slst)
rs = NULL;
- while (!Lst_IsEmpty (srcs)) {
- s = (Src *)Lst_DeQueue(srcs);
+ while (!Lst_IsEmpty(srcs)) {
+ s = Lst_Dequeue(srcs);
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "\ttrying %s...", s->file);
- }
+ SUFF_DEBUG1("\ttrying %s...", s->file);
/*
* A file is considered to exist if either a node exists in the
@@ -1388,51 +1127,41 @@ SuffFindThem(Lst srcs, Lst slst)
break;
}
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "not there\n");
- }
+ SUFF_DEBUG0("not there\n");
SuffAddLevel(srcs, s);
- Lst_AtEnd(slst, s);
+ Lst_Append(slst, s);
}
- if (DEBUG(SUFF) && rs) {
- fprintf(debug_file, "got it\n");
+ if (rs) {
+ SUFF_DEBUG0("got it\n");
}
return rs;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffFindCmds --
- * See if any of the children of the target in the Src structure is
- * one from which the target can be transformed. If there is one,
- * a Src structure is put together for it and returned.
+/* See if any of the children of the target in the Src structure is one from
+ * which the target can be transformed. If there is one, a Src structure is
+ * put together for it and returned.
*
* Input:
- * targ Src structure to play with
+ * targ Src to play with
*
* Results:
- * The Src structure of the "winning" child, or NULL if no such beast.
- *
- * Side Effects:
- * A Src structure may be allocated.
- *
- *-----------------------------------------------------------------------
+ * The Src of the "winning" child, or NULL.
*/
static Src *
SuffFindCmds(Src *targ, Lst slst)
{
LstNode ln; /* General-purpose list node */
GNode *t, /* Target GNode */
- *s; /* Source GNode */
+ *s; /* Source GNode */
int prefLen;/* The length of the defined prefix */
Suff *suff; /* Suffix on matching beastie */
Src *ret; /* Return value */
char *cp;
t = targ->node;
- (void)Lst_Open(t->children);
+ Lst_Open(t->children);
prefLen = strlen(targ->pref);
for (;;) {
@@ -1441,7 +1170,7 @@ SuffFindCmds(Src *targ, Lst slst)
Lst_Close(t->children);
return NULL;
}
- s = (GNode *)Lst_Datum(ln);
+ s = LstNode_Datum(ln);
if (s->type & OP_OPTIONAL && Lst_IsEmpty(t->commands)) {
/*
@@ -1466,7 +1195,7 @@ SuffFindCmds(Src *targ, Lst slst)
* The node matches the prefix ok, see if it has a known
* suffix.
*/
- ln = Lst_Find(sufflist, &cp[prefLen], SuffSuffHasNameP);
+ ln = Lst_Find(sufflist, SuffSuffHasName, &cp[prefLen]);
if (ln == NULL)
continue;
/*
@@ -1475,9 +1204,11 @@ SuffFindCmds(Src *targ, Lst slst)
*
* XXX: Handle multi-stage transformations here, too.
*/
- suff = (Suff *)Lst_Datum(ln);
+ suff = LstNode_Datum(ln);
- if (Lst_Member(suff->parents, targ->suff) != NULL)
+ /* XXX: Can targ->suff be NULL here? */
+ if (targ->suff != NULL &&
+ Lst_FindDatum(suff->parents, targ->suff) != NULL)
break;
}
@@ -1497,41 +1228,30 @@ SuffFindCmds(Src *targ, Lst slst)
ret->children = 0;
targ->children += 1;
#ifdef DEBUG_SRC
- ret->cp = Lst_Init(FALSE);
+ ret->cp = Lst_Init();
fprintf(debug_file, "3 add %p %p\n", targ, ret);
- Lst_AtEnd(targ->cp, ret);
+ Lst_Append(targ->cp, ret);
#endif
- Lst_AtEnd(slst, ret);
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "\tusing existing source %s\n", s->name);
- }
+ Lst_Append(slst, ret);
+ SUFF_DEBUG1("\tusing existing source %s\n", s->name);
+ Lst_Close(t->children);
return ret;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffExpandChildren --
- * Expand the names of any children of a given node that contain
- * variable invocations or file wildcards into actual targets.
+/* Expand the names of any children of a given node that contain variable
+ * invocations or file wildcards into actual targets.
+ *
+ * The expanded node is removed from the parent's list of children, and the
+ * parent's unmade counter is decremented, but other nodes may be added.
*
* Input:
* cln Child to examine
* pgn Parent node being processed
- *
- * Results:
- * === 0 (continue)
- *
- * Side Effects:
- * The expanded node is removed from the parent's list of children,
- * and the parent's unmade counter is decremented, but other nodes
- * may be added.
- *
- *-----------------------------------------------------------------------
*/
static void
SuffExpandChildren(LstNode cln, GNode *pgn)
{
- GNode *cgn = (GNode *)Lst_Datum(cln);
+ GNode *cgn = LstNode_Datum(cln);
GNode *gn; /* New source 8) */
char *cp; /* Expanded value */
@@ -1554,13 +1274,11 @@ SuffExpandChildren(LstNode cln, GNode *pgn)
return;
}
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "Expanding \"%s\"...", cgn->name);
- }
- cp = Var_Subst(NULL, cgn->name, pgn, VARF_UNDEFERR|VARF_WANTRES);
+ SUFF_DEBUG1("Expanding \"%s\"...", cgn->name);
+ cp = Var_Subst(cgn->name, pgn, VARE_UNDEFERR|VARE_WANTRES);
- if (cp != NULL) {
- Lst members = Lst_Init(FALSE);
+ {
+ Lst members = Lst_Init();
if (cgn->type & OP_ARCHV) {
/*
@@ -1592,7 +1310,7 @@ SuffExpandChildren(LstNode cln, GNode *pgn)
*/
*cp++ = '\0';
gn = Targ_FindNode(start, TARG_CREATE);
- (void)Lst_AtEnd(members, gn);
+ Lst_Append(members, gn);
while (*cp == ' ' || *cp == '\t') {
cp++;
}
@@ -1606,12 +1324,12 @@ SuffExpandChildren(LstNode cln, GNode *pgn)
* Start of a variable spec -- contact variable module
* to find the end so we can skip over it.
*/
- char *junk;
+ const char *junk;
int len;
void *freeIt;
- junk = Var_Parse(cp, pgn, VARF_UNDEFERR|VARF_WANTRES,
- &len, &freeIt);
+ junk = Var_Parse(cp, pgn, VARE_UNDEFERR|VARE_WANTRES,
+ &len, &freeIt);
if (junk != var_Error) {
cp += len - 1;
}
@@ -1630,7 +1348,7 @@ SuffExpandChildren(LstNode cln, GNode *pgn)
* Stuff left over -- add it to the list too
*/
gn = Targ_FindNode(start, TARG_CREATE);
- (void)Lst_AtEnd(members, gn);
+ Lst_Append(members, gn);
}
/*
* Point cp back at the beginning again so the variable value
@@ -1643,28 +1361,25 @@ SuffExpandChildren(LstNode cln, GNode *pgn)
* Add all elements of the members list to the parent node.
*/
while(!Lst_IsEmpty(members)) {
- gn = (GNode *)Lst_DeQueue(members);
+ gn = Lst_Dequeue(members);
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "%s...", gn->name);
- }
+ SUFF_DEBUG1("%s...", gn->name);
/* Add gn to the parents child list before the original child */
- (void)Lst_InsertBefore(pgn->children, cln, gn);
- (void)Lst_AtEnd(gn->parents, pgn);
+ Lst_InsertBefore(pgn->children, cln, gn);
+ Lst_Append(gn->parents, pgn);
pgn->unmade++;
/* Expand wildcards on new node */
- SuffExpandWildcards(Lst_Prev(cln), pgn);
+ SuffExpandWildcards(LstNode_Prev(cln), pgn);
}
- Lst_Destroy(members, NULL);
+ Lst_Free(members);
/*
* Free the result
*/
free(cp);
}
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "\n");
- }
+
+ SUFF_DEBUG0("\n");
/*
* Now the source is expanded, remove it from the list of children to
@@ -1672,13 +1387,13 @@ SuffExpandChildren(LstNode cln, GNode *pgn)
*/
pgn->unmade--;
Lst_Remove(pgn->children, cln);
- Lst_Remove(cgn->parents, Lst_Member(cgn->parents, pgn));
+ Lst_Remove(cgn->parents, Lst_FindDatum(cgn->parents, pgn));
}
static void
SuffExpandWildcards(LstNode cln, GNode *pgn)
{
- GNode *cgn = (GNode *)Lst_Datum(cln);
+ GNode *cgn = LstNode_Datum(cln);
GNode *gn; /* New source 8) */
char *cp; /* Expanded value */
Lst explist; /* List of expansions */
@@ -1689,34 +1404,27 @@ SuffExpandWildcards(LstNode cln, GNode *pgn)
/*
* Expand the word along the chosen path
*/
- explist = Lst_Init(FALSE);
+ explist = Lst_Init();
Dir_Expand(cgn->name, Suff_FindPath(cgn), explist);
while (!Lst_IsEmpty(explist)) {
/*
* Fetch next expansion off the list and find its GNode
*/
- cp = (char *)Lst_DeQueue(explist);
+ cp = Lst_Dequeue(explist);
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "%s...", cp);
- }
+ SUFF_DEBUG1("%s...", cp);
gn = Targ_FindNode(cp, TARG_CREATE);
/* Add gn to the parents child list before the original child */
- (void)Lst_InsertBefore(pgn->children, cln, gn);
- (void)Lst_AtEnd(gn->parents, pgn);
+ Lst_InsertBefore(pgn->children, cln, gn);
+ Lst_Append(gn->parents, pgn);
pgn->unmade++;
}
- /*
- * Nuke what's left of the list
- */
- Lst_Destroy(explist, NULL);
+ Lst_Free(explist);
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "\n");
- }
+ SUFF_DEBUG0("\n");
/*
* Now the source is expanded, remove it from the list of children to
@@ -1724,28 +1432,19 @@ SuffExpandWildcards(LstNode cln, GNode *pgn)
*/
pgn->unmade--;
Lst_Remove(pgn->children, cln);
- Lst_Remove(cgn->parents, Lst_Member(cgn->parents, pgn));
+ Lst_Remove(cgn->parents, Lst_FindDatum(cgn->parents, pgn));
}
-/*-
- *-----------------------------------------------------------------------
- * Suff_FindPath --
- * Find a path along which to expand the node.
+/* Find a path along which to expand the node.
*
- * If the word has a known suffix, use that path.
- * If it has no known suffix, use the default system search path.
+ * If the word has a known suffix, use that path.
+ * If it has no known suffix, use the default system search path.
*
* Input:
* gn Node being examined
*
* Results:
* The appropriate path to search for the GNode.
- *
- * Side Effects:
- * XXX: We could set the suffix here so that we don't have to scan
- * again.
- *
- *-----------------------------------------------------------------------
*/
Lst
Suff_FindPath(GNode* gn)
@@ -1753,24 +1452,20 @@ Suff_FindPath(GNode* gn)
Suff *suff = gn->suffix;
if (suff == NULL) {
- SuffixCmpData sd; /* Search string data */
+ SuffSuffGetSuffixArgs sd; /* Search string data */
LstNode ln;
sd.len = strlen(gn->name);
sd.ename = gn->name + sd.len;
- ln = Lst_Find(sufflist, &sd, SuffSuffIsSuffixP);
+ ln = Lst_Find(sufflist, SuffSuffIsSuffix, &sd);
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "Wildcard expanding \"%s\"...", gn->name);
- }
+ SUFF_DEBUG1("Wildcard expanding \"%s\"...", gn->name);
if (ln != NULL)
- suff = (Suff *)Lst_Datum(ln);
+ suff = LstNode_Datum(ln);
/* XXX: Here we can save the suffix so we don't have to do this again */
}
if (suff != NULL) {
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "suffix is \"%s\"...", suff->name);
- }
+ SUFF_DEBUG1("suffix is \"%s\"...", suff->name);
return suff->searchPath;
} else {
/*
@@ -1780,11 +1475,8 @@ Suff_FindPath(GNode* gn)
}
}
-/*-
- *-----------------------------------------------------------------------
- * SuffApplyTransform --
- * Apply a transformation rule, given the source and target nodes
- * and suffixes.
+/* Apply a transformation rule, given the source and target nodes and
+ * suffixes.
*
* Input:
* tGn Target node
@@ -1801,8 +1493,6 @@ Suff_FindPath(GNode* gn)
* All attributes but OP_DEPMASK and OP_TRANSFORM are applied
* to the target. The target also inherits all the sources for
* the transformation rule.
- *
- *-----------------------------------------------------------------------
*/
static Boolean
SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s)
@@ -1814,15 +1504,15 @@ SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s)
/*
* Form the proper links between the target and source.
*/
- (void)Lst_AtEnd(tGn->children, sGn);
- (void)Lst_AtEnd(sGn->parents, tGn);
+ Lst_Append(tGn->children, sGn);
+ Lst_Append(sGn->parents, tGn);
tGn->unmade += 1;
/*
* Locate the transformation rule itself
*/
- tname = str_concat(s->name, t->name, 0);
- ln = Lst_Find(transforms, tname, SuffGNHasNameP);
+ tname = str_concat2(s->name, t->name);
+ ln = Lst_Find(transforms, SuffGNHasName, tname);
free(tname);
if (ln == NULL) {
@@ -1834,11 +1524,9 @@ SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s)
return FALSE;
}
- gn = (GNode *)Lst_Datum(ln);
+ gn = LstNode_Datum(ln);
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "\tapplying %s -> %s to \"%s\"\n", s->name, t->name, tGn->name);
- }
+ SUFF_DEBUG3("\tapplying %s -> %s to \"%s\"\n", s->name, t->name, tGn->name);
/*
* Record last child for expansion purposes
@@ -1853,8 +1541,8 @@ SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s)
/*
* Deal with wildcards and variables in any acquired sources
*/
- for (ln = Lst_Succ(ln); ln != NULL; ln = nln) {
- nln = Lst_Succ(ln);
+ for (ln = ln != NULL ? LstNode_Next(ln) : NULL; ln != NULL; ln = nln) {
+ nln = LstNode_Next(ln);
SuffExpandChildren(ln, tGn);
}
@@ -1862,27 +1550,19 @@ SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s)
* Keep track of another parent to which this beast is transformed so
* the .IMPSRC variable can be set correctly for the parent.
*/
- (void)Lst_AtEnd(sGn->iParents, tGn);
+ Lst_Append(sGn->implicitParents, tGn);
return TRUE;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffFindArchiveDeps --
- * Locate dependencies for an OP_ARCHV node.
+/* Locate dependencies for an OP_ARCHV node.
*
* Input:
* gn Node for which to locate dependencies
*
- * Results:
- * None
- *
* Side Effects:
* Same as Suff_FindDeps
- *
- *-----------------------------------------------------------------------
*/
static void
SuffFindArchiveDeps(GNode *gn, Lst slst)
@@ -1890,13 +1570,7 @@ SuffFindArchiveDeps(GNode *gn, Lst slst)
char *eoarch; /* End of archive portion */
char *eoname; /* End of member portion */
GNode *mem; /* Node for member */
- static const char *copy[] = {
- /* Variables to be copied from the member node */
- TARGET, /* Must be first */
- PREFIX, /* Must be second */
- };
LstNode ln, nln; /* Next suffix node to check */
- int i; /* Index into copy and vals */
Suff *ms; /* Suffix descriptor for member */
char *name; /* Start of member's name */
@@ -1932,18 +1606,19 @@ SuffFindArchiveDeps(GNode *gn, Lst slst)
/*
* Create the link between the two nodes right off
*/
- (void)Lst_AtEnd(gn->children, mem);
- (void)Lst_AtEnd(mem->parents, gn);
+ Lst_Append(gn->children, mem);
+ Lst_Append(mem->parents, gn);
gn->unmade += 1;
/*
* Copy in the variables from the member node to this one.
*/
- for (i = (sizeof(copy)/sizeof(copy[0]))-1; i >= 0; i--) {
- char *p1;
- Var_Set(copy[i], Var_Value(copy[i], mem, &p1), gn);
- free(p1);
-
+ {
+ char *freeIt;
+ Var_Set(PREFIX, Var_Value(PREFIX, mem, &freeIt), gn);
+ bmake_free(freeIt);
+ Var_Set(TARGET, Var_Value(TARGET, mem, &freeIt), gn);
+ bmake_free(freeIt);
}
ms = mem->suffix;
@@ -1951,9 +1626,7 @@ SuffFindArchiveDeps(GNode *gn, Lst slst)
/*
* Didn't know what it was -- use .NULL suffix if not in make mode
*/
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "using null suffix\n");
- }
+ SUFF_DEBUG0("using null suffix\n");
ms = suffNull;
}
@@ -1974,7 +1647,7 @@ SuffFindArchiveDeps(GNode *gn, Lst slst)
* that still contain variables or wildcards in their names.
*/
for (ln = Lst_First(gn->children); ln != NULL; ln = nln) {
- nln = Lst_Succ(ln);
+ nln = LstNode_Next(ln);
SuffExpandChildren(ln, gn);
}
@@ -1985,24 +1658,23 @@ SuffFindArchiveDeps(GNode *gn, Lst slst)
* through the entire list, we just look at suffixes to which the
* member's suffix may be transformed...
*/
- SuffixCmpData sd; /* Search string data */
+ SuffSuffGetSuffixArgs sd; /* Search string data */
/*
* Use first matching suffix...
*/
sd.len = eoarch - gn->name;
sd.ename = eoarch;
- ln = Lst_Find(ms->parents, &sd, SuffSuffIsSuffixP);
+ ln = Lst_Find(ms->parents, SuffSuffIsSuffix, &sd);
if (ln != NULL) {
/*
* Got one -- apply it
*/
- if (!SuffApplyTransform(gn, mem, (Suff *)Lst_Datum(ln), ms) &&
- DEBUG(SUFF))
- {
- fprintf(debug_file, "\tNo transformation from %s -> %s\n",
- ms->name, ((Suff *)Lst_Datum(ln))->name);
+ Suff *suff = LstNode_Datum(ln);
+ if (!SuffApplyTransform(gn, mem, suff, ms)) {
+ SUFF_DEBUG2("\tNo transformation from %s -> %s\n",
+ ms->name, suff->name);
}
}
}
@@ -2030,21 +1702,13 @@ SuffFindArchiveDeps(GNode *gn, Lst slst)
mem->type |= OP_MEMBER | OP_JOIN | OP_MADE;
}
-/*-
- *-----------------------------------------------------------------------
- * SuffFindNormalDeps --
- * Locate implicit dependencies for regular targets.
+/* Locate implicit dependencies for regular targets.
*
* Input:
* gn Node for which to find sources
*
- * Results:
- * None.
- *
* Side Effects:
- * Same as Suff_FindDeps...
- *
- *-----------------------------------------------------------------------
+ * Same as Suff_FindDeps
*/
static void
SuffFindNormalDeps(GNode *gn, Lst slst)
@@ -2060,7 +1724,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
Src *src; /* General Src pointer */
char *pref; /* Prefix to use */
Src *targ; /* General Src target pointer */
- SuffixCmpData sd; /* Search string data */
+ SuffSuffGetSuffixArgs sd; /* Search string data */
sd.len = strlen(gn->name);
@@ -2072,8 +1736,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
@@ -2102,34 +1766,27 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
/*
* Look for next possible suffix...
*/
- ln = Lst_FindFrom(sufflist, ln, &sd, SuffSuffIsSuffixP);
+ ln = Lst_FindFrom(sufflist, ln, SuffSuffIsSuffix, &sd);
if (ln != NULL) {
- int prefLen; /* Length of the prefix */
+ const char *eopref;
/*
* Allocate a Src structure to which things can be transformed
*/
targ = bmake_malloc(sizeof(Src));
targ->file = bmake_strdup(gn->name);
- targ->suff = (Suff *)Lst_Datum(ln);
+ targ->suff = LstNode_Datum(ln);
targ->suff->refCount++;
targ->node = gn;
targ->parent = NULL;
targ->children = 0;
#ifdef DEBUG_SRC
- targ->cp = Lst_Init(FALSE);
+ targ->cp = Lst_Init();
#endif
- /*
- * Allocate room for the prefix, whose end is found by
- * subtracting the length of the suffix from
- * the end of the name.
- */
- prefLen = (eoname - targ->suff->nameLen) - sopref;
- targ->pref = bmake_malloc(prefLen + 1);
- memcpy(targ->pref, sopref, prefLen);
- targ->pref[prefLen] = '\0';
+ eopref = eoname - targ->suff->nameLen;
+ targ->pref = bmake_strsedup(sopref, eopref);
/*
* Add nodes from which the target can be made
@@ -2139,12 +1796,12 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
/*
* Record the target so we can nuke it
*/
- (void)Lst_AtEnd(targs, targ);
+ Lst_Append(targs, targ);
/*
* Search from this suffix's successor...
*/
- ln = Lst_Succ(ln);
+ ln = LstNode_Next(ln);
}
}
@@ -2152,9 +1809,8 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
* Handle target of unknown suffix...
*/
if (Lst_IsEmpty(targs) && suffNull != NULL) {
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
- }
+ SUFF_DEBUG1("\tNo known suffix on %s. Using .NULL suffix\n",
+ gn->name);
targ = bmake_malloc(sizeof(Src));
targ->file = bmake_strdup(gn->name);
@@ -2165,7 +1821,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
targ->children = 0;
targ->pref = bmake_strdup(sopref);
#ifdef DEBUG_SRC
- targ->cp = Lst_Init(FALSE);
+ targ->cp = Lst_Init();
#endif
/*
@@ -2177,14 +1833,12 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
if (Lst_IsEmpty(gn->commands))
SuffAddLevel(srcs, targ);
else {
- if (DEBUG(SUFF))
- fprintf(debug_file, "not ");
+ SUFF_DEBUG0("not ");
}
- if (DEBUG(SUFF))
- fprintf(debug_file, "adding suffix rules\n");
+ SUFF_DEBUG0("adding suffix rules\n");
- (void)Lst_AtEnd(targs, targ);
+ Lst_Append(targs, targ);
}
/*
@@ -2199,7 +1853,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
* for setting the local variables.
*/
if (!Lst_IsEmpty(targs)) {
- targ = (Src *)Lst_Datum(Lst_First(targs));
+ targ = LstNode_Datum(Lst_First(targs));
} else {
targ = NULL;
}
@@ -2223,14 +1877,12 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
* that still contain variables or wildcards in their names.
*/
for (ln = Lst_First(gn->children); ln != NULL; ln = nln) {
- nln = Lst_Succ(ln);
+ nln = LstNode_Next(ln);
SuffExpandChildren(ln, gn);
}
if (targ == NULL) {
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "\tNo valid suffix on %s\n", gn->name);
- }
+ SUFF_DEBUG1("\tNo valid suffix on %s\n", gn->name);
sfnd_abort:
/*
@@ -2314,8 +1966,8 @@ sfnd_abort:
* up to, but not including, the parent node.
*/
while (bottom && bottom->parent != NULL) {
- if (Lst_Member(slst, bottom) == NULL) {
- Lst_AtEnd(slst, bottom);
+ if (Lst_FindDatum(slst, bottom) == NULL) {
+ Lst_Append(slst, bottom);
}
bottom = bottom->parent;
}
@@ -2390,45 +2042,31 @@ sfnd_abort:
*/
sfnd_return:
if (bottom)
- if (Lst_Member(slst, bottom) == NULL)
- Lst_AtEnd(slst, bottom);
+ if (Lst_FindDatum(slst, bottom) == NULL)
+ Lst_Append(slst, bottom);
while (SuffRemoveSrc(srcs) || SuffRemoveSrc(targs))
continue;
- Lst_Concat(slst, srcs, LST_CONCLINK);
- Lst_Concat(slst, targs, LST_CONCLINK);
+ Lst_MoveAll(slst, srcs);
+ Lst_MoveAll(slst, targs);
}
-/*-
- *-----------------------------------------------------------------------
- * Suff_FindDeps --
- * Find implicit sources for the target described by the graph node
- * gn
- *
- * Results:
- * Nothing.
+/* Find implicit sources for the target described by the graph node.
*
- * Side Effects:
- * Nodes are added to the graph below the passed-in node. The nodes
- * are marked to have their IMPSRC variable filled in. The
- * PREFIX variable is set for the given node and all its
- * implied children.
- *
- * Notes:
- * The path found by this target is the shortest path in the
- * transformation graph, which may pass through non-existent targets,
- * to an existing target. The search continues on all paths from the
- * root suffix until a file is found. I.e. if there's a path
- * .o -> .c -> .l -> .l,v from the root and the .l,v file exists but
- * the .c and .l files don't, the search will branch out in
- * all directions from .o and again from all the nodes on the
- * next level until the .l,v node is encountered.
+ * Nodes are added to the graph below the passed-in node. The nodes are
+ * marked to have their IMPSRC variable filled in. The PREFIX variable is set
+ * for the given node and all its implied children.
*
- *-----------------------------------------------------------------------
+ * The path found by this target is the shortest path in the transformation
+ * graph, which may pass through non-existent targets, to an existing target.
+ * The search continues on all paths from the root suffix until a file is
+ * found. I.e. if there's a path .o -> .c -> .l -> .l,v from the root and the
+ * .l,v file exists but the .c and .l files don't, the search will branch out
+ * in all directions from .o and again from all the nodes on the next level
+ * until the .l,v node is encountered.
*/
-
void
Suff_FindDeps(GNode *gn)
{
@@ -2438,32 +2076,20 @@ Suff_FindDeps(GNode *gn)
continue;
}
-
-/*
- * Input:
- * gn node we're dealing with
- *
- */
static void
SuffFindDeps(GNode *gn, Lst slst)
{
- if (gn->type & OP_DEPS_FOUND) {
- /*
- * If dependencies already found, no need to do it again...
- */
+ if (gn->type & OP_DEPS_FOUND)
return;
- } else {
- gn->type |= OP_DEPS_FOUND;
- }
+ gn->type |= OP_DEPS_FOUND;
+
/*
* Make sure we have these set, may get revised below.
*/
Var_Set(TARGET, gn->path ? gn->path : gn->name, gn);
Var_Set(PREFIX, gn->name, gn);
- if (DEBUG(SUFF)) {
- fprintf(debug_file, "SuffFindDeps (%s)\n", gn->name);
- }
+ SUFF_DEBUG1("SuffFindDeps (%s)\n", gn->name);
if (gn->type & OP_ARCHV) {
SuffFindArchiveDeps(gn, slst);
@@ -2479,11 +2105,11 @@ SuffFindDeps(GNode *gn, Lst slst)
LstNode ln;
Suff *s;
- ln = Lst_Find(sufflist, LIBSUFF, SuffSuffHasNameP);
+ ln = Lst_Find(sufflist, SuffSuffHasName, LIBSUFF);
if (gn->suffix)
gn->suffix->refCount--;
if (ln != NULL) {
- gn->suffix = s = (Suff *)Lst_Datum(ln);
+ gn->suffix = s = LstNode_Datum(ln);
gn->suffix->refCount++;
Arch_FindLib(gn, s->searchPath);
} else {
@@ -2501,25 +2127,13 @@ SuffFindDeps(GNode *gn, Lst slst)
}
}
-/*-
- *-----------------------------------------------------------------------
- * Suff_SetNull --
- * Define which suffix is the null suffix.
+/* Define which suffix is the null suffix.
+ *
+ * Need to handle the changing of the null suffix gracefully so the old
+ * transformation rules don't just go away.
*
* Input:
* name Name of null suffix
- *
- * Results:
- * None.
- *
- * Side Effects:
- * 'suffNull' is altered.
- *
- * Notes:
- * Need to handle the changing of the null suffix gracefully so the
- * old transformation rules don't just go away.
- *
- *-----------------------------------------------------------------------
*/
void
Suff_SetNull(char *name)
@@ -2527,9 +2141,9 @@ Suff_SetNull(char *name)
Suff *s;
LstNode ln;
- ln = Lst_Find(sufflist, name, SuffSuffHasNameP);
+ ln = Lst_Find(sufflist, SuffSuffHasName, name);
if (ln != NULL) {
- s = (Suff *)Lst_Datum(ln);
+ s = LstNode_Datum(ln);
if (suffNull != NULL) {
suffNull->flags &= ~SUFF_NULL;
}
@@ -2544,26 +2158,16 @@ Suff_SetNull(char *name)
}
}
-/*-
- *-----------------------------------------------------------------------
- * Suff_Init --
- * Initialize suffixes module
- *
- * Results:
- * None
- *
- * Side Effects:
- * Many
- *-----------------------------------------------------------------------
- */
+/* Initialize the suffixes module. */
void
Suff_Init(void)
{
#ifdef CLEANUP
- suffClean = Lst_Init(FALSE);
+ suffClean = Lst_Init();
+ sufflist = Lst_Init();
#endif
- srclist = Lst_Init(FALSE);
- transforms = Lst_Init(FALSE);
+ srclist = Lst_Init();
+ transforms = Lst_Init();
/*
* Create null suffix for single-suffix rules (POSIX). The thing doesn't
@@ -2574,19 +2178,7 @@ Suff_Init(void)
}
-/*-
- *----------------------------------------------------------------------
- * Suff_End --
- * Cleanup the this module
- *
- * Results:
- * None
- *
- * Side Effects:
- * The memory is free'd.
- *----------------------------------------------------------------------
- */
-
+/* Clean up the suffixes module. */
void
Suff_End(void)
{
@@ -2595,8 +2187,8 @@ Suff_End(void)
Lst_Destroy(suffClean, SuffFree);
if (suffNull)
SuffFree(suffNull);
- Lst_Destroy(srclist, NULL);
- Lst_Destroy(transforms, NULL);
+ Lst_Free(srclist);
+ Lst_Free(transforms);
#endif
}
@@ -2614,30 +2206,15 @@ static int
SuffPrintSuff(void *sp, void *dummy MAKE_ATTR_UNUSED)
{
Suff *s = (Suff *)sp;
- int flags;
- int flag;
fprintf(debug_file, "# `%s' [%d] ", s->name, s->refCount);
- flags = s->flags;
- if (flags) {
- fputs(" (", debug_file);
- while (flags) {
- flag = 1 << (ffs(flags) - 1);
- flags &= ~flag;
- switch (flag) {
- case SUFF_NULL:
- fprintf(debug_file, "NULL");
- break;
- case SUFF_INCLUDE:
- fprintf(debug_file, "INCLUDE");
- break;
- case SUFF_LIBRARY:
- fprintf(debug_file, "LIBRARY");
- break;
- }
- fputc(flags ? '|' : ')', debug_file);
- }
+ if (s->flags != 0) {
+ char flags_buf[SuffFlags_ToStringSize];
+
+ fprintf(debug_file, " (%s)",
+ Enum_FlagsToString(flags_buf, sizeof flags_buf,
+ s->flags, SuffFlags_ToStringSpecs));
}
fputc('\n', debug_file);
fprintf(debug_file, "#\tTo: ");