config.y revision 72000
1%union { 2 char *str; 3 int val; 4 struct file_list *file; 5} 6 7%token ARCH 8%token COMMA 9%token CONFIG 10%token CPU 11%token DEVICE 12%token EQUALS 13%token HINTS 14%token IDENT 15%token MAXUSERS 16%token PROFILE 17%token OPTIONS 18%token MAKEOPTIONS 19%token SEMICOLON 20 21%token <str> ID 22%token <val> NUMBER 23 24%type <str> Save_id 25%type <str> Opt_value 26%type <str> Dev 27 28%{ 29 30/* 31 * Copyright (c) 1988, 1993 32 * The Regents of the University of California. All rights reserved. 33 * 34 * Redistribution and use in source and binary forms, with or without 35 * modification, are permitted provided that the following conditions 36 * are met: 37 * 1. Redistributions of source code must retain the above copyright 38 * notice, this list of conditions and the following disclaimer. 39 * 2. Redistributions in binary form must reproduce the above copyright 40 * notice, this list of conditions and the following disclaimer in the 41 * documentation and/or other materials provided with the distribution. 42 * 3. All advertising materials mentioning features or use of this software 43 * must display the following acknowledgement: 44 * This product includes software developed by the University of 45 * California, Berkeley and its contributors. 46 * 4. Neither the name of the University nor the names of its contributors 47 * may be used to endorse or promote products derived from this software 48 * without specific prior written permission. 49 * 50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 60 * SUCH DAMAGE. 61 * 62 * @(#)config.y 8.1 (Berkeley) 6/6/93 63 * $FreeBSD: head/usr.sbin/config/config.y 72000 2001-02-04 13:17:38Z peter $ 64 */ 65 66#include <ctype.h> 67#include <err.h> 68#include <stdio.h> 69#include <string.h> 70 71#include "config.h" 72 73static struct device cur; 74static struct device *curp = 0; 75 76struct device *dtab; 77char *ident; 78char *hints; 79int hintmode; 80int yyline; 81struct file_list *ftab; 82char errbuf[80]; 83int maxusers; 84 85#define ns(s) strdup(s) 86 87static void yyerror(char *s); 88 89static char * 90devopt(char *dev) 91{ 92 char *ret = malloc(strlen(dev) + 5); 93 94 sprintf(ret, "DEV_%s", dev); 95 raisestr(ret); 96 return ret; 97} 98 99%} 100%% 101Configuration: 102 Many_specs 103 ; 104 105Many_specs: 106 Many_specs Spec 107 | 108 /* lambda */ 109 ; 110 111Spec: 112 Device_spec SEMICOLON 113 = { newdev(&cur); } | 114 Config_spec SEMICOLON 115 | 116 SEMICOLON 117 | 118 error SEMICOLON 119 ; 120 121Config_spec: 122 ARCH Save_id 123 = { 124 machinename = $2; 125 } | 126 CPU Save_id 127 = { 128 struct cputype *cp = 129 (struct cputype *)malloc(sizeof (struct cputype)); 130 memset(cp, 0, sizeof(*cp)); 131 cp->cpu_name = $2; 132 cp->cpu_next = cputype; 133 cputype = cp; 134 } | 135 OPTIONS Opt_list 136 | 137 MAKEOPTIONS Mkopt_list 138 | 139 IDENT ID 140 = { ident = $2; } | 141 System_spec 142 | 143 MAXUSERS NUMBER 144 = { maxusers = $2; } | 145 PROFILE NUMBER 146 = { profiling = $2; } | 147 HINTS ID 148 = { 149 hints = $2; 150 hintmode = 1; 151 }; 152 153System_spec: 154 CONFIG System_id System_parameter_list 155 = { errx(1, "line %d: root/dump/swap specifications obsolete", yyline);} 156 | 157 CONFIG System_id 158 ; 159 160System_id: 161 Save_id 162 = { 163 struct opt *op = (struct opt *)malloc(sizeof (struct opt)); 164 memset(op, 0, sizeof(*op)); 165 op->op_name = ns("KERNEL"); 166 op->op_ownfile = 0; 167 op->op_next = mkopt; 168 op->op_value = $1; 169 op->op_line = yyline + 1; 170 mkopt = op; 171 }; 172 173System_parameter_list: 174 System_parameter_list ID 175 | ID 176 ; 177 178Opt_list: 179 Opt_list COMMA Option 180 | 181 Option 182 ; 183 184Option: 185 Save_id 186 = { 187 struct opt *op = (struct opt *)malloc(sizeof (struct opt)); 188 char *s; 189 memset(op, 0, sizeof(*op)); 190 op->op_name = $1; 191 op->op_next = opt; 192 op->op_value = 0; 193 /* 194 * op->op_line is 1-based; yyline is 0-based but is now 1 195 * larger than when `Save_id' was lexed. 196 */ 197 op->op_line = yyline; 198 opt = op; 199 if ((s = strchr(op->op_name, '='))) 200 errx(1, "line %d: The `=' in options should not be quoted", yyline); 201 } | 202 Save_id EQUALS Opt_value 203 = { 204 struct opt *op = (struct opt *)malloc(sizeof (struct opt)); 205 memset(op, 0, sizeof(*op)); 206 op->op_name = $1; 207 op->op_next = opt; 208 op->op_value = $3; 209 op->op_line = yyline + 1; 210 opt = op; 211 } ; 212 213Opt_value: 214 ID 215 = { $$ = $1; } | 216 NUMBER 217 = { 218 char buf[80]; 219 220 (void) snprintf(buf, sizeof(buf), "%d", $1); 221 $$ = ns(buf); 222 } ; 223 224Save_id: 225 ID 226 = { $$ = $1; } 227 ; 228 229Mkopt_list: 230 Mkopt_list COMMA Mkoption 231 | 232 Mkoption 233 ; 234 235Mkoption: 236 Save_id EQUALS Opt_value 237 = { 238 struct opt *op = (struct opt *)malloc(sizeof (struct opt)); 239 memset(op, 0, sizeof(*op)); 240 op->op_name = $1; 241 op->op_ownfile = 0; /* for now */ 242 op->op_next = mkopt; 243 op->op_value = $3; 244 op->op_line = yyline + 1; 245 mkopt = op; 246 } ; 247 248Dev: 249 ID 250 = { $$ = $1; } 251 ; 252 253Device_spec: 254 DEVICE Dev 255 = { 256 struct opt *op = (struct opt *)malloc(sizeof (struct opt)); 257 memset(op, 0, sizeof(*op)); 258 op->op_name = devopt($2); 259 op->op_next = opt; 260 op->op_value = ns("1"); 261 op->op_line = yyline; 262 opt = op; 263 /* and the device part */ 264 cur.d_name = $2; 265 cur.d_count = UNKNOWN; 266 } | 267 DEVICE Dev NUMBER 268 = { 269 struct opt *op = (struct opt *)malloc(sizeof (struct opt)); 270 memset(op, 0, sizeof(*op)); 271 op->op_name = devopt($2); 272 op->op_next = opt; 273 op->op_value = ns("1"); 274 op->op_line = yyline; 275 opt = op; 276 /* and the device part */ 277 cur.d_name = $2; 278 cur.d_count = $3; 279 if (cur.d_count == 0) 280 errx(1, "line %d: devices with zero units are not likely to be correct", yyline); 281 } ; 282 283%% 284 285static void 286yyerror(char *s) 287{ 288 289 errx(1, "line %d: %s", yyline + 1, s); 290} 291 292/* 293 * add a device to the list of devices 294 */ 295static void 296newdev(struct device *dp) 297{ 298 struct device *np; 299 300 np = (struct device *) malloc(sizeof *np); 301 memset(np, 0, sizeof(*np)); 302 *np = *dp; 303 np->d_name = dp->d_name; 304 np->d_count = dp->d_count; 305 np->d_next = 0; 306 if (curp == 0) 307 dtab = np; 308 else 309 curp->d_next = np; 310 curp = np; 311} 312