|
|
1.1 ! root 1: %{ ! 2: ! 3: /* ! 4: * Copyright (c) 1980 Regents of the University of California. ! 5: * All rights reserved. The Berkeley software License Agreement ! 6: * specifies the terms and conditions for redistribution. ! 7: * ! 8: * @(#)config.l 5.2 (Berkeley) 4/18/86 ! 9: */ ! 10: ! 11: #include <ctype.h> ! 12: #include "y.tab.h" ! 13: #include "config.h" ! 14: ! 15: #define tprintf if (do_trace) printf ! 16: ! 17: /* ! 18: * Key word table ! 19: */ ! 20: ! 21: struct kt { ! 22: char *kt_name; ! 23: int kt_val; ! 24: } key_words[] = { ! 25: { "and", AND }, ! 26: { "args", ARGS }, ! 27: { "at", AT }, ! 28: { "config", CONFIG }, ! 29: { "controller", CONTROLLER }, ! 30: { "cpu", CPU }, ! 31: { "csr", CSR }, ! 32: { "device", DEVICE }, ! 33: { "disk", DISK }, ! 34: { "drive", DRIVE }, ! 35: { "dst", DST }, ! 36: { "dumps", DUMPS }, ! 37: { "flags", FLAGS }, ! 38: { "hz", HZ }, ! 39: { "ident", IDENT }, ! 40: { "machine", MACHINE }, ! 41: { "major", MAJOR }, ! 42: { "makeoptions", MAKEOPTIONS }, ! 43: { "master", MASTER }, ! 44: { "maxusers", MAXUSERS }, ! 45: { "mba", MBA }, ! 46: { "minor", MINOR }, ! 47: { "nexus", NEXUS }, ! 48: { "on", ON }, ! 49: { "options", OPTIONS }, ! 50: { "priority", PRIORITY }, ! 51: { "pseudo-device",PSEUDO_DEVICE }, ! 52: { "root", ROOT }, ! 53: { "size", SIZE }, ! 54: { "slave", SLAVE }, ! 55: { "swap", SWAP }, ! 56: { "tape", DEVICE }, ! 57: { "timezone", TIMEZONE }, ! 58: { "trace", TRACE }, ! 59: { "uba", UBA }, ! 60: { "vector", VECTOR }, ! 61: { 0, 0 }, ! 62: }; ! 63: %} ! 64: WORD [A-Za-z_][-A-Za-z_]* ! 65: %% ! 66: {WORD} { ! 67: int i; ! 68: ! 69: if ((i = kw_lookup(yytext)) == -1) ! 70: { ! 71: yylval.str = yytext; ! 72: tprintf("id(%s) ", yytext); ! 73: return ID; ! 74: } ! 75: tprintf("(%s) ", yytext); ! 76: return i; ! 77: } ! 78: \"[^"]+\" { ! 79: yytext[strlen(yytext)-1] = '\0'; ! 80: yylval.str = yytext + 1; ! 81: return ID; ! 82: } ! 83: 0[0-7]* { ! 84: yylval.val = octal(yytext); ! 85: tprintf("#O:%o ", yylval.val); ! 86: return NUMBER; ! 87: } ! 88: 0x[0-9a-fA-F]+ { ! 89: yylval.val = hex(yytext); ! 90: tprintf("#X:%x ", yylval.val); ! 91: return NUMBER; ! 92: } ! 93: [1-9][0-9]* { ! 94: yylval.val = atoi(yytext); ! 95: tprintf("#D:%d ", yylval.val); ! 96: return NUMBER; ! 97: } ! 98: [0-9]"."[0-9]* { ! 99: double atof(); ! 100: yylval.val = (int) (60 * atof(yytext) + 0.5); ! 101: return FPNUMBER; ! 102: } ! 103: "-" { ! 104: return MINUS; ! 105: } ! 106: "?" { ! 107: yylval.val = -1; ! 108: tprintf("? "); ! 109: return NUMBER; ! 110: } ! 111: \n/[ \t] { ! 112: yyline++; ! 113: tprintf("\n... "); ! 114: } ! 115: \n { ! 116: yyline++; ! 117: tprintf("\n"); ! 118: return SEMICOLON; ! 119: } ! 120: #.* { /* Ignored (comment) */; } ! 121: [ \t]* { /* Ignored (white space) */; } ! 122: ";" { return SEMICOLON; } ! 123: "," { return COMMA; } ! 124: "=" { return EQUALS; } ! 125: "@" { return AT; } ! 126: . { return yytext[0]; } ! 127: ! 128: %% ! 129: /* ! 130: * kw_lookup ! 131: * Look up a string in the keyword table. Returns a -1 if the ! 132: * string is not a keyword otherwise it returns the keyword number ! 133: */ ! 134: ! 135: kw_lookup(word) ! 136: register char *word; ! 137: { ! 138: register struct kt *kp; ! 139: ! 140: for (kp = key_words; kp->kt_name != 0; kp++) ! 141: if (eq(word, kp->kt_name)) ! 142: return kp->kt_val; ! 143: return -1; ! 144: } ! 145: ! 146: /* ! 147: * Number conversion routines ! 148: */ ! 149: ! 150: octal(str) ! 151: char *str; ! 152: { ! 153: int num; ! 154: ! 155: (void) sscanf(str, "%o", &num); ! 156: return num; ! 157: } ! 158: ! 159: hex(str) ! 160: char *str; ! 161: { ! 162: int num; ! 163: ! 164: (void) sscanf(str+2, "%x", &num); ! 165: return num; ! 166: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.