lint.c revision 1.2 1 /* $NetBSD: lint.c,v 1.2 2007/01/08 18:08:24 cube Exp $ */
2
3 /*
4 * Copyright (c) 2006 The NetBSD Foundation.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to the NetBSD Foundation
8 * by Quentin Garnier.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of The NetBSD Foundation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #if HAVE_NBTOOL_CONFIG_H
36 #include "nbtool_config.h"
37 #endif
38
39 #include <stdlib.h>
40
41 #include "defs.h"
42
43 void
44 emit_params()
45 {
46
47 printf("version\t%d\n", CONFIG_VERSION);
48 printf("ident\t\"LINT_%s\"\n", conffile);
49 printf("maxusers\t%d\n", defmaxusers);
50 printf("config lint root on ?\n");
51 printf("\n");
52 }
53
54 enum opt_types {
55 OT_FLAG,
56 OT_PARAM,
57 OT_FS
58 };
59
60 static struct opt_type {
61 enum opt_types ot_type;
62 const char *ot_name;
63 struct hashtab **ot_ht;
64 } opt_types[] = {
65 { OT_FLAG, "options", &opttab },
66 { OT_PARAM, "options", &opttab },
67 { OT_FS, "file-system", &fsopttab },
68 };
69
70 static int
71 do_emit_option(const char *name, void *value, void *v)
72 {
73 struct nvlist *nv = value;
74 const struct opt_type *ot = v;
75
76 if (nv->nv_flags & NV_OBSOLETE)
77 return 0;
78
79 if (ht_lookup(*(ot->ot_ht), name))
80 return 0;
81
82 printf("%s\t%s", ot->ot_name, nv->nv_name);
83 if (ot->ot_type == OT_PARAM)
84 printf("=%s", nv->nv_str ? nv->nv_str : "1");
85 printf("\n");
86
87 return 1;
88 }
89
90
91 void
92 emit_options()
93 {
94
95 (void)ht_enumerate(defflagtab, do_emit_option, &opt_types[0]);
96 printf("\n");
97 (void)ht_enumerate(defparamtab, do_emit_option, &opt_types[1]);
98 printf("\n");
99 (void)ht_enumerate(deffstab, do_emit_option, &opt_types[2]);
100 printf("\n");
101 }
102
103 static void
104 do_emit_instances(struct devbase *d, struct attr *at)
105 {
106 struct nvlist *nv, *nv1;
107 struct attr *a;
108 struct deva *da;
109
110 if (at != NULL) {
111 for (da = d->d_ahead; da != NULL; da = da->d_bsame)
112 if (onlist(da->d_atlist, at))
113 break;
114 if (da == NULL)
115 panic("do_emit_instances: no deva found for %s at %s",
116 d->d_name, at->a_name);
117
118 if (da->d_isdef > 1)
119 return;
120 da->d_isdef = 2;
121 }
122
123 if (at == NULL && !d->d_ispseudo)
124 printf("%s0\tat\troot\n", d->d_name);
125 else if (!d->d_ispseudo) {
126 printf("%s0\tat\t%s?", d->d_name, at->a_name);
127
128 for (nv = at->a_locs; nv != NULL; nv = nv->nv_next) {
129 if (nv->nv_int == 0)
130 printf(" %s %c", nv->nv_name,
131 nv->nv_str ? '?' : '0');
132 }
133
134 printf("\n");
135 }
136
137 for (nv = d->d_attrs; nv != NULL; nv = nv->nv_next) {
138 a = nv->nv_ptr;
139 for (nv1 = a->a_devs; nv1 != NULL; nv1 = nv1->nv_next)
140 do_emit_instances(nv1->nv_ptr, a);
141 }
142 }
143
144 /* ARGSUSED */
145 static int
146 emit_root_instance(const char *name, void *value, void *v)
147 {
148
149 do_emit_instances((struct devbase *)value, NULL);
150
151 return 1;
152 }
153
154 /* ARGSUSED */
155 static int
156 emit_pseudo_instance(const char *name, void *value, void *v)
157 {
158 struct devbase *d = value;
159
160 if (d->d_ispseudo)
161 printf("pseudo-device\t%s\n", d->d_name);
162 return 0;
163 }
164
165 void
166 emit_instances()
167 {
168
169 (void)ht_enumerate(devroottab, emit_root_instance, NULL);
170 printf("\n");
171 (void)ht_enumerate(devbasetab, emit_pseudo_instance, NULL);
172 }
173