Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make(1): add Hash_ForEach to avoid duplicate code
details: https://anonhg.NetBSD.org/src/rev/9234266703a9
branches: trunk
changeset: 1011572:9234266703a9
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jul 03 17:03:09 2020 +0000
description:
make(1): add Hash_ForEach to avoid duplicate code
diffstat:
usr.bin/make/hash.c | 17 ++++++++++++++---
usr.bin/make/hash.h | 3 ++-
usr.bin/make/var.c | 39 ++++++++++++++-------------------------
3 files changed, 30 insertions(+), 29 deletions(-)
diffs (156 lines):
diff -r e19f1acd7c23 -r 9234266703a9 usr.bin/make/hash.c
--- a/usr.bin/make/hash.c Fri Jul 03 17:00:47 2020 +0000
+++ b/usr.bin/make/hash.c Fri Jul 03 17:03:09 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hash.c,v 1.21 2020/07/03 08:02:55 rillig Exp $ */
+/* $NetBSD: hash.c,v 1.22 2020/07/03 17:03:09 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: hash.c,v 1.21 2020/07/03 08:02:55 rillig Exp $";
+static char rcsid[] = "$NetBSD: hash.c,v 1.22 2020/07/03 17:03:09 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)hash.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: hash.c,v 1.21 2020/07/03 08:02:55 rillig Exp $");
+__RCSID("$NetBSD: hash.c,v 1.22 2020/07/03 17:03:09 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -464,3 +464,14 @@
}
free(oldhp);
}
+
+void Hash_ForEach(Hash_Table *t, void (*action)(void *, void *), void *data)
+{
+ Hash_Search search;
+ Hash_Entry *e;
+
+ for (e = Hash_EnumFirst(t, &search);
+ e != NULL;
+ e = Hash_EnumNext(&search))
+ action(Hash_GetValue(e), data);
+}
diff -r e19f1acd7c23 -r 9234266703a9 usr.bin/make/hash.h
--- a/usr.bin/make/hash.h Fri Jul 03 17:00:47 2020 +0000
+++ b/usr.bin/make/hash.h Fri Jul 03 17:03:09 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hash.h,v 1.12 2017/05/31 21:07:03 maya Exp $ */
+/* $NetBSD: hash.h,v 1.13 2020/07/03 17:03:09 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -145,5 +145,6 @@
void Hash_DeleteEntry(Hash_Table *, Hash_Entry *);
Hash_Entry *Hash_EnumFirst(Hash_Table *, Hash_Search *);
Hash_Entry *Hash_EnumNext(Hash_Search *);
+void Hash_ForEach(Hash_Table *, void (*)(void *, void *), void *);
#endif /* _HASH_H */
diff -r e19f1acd7c23 -r 9234266703a9 usr.bin/make/var.c
--- a/usr.bin/make/var.c Fri Jul 03 17:00:47 2020 +0000
+++ b/usr.bin/make/var.c Fri Jul 03 17:03:09 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.240 2020/07/03 17:00:47 rillig Exp $ */
+/* $NetBSD: var.c,v 1.241 2020/07/03 17:03:09 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.240 2020/07/03 17:00:47 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.241 2020/07/03 17:03:09 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: var.c,v 1.240 2020/07/03 17:00:47 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.241 2020/07/03 17:03:09 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -338,7 +338,6 @@
static char *VarOrder(const char *, const char);
static char *VarUniq(const char *);
static int VarWordCompare(const void *, const void *);
-static void VarPrintVar(void *);
#define BROPEN '{'
#define BRCLOSE '}'
@@ -673,6 +672,13 @@
return 1;
}
+static void
+Var_ExportVars_callback(void *entry, void *unused MAKE_ATTR_UNUSED)
+{
+ Var *var = entry;
+ Var_Export1(var->name, 0);
+}
+
/*
* This gets called from our children.
*/
@@ -680,9 +686,6 @@
Var_ExportVars(void)
{
char tmp[BUFSIZ];
- Hash_Entry *var;
- Hash_Search state;
- Var *v;
char *val;
int n;
@@ -699,15 +702,8 @@
return;
if (VAR_EXPORTED_ALL == var_exportedVars) {
- /*
- * Ouch! This is crazy...
- */
- for (var = Hash_EnumFirst(&VAR_GLOBAL->context, &state);
- var != NULL;
- var = Hash_EnumNext(&state)) {
- v = (Var *)Hash_GetValue(var);
- Var_Export1(v->name, 0);
- }
+ /* Ouch! This is crazy... */
+ Hash_ForEach(&VAR_GLOBAL->context, Var_ExportVars_callback, NULL);
return;
}
/*
@@ -4291,7 +4287,7 @@
/****************** PRINT DEBUGGING INFO *****************/
static void
-VarPrintVar(void *vp)
+VarPrintVar(void *vp, void *data MAKE_ATTR_UNUSED)
{
Var *v = (Var *)vp;
fprintf(debug_file, "%-16s = %s\n", v->name, Buf_GetAll(&v->val, NULL));
@@ -4306,12 +4302,5 @@
void
Var_Dump(GNode *ctxt)
{
- Hash_Search search;
- Hash_Entry *h;
-
- for (h = Hash_EnumFirst(&ctxt->context, &search);
- h != NULL;
- h = Hash_EnumNext(&search)) {
- VarPrintVar(Hash_GetValue(h));
- }
+ Hash_ForEach(&ctxt->context, VarPrintVar, NULL);
}
Home |
Main Index |
Thread Index |
Old Index