lint.c revision 1.3
1/* $NetBSD: lint.c,v 1.3 2007/01/09 13:03:47 cube Exp $ */ 2 3/* 4 * Copyright (c) 2007 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 43void 44emit_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 54enum opt_types { 55 OT_FLAG, 56 OT_PARAM, 57 OT_FS 58}; 59 60static 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 70static int 71do_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 struct nvlist *nv2 = ht_lookup(defoptlint, nv->nv_name); 85 if (nv2 == NULL) 86 nv2 = nv; 87 printf("=\"%s\"", nv2->nv_str ? nv2->nv_str : "1"); 88 } 89 printf("\n"); 90 91 return 1; 92} 93 94 95void 96emit_options() 97{ 98 99 (void)ht_enumerate(defflagtab, do_emit_option, &opt_types[0]); 100 printf("\n"); 101 (void)ht_enumerate(defparamtab, do_emit_option, &opt_types[1]); 102 printf("\n"); 103 (void)ht_enumerate(deffstab, do_emit_option, &opt_types[2]); 104 printf("\n"); 105} 106 107static void 108do_emit_instances(struct devbase *d, struct attr *at) 109{ 110 struct nvlist *nv, *nv1; 111 struct attr *a; 112 struct deva *da; 113 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); 121 122 if (da->d_isdef > 1) 123 return; 124 da->d_isdef = 2; 125 } 126 127 if (at == NULL && !d->d_ispseudo) 128 printf("%s0\tat\troot\n", d->d_name); 129 else if (!d->d_ispseudo) { 130 printf("%s0\tat\t%s?", d->d_name, at->a_name); 131 132 for (nv = at->a_locs; nv != NULL; nv = nv->nv_next) { 133 if (nv->nv_int == 0) 134 printf(" %s %c", nv->nv_name, 135 nv->nv_str ? '?' : '0'); 136 } 137 138 printf("\n"); 139 } 140 141 for (nv = d->d_attrs; nv != NULL; nv = nv->nv_next) { 142 a = nv->nv_ptr; 143 for (nv1 = a->a_devs; nv1 != NULL; nv1 = nv1->nv_next) 144 do_emit_instances(nv1->nv_ptr, a); 145 } 146} 147 148/* ARGSUSED */ 149static int 150emit_root_instance(const char *name, void *value, void *v) 151{ 152 153 do_emit_instances((struct devbase *)value, NULL); 154 155 return 1; 156} 157 158/* ARGSUSED */ 159static int 160emit_pseudo_instance(const char *name, void *value, void *v) 161{ 162 struct devbase *d = value; 163 164 if (d->d_ispseudo) 165 printf("pseudo-device\t%s\n", d->d_name); 166 return 0; 167} 168 169void 170emit_instances() 171{ 172 173 (void)ht_enumerate(devroottab, emit_root_instance, NULL); 174 printf("\n"); 175 (void)ht_enumerate(devbasetab, emit_pseudo_instance, NULL); 176} 177