Module Name: othersrc
Committed By: dholland
Date: Mon Mar 4 23:52:07 UTC 2013
Modified Files:
othersrc/usr.bin/dholland-make2: arch.c
Log Message:
Use arrays, not lists.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 othersrc/usr.bin/dholland-make2/arch.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/arch.c
diff -u othersrc/usr.bin/dholland-make2/arch.c:1.3 othersrc/usr.bin/dholland-make2/arch.c:1.4
--- othersrc/usr.bin/dholland-make2/arch.c:1.3 Mon Mar 4 23:03:41 2013
+++ othersrc/usr.bin/dholland-make2/arch.c Mon Mar 4 23:52:07 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: arch.c,v 1.3 2013/03/04 23:03:41 dholland Exp $ */
+/* $NetBSD: arch.c,v 1.4 2013/03/04 23:52:07 dholland Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -137,8 +137,7 @@
#include "dir.h"
#include "config.h"
-MAKE_RCSID("$NetBSD: arch.c,v 1.3 2013/03/04 23:03:41 dholland Exp $");
-
+MAKE_RCSID("$NetBSD: arch.c,v 1.4 2013/03/04 23:52:07 dholland Exp $");
#ifdef TARGET_MACHINE
#undef MAKE_MACHINE
@@ -149,8 +148,6 @@ MAKE_RCSID("$NetBSD: arch.c,v 1.3 2013/0
#define MAKE_MACHINE_ARCH TARGET_MACHINE_ARCH
#endif
-static Lst archives; /* Lst of archives we've already examined */
-
typedef struct Arch {
char *name; /* Name of archive */
Hash_Table members; /* All the members of the archive described
@@ -159,10 +156,10 @@ typedef struct Arch {
size_t fnamesize; /* Size of the string table */
} Arch;
-static int ArchFindArchive(const void *, const void *);
-#ifdef CLEANUP
-static void ArchFree(void *);
-#endif
+DECLARRAY_BYTYPE(archlist, struct Arch, static);
+DEFARRAY_BYTYPE(archlist, struct Arch, MAKE_ATTR_UNUSED static);
+typedef struct archlist ArchList;
+
static struct ar_hdr *ArchStatMember(char *, char *, Boolean);
static FILE *ArchFindMember(char *, char *, struct ar_hdr *, const char *);
#if defined(__svr4__) || defined(__SVR4) || defined(__ELF__)
@@ -170,6 +167,9 @@ static FILE *ArchFindMember(char *, char
static int ArchSVR4Entry(Arch *, char *, size_t, FILE *);
#endif
+/* Archives we've already examined */
+static ArchList archives;
+
#ifdef CLEANUP
/*-
*-----------------------------------------------------------------------
@@ -185,9 +185,8 @@ static int ArchSVR4Entry(Arch *, char *,
*-----------------------------------------------------------------------
*/
static void
-ArchFree(void *ap)
+ArchFree(Arch *a)
{
- Arch *a = (Arch *)ap;
Hash_Search search;
Hash_Entry *entry;
@@ -206,7 +205,6 @@ ArchFree(void *ap)
#endif
-
/*-
*-----------------------------------------------------------------------
* Arch_ParseArchive --
@@ -470,26 +468,34 @@ Arch_ParseArchive(char **linePtr, Lst no
/*-
*-----------------------------------------------------------------------
- * ArchFindArchive --
- * See if the given archive is the one we are looking for. Called
- * From ArchStatMember and ArchFindMember via Lst_Find.
+ * FindArchive --
+ * Find an archive by name. Called from ArchStatMember.
*
* Input:
- * ar Current list element
- * archName Name we want
+ * name Name we want
*
* Results:
- * 0 if it is, non-zero if it isn't.
+ * The archive, or NULL if it doesn't exist.
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
-static int
-ArchFindArchive(const void *ar, const void *archName)
+static Arch *
+FindArchive(const char *name)
{
- return (strcmp(archName, ((const Arch *)ar)->name));
+ unsigned i, num;
+ Arch *a;
+
+ num = archlist_num(&archives);
+ for (i=0; i<num; i++) {
+ a = archlist_get(&archives, i);
+ if (!strcmp(name, a->name)) {
+ return a;
+ }
+ }
+ return NULL;
}
/*-
@@ -523,7 +529,6 @@ ArchStatMember(char *archive, char *memb
int size; /* Size of archive member */
char *cp; /* Useful character pointer */
char magic[SARMAG];
- LstNode ln; /* Lst member containing archive descriptor */
Arch *ar; /* Archive descriptor */
Hash_Entry *he; /* Entry containing member's description */
struct ar_hdr arh; /* archive-member header for reading archive */
@@ -541,10 +546,8 @@ ArchStatMember(char *archive, char *memb
member = cp + 1;
}
- ln = Lst_Find(archives, archive, ArchFindArchive);
- if (ln != NULL) {
- ar = (Arch *)Lst_Datum(ln);
-
+ ar = FindArchive(archive);
+ if (ar != NULL) {
he = Hash_FindEntry(&ar->members, member);
if (he != NULL) {
@@ -688,7 +691,7 @@ ArchStatMember(char *archive, char *memb
fclose(arch);
- (void)Lst_AtEnd(archives, ar);
+ archlist_add(&archives, ar, NULL);
/*
* Now that the archive has been read and cached, we can look into
@@ -1286,7 +1289,7 @@ Arch_LibOODate(GNode *gn)
void
Arch_Init(void)
{
- archives = Lst_Init(FALSE);
+ archlist_init(&archives);
}
@@ -1308,7 +1311,13 @@ void
Arch_End(void)
{
#ifdef CLEANUP
- Lst_Destroy(archives, ArchFree);
+ unsigned i;
+
+ for (i=0; i<archlist_num(&archives); i++) {
+ ArchFree(archlist_get(&archives, i));
+ }
+ archlist_setsize(&archives, 0);
+ archlist_cleanup(&archives);
#endif
}