Module Name: othersrc
Committed By: dholland
Date: Sat Mar 23 17:56: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.13 -r1.14 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.13 othersrc/usr.bin/dholland-make2/suff.c:1.14
--- othersrc/usr.bin/dholland-make2/suff.c:1.13 Sat Mar 23 17:47:11 2013
+++ othersrc/usr.bin/dholland-make2/suff.c Sat Mar 23 17:56:58 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: suff.c,v 1.13 2013/03/23 17:47:11 dholland Exp $ */
+/* $NetBSD: suff.c,v 1.14 2013/03/23 17:56: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.13 2013/03/23 17:47:11 dholland Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.14 2013/03/23 17:56:58 dholland Exp $");
#define CLEANUP
@@ -205,7 +205,7 @@ static struct sufflist sufflist; /* all
static struct sufflist suffClean; /* suffixes to be cleaned */
#endif
static struct srclist srclist; /* sources */
-static Lst transforms; /* Lst of transformation rules */
+static GList transforms; /* transformation rules */
static int sNum = 0; /* Counter for assigning suffix numbers */
@@ -216,13 +216,12 @@ static Suff *emptySuff; /* The empt
static const char *SuffStrIsPrefix(const char *, const char *);
static const char *SuffSuffIsSuffix(const Suff *, const SuffixCmpData *);
-static int SuffGNHasNameP(const void *, const void *);
static void SuffUnRef(struct sufflist *, Suff *);
static void SuffFree(void *);
static void SuffInsert(struct sufflist *, Suff *);
static void SuffRemove(struct sufflist *, Suff *);
static Boolean SuffParseTransform(char *, Suff **, Suff **);
-static int SuffRebuildGraph(void *, void *);
+static void SuffRebuildGraph(GNode *, Suff *);
static void SuffAddSrc(Suff *, struct srclist *, Src *);
static int SuffRemoveSrc(struct srclist *);
static void SuffAddLevel(struct srclist *, Src *);
@@ -236,7 +235,7 @@ static void SuffFindArchiveDeps(GNode *,
static void SuffFindNormalDeps(GNode *, struct srclist *);
static void SuffPrintName(Suff *);
static void SuffPrintSuff(Suff *);
-static int SuffPrintTrans(void *, void *);
+static void SuffPrintTrans(GNode *);
/*************** Lst Predicates ****************/
/*-
@@ -306,24 +305,33 @@ SuffSuffIsSuffix(const Suff *s, const Su
/*-
*-----------------------------------------------------------------------
- * SuffGNHasNameP --
- * See if the graph node has the desired name
+ * findtransform --
+ * find an entry in transforms[] by name
*
* Input:
- * gn current node we're looking at
- * name name we're looking for
+ * name name of node we're looking for
*
* Results:
- * 0 if it does. non-zero if it doesn't
+ * the GNode, or NULL if it's not there
*
* Side Effects:
* None
*-----------------------------------------------------------------------
*/
-static int
-SuffGNHasNameP(const void *gn, const void *name)
+static GNode *
+findtransform(const char *name)
{
- return (strcmp(name, ((const GNode *)gn)->name));
+ unsigned i, num;
+ GNode *gn;
+
+ num = glist_num(&transforms);
+ for (i=0; i<num; i++) {
+ gn = glist_get(&transforms, i);
+ if (!strcmp(name, gn->name)) {
+ return gn;
+ }
+ }
+ return NULL;
}
/*********** Maintenance Functions ************/
@@ -638,7 +646,7 @@ Suff_IsTransform(char *str)
* 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
+ * The node is placed on the end of transforms[] and links are
* made between the two suffixes mentioned in the target name
*-----------------------------------------------------------------------
*/
@@ -648,16 +656,15 @@ Suff_AddTransform(char *line)
GNode *gn; /* GNode of transformation rule */
Suff *s, /* source suffix */
*t; /* target suffix */
- LstNode ln; /* Node for existing transformation */
- ln = Lst_Find(transforms, line, SuffGNHasNameP);
- if (ln == NULL) {
+ gn = findtransform(line);
+ if (gn == 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);
+ glist_add(&transforms, gn, NULL);
} else {
/*
* New specification for transformation rule. Just nuke the old list
@@ -665,7 +672,6 @@ Suff_AddTransform(char *line)
* free the commands themselves, because a given command can be
* attached to several different transformations.
*/
- gn = (GNode *)Lst_Datum(ln);
stringarray_setsize(&gn->commands, 0);
glist_setsize(&gn->children, 0);
}
@@ -783,11 +789,9 @@ Suff_EndTransform(void *gnp, void *dummy
*
*-----------------------------------------------------------------------
*/
-static int
-SuffRebuildGraph(void *transformp, void *sp)
+static void
+SuffRebuildGraph(GNode *transform, Suff *s)
{
- GNode *transform = (GNode *)transformp;
- Suff *s = (Suff *)sp;
const char *cp;
Suff *s2;
SuffixCmpData sd;
@@ -810,7 +814,7 @@ SuffRebuildGraph(void *transformp, void
*/
SuffInsert(&s2->children, s);
SuffInsert(&s->parents, s2);
- return 0;
+ return;
}
}
}
@@ -844,7 +848,6 @@ SuffRebuildGraph(void *transformp, void
}
}
}
- return(0);
}
/*-
@@ -1007,7 +1010,10 @@ Suff_AddSuffix(char *str, GNode **gn)
* Look for any existing transformations from or to this suffix.
* XXX: Only do this after a Suff_ClearSuffixes?
*/
- Lst_ForEach(transforms, SuffRebuildGraph, s);
+ num = glist_num(&transforms);
+ for (i=0; i<num; i++) {
+ SuffRebuildGraph(glist_get(&transforms, i), s);
+ }
}
/*-
@@ -1846,7 +1852,6 @@ Suff_FindPath(GNode* gn)
static Boolean
SuffApplyTransform(GNode *tGn, GNode *sGn, Suff *t, Suff *s)
{
- LstNode ln; /* General node */
char *tname; /* Name of transformation rule */
GNode *gn; /* Node for same */
unsigned pos, i;
@@ -1862,10 +1867,10 @@ SuffApplyTransform(GNode *tGn, GNode *sG
* Locate the transformation rule itself
*/
tname = str_concat(s->name, t->name, 0);
- ln = Lst_Find(transforms, tname, SuffGNHasNameP);
+ gn = findtransform(tname);
free(tname);
- if (ln == NULL) {
+ if (gn == NULL) {
/*
* Not really such a transformation rule (can happen when we're
* called to link an OP_MEMBER and OP_ARCHV node), so return
@@ -1874,8 +1879,6 @@ SuffApplyTransform(GNode *tGn, GNode *sG
return(FALSE);
}
- gn = (GNode *)Lst_Datum(ln);
-
if (DEBUG(SUFF)) {
fprintf(debug_file, "\tapplying %s -> %s to \"%s\"\n", s->name, t->name, tGn->name);
}
@@ -2595,7 +2598,7 @@ Suff_Init(void)
sufflist_init(&suffClean);
#endif
srclist_init(&srclist);
- transforms = Lst_Init(FALSE);
+ glist_init(&transforms);
sNum = 0;
/*
@@ -2655,7 +2658,8 @@ Suff_End(void)
if (suffNull)
SuffFree(suffNull);
srclist_cleanup(&srclist);
- Lst_Destroy(transforms, NULL);
+ glist_setsize(&transforms, 0);
+ glist_cleanup(&transforms);
#endif
}
@@ -2718,10 +2722,9 @@ SuffPrintSuff(Suff *s)
fputc('\n', debug_file);
}
-static int
-SuffPrintTrans(void *tp, void *dummy)
+static void
+SuffPrintTrans(GNode *t)
{
- GNode *t = (GNode *)tp;
unsigned i;
fprintf(debug_file, "%-16s: ", t->name);
@@ -2731,7 +2734,6 @@ SuffPrintTrans(void *tp, void *dummy)
Targ_PrintCmd(stringarray_get(&t->commands, i));
}
fputc('\n', debug_file);
- return(dummy ? 0 : 0);
}
void
@@ -2746,5 +2748,8 @@ Suff_PrintAll(void)
}
fprintf(debug_file, "#*** Transformations:\n");
- Lst_ForEach(transforms, SuffPrintTrans, NULL);
+ num = glist_num(&transforms);
+ for (i=0; i<num; i++) {
+ SuffPrintTrans(glist_get(&transforms, i));
+ }
}