config.y revision 72844
11553Srgrimes%union { 21553Srgrimes char *str; 31553Srgrimes int val; 41553Srgrimes struct file_list *file; 51553Srgrimes} 61553Srgrimes 752653Smarcel%token ARCH 81553Srgrimes%token COMMA 946855Speter%token CONFIG 101553Srgrimes%token CPU 111553Srgrimes%token DEVICE 121553Srgrimes%token EQUALS 1361640Speter%token HINTS 141553Srgrimes%token IDENT 151553Srgrimes%token MAXUSERS 1667109Sphk%token PROFILE 171553Srgrimes%token OPTIONS 181553Srgrimes%token MAKEOPTIONS 191553Srgrimes%token SEMICOLON 201553Srgrimes 211553Srgrimes%token <str> ID 221553Srgrimes%token <val> NUMBER 231553Srgrimes 241553Srgrimes%type <str> Save_id 2546104Sluoqi%type <str> Opt_value 261553Srgrimes%type <str> Dev 271553Srgrimes 281553Srgrimes%{ 291553Srgrimes 301553Srgrimes/* 311553Srgrimes * Copyright (c) 1988, 1993 321553Srgrimes * The Regents of the University of California. All rights reserved. 331553Srgrimes * 341553Srgrimes * Redistribution and use in source and binary forms, with or without 351553Srgrimes * modification, are permitted provided that the following conditions 361553Srgrimes * are met: 371553Srgrimes * 1. Redistributions of source code must retain the above copyright 381553Srgrimes * notice, this list of conditions and the following disclaimer. 391553Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 401553Srgrimes * notice, this list of conditions and the following disclaimer in the 411553Srgrimes * documentation and/or other materials provided with the distribution. 421553Srgrimes * 3. All advertising materials mentioning features or use of this software 431553Srgrimes * must display the following acknowledgement: 441553Srgrimes * This product includes software developed by the University of 451553Srgrimes * California, Berkeley and its contributors. 461553Srgrimes * 4. Neither the name of the University nor the names of its contributors 471553Srgrimes * may be used to endorse or promote products derived from this software 481553Srgrimes * without specific prior written permission. 491553Srgrimes * 501553Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 511553Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 521553Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 531553Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 541553Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 551553Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 561553Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 571553Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 581553Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 591553Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 601553Srgrimes * SUCH DAMAGE. 611553Srgrimes * 621553Srgrimes * @(#)config.y 8.1 (Berkeley) 6/6/93 6352007Speter * $FreeBSD: head/usr.sbin/config/config.y 72844 2001-02-22 04:00:29Z peter $ 641553Srgrimes */ 651553Srgrimes 661553Srgrimes#include <ctype.h> 6729451Scharnier#include <err.h> 681553Srgrimes#include <stdio.h> 6912772Speter#include <string.h> 701553Srgrimes 7145775Speter#include "config.h" 7245775Speter 7345744Speterstatic struct device *curp = 0; 741553Srgrimes 7545744Speterstruct device *dtab; 7645744Speterchar *ident; 7761640Speterchar *hints; 7865091Speterint hintmode; 7945744Speterint yyline; 8046821Speterstruct file_list *ftab; 8145744Speterchar errbuf[80]; 8245744Speterint maxusers; 8345744Speter 8420458Sjoerg#define ns(s) strdup(s) 8520458Sjoerg 8672684Speterstatic void yyerror(const char *s); 8729451Scharnier 8871251Speterstatic char * 8971251Speterdevopt(char *dev) 9071251Speter{ 9171251Speter char *ret = malloc(strlen(dev) + 5); 9271251Speter 9371251Speter sprintf(ret, "DEV_%s", dev); 9471251Speter raisestr(ret); 9571251Speter return ret; 9671251Speter} 9745775Speter 981553Srgrimes%} 991553Srgrimes%% 1001553SrgrimesConfiguration: 1011553Srgrimes Many_specs 1021553Srgrimes ; 1031553Srgrimes 1041553SrgrimesMany_specs: 1051553Srgrimes Many_specs Spec 1061553Srgrimes | 1071553Srgrimes /* lambda */ 1081553Srgrimes ; 1091553Srgrimes 1101553SrgrimesSpec: 1111553Srgrimes Device_spec SEMICOLON 11272841Speter | 1131553Srgrimes Config_spec SEMICOLON 1141553Srgrimes | 1151553Srgrimes SEMICOLON 1161553Srgrimes | 1171553Srgrimes error SEMICOLON 1181553Srgrimes ; 1191553Srgrimes 1201553SrgrimesConfig_spec: 12152653Smarcel ARCH Save_id 1221553Srgrimes = { 12372000Speter machinename = $2; 1241553Srgrimes } | 12546104Sluoqi CPU Save_id 1261553Srgrimes = { 1271553Srgrimes struct cputype *cp = 1281553Srgrimes (struct cputype *)malloc(sizeof (struct cputype)); 12912772Speter memset(cp, 0, sizeof(*cp)); 13020458Sjoerg cp->cpu_name = $2; 1311553Srgrimes cp->cpu_next = cputype; 1321553Srgrimes cputype = cp; 1331553Srgrimes } | 1341553Srgrimes OPTIONS Opt_list 1351553Srgrimes | 1361553Srgrimes MAKEOPTIONS Mkopt_list 1371553Srgrimes | 1381553Srgrimes IDENT ID 13920458Sjoerg = { ident = $2; } | 14046855Speter System_spec 14146855Speter | 1421553Srgrimes MAXUSERS NUMBER 14361640Speter = { maxusers = $2; } | 14467109Sphk PROFILE NUMBER 14567109Sphk = { profiling = $2; } | 14661640Speter HINTS ID 14765091Speter = { 14865091Speter hints = $2; 14965091Speter hintmode = 1; 15065091Speter }; 1511553Srgrimes 15246855SpeterSystem_spec: 15346855Speter CONFIG System_id System_parameter_list 15471363Speter = { errx(1, "line %d: root/dump/swap specifications obsolete", yyline);} 15546855Speter | 15646855Speter CONFIG System_id 15746855Speter ; 15846855Speter 15946855SpeterSystem_id: 16046855Speter Save_id 16172844Speter = { newopt(&mkopt, ns("KERNEL"), $1); }; 16246855Speter 16346855SpeterSystem_parameter_list: 16446855Speter System_parameter_list ID 16546855Speter | ID 16646855Speter ; 16746855Speter 1681553SrgrimesOpt_list: 1691553Srgrimes Opt_list COMMA Option 1701553Srgrimes | 1711553Srgrimes Option 1721553Srgrimes ; 1731553Srgrimes 1741553SrgrimesOption: 17546104Sluoqi Save_id 1761553Srgrimes = { 17712772Speter char *s; 17872841Speter 17972844Speter newopt(&opt, $1, NULL); 18072841Speter if ((s = strchr($1, '='))) 18171363Speter errx(1, "line %d: The `=' in options should not be quoted", yyline); 1821553Srgrimes } | 18346104Sluoqi Save_id EQUALS Opt_value 1841553Srgrimes = { 18572844Speter newopt(&opt, $1, $3); 1861553Srgrimes } ; 1871553Srgrimes 18846104SluoqiOpt_value: 1891553Srgrimes ID 19046021Speter = { $$ = $1; } | 1911553Srgrimes NUMBER 19246021Speter = { 19346021Speter char buf[80]; 1941553Srgrimes 19546021Speter (void) snprintf(buf, sizeof(buf), "%d", $1); 19646021Speter $$ = ns(buf); 19746021Speter } ; 1981553Srgrimes 1991553SrgrimesSave_id: 2001553Srgrimes ID 20120458Sjoerg = { $$ = $1; } 2021553Srgrimes ; 2031553Srgrimes 2041553SrgrimesMkopt_list: 2051553Srgrimes Mkopt_list COMMA Mkoption 2061553Srgrimes | 2071553Srgrimes Mkoption 2081553Srgrimes ; 2091553Srgrimes 2101553SrgrimesMkoption: 21146104Sluoqi Save_id EQUALS Opt_value 21272844Speter = { newopt(&mkopt, $1, $3); } ; 2131553Srgrimes 2141553SrgrimesDev: 2151553Srgrimes ID 21620458Sjoerg = { $$ = $1; } 2171553Srgrimes ; 2181553Srgrimes 2191553SrgrimesDevice_spec: 22061640Speter DEVICE Dev 22153047Speter = { 22272844Speter newopt(&opt, devopt($2), ns("1")); 22371251Speter /* and the device part */ 22472841Speter newdev($2, UNKNOWN); 22553047Speter } | 22661640Speter DEVICE Dev NUMBER 22753047Speter = { 22872844Speter newopt(&opt, devopt($2), ns("1")); 22971251Speter /* and the device part */ 23072841Speter newdev($2, $3); 23172841Speter if ($3 == 0) 23271363Speter errx(1, "line %d: devices with zero units are not likely to be correct", yyline); 23346021Speter } ; 2341553Srgrimes 2351553Srgrimes%% 2361553Srgrimes 23745775Speterstatic void 23872684Speteryyerror(const char *s) 2391553Srgrimes{ 24029493Scharnier 24171363Speter errx(1, "line %d: %s", yyline + 1, s); 2421553Srgrimes} 2431553Srgrimes 2441553Srgrimes/* 2451553Srgrimes * add a device to the list of devices 2461553Srgrimes */ 24745744Speterstatic void 24872841Speternewdev(char *name, int count) 2491553Srgrimes{ 25061640Speter struct device *np; 2511553Srgrimes 2521553Srgrimes np = (struct device *) malloc(sizeof *np); 25312772Speter memset(np, 0, sizeof(*np)); 25472841Speter np->d_name = name; 25572841Speter np->d_count = count; 2561553Srgrimes np->d_next = 0; 2571553Srgrimes if (curp == 0) 2581553Srgrimes dtab = np; 2591553Srgrimes else 2601553Srgrimes curp->d_next = np; 2611553Srgrimes curp = np; 2621553Srgrimes} 26372841Speter 26472841Speterstatic void 26572844Speternewopt(struct opt **list, char *name, char *value) 26672841Speter{ 26772841Speter struct opt *op; 26872841Speter 26972841Speter op = (struct opt *)malloc(sizeof (struct opt)); 27072841Speter memset(op, 0, sizeof(*op)); 27172841Speter op->op_name = name; 27272841Speter op->op_ownfile = 0; 27372841Speter op->op_value = value; 27472844Speter op->op_next = *list; 27572844Speter *list = op; 27672841Speter} 277