Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | /* * Mach Operating System * Copyright (c) 1990 Carnegie-Mellon University * Copyright (c) 1989 Carnegie-Mellon University * Copyright (c) 1988 Carnegie-Mellon University * Copyright (c) 1987 Carnegie-Mellon University * All rights reserved. The CMU software License Agreement specifies * the terms and conditions for use and redistribution. */ /* * Copyright (c) 1988 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by the University of California, Berkeley. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * @(#)config.y 5.8 (Berkeley) 6/18/88 */ %union { char *str; int val; struct file_list *file; struct idlst *lst; } %token BUILDDIR %token COMMA %token EQUALS %token INIT %token MACHINE %token OBJECTDIR %token OPTIONS %token MAKEOPTIONS %token PSEUDO_DEVICE %token SEMICOLON %token SOURCEDIR %token TRACE %token <str> ID %token <val> NUMBER %type <str> Save_id %type <str> Opt_value %type <str> Dev %{ #include "config.h" #include <ctype.h> #include <stdio.h> struct device cur; struct device *curp = 0; char *temp_id; char *val_id; /* char *malloc(); */ int yylex(void); void deverror(const char *systemname, const char *devtype); %} %% Configuration: Many_specs ; Many_specs: Many_specs Spec | /* lambda */ ; Spec: Device_spec SEMICOLON { newdev(&cur); } | Config_spec SEMICOLON | TRACE SEMICOLON { do_trace = !do_trace; } | SEMICOLON | error SEMICOLON ; Config_spec: MACHINE Save_id { machinename = ns($2); } | OPTIONS Opt_list | MAKEOPTIONS Mkopt_list | BUILDDIR Save_id { build_directory = ns($2); } | OBJECTDIR Save_id { object_directory = ns($2); } | SOURCEDIR Save_id { source_directory = ns($2); } ; Opt_list: Opt_list COMMA Option | Option ; Option: Save_id { struct opt *op = (struct opt *)malloc(sizeof (struct opt)); op->op_name = ns($1); op->op_next = (struct opt *) 0; op->op_value = 0; if (opt == (struct opt *) 0) opt = op; else opt_tail->op_next = op; opt_tail = op; free(temp_id); } | Save_id EQUALS Opt_value { struct opt *op = (struct opt *)malloc(sizeof (struct opt)); op->op_name = ns($1); op->op_next = (struct opt *) 0; op->op_value = ns($3); if (opt == (struct opt *) 0) opt = op; else opt_tail->op_next = op; opt_tail = op; free(temp_id); if (val_id) free(val_id); } ; Opt_value: ID { $$ = val_id = ns($1); } | NUMBER { char nb[16]; (void) sprintf(nb, "%u", $1); $$ = val_id = ns(nb); } | /* lambda from MIPS -- WHY */ { $$ = val_id = ns(""); } ; Save_id: ID { $$ = temp_id = ns($1); } ; Mkopt_list: Mkopt_list COMMA Mkoption | Mkoption ; Mkoption: Save_id { struct opt *op = (struct opt *)malloc(sizeof (struct opt)); op->op_name = ns($1); op->op_next = (struct opt *) 0; op->op_value = 0; mkopt = op; free(temp_id); } | Save_id EQUALS Opt_value { struct opt *op = (struct opt *)malloc(sizeof (struct opt)); op->op_name = ns($1); op->op_next = (struct opt *) 0; op->op_value = ns($3); if (mkopt == (struct opt *) 0) mkopt = op; else mkopt_tail->op_next = op; mkopt_tail = op; free(temp_id); if (val_id) free(val_id); } ; Dev: ID { $$ = ns($1); } ; Device_spec: PSEUDO_DEVICE Init_dev Dev { cur.d_name = $3; cur.d_type = PSEUDO_DEVICE; } | PSEUDO_DEVICE Init_dev Dev NUMBER { cur.d_name = $3; cur.d_type = PSEUDO_DEVICE; cur.d_slave = $4; } | PSEUDO_DEVICE Init_dev Dev INIT ID { cur.d_name = $3; cur.d_type = PSEUDO_DEVICE; cur.d_init = ns($5); } | PSEUDO_DEVICE Init_dev Dev NUMBER INIT ID { cur.d_name = $3; cur.d_type = PSEUDO_DEVICE; cur.d_slave = $4; cur.d_init = ns($6); }; Init_dev: /* lambda */ { init_dev(&cur); }; %% void yyerror(const char *s) { fprintf(stderr, "config: line %d: %s\n", yyline, s); } /* * return the passed string in a new space */ char * ns(const char *str) { register char *cp; cp = malloc((unsigned)(strlen(str)+1)); (void) strcpy(cp, str); return (cp); } /* * add a device to the list of devices */ void newdev(struct device *dp) { register struct device *np; np = (struct device *) malloc(sizeof *np); *np = *dp; if (curp == 0) dtab = np; else curp->d_next = np; curp = np; curp->d_next = 0; } void init_dev(struct device *dp) { dp->d_name = "OHNO!!!"; dp->d_type = PSEUDO_DEVICE; dp->d_flags = 0; dp->d_slave = UNKNOWN; dp->d_init = 0; } void deverror(const char *systemname, const char *devtype) { fprintf(stderr, "config: %s: %s device not configured\n", systemname, devtype); } |