config.y revision 72000
10Sduke%union { 23261Sohair char *str; 30Sduke int val; 40Sduke struct file_list *file; 50Sduke} 60Sduke 70Sduke%token ARCH 80Sduke%token COMMA 90Sduke%token CONFIG 100Sduke%token CPU 110Sduke%token DEVICE 120Sduke%token EQUALS 130Sduke%token HINTS 140Sduke%token IDENT 150Sduke%token MAXUSERS 160Sduke%token PROFILE 170Sduke%token OPTIONS 180Sduke%token MAKEOPTIONS 192362Sohair%token SEMICOLON 202362Sohair 212362Sohair%token <str> ID 220Sduke%token <val> NUMBER 230Sduke 240Sduke%type <str> Save_id 250Sduke%type <str> Opt_value 260Sduke%type <str> Dev 270Sduke 280Sduke%{ 290Sduke 300Sduke/* 310Sduke * Copyright (c) 1988, 1993 320Sduke * The Regents of the University of California. All rights reserved. 330Sduke * 340Sduke * Redistribution and use in source and binary forms, with or without 350Sduke * modification, are permitted provided that the following conditions 360Sduke * are met: 370Sduke * 1. Redistributions of source code must retain the above copyright 380Sduke * notice, this list of conditions and the following disclaimer. 390Sduke * 2. Redistributions in binary form must reproduce the above copyright 400Sduke * notice, this list of conditions and the following disclaimer in the 410Sduke * documentation and/or other materials provided with the distribution. 420Sduke * 3. All advertising materials mentioning features or use of this software 430Sduke * must display the following acknowledgement: 440Sduke * This product includes software developed by the University of 450Sduke * California, Berkeley and its contributors. 460Sduke * 4. Neither the name of the University nor the names of its contributors 470Sduke * may be used to endorse or promote products derived from this software 480Sduke * without specific prior written permission. 490Sduke * 500Sduke * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 510Sduke * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 520Sduke * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 530Sduke * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 540Sduke * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 550Sduke * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 560Sduke * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 570Sduke * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 580Sduke * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 590Sduke * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 600Sduke * SUCH DAMAGE. 610Sduke * 620Sduke * @(#)config.y 8.1 (Berkeley) 6/6/93 630Sduke * $FreeBSD: head/usr.sbin/config/config.y 72000 2001-02-04 13:17:38Z peter $ 640Sduke */ 650Sduke 660Sduke#include <ctype.h> 672496Salanb#include <err.h> 680Sduke#include <stdio.h> 690Sduke#include <string.h> 700Sduke 710Sduke#include "config.h" 720Sduke 730Sdukestatic struct device cur; 740Sdukestatic struct device *curp = 0; 750Sduke 760Sdukestruct device *dtab; 770Sdukechar *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