config.y revision 71363
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 71363 2001-01-22 07:03:06Z 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 if (!strcmp($2, "i386")) { 125 machine = MACHINE_I386; 126 machinename = "i386"; 127 } else if (!strcmp($2, "pc98")) { 128 machine = MACHINE_PC98; 129 machinename = "pc98"; 130 } else if (!strcmp($2, "alpha")) { 131 machine = MACHINE_ALPHA; 132 machinename = "alpha"; 133 } else if (!strcmp($2, "ia64")) { 134 machine = MACHINE_IA64; 135 machinename = "ia64"; 136 } else 137 yyerror("Unknown machine type"); 138 } | 139 CPU Save_id 140 = { 141 struct cputype *cp = 142 (struct cputype *)malloc(sizeof (struct cputype)); 143 memset(cp, 0, sizeof(*cp)); 144 cp->cpu_name = $2; 145 cp->cpu_next = cputype; 146 cputype = cp; 147 } | 148 OPTIONS Opt_list 149 | 150 MAKEOPTIONS Mkopt_list 151 | 152 IDENT ID 153 = { ident = $2; } | 154 System_spec 155 | 156 MAXUSERS NUMBER 157 = { maxusers = $2; } | 158 PROFILE NUMBER 159 = { profiling = $2; } | 160 HINTS ID 161 = { 162 hints = $2; 163 hintmode = 1; 164 }; 165 166System_spec: 167 CONFIG System_id System_parameter_list 168 = { errx(1, "line %d: root/dump/swap specifications obsolete", yyline);} 169 | 170 CONFIG System_id 171 ; 172 173System_id: 174 Save_id 175 = { 176 struct opt *op = (struct opt *)malloc(sizeof (struct opt)); 177 memset(op, 0, sizeof(*op)); 178 op->op_name = ns("KERNEL"); 179 op->op_ownfile = 0; 180 op->op_next = mkopt; 181 op->op_value = $1; 182 op->op_line = yyline + 1; 183 mkopt = op; 184 }; 185 186System_parameter_list: 187 System_parameter_list ID 188 | ID 189 ; 190 191Opt_list: 192 Opt_list COMMA Option 193 | 194 Option 195 ; 196 197Option: 198 Save_id 199 = { 200 struct opt *op = (struct opt *)malloc(sizeof (struct opt)); 201 char *s; 202 memset(op, 0, sizeof(*op)); 203 op->op_name = $1; 204 op->op_next = opt; 205 op->op_value = 0; 206 /* 207 * op->op_line is 1-based; yyline is 0-based but is now 1 208 * larger than when `Save_id' was lexed. 209 */ 210 op->op_line = yyline; 211 opt = op; 212 if ((s = strchr(op->op_name, '='))) 213 errx(1, "line %d: The `=' in options should not be quoted", yyline); 214 } | 215 Save_id EQUALS Opt_value 216 = { 217 struct opt *op = (struct opt *)malloc(sizeof (struct opt)); 218 memset(op, 0, sizeof(*op)); 219 op->op_name = $1; 220 op->op_next = opt; 221 op->op_value = $3; 222 op->op_line = yyline + 1; 223 opt = op; 224 } ; 225 226Opt_value: 227 ID 228 = { $$ = $1; } | 229 NUMBER 230 = { 231 char buf[80]; 232 233 (void) snprintf(buf, sizeof(buf), "%d", $1); 234 $$ = ns(buf); 235 } ; 236 237Save_id: 238 ID 239 = { $$ = $1; } 240 ; 241 242Mkopt_list: 243 Mkopt_list COMMA Mkoption 244 | 245 Mkoption 246 ; 247 248Mkoption: 249 Save_id EQUALS Opt_value 250 = { 251 struct opt *op = (struct opt *)malloc(sizeof (struct opt)); 252 memset(op, 0, sizeof(*op)); 253 op->op_name = $1; 254 op->op_ownfile = 0; /* for now */ 255 op->op_next = mkopt; 256 op->op_value = $3; 257 op->op_line = yyline + 1; 258 mkopt = op; 259 } ; 260 261Dev: 262 ID 263 = { $$ = $1; } 264 ; 265 266Device_spec: 267 DEVICE Dev 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_type = DEVICE; 278 cur.d_name = $2; 279 cur.d_count = UNKNOWN; 280 } | 281 DEVICE Dev NUMBER 282 = { 283 struct opt *op = (struct opt *)malloc(sizeof (struct opt)); 284 memset(op, 0, sizeof(*op)); 285 op->op_name = devopt($2); 286 op->op_next = opt; 287 op->op_value = ns("1"); 288 op->op_line = yyline; 289 opt = op; 290 /* and the device part */ 291 cur.d_type = DEVICE; 292 cur.d_name = $2; 293 cur.d_count = $3; 294 if (cur.d_count == 0) 295 errx(1, "line %d: devices with zero units are not likely to be correct", yyline); 296 } ; 297 298%% 299 300static void 301yyerror(char *s) 302{ 303 304 errx(1, "line %d: %s", yyline + 1, s); 305} 306 307/* 308 * add a device to the list of devices 309 */ 310static void 311newdev(struct device *dp) 312{ 313 struct device *np; 314 315 np = (struct device *) malloc(sizeof *np); 316 memset(np, 0, sizeof(*np)); 317 *np = *dp; 318 np->d_name = dp->d_name; 319 np->d_type = dp->d_type; 320 np->d_count = dp->d_count; 321 np->d_next = 0; 322 if (curp == 0) 323 dtab = np; 324 else 325 curp->d_next = np; 326 curp = np; 327} 328