Module Name: othersrc
Committed By: dholland
Date: Sat Mar 23 17:09:40 UTC 2013
Modified Files:
othersrc/usr.bin/dholland-make2: graph.h suff.c
Log Message:
More arrays, fewer lists.
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 othersrc/usr.bin/dholland-make2/graph.h
cvs rdiff -u -r1.9 -r1.10 othersrc/usr.bin/dholland-make2/suff.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: othersrc/usr.bin/dholland-make2/graph.h
diff -u othersrc/usr.bin/dholland-make2/graph.h:1.6 othersrc/usr.bin/dholland-make2/graph.h:1.7
--- othersrc/usr.bin/dholland-make2/graph.h:1.6 Tue Mar 5 04:27:27 2013
+++ othersrc/usr.bin/dholland-make2/graph.h Sat Mar 23 17:09:40 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: graph.h,v 1.6 2013/03/05 04:27:27 dholland Exp $ */
+/* $NetBSD: graph.h,v 1.7 2013/03/23 17:09:40 dholland Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -174,7 +174,7 @@ struct GNode {
Hash_Table context; /* The local variables */
struct stringarray commands;/* Creation commands */
- struct _Suff *suffix; /* Suffix for the node (determined by
+ struct Suff *suffix; /* Suffix for the node (determined by
* Suff_FindDeps and opaque to everyone
* but the Suff module) */
const char *fname; /* filename where the GNode got defined */
Index: othersrc/usr.bin/dholland-make2/suff.c
diff -u othersrc/usr.bin/dholland-make2/suff.c:1.9 othersrc/usr.bin/dholland-make2/suff.c:1.10
--- othersrc/usr.bin/dholland-make2/suff.c:1.9 Fri Mar 22 22:59:24 2013
+++ othersrc/usr.bin/dholland-make2/suff.c Sat Mar 23 17:09:40 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: suff.c,v 1.9 2013/03/22 22:59:24 dholland Exp $ */
+/* $NetBSD: suff.c,v 1.10 2013/03/23 17:09:40 dholland Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -131,12 +131,16 @@
#include "hash.h"
#include "dir.h"
-MAKE_RCSID("$NetBSD: suff.c,v 1.9 2013/03/22 22:59:24 dholland Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.10 2013/03/23 17:09:40 dholland Exp $");
/*
* Structure describing an individual suffix.
*/
-typedef struct _Suff {
+
+struct Suff;
+DECLARRAY_BYTYPE(sufflist, struct Suff, static);
+
+typedef struct Suff {
char *name; /* The suffix itself */
int nameLen; /* Length of the suffix */
short flags; /* Type of suffix */
@@ -146,9 +150,10 @@ typedef struct _Suff {
struct patharray searchPath;/* The path along which files of this suffix
* may be found */
int sNum; /* The suffix number */
+ /* XXX: the handling of refCount is all broken */
int refCount; /* Reference count of list membership */
- Lst parents; /* Suffixes we have a transformation to */
- Lst children; /* Suffixes we have a transformation from */
+ struct sufflist parents; /* Suffixes we have a transformation to */
+ struct sufflist children; /* Suffixes we have a transformation from */
Lst ref; /* List of lists this suffix is referenced */
} Suff;
@@ -156,7 +161,7 @@ typedef struct _Suff {
* for SuffSuffIsSuffix
*/
typedef struct {
- char *ename; /* The end of the name */
+ const char *ename; /* The end of the name */
int len; /* Length of the name */
} SuffixCmpData;
@@ -180,10 +185,6 @@ typedef struct _Src {
* A structure for passing more than one argument to the Lst-library-invoked
* function...
*/
-typedef struct {
- Lst l;
- Src *s;
-} LstSrc;
typedef struct {
GNode **gn;
@@ -191,9 +192,13 @@ typedef struct {
Boolean r;
} GNodeSuff;
-static Lst sufflist; /* Lst of suffixes */
+DEFARRAY_BYTYPE(sufflist, Suff, MAKE_ATTR_UNUSED static);
+
+#define CLEANUP
+
+static struct sufflist sufflist; /* suffixes */
#ifdef CLEANUP
-static Lst suffClean; /* Lst of suffixes to be cleaned */
+static struct sufflist suffClean; /* suffixes to be cleaned */
#endif
static Lst srclist; /* Lst of sources */
static Lst transforms; /* Lst of transformation rules */
@@ -206,18 +211,15 @@ static Suff *emptySuff; /* The empt
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 const char *SuffSuffIsSuffix(const Suff *, const SuffixCmpData *);
static int SuffGNHasNameP(const void *, const void *);
-static void SuffUnRef(void *, void *);
+static void SuffUnRef(struct sufflist *, Suff *);
static void SuffFree(void *);
-static void SuffInsert(Lst, Suff *);
-static void SuffRemove(Lst, Suff *);
+static void SuffInsert(struct sufflist *, Suff *);
+static void SuffRemove(struct sufflist *, Suff *);
static Boolean SuffParseTransform(char *, Suff **, Suff **);
static int SuffRebuildGraph(void *, void *);
-static int SuffAddSrc(void *, void *);
+static void SuffAddSrc(Suff *, Lst, Src *);
static int SuffRemoveSrc(Lst);
static void SuffAddLevel(Lst, Src *);
static Src *SuffFindThem(Lst, Lst);
@@ -228,8 +230,8 @@ static Boolean SuffApplyTransform(GNode
static void SuffFindDeps(GNode *, Lst);
static void SuffFindArchiveDeps(GNode *, Lst);
static void SuffFindNormalDeps(GNode *, Lst);
-static int SuffPrintName(void *, void *);
-static int SuffPrintSuff(void *, void *);
+static void SuffPrintName(Suff *);
+static void SuffPrintSuff(Suff *);
static int SuffPrintTrans(void *, void *);
/*************** Lst Predicates ****************/
@@ -278,11 +280,11 @@ SuffStrIsPrefix(const char *pref, const
* None
*-----------------------------------------------------------------------
*/
-static char *
+static const char *
SuffSuffIsSuffix(const Suff *s, const SuffixCmpData *sd)
{
- char *p1; /* Pointer into suffix name */
- char *p2; /* Pointer into string being examined */
+ const char *p1; /* Pointer into suffix name */
+ const char *p2; /* Pointer into string being examined */
if (sd->len < s->nameLen)
return NULL; /* this string is shorter than the suffix */
@@ -300,74 +302,6 @@ SuffSuffIsSuffix(const Suff *s, const Su
/*-
*-----------------------------------------------------------------------
- * 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)
-{
- return(!SuffSuffIsSuffix(s, sd));
-}
-
-/*-
- *-----------------------------------------------------------------------
- * 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)
-{
- return (strcmp(sname, ((const Suff *)s)->name));
-}
-
-/*-
- *-----------------------------------------------------------------------
- * 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
-SuffSuffIsPrefix(const void *s, const void *str)
-{
- return SuffStrIsPrefix(((const Suff *)s)->name, str) == NULL;
-}
-
-/*-
- *-----------------------------------------------------------------------
* SuffGNHasNameP --
* See if the graph node has the desired name
*
@@ -391,15 +325,28 @@ SuffGNHasNameP(const void *gn, const voi
/*********** Maintenance Functions ************/
static void
-SuffUnRef(void *lp, void *sp)
+suff_incref(Suff *s)
{
- Lst l = (Lst) lp;
+ s->refCount++;
+}
- LstNode ln = Lst_Member(l, sp);
- if (ln != NULL) {
- Lst_Remove(l, ln);
- ((Suff *)sp)->refCount--;
- }
+static void
+suff_decref(Suff *s)
+{
+ s->refCount--;
+ // XXX should destroy here but we need a cleanup pass first
+}
+
+static void
+SuffUnRef(struct sufflist *l, Suff *s)
+{
+ unsigned pos;
+
+ pos = sufflist_find(l, s);
+ if (pos != ARRAY_NOTFOUND) {
+ sufflist_remove(l, pos);
+ s->refCount--;
+ }
}
/*-
@@ -434,8 +381,10 @@ SuffFree(void *sp)
#endif
Lst_Destroy(s->ref, NULL);
- Lst_Destroy(s->children, NULL);
- Lst_Destroy(s->parents, NULL);
+ sufflist_setsize(&s->children, 0);
+ sufflist_cleanup(&s->children);
+ sufflist_setsize(&s->parents, 0);
+ sufflist_cleanup(&s->parents);
for (i=0; i<patharray_num(&s->searchPath); i++) {
Dir_Destroy(patharray_get(&s->searchPath, i));
}
@@ -460,11 +409,11 @@ SuffFree(void *sp)
*-----------------------------------------------------------------------
*/
static void
-SuffRemove(Lst l, Suff *s)
+SuffRemove(struct sufflist *l, Suff *s)
{
SuffUnRef(l, s);
if (s->refCount == 0) {
- SuffUnRef(sufflist, s);
+ SuffUnRef(&sufflist, s);
SuffFree(s);
}
}
@@ -487,37 +436,34 @@ SuffRemove(Lst l, Suff *s)
*-----------------------------------------------------------------------
*/
static void
-SuffInsert(Lst l, Suff *s)
+SuffInsert(struct sufflist *l, Suff *s)
{
- LstNode ln; /* current element in l we're examining */
- Suff *s2 = NULL; /* the suffix descriptor in this element */
+ Suff *s2 = NULL; /* current element in l we're examining */
+ unsigned pos, num;
- if (Lst_Open(l) == FAILURE) {
- return;
- }
- while ((ln = Lst_Next(l)) != NULL) {
- s2 = (Suff *)Lst_Datum(ln);
+ num = sufflist_num(l);
+ for (pos=0; pos<num; pos++) {
+ s2 = sufflist_get(l, pos);
if (s2->sNum >= s->sNum) {
break;
}
}
-
- Lst_Close(l);
if (DEBUG(SUFF)) {
fprintf(debug_file, "inserting %s(%d)...", s->name, s->sNum);
}
- if (ln == NULL) {
+ if (pos == num) {
if (DEBUG(SUFF)) {
fprintf(debug_file, "at end of list\n");
}
- (void)Lst_AtEnd(l, s);
+ sufflist_add(l, s, NULL);
s->refCount++;
(void)Lst_AtEnd(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);
+ sufflist_insert(l, pos);
+ sufflist_set(l, pos, s);
s->refCount++;
(void)Lst_AtEnd(s->ref, l);
} else if (DEBUG(SUFF)) {
@@ -546,9 +492,14 @@ void
Suff_ClearSuffixes(void)
{
#ifdef CLEANUP
- Lst_Concat(suffClean, sufflist, LST_CONCLINK);
+ unsigned i, num;
+
+ num = sufflist_num(&sufflist);
+ for (i=0; i<num; i++) {
+ sufflist_add(&suffClean, sufflist_get(&sufflist, i), NULL);
+ }
#endif
- sufflist = Lst_Init(FALSE);
+ sufflist_setsize(&sufflist, 0);
sNum = 0;
suffNull = emptySuff;
}
@@ -574,36 +525,62 @@ Suff_ClearSuffixes(void)
static Boolean
SuffParseTransform(char *str, Suff **srcPtr, Suff **targPtr)
{
- LstNode srcLn; /* element in suffix list of trans source*/
- Suff *src; /* Source of transformation */
- LstNode targLn; /* element in suffix list of trans target*/
- char *str2; /* Extra pointer (maybe target suffix) */
- LstNode singleLn; /* element in suffix list of any suffix
- * that exactly matches str */
- Suff *single = NULL;/* Source of possible transformation to
- * null suffix */
-
- srcLn = NULL;
- singleLn = NULL;
-
- /*
- * Loop looking first for a suffix that matches the start of the
- * string and then for one that exactly matches the rest of it. If
- * we can find two that meet these criteria, we've successfully
- * parsed the string.
- */
- for (;;) {
- if (srcLn == NULL) {
- srcLn = Lst_Find(sufflist, str, SuffSuffIsPrefix);
- } else {
- srcLn = Lst_FindFrom(sufflist, Lst_Succ(srcLn), str,
- SuffSuffIsPrefix);
+ /*
+ * STR is a string that might be of the form ".c.o". If it is
+ * two defined suffixes jammed together, find them and return
+ * TRUE. If there is more than one possible decomposition,
+ * return the first one, as determined by the order of the
+ * global suffix list. If there is no decomposition, but the
+ * whole string matches a defined suffix, decompose it into
+ * that and the empty suffix. If nothing matches, return
+ * FALSE.
+ *
+ * Because SUFFLIST is not kept in an order useful for this
+ * lookup, we need to search stupidly. The number of suffixes
+ * in typical usage is not *that* large, but this function is
+ * called for every target the parser scans (I think more than
+ * once actually) and this happens inside the expansion of for
+ * loops, so it might be worth maintaining an index on
+ * SUFFLIST to speed this up.
+ */
+
+ unsigned numsuffixes;
+ unsigned srcpos, targpos;
+ Suff *src, *targ;
+ const char *targname;
+ size_t targlen;
+ Suff *srctoempty;
+
+ srctoempty = NULL;
+ numsuffixes = sufflist_num(&sufflist);
+ for (srcpos = 0; srcpos < numsuffixes; srcpos++) {
+ src = sufflist_get(&sufflist, srcpos);
+ targname = SuffStrIsPrefix(src->name, str);
+ if (targname == NULL) {
+ /* src->name is not a prefix of STR */
+ continue;
+ }
+ targlen = strlen(targname);
+ if (targlen == 0) {
+ /* found a match for all of STR */
+ srctoempty = src;
+ continue;
+ }
+ for (targpos = 0; targpos < numsuffixes; targpos++) {
+ targ = sufflist_get(&sufflist, targpos);
+ if (targ->nameLen != targlen) {
+ continue;
+ }
+ if (!strcmp(targ->name, targname)) {
+ /* found */
+ *srcPtr = src;
+ *targPtr = targ;
+ return TRUE;
+ }
+ }
}
- if (srcLn == NULL) {
- /*
- * Ran out of source suffixes -- no such rule
- */
- if (singleLn != NULL) {
+
+ if (srctoempty != NULL) {
/*
* Not so fast Mr. Smith! There was a suffix that encompassed
* the entire string, so we assume it was a transformation
@@ -613,26 +590,13 @@ SuffParseTransform(char *str, Suff **src
*
* XXX: Use emptySuff over suffNull?
*/
- *srcPtr = single;
+ *srcPtr = srctoempty;
*targPtr = suffNull;
- return(TRUE);
- }
- return (FALSE);
+ return TRUE;
}
- src = (Suff *)Lst_Datum(srcLn);
- str2 = str + src->nameLen;
- if (*str2 == '\0') {
- single = src;
- singleLn = srcLn;
- } else {
- targLn = Lst_Find(sufflist, str2, SuffSuffHasNameP);
- if (targLn != NULL) {
- *srcPtr = src;
- *targPtr = (Suff *)Lst_Datum(targLn);
- return (TRUE);
- }
- }
- }
+
+ /* nothing found */
+ return FALSE;
}
/*-
@@ -716,8 +680,8 @@ Suff_AddTransform(char *line)
fprintf(debug_file, "defining transformation from `%s' to `%s'\n",
s->name, t->name);
}
- SuffInsert(t->children, s);
- SuffInsert(s->parents, t);
+ SuffInsert(&t->children, s);
+ SuffInsert(&s->parents, t);
return (gn);
}
@@ -761,17 +725,15 @@ Suff_EndTransform(void *gnp, void *dummy
* actual transformation rules. (e.g. .DEFAULT)
*/
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);
}
/*
- * Store s->parents because s could be deleted in SuffRemove
+ * Hold a reference to s so it doesn't evaporate under us
*/
- p = s->parents;
+ suff_incref(s);
/*
* Remove the source from the target's children list. We check for a
@@ -781,12 +743,14 @@ Suff_EndTransform(void *gnp, void *dummy
* We'll be called twice when the next target is seen, but .c and .o
* are only linked once...
*/
- SuffRemove(t->children, s);
+ SuffRemove(&t->children, s);
/*
* Remove the target from the source's parents list
*/
- SuffRemove(p, t);
+ SuffRemove(&s->parents, t);
+
+ suff_decref(s);
}
} else if ((gn->type & OP_TRANSFORM) && DEBUG(SUFF)) {
fprintf(debug_file, "transformation %s complete\n", gn->name);
@@ -823,26 +787,30 @@ SuffRebuildGraph(void *transformp, void
{
GNode *transform = (GNode *)transformp;
Suff *s = (Suff *)sp;
- char *cp;
- LstNode ln;
+ const char *cp;
Suff *s2;
SuffixCmpData sd;
+ unsigned i, numsuffixes;
+ size_t matchlen;
+
+ numsuffixes = sufflist_num(&sufflist);
/*
* First see if it is a transformation from this suffix.
*/
- cp = UNCONST(SuffStrIsPrefix(s->name, transform->name));
+ cp = SuffStrIsPrefix(s->name, transform->name);
if (cp != NULL) {
- ln = Lst_Find(sufflist, cp, SuffSuffHasNameP);
- if (ln != NULL) {
- /*
- * Found target. Link in and return, since it can't be anything
- * else.
- */
- s2 = (Suff *)Lst_Datum(ln);
- SuffInsert(s2->children, s);
- SuffInsert(s->parents, s2);
- return(0);
+ for (i=0; i<numsuffixes; i++) {
+ s2 = sufflist_get(&sufflist, i);
+ if (!strcmp(s2->name, cp)) {
+ /*
+ * Found target. Link in and return, since it can't be
+ * anything else.
+ */
+ SuffInsert(&s2->children, s);
+ SuffInsert(&s->parents, s2);
+ return 0;
+ }
}
}
@@ -854,21 +822,25 @@ SuffRebuildGraph(void *transformp, void
cp = SuffSuffIsSuffix(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);
- /*
- * Replace the start of the target suffix
- */
- cp[1] = s->name[0];
- if (ln != NULL) {
- /*
- * Found it -- establish the proper relationship
- */
- s2 = (Suff *)Lst_Datum(ln);
- SuffInsert(s->children, s2);
- SuffInsert(s2->parents, s);
+ * For reasons best known to whoever wrote it,
+ * SuffSuffIsSuffix returns one less than the pointer to
+ * the suffix inside transform->name, instead of the
+ * pointer to the suffix.
+ */
+ cp++;
+
+ matchlen = cp - transform->name;
+ for (i=0; i<numsuffixes; i++) {
+ s2 = sufflist_get(&sufflist, i);
+ if (s2->nameLen == matchlen &&
+ !memcmp(s2->name, transform->name, matchlen)) {
+ /*
+ * Found it -- establish the proper relationship
+ */
+ SuffInsert(&s->children, s2);
+ SuffInsert(&s2->parents, s);
+ break;
+ }
}
}
return(0);
@@ -925,8 +897,8 @@ SuffScanTargets(GNode *target, GNodeSuff
fprintf(debug_file, "defining transformation from `%s' to `%s'\n",
s->name, t->name);
}
- SuffInsert(t->children, s);
- SuffInsert(s->parents, t);
+ SuffInsert(&t->children, s);
+ SuffInsert(&s->parents, t);
}
return 0;
}
@@ -950,30 +922,70 @@ SuffScanTargets(GNode *target, GNodeSuff
* transform and that target happened to be the main target.
*-----------------------------------------------------------------------
*/
+
+static Suff *
+SuffFindByName(const char *name)
+{
+ unsigned i, num;
+ Suff *s;
+
+ num = sufflist_num(&sufflist);
+ for (i=0; i<num; i++) {
+ s = sufflist_get(&sufflist, i);
+ if (!strcmp(s->name, name)) {
+ return s;
+ }
+ }
+ return NULL;
+}
+
+static Suff *
+SuffFindBySuffix(struct sufflist *list, const char *name)
+{
+ unsigned i, num;
+ Suff *s;
+ SuffixCmpData sd; /* Search string data */
+
+ sd.len = strlen(name);
+ sd.ename = name + sd.len;
+
+ num = sufflist_num(list);
+ for (i=0; i<num; i++) {
+ s = sufflist_get(list, i);
+ if (SuffSuffIsSuffix(s, &sd) != NULL) {
+ return s;
+ }
+ }
+ return NULL;
+}
+
void
Suff_AddSuffix(char *str, GNode **gn)
{
- Suff *s; /* new suffix descriptor */
- LstNode ln;
- GNodeSuff gs;
- GList *alltargets;
- unsigned i, num;
+ Suff *s; /* new suffix descriptor */
+ GNodeSuff gs;
+ GList *alltargets;
+ unsigned i, num;
+
+ s = SuffFindByName(str);
+ if (s != NULL) {
+ /* Already exists. */
+ return;
+ }
- ln = Lst_Find(sufflist, str, SuffSuffHasNameP);
- if (ln == NULL) {
s = bmake_malloc(sizeof(Suff));
s->name = bmake_strdup(str);
s->nameLen = strlen(s->name);
patharray_init(&s->searchPath);
- s->children = Lst_Init(FALSE);
- s->parents = Lst_Init(FALSE);
+ sufflist_init(&s->children);
+ sufflist_init(&s->parents);
s->ref = Lst_Init(FALSE);
s->sNum = sNum++;
s->flags = 0;
s->refCount = 1;
- (void)Lst_AtEnd(sufflist, s);
+ sufflist_add(&sufflist, s, NULL);
/*
* We also look at our existing targets list to see if adding
* this suffix will make one of our current targets mutate into
@@ -996,7 +1008,6 @@ Suff_AddSuffix(char *str, GNode **gn)
* XXX: Only do this after a Suff_ClearSuffixes?
*/
Lst_ForEach(transforms, SuffRebuildGraph, s);
- }
}
/*-
@@ -1015,14 +1026,12 @@ Suff_AddSuffix(char *str, GNode **gn)
struct patharray *
Suff_GetPath(char *sname)
{
- LstNode ln;
Suff *s;
- ln = Lst_Find(sufflist, sname, SuffSuffHasNameP);
- if (ln == NULL) {
+ s = SuffFindByName(sname);
+ if (s == NULL) {
return NULL;
} else {
- s = (Suff *)Lst_Datum(ln);
return &s->searchPath;
}
}
@@ -1050,21 +1059,17 @@ void
Suff_DoPaths(void)
{
Suff *s;
- LstNode ln;
char *ptr;
struct patharray inIncludes; /* Cumulative .INCLUDES path */
struct patharray inLibs; /* Cumulative .LIBS path */
unsigned i, num;
- if (Lst_Open(sufflist) == FAILURE) {
- return;
- }
-
patharray_init(&inIncludes);
patharray_init(&inLibs);
- while ((ln = Lst_Next(sufflist)) != NULL) {
- s = (Suff *)Lst_Datum(ln);
+ num = sufflist_num(&sufflist);
+ for (i=0; i<num; i++) {
+ s = sufflist_get(&sufflist, i);
if (patharray_num(&s->searchPath) > 0) {
#ifdef INCLUDES
if (s->flags & SUFF_INCLUDE) {
@@ -1076,8 +1081,6 @@ Suff_DoPaths(void)
Dir_Concat(&inLibs, &s->searchPath);
}
#endif /* LIBRARIES */
- } else {
- num = patharray_num(&s->searchPath);
}
Dir_Concat(&s->searchPath, &dirSearchPath);
}
@@ -1103,8 +1106,6 @@ Suff_DoPaths(void)
}
patharray_setsize(&inLibs, 0);
patharray_cleanup(&inLibs);
-
- Lst_Close(sufflist);
}
/*-
@@ -1128,12 +1129,10 @@ Suff_DoPaths(void)
void
Suff_AddInclude(char *sname)
{
- LstNode ln;
Suff *s;
- ln = Lst_Find(sufflist, sname, SuffSuffHasNameP);
- if (ln != NULL) {
- s = (Suff *)Lst_Datum(ln);
+ s = SuffFindByName(sname);
+ if (s != NULL) {
s->flags |= SUFF_INCLUDE;
}
}
@@ -1160,12 +1159,10 @@ Suff_AddInclude(char *sname)
void
Suff_AddLib(char *sname)
{
- LstNode ln;
Suff *s;
- ln = Lst_Find(sufflist, sname, SuffSuffHasNameP);
- if (ln != NULL) {
- s = (Suff *)Lst_Datum(ln);
+ s = SuffFindByName(sname);
+ if (s != NULL) {
s->flags |= SUFF_LIBRARY;
}
}
@@ -1180,25 +1177,21 @@ Suff_AddLib(char *sname)
* 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
+ * s suffix for which to create a Src structure
+ * ll list for the new Src
+ * targ parent for the new Src
*
* Results:
- * always returns 0
+ * nil
*
* Side Effects:
* A Src structure is created and tacked onto the end of the list
*-----------------------------------------------------------------------
*/
-static int
-SuffAddSrc(void *sp, void *lsp)
+static void
+SuffAddSrc(Suff *s, Lst ll, Src *targ)
{
- Suff *s = (Suff *)sp;
- LstSrc *ls = (LstSrc *)lsp;
Src *s2; /* new Src structure */
- Src *targ; /* Target structure */
-
- targ = ls->s;
if ((s->flags & SUFF_NULL) && (*s->name != '\0')) {
/*
@@ -1215,7 +1208,7 @@ SuffAddSrc(void *sp, void *lsp)
s->refCount++;
s2->children = 0;
targ->children += 1;
- (void)Lst_AtEnd(ls->l, s2);
+ (void)Lst_AtEnd(ll, s2);
#ifdef DEBUG_SRC
s2->cp = Lst_Init(FALSE);
Lst_AtEnd(targ->cp, s2);
@@ -1233,7 +1226,7 @@ SuffAddSrc(void *sp, void *lsp)
s->refCount++;
s2->children = 0;
targ->children += 1;
- (void)Lst_AtEnd(ls->l, s2);
+ (void)Lst_AtEnd(ll, s2);
#ifdef DEBUG_SRC
s2->cp = Lst_Init(FALSE);
Lst_AtEnd(targ->cp, s2);
@@ -1241,8 +1234,6 @@ SuffAddSrc(void *sp, void *lsp)
Lst_ForEach(ls->l, PrintAddr, NULL);
fprintf(debug_file, "\n");
#endif
-
- return(0);
}
/*-
@@ -1264,12 +1255,14 @@ SuffAddSrc(void *sp, void *lsp)
static void
SuffAddLevel(Lst l, Src *targ)
{
- LstSrc ls;
+ unsigned i, num;
+ Suff *s;
- ls.s = targ;
- ls.l = l;
-
- Lst_ForEach(targ->suff->children, SuffAddSrc, &ls);
+ num = sufflist_num(&targ->suff->children);
+ for (i=0; i<num; i++) {
+ s = sufflist_get(&targ->suff->children, i);
+ SuffAddSrc(s, l, targ);
+ }
}
/*-
@@ -1426,7 +1419,6 @@ SuffFindThem(Lst srcs, Lst slst)
static Src *
SuffFindCmds(Src *targ, Lst slst)
{
- LstNode ln; /* General-purpose list node */
GNode *t, /* Target GNode */
*s; /* Source GNode */
int prefLen;/* The length of the defined prefix */
@@ -1469,8 +1461,8 @@ 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);
- if (ln == NULL)
+ suff = SuffFindByName(&cp[prefLen]);
+ if (suff == NULL)
continue;
/*
* It even has a known suffix, see if there's a transformation
@@ -1478,10 +1470,10 @@ SuffFindCmds(Src *targ, Lst slst)
*
* XXX: Handle multi-stage transformations here, too.
*/
- suff = (Suff *)Lst_Datum(ln);
- if (Lst_Member(suff->parents, targ->suff) != NULL)
+ if (sufflist_contains(&suff->parents, targ->suff)) {
break;
+ }
}
/*
@@ -1802,17 +1794,10 @@ Suff_FindPath(GNode* gn)
Suff *suff = gn->suffix;
if (suff == NULL) {
- SuffixCmpData sd; /* Search string data */
- LstNode ln;
- sd.len = strlen(gn->name);
- sd.ename = gn->name + sd.len;
- ln = Lst_Find(sufflist, &sd, SuffSuffIsSuffixP);
-
+ suff = SuffFindBySuffix(&sufflist, gn->name);
if (DEBUG(SUFF)) {
fprintf(debug_file, "Wildcard expanding \"%s\"...", gn->name);
}
- if (ln != NULL)
- suff = (Suff *)Lst_Datum(ln);
/* XXX: Here we can save the suffix so we don't have to do this again */
}
@@ -2017,25 +2002,19 @@ SuffFindArchiveDeps(GNode *gn, Lst slst)
* through the entire list, we just look at suffixes to which the
* member's suffix may be transformed...
*/
- LstNode ln;
- SuffixCmpData sd; /* Search string data */
+ Suff *suff;
/*
* Use first matching suffix...
*/
- sd.len = eoarch - gn->name;
- sd.ename = eoarch;
- ln = Lst_Find(ms->parents, &sd, SuffSuffIsSuffixP);
-
- if (ln != NULL) {
+ suff = SuffFindBySuffix(&ms->parents, eoarch);
+ if (suff != NULL) {
/*
* Got one -- apply it
*/
- if (!SuffApplyTransform(gn, mem, (Suff *)Lst_Datum(ln), ms) &&
- DEBUG(SUFF))
- {
+ if (!SuffApplyTransform(gn, mem, suff, ms) && DEBUG(SUFF)) {
fprintf(debug_file, "\tNo transformation from %s -> %s\n",
- ms->name, ((Suff *)Lst_Datum(ln))->name);
+ ms->name, suff->name);
}
}
}
@@ -2083,7 +2062,6 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
{
char *eoname; /* End of name */
char *sopref; /* Start of prefix */
- LstNode ln; /* Next suffix node to check */
Lst srcs; /* List of sources at which to look */
Lst targs; /* List of targets to which things can be
* transformed. They all have the same file,
@@ -2093,6 +2071,8 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
char *pref; /* Prefix to use */
Src *targ; /* General Src target pointer */
SuffixCmpData sd; /* Search string data */
+ unsigned pos, num;
+ Suff *suff;
sd.len = strlen(gn->name);
@@ -2100,10 +2080,11 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
sopref = gn->name;
+ num = sufflist_num(&sufflist);
+
/*
* Begin at the beginning...
*/
- ln = Lst_First(sufflist);
srcs = Lst_Init(FALSE);
targs = Lst_Init(FALSE);
@@ -2126,13 +2107,14 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
* Should we find one, we discard the one we found before.
*/
- while (ln != NULL) {
- /*
- * Look for next possible suffix...
- */
- ln = Lst_FindFrom(sufflist, ln, &sd, SuffSuffIsSuffixP);
+ for (pos = 0; pos < num; pos++) {
+ suff = sufflist_get(&sufflist, pos);
+ if (SuffSuffIsSuffix(suff, &sd)) {
+
+ /*
+ * Next possible suffix...
+ */
- if (ln != NULL) {
int prefLen; /* Length of the prefix */
/*
@@ -2140,7 +2122,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
*/
targ = bmake_malloc(sizeof(Src));
targ->file = bmake_strdup(gn->name);
- targ->suff = (Suff *)Lst_Datum(ln);
+ targ->suff = suff;
targ->suff->refCount++;
targ->node = gn;
targ->parent = NULL;
@@ -2167,11 +2149,6 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
* Record the target so we can nuke it
*/
(void)Lst_AtEnd(targs, targ);
-
- /*
- * Search from this suffix's successor...
- */
- ln = Lst_Succ(ln);
}
}
@@ -2513,14 +2490,13 @@ SuffFindDeps(GNode *gn, Lst slst)
* set the TARGET variable to the node's name in order to give it a
* value).
*/
- LstNode ln;
Suff *s;
- ln = Lst_Find(sufflist, LIBSUFF, SuffSuffHasNameP);
+ s = SuffFindByName(LIBSUFF);
if (gn->suffix)
gn->suffix->refCount--;
- if (ln != NULL) {
- gn->suffix = s = (Suff *)Lst_Datum(ln);
+ if (s != NULL) {
+ gn->suffix = s;
gn->suffix->refCount++;
Arch_FindLib(gn, &s->searchPath);
} else {
@@ -2562,11 +2538,9 @@ void
Suff_SetNull(char *name)
{
Suff *s;
- LstNode ln;
- ln = Lst_Find(sufflist, name, SuffSuffHasNameP);
- if (ln != NULL) {
- s = (Suff *)Lst_Datum(ln);
+ s = SuffFindByName(name);
+ if (s != NULL) {
if (suffNull != NULL) {
suffNull->flags &= ~SUFF_NULL;
}
@@ -2596,9 +2570,9 @@ Suff_SetNull(char *name)
void
Suff_Init(void)
{
- sufflist = Lst_Init(FALSE);
+ sufflist_init(&sufflist);
#ifdef CLEANUP
- suffClean = Lst_Init(FALSE);
+ sufflist_init(&suffClean);
#endif
srclist = Lst_Init(FALSE);
transforms = Lst_Init(FALSE);
@@ -2615,8 +2589,8 @@ Suff_Init(void)
suffNull->nameLen = 0;
patharray_init(&suffNull->searchPath);
Dir_Concat(&suffNull->searchPath, &dirSearchPath);
- suffNull->children = Lst_Init(FALSE);
- suffNull->parents = Lst_Init(FALSE);
+ sufflist_init(&suffNull->children);
+ sufflist_init(&suffNull->parents);
suffNull->ref = Lst_Init(FALSE);
suffNull->sNum = sNum++;
suffNull->flags = SUFF_NULL;
@@ -2638,14 +2612,30 @@ Suff_Init(void)
*----------------------------------------------------------------------
*/
+static void
+sufflist_purge(struct sufflist *l)
+{
+ unsigned i, num;
+ Suff *s;
+
+ num = sufflist_num(l);
+ for (i=0; i<num; i++) {
+ s = sufflist_get(l, i);
+ SuffFree(s);
+ }
+ sufflist_setsize(l, 0);
+}
+
void
Suff_End(void)
{
#ifdef CLEANUP
- Lst_Destroy(sufflist, SuffFree);
- Lst_Destroy(suffClean, SuffFree);
- if (suffNull)
- SuffFree(suffNull);
+ sufflist_purge(&sufflist);
+ sufflist_purge(&suffClean);
+ sufflist_cleanup(&sufflist);
+ sufflist_cleanup(&suffClean);
+ if (suffNull)
+ SuffFree(suffNull);
Lst_Destroy(srclist, NULL);
Lst_Destroy(transforms, NULL);
#endif
@@ -2654,18 +2644,18 @@ Suff_End(void)
/********************* DEBUGGING FUNCTIONS **********************/
-static int SuffPrintName(void *s, void *dummy)
+static void
+SuffPrintName(Suff *s)
{
- fprintf(debug_file, "%s ", ((Suff *)s)->name);
- return (dummy ? 0 : 0);
+ fprintf(debug_file, "%s ", s->name);
}
-static int
-SuffPrintSuff(void *sp, void *dummy)
+static void
+SuffPrintSuff(Suff *s)
{
- Suff *s = (Suff *)sp;
int flags;
int flag;
+ unsigned i, num;
fprintf(debug_file, "# `%s' [%d] ", s->name, s->refCount);
@@ -2690,16 +2680,24 @@ SuffPrintSuff(void *sp, void *dummy)
}
}
fputc('\n', debug_file);
+
fprintf(debug_file, "#\tTo: ");
- Lst_ForEach(s->parents, SuffPrintName, NULL);
+ num = sufflist_num(&s->parents);
+ for (i=0; i<num; i++) {
+ SuffPrintName(sufflist_get(&s->parents, i));
+ }
fputc('\n', debug_file);
+
fprintf(debug_file, "#\tFrom: ");
- Lst_ForEach(s->children, SuffPrintName, NULL);
+ num = sufflist_num(&s->children);
+ for (i=0; i<num; i++) {
+ SuffPrintName(sufflist_get(&s->children, i));
+ }
fputc('\n', debug_file);
+
fprintf(debug_file, "#\tSearch Path: ");
Dir_PrintPath(&s->searchPath);
fputc('\n', debug_file);
- return (dummy ? 0 : 0);
}
static int
@@ -2721,8 +2719,13 @@ SuffPrintTrans(void *tp, void *dummy)
void
Suff_PrintAll(void)
{
+ unsigned i, num;
+
fprintf(debug_file, "#*** Suffixes:\n");
- Lst_ForEach(sufflist, SuffPrintSuff, NULL);
+ num = sufflist_num(&sufflist);
+ for (i=0; i<num; i++) {
+ SuffPrintSuff(sufflist_get(&sufflist, i));
+ }
fprintf(debug_file, "#*** Transformations:\n");
Lst_ForEach(transforms, SuffPrintTrans, NULL);