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