Module Name: othersrc
Committed By: dholland
Date: Sat Mar 23 17:33:58 UTC 2013
Modified Files:
othersrc/usr.bin/dholland-make2: suff.c
Log Message:
More arrays, fewer lists.
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 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/suff.c
diff -u othersrc/usr.bin/dholland-make2/suff.c:1.10 othersrc/usr.bin/dholland-make2/suff.c:1.11
--- othersrc/usr.bin/dholland-make2/suff.c:1.10 Sat Mar 23 17:09:40 2013
+++ othersrc/usr.bin/dholland-make2/suff.c Sat Mar 23 17:33:58 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: suff.c,v 1.10 2013/03/23 17:09:40 dholland Exp $ */
+/* $NetBSD: suff.c,v 1.11 2013/03/23 17:33:58 dholland Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
#include "hash.h"
#include "dir.h"
-MAKE_RCSID("$NetBSD: suff.c,v 1.10 2013/03/23 17:09:40 dholland Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.11 2013/03/23 17:33:58 dholland Exp $");
/*
* Structure describing an individual suffix.
@@ -168,11 +168,15 @@ typedef struct {
/*
* Structure used in the search for implied sources.
*/
-typedef struct _Src {
+
+struct Src;
+DECLARRAY_BYTYPE(srclist, struct Src, static);
+
+typedef struct Src {
char *file; /* The file to look for */
char *pref; /* Prefix from which file was formed */
Suff *suff; /* The suffix on the file */
- struct _Src *parent; /* The Src for which this is a source */
+ struct Src *parent; /* The Src for which this is a source */
GNode *node; /* The node describing the file */
int children; /* Count of existing children (so we don't free
* this thing too early or never nuke it) */
@@ -193,14 +197,15 @@ typedef struct {
} GNodeSuff;
DEFARRAY_BYTYPE(sufflist, Suff, MAKE_ATTR_UNUSED static);
+DEFARRAY_BYTYPE(srclist, Src, MAKE_ATTR_UNUSED static);
#define CLEANUP
-static struct sufflist sufflist; /* suffixes */
+static struct sufflist sufflist; /* all current suffixes */
#ifdef CLEANUP
static struct sufflist suffClean; /* suffixes to be cleaned */
#endif
-static Lst srclist; /* Lst of sources */
+static struct srclist srclist; /* sources */
static Lst transforms; /* Lst of transformation rules */
static int sNum = 0; /* Counter for assigning suffix numbers */
@@ -219,17 +224,17 @@ static void SuffInsert(struct sufflist *
static void SuffRemove(struct sufflist *, Suff *);
static Boolean SuffParseTransform(char *, Suff **, Suff **);
static int SuffRebuildGraph(void *, void *);
-static void SuffAddSrc(Suff *, Lst, Src *);
-static int SuffRemoveSrc(Lst);
-static void SuffAddLevel(Lst, Src *);
-static Src *SuffFindThem(Lst, Lst);
-static Src *SuffFindCmds(Src *, Lst);
+static void SuffAddSrc(Suff *, struct srclist *, Src *);
+static int SuffRemoveSrc(struct srclist *);
+static void SuffAddLevel(struct srclist *, Src *);
+static Src *SuffFindThem(struct srclist *, struct srclist *);
+static Src *SuffFindCmds(Src *, struct srclist *);
static unsigned SuffExpandChildren(GNode *, unsigned, GNode *);
static unsigned SuffExpandWildcards(GNode *, unsigned, GNode *);
static Boolean SuffApplyTransform(GNode *, GNode *, Suff *, Suff *);
-static void SuffFindDeps(GNode *, Lst);
-static void SuffFindArchiveDeps(GNode *, Lst);
-static void SuffFindNormalDeps(GNode *, Lst);
+static void SuffFindDeps(GNode *, struct srclist *);
+static void SuffFindArchiveDeps(GNode *, struct srclist *);
+static void SuffFindNormalDeps(GNode *, struct srclist *);
static void SuffPrintName(Suff *);
static void SuffPrintSuff(Suff *);
static int SuffPrintTrans(void *, void *);
@@ -1189,7 +1194,7 @@ Suff_AddLib(char *sname)
*-----------------------------------------------------------------------
*/
static void
-SuffAddSrc(Suff *s, Lst ll, Src *targ)
+SuffAddSrc(Suff *s, struct srclist *ll, Src *targ)
{
Src *s2; /* new Src structure */
@@ -1208,7 +1213,7 @@ SuffAddSrc(Suff *s, Lst ll, Src *targ)
s->refCount++;
s2->children = 0;
targ->children += 1;
- (void)Lst_AtEnd(ll, s2);
+ srclist_add(ll, s2, NULL);
#ifdef DEBUG_SRC
s2->cp = Lst_Init(FALSE);
Lst_AtEnd(targ->cp, s2);
@@ -1226,7 +1231,7 @@ SuffAddSrc(Suff *s, Lst ll, Src *targ)
s->refCount++;
s2->children = 0;
targ->children += 1;
- (void)Lst_AtEnd(ll, s2);
+ srclist_add(ll, s2, NULL);
#ifdef DEBUG_SRC
s2->cp = Lst_Init(FALSE);
Lst_AtEnd(targ->cp, s2);
@@ -1253,7 +1258,7 @@ SuffAddSrc(Suff *s, Lst ll, Src *targ)
*-----------------------------------------------------------------------
*/
static void
-SuffAddLevel(Lst l, Src *targ)
+SuffAddLevel(struct srclist *l, Src *targ)
{
unsigned i, num;
Suff *s;
@@ -1278,24 +1283,20 @@ SuffAddLevel(Lst l, Src *targ)
*----------------------------------------------------------------------
*/
static int
-SuffRemoveSrc(Lst l)
+SuffRemoveSrc(struct srclist *l)
{
- LstNode ln;
Src *s;
- int t = 0;
+ unsigned i, num;
- if (Lst_Open(l) == FAILURE) {
- return 0;
- }
#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);
+ num = srclist_num(l);
+ for (i=0; i<num; i++) {
+ s = srclist_get(l, i);
if (s->children == 0) {
free(s->file);
if (!s->parent)
@@ -1312,10 +1313,8 @@ SuffRemoveSrc(Lst l)
fprintf(debug_file, "free: [l=%x] p=%x %d\n", l, s, s->children);
Lst_Destroy(s->cp, NULL);
#endif
- Lst_Remove(l, ln);
+ srclist_remove(l, i);
free(s);
- t |= 1;
- Lst_Close(l);
return TRUE;
}
#ifdef DEBUG_SRC
@@ -1327,9 +1326,7 @@ SuffRemoveSrc(Lst l)
#endif
}
- Lst_Close(l);
-
- return t;
+ return FALSE;
}
/*-
@@ -1348,7 +1345,7 @@ SuffRemoveSrc(Lst l)
*-----------------------------------------------------------------------
*/
static Src *
-SuffFindThem(Lst srcs, Lst slst)
+SuffFindThem(struct srclist *srcs, struct srclist *slst)
{
Src *s; /* current Src */
Src *rs; /* returned Src */
@@ -1356,8 +1353,10 @@ SuffFindThem(Lst srcs, Lst slst)
rs = NULL;
- while (!Lst_IsEmpty (srcs)) {
- s = (Src *)Lst_DeQueue(srcs);
+ /* XXX there must be a better way to write this loop */
+ while (srclist_num(srcs) > 0) {
+ s = srclist_get(srcs, 0);
+ srclist_remove(srcs, 0);
if (DEBUG(SUFF)) {
fprintf(debug_file, "\ttrying %s...", s->file);
@@ -1389,7 +1388,7 @@ SuffFindThem(Lst srcs, Lst slst)
}
SuffAddLevel(srcs, s);
- Lst_AtEnd(slst, s);
+ srclist_add(slst, s, NULL);
}
if (DEBUG(SUFF) && rs) {
@@ -1417,7 +1416,7 @@ SuffFindThem(Lst srcs, Lst slst)
*-----------------------------------------------------------------------
*/
static Src *
-SuffFindCmds(Src *targ, Lst slst)
+SuffFindCmds(Src *targ, struct srclist *slst)
{
GNode *t, /* Target GNode */
*s; /* Source GNode */
@@ -1496,7 +1495,7 @@ SuffFindCmds(Src *targ, Lst slst)
fprintf(debug_file, "3 add %x %x\n", targ, ret);
Lst_AtEnd(targ->cp, ret);
#endif
- Lst_AtEnd(slst, ret);
+ srclist_add(slst, ret, NULL);
if (DEBUG(SUFF)) {
fprintf(debug_file, "\tusing existing source %s\n", s->name);
}
@@ -1923,7 +1922,7 @@ SuffApplyTransform(GNode *tGn, GNode *sG
*-----------------------------------------------------------------------
*/
static void
-SuffFindArchiveDeps(GNode *gn, Lst slst)
+SuffFindArchiveDeps(GNode *gn, struct srclist *slst)
{
char *eoarch; /* End of archive portion */
char *eoname; /* End of member portion */
@@ -2058,12 +2057,12 @@ SuffFindArchiveDeps(GNode *gn, Lst slst)
*-----------------------------------------------------------------------
*/
static void
-SuffFindNormalDeps(GNode *gn, Lst slst)
+SuffFindNormalDeps(GNode *gn, struct srclist *slst)
{
char *eoname; /* End of name */
char *sopref; /* Start of prefix */
- Lst srcs; /* List of sources at which to look */
- Lst targs; /* List of targets to which things can be
+ struct srclist srcs; /* Sources at which to look */
+ struct srclist targs; /* Targets to which things can be
* transformed. They all have the same file,
* but different suff and pref fields */
Src *bottom; /* Start of found transformation path */
@@ -2071,7 +2070,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
char *pref; /* Prefix to use */
Src *targ; /* General Src target pointer */
SuffixCmpData sd; /* Search string data */
- unsigned pos, num;
+ unsigned pos, i, num;
Suff *suff;
@@ -2085,8 +2084,8 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
/*
* Begin at the beginning...
*/
- srcs = Lst_Init(FALSE);
- targs = Lst_Init(FALSE);
+ srclist_init(&srcs);
+ srclist_init(&targs);
/*
* We're caught in a catch-22 here. On the one hand, we want to use any
@@ -2143,19 +2142,19 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
/*
* Add nodes from which the target can be made
*/
- SuffAddLevel(srcs, targ);
+ SuffAddLevel(&srcs, targ);
/*
* Record the target so we can nuke it
*/
- (void)Lst_AtEnd(targs, targ);
+ srclist_add(&targs, targ, NULL);
}
}
/*
* Handle target of unknown suffix...
*/
- if (Lst_IsEmpty(targs) && suffNull != NULL) {
+ if (srclist_num(&targs) == 0 && suffNull != NULL) {
if (DEBUG(SUFF)) {
fprintf(debug_file, "\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
}
@@ -2179,7 +2178,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
* don't do this anymore.
*/
if (stringarray_num(&gn->commands) == 0)
- SuffAddLevel(srcs, targ);
+ SuffAddLevel(&srcs, targ);
else {
if (DEBUG(SUFF))
fprintf(debug_file, "not ");
@@ -2188,22 +2187,22 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
if (DEBUG(SUFF))
fprintf(debug_file, "adding suffix rules\n");
- (void)Lst_AtEnd(targs, targ);
+ srclist_add(&targs, targ, NULL);
}
/*
* Using the list of possible sources built up from the target suffix(es),
* try and find an existing file/target that matches.
*/
- bottom = SuffFindThem(srcs, slst);
+ bottom = SuffFindThem(&srcs, slst);
if (bottom == NULL) {
/*
* No known transformations -- use the first suffix found for setting
* the local variables.
*/
- if (!Lst_IsEmpty(targs)) {
- targ = (Src *)Lst_Datum(Lst_First(targs));
+ if (srclist_num(&targs) > 0) {
+ targ = srclist_get(&targs, 0);
} else {
targ = NULL;
}
@@ -2323,8 +2322,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 (!srclist_contains(slst, bottom)) {
+ srclist_add(slst, bottom, NULL);
}
bottom = bottom->parent;
}
@@ -2398,15 +2397,30 @@ sfnd_abort:
* two lists.
*/
sfnd_return:
- if (bottom)
- if (Lst_Member(slst, bottom) == NULL)
- Lst_AtEnd(slst, bottom);
+ if (bottom) {
+ if (!srclist_contains(slst, bottom)) {
+ srclist_add(slst, bottom, NULL);
+ }
+ }
- while (SuffRemoveSrc(srcs) || SuffRemoveSrc(targs))
+ while (SuffRemoveSrc(&srcs) || SuffRemoveSrc(&targs)) {
continue;
+ }
+
+ num = srclist_num(&srcs);
+ for (i=0; i<num; i++) {
+ srclist_add(slst, srclist_get(&srcs, i), NULL);
+ }
+ srclist_setsize(&srcs, 0);
+
+ num = srclist_num(&targs);
+ for (i=0; i<num; i++) {
+ srclist_add(slst, srclist_get(&targs, i), NULL);
+ }
+ srclist_setsize(&targs, 0);
- Lst_Concat(slst, srcs, LST_CONCLINK);
- Lst_Concat(slst, targs, LST_CONCLINK);
+ srclist_cleanup(&srcs);
+ srclist_cleanup(&targs);
}
@@ -2442,8 +2456,8 @@ void
Suff_FindDeps(GNode *gn)
{
- SuffFindDeps(gn, srclist);
- while (SuffRemoveSrc(srclist))
+ SuffFindDeps(gn, &srclist);
+ while (SuffRemoveSrc(&srclist))
continue;
}
@@ -2454,7 +2468,7 @@ Suff_FindDeps(GNode *gn)
*
*/
static void
-SuffFindDeps(GNode *gn, Lst slst)
+SuffFindDeps(GNode *gn, struct srclist *slst)
{
if (gn->type & OP_DEPS_FOUND) {
/*
@@ -2574,7 +2588,7 @@ Suff_Init(void)
#ifdef CLEANUP
sufflist_init(&suffClean);
#endif
- srclist = Lst_Init(FALSE);
+ srclist_init(&srclist);
transforms = Lst_Init(FALSE);
sNum = 0;
@@ -2636,7 +2650,7 @@ Suff_End(void)
sufflist_cleanup(&suffClean);
if (suffNull)
SuffFree(suffNull);
- Lst_Destroy(srclist, NULL);
+ srclist_cleanup(&srclist);
Lst_Destroy(transforms, NULL);
#endif
}