Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/config merge a bit of duplicated code.
details: https://anonhg.NetBSD.org/src/rev/a49e5d1d3ef3
branches: trunk
changeset: 333607:a49e5d1d3ef3
user: christos <christos%NetBSD.org@localhost>
date: Mon Nov 10 21:13:04 2014 +0000
description:
merge a bit of duplicated code.
diffstat:
usr.bin/config/mkdevsw.c | 77 +++++++++++++++++++++++++----------------------
1 files changed, 41 insertions(+), 36 deletions(-)
diffs (121 lines):
diff -r 24bfa32d3c97 -r a49e5d1d3ef3 usr.bin/config/mkdevsw.c
--- a/usr.bin/config/mkdevsw.c Mon Nov 10 20:52:47 2014 +0000
+++ b/usr.bin/config/mkdevsw.c Mon Nov 10 21:13:04 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mkdevsw.c,v 1.11 2014/10/29 17:14:50 christos Exp $ */
+/* $NetBSD: mkdevsw.c,v 1.12 2014/11/10 21:13:04 christos Exp $ */
/*
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: mkdevsw.c,v 1.11 2014/10/29 17:14:50 christos Exp $");
+__RCSID("$NetBSD: mkdevsw.c,v 1.12 2014/11/10 21:13:04 christos Exp $");
#include <stdio.h>
#include <string.h>
@@ -89,37 +89,54 @@
"#include <sys/conf.h>\n", fp);
}
+static void
+dentry(FILE *fp, struct hashtab *t, devmajor_t i, char p)
+{
+ const struct devm *dm;
+ char mstr[16];
+
+ (void)snprintf(mstr, sizeof(mstr), "%d", i);
+ if ((dm = ht_lookup(t, intern(mstr))) == NULL)
+ return;
+
+ fprintf(fp, "extern const struct %cdevsw %s_%cdevsw;\n",
+ p, dm->dm_name, p);
+}
+
+static void
+pentry(FILE *fp, struct hashtab *t, devmajor_t i, char p)
+{
+ const struct devm *dm;
+ char mstr[16];
+
+ (void)snprintf(mstr, sizeof(mstr), "%d", i);
+ dm = ht_lookup(t, intern(mstr));
+
+ if (dm)
+ fprintf(fp, "\t&%s_%cdevsw", dm->dm_name, p);
+ else
+ fputs("\tNULL", fp);
+
+ fprintf(fp, ",\t// %3d\n", i);
+}
+
/*
* Emit device switch table for character/block device.
*/
static void
emitdevm(FILE *fp)
{
- struct devm *dm;
- char mstr[16];
devmajor_t i;
fputs("\n/* device switch table for block device */\n", fp);
- for (i = 0 ; i <= maxbdevm ; i++) {
- (void)snprintf(mstr, sizeof(mstr), "%d", i);
- if ((dm = ht_lookup(bdevmtab, intern(mstr))) == NULL)
- continue;
-
- fprintf(fp, "extern const struct bdevsw %s_bdevsw;\n",
- dm->dm_name);
- }
+ for (i = 0; i <= maxbdevm ; i++)
+ dentry(fp, cdevmtab, i, 'b');
fputs("\nconst struct bdevsw *bdevsw0[] = {\n", fp);
- for (i = 0 ; i <= maxbdevm ; i++) {
- (void)snprintf(mstr, sizeof(mstr), "%d", i);
- if ((dm = ht_lookup(bdevmtab, intern(mstr))) == NULL) {
- fprintf(fp, "\tNULL,\n");
- } else {
- fprintf(fp, "\t&%s_bdevsw,\n", dm->dm_name);
- }
- }
+ for (i = 0; i <= maxbdevm; i++)
+ pentry(fp, bdevmtab, i, 'b');
fputs("};\n\nconst struct bdevsw **bdevsw = bdevsw0;\n", fp);
@@ -128,25 +145,13 @@
fputs("\n/* device switch table for character device */\n", fp);
- for (i = 0 ; i <= maxcdevm ; i++) {
- (void)snprintf(mstr, sizeof(mstr), "%d", i);
- if ((dm = ht_lookup(cdevmtab, intern(mstr))) == NULL)
- continue;
-
- fprintf(fp, "extern const struct cdevsw %s_cdevsw;\n",
- dm->dm_name);
- }
+ for (i = 0; i <= maxcdevm; i++)
+ dentry(fp, cdevmtab, i, 'c');
fputs("\nconst struct cdevsw *cdevsw0[] = {\n", fp);
- for (i = 0 ; i <= maxcdevm ; i++) {
- (void)snprintf(mstr, sizeof(mstr), "%d", i);
- if ((dm = ht_lookup(cdevmtab, intern(mstr))) == NULL) {
- fprintf(fp, "\tNULL,\n");
- } else {
- fprintf(fp, "\t&%s_cdevsw,\n", dm->dm_name);
- }
- }
+ for (i = 0; i <= maxcdevm; i++)
+ pentry(fp, cdevmtab, i, 'c');
fputs("};\n\nconst struct cdevsw **cdevsw = cdevsw0;\n", fp);
Home |
Main Index |
Thread Index |
Old Index