Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / usr.bin / config / lint.c
blobb55064ffb9fcb0bc6725c57d5c7cb2947e4d8570
1 /* $NetBSD: lint.c,v 1.7 2008/12/28 01:23:46 christos Exp $ */
3 /*
4 * Copyright (c) 2007 The NetBSD Foundation.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #if HAVE_NBTOOL_CONFIG_H
30 #include "nbtool_config.h"
31 #endif
33 #include <stdlib.h>
35 #include "defs.h"
37 void
38 emit_params()
41 printf("version\t%d\n", CONFIG_VERSION);
42 printf("ident\t\"LINT_%s\"\n", conffile);
43 printf("maxusers\t%d\n", defmaxusers);
44 printf("config netbsdlint root on ?\n");
45 printf("\n");
48 enum opt_types {
49 OT_FLAG,
50 OT_PARAM,
51 OT_FS
54 static struct opt_type {
55 enum opt_types ot_type;
56 const char *ot_name;
57 struct hashtab **ot_ht;
58 } opt_types[] = {
59 { OT_FLAG, "options", &opttab },
60 { OT_PARAM, "options", &opttab },
61 { OT_FS, "file-system", &fsopttab },
64 static int
65 do_emit_option(const char *name, void *value, void *v)
67 struct nvlist *nv = value;
68 const struct opt_type *ot = v;
70 if (nv->nv_flags & NV_OBSOLETE)
71 return 0;
73 if (ht_lookup(*(ot->ot_ht), name))
74 return 0;
76 printf("%s\t%s", ot->ot_name, nv->nv_name);
77 if (ot->ot_type == OT_PARAM) {
78 struct nvlist *nv2 = ht_lookup(defoptlint, nv->nv_name);
79 if (nv2 == NULL)
80 nv2 = nv;
81 printf("=\"%s\"", nv2->nv_str ? nv2->nv_str : "1");
83 printf("\n");
85 return 1;
89 void
90 emit_options()
93 (void)ht_enumerate(defflagtab, do_emit_option, &opt_types[0]);
94 printf("\n");
95 (void)ht_enumerate(defparamtab, do_emit_option, &opt_types[1]);
96 printf("\n");
97 (void)ht_enumerate(deffstab, do_emit_option, &opt_types[2]);
98 printf("\n");
101 static void
102 do_emit_instances(struct devbase *d, struct attr *at)
104 struct nvlist *nv, *nv1;
105 struct attr *a;
106 struct deva *da;
109 * d_isdef is used to check whether a deva has been seen or not,
110 * for there are devices that can be their own ancestor (e.g.
111 * uhub, pci).
114 if (at != NULL) {
115 for (da = d->d_ahead; da != NULL; da = da->d_bsame)
116 if (onlist(da->d_atlist, at))
117 break;
118 if (da == NULL)
119 panic("do_emit_instances: no deva found for %s at %s",
120 d->d_name, at->a_name);
122 if (da->d_isdef > 1)
123 return;
124 da->d_isdef = 2;
127 if (at == NULL && !d->d_ispseudo && d->d_ihead == NULL)
128 printf("%s0\tat\troot\n", d->d_name);
129 else if (at != NULL && !d->d_ispseudo && da->d_ihead == NULL) {
130 printf("%s0\tat\t%s?", d->d_name, at->a_name);
132 for (nv = at->a_locs; nv != NULL; nv = nv->nv_next) {
133 if (nv->nv_num == 0)
134 printf(" %s %c", nv->nv_name,
135 nv->nv_str ? '?' : '0');
138 printf("\n");
142 * Children attachments are found the same way as in the orphan
143 * detection code in main.c.
145 for (nv = d->d_attrs; nv != NULL; nv = nv->nv_next) {
146 a = nv->nv_ptr;
147 for (nv1 = a->a_devs; nv1 != NULL; nv1 = nv1->nv_next)
148 do_emit_instances(nv1->nv_ptr, a);
152 /* ARGSUSED */
153 static int
154 emit_root_instance(const char *name, void *value, void *v)
157 do_emit_instances((struct devbase *)value, NULL);
159 return 1;
162 /* ARGSUSED */
163 static int
164 emit_pseudo_instance(const char *name, void *value, void *v)
166 struct devbase *d = value;
168 if (d->d_ispseudo && d->d_ihead == NULL)
169 printf("pseudo-device\t%s\n", d->d_name);
170 return 0;
173 void
174 emit_instances()
177 (void)ht_enumerate(devroottab, emit_root_instance, NULL);
178 printf("\n");
179 (void)ht_enumerate(devbasetab, emit_pseudo_instance, NULL);