Annotation of 43BSDTahoe/etc/config/config.l, revision 1.1.1.1

1.1       root        1: %{
                      2: 
                      3: /*
                      4:  * Copyright (c) 1980 Regents of the University of California.
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms are permitted
                      8:  * provided that the above copyright notice and this paragraph are
                      9:  * duplicated in all such forms and that any documentation,
                     10:  * advertising materials, and other materials related to such
                     11:  * distribution and use acknowledge that the software was developed
                     12:  * by the University of California, Berkeley.  The name of the
                     13:  * University may not be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  *
                     19:  *     @(#)config.l    5.5 (Berkeley) 6/18/88
                     20:  */
                     21: 
                     22: #include <ctype.h>
                     23: #include "y.tab.h"
                     24: #include "config.h"
                     25: 
                     26: #define tprintf if (do_trace) printf
                     27: 
                     28: /*
                     29:  * Key word table
                     30:  */
                     31: 
                     32: struct kt {
                     33:        char *kt_name;
                     34:        int kt_val;
                     35: } key_words[] = {
                     36:        { "and",        AND },
                     37:        { "args",       ARGS },
                     38:        { "at",         AT },
                     39:        { "config",     CONFIG },
                     40:        { "controller", CONTROLLER },
                     41:        { "cpu",        CPU },
                     42:        { "csr",        CSR },
                     43:        { "device",     DEVICE },
                     44:        { "disk",       DISK },
                     45:        { "drive",      DRIVE },
                     46:        { "dst",        DST },
                     47:        { "dumps",      DUMPS },
                     48:        { "flags",      FLAGS },
                     49:        { "hz",         HZ },
                     50:        { "ident",      IDENT },
                     51:        { "machine",    MACHINE },
                     52:        { "major",      MAJOR },
                     53:        { "makeoptions", MAKEOPTIONS },
                     54:        { "master",     MASTER },
                     55:        { "maxusers",   MAXUSERS },
                     56:        { "minor",      MINOR },
                     57:        { "nexus",      NEXUS },
                     58:        { "on",         ON },
                     59:        { "options",    OPTIONS },
                     60:        { "priority",   PRIORITY },
                     61:        { "pseudo-device",PSEUDO_DEVICE },
                     62:        { "root",       ROOT },
                     63:        { "size",       SIZE },
                     64:        { "slave",      SLAVE },
                     65:        { "swap",       SWAP },
                     66:        { "tape",       DEVICE },
                     67:        { "timezone",   TIMEZONE },
                     68:        { "trace",      TRACE },
                     69:        { "vector",     VECTOR },
                     70:        { 0, 0 },
                     71: };
                     72: %}
                     73: WORD   [A-Za-z_][-A-Za-z_]*
                     74: %%
                     75: {WORD}         {
                     76:                        int i;
                     77: 
                     78:                        if ((i = kw_lookup(yytext)) == -1)
                     79:                        {
                     80:                                yylval.str = yytext;
                     81:                                tprintf("id(%s) ", yytext);
                     82:                                return ID;
                     83:                        }
                     84:                        tprintf("(%s) ", yytext);
                     85:                        return i;
                     86:                }
                     87: \"[^"]+\"      {
                     88:                        yytext[strlen(yytext)-1] = '\0';
                     89:                        yylval.str = yytext + 1;
                     90:                        return ID;
                     91:                }
                     92: 0[0-7]*                {
                     93:                        yylval.val = octal(yytext);
                     94:                        tprintf("#O:%o ", yylval.val);
                     95:                        return NUMBER;
                     96:                }
                     97: 0x[0-9a-fA-F]+ {
                     98:                        yylval.val = hex(yytext);
                     99:                        tprintf("#X:%x ", yylval.val);
                    100:                        return NUMBER;
                    101:                }
                    102: [1-9][0-9]*    {
                    103:                        yylval.val = atoi(yytext);
                    104:                        tprintf("#D:%d ", yylval.val);
                    105:                        return NUMBER;
                    106:                }
                    107: [0-9]"."[0-9]* {
                    108:                        double atof();
                    109:                        yylval.val = (int) (60 * atof(yytext) + 0.5);
                    110:                        return FPNUMBER;
                    111:                }
                    112: "-"            {
                    113:                        return MINUS;
                    114:                }
                    115: "?"            {
                    116:                        yylval.val = -1;
                    117:                        tprintf("? ");
                    118:                        return NUMBER;
                    119:                }
                    120: \n/[ \t]       {
                    121:                        yyline++;
                    122:                        tprintf("\n... ");
                    123:                }
                    124: \n             {
                    125:                        yyline++;
                    126:                        tprintf("\n");
                    127:                        return SEMICOLON;
                    128:                }
                    129: #.*            {       /* Ignored (comment) */;        }
                    130: [ \t]*         {       /* Ignored (white space) */;    }
                    131: ";"            {       return SEMICOLON;               }
                    132: ","            {       return COMMA;                   }
                    133: "="            {       return EQUALS;                  }
                    134: "@"            {       return AT;                      }
                    135: .              {       return yytext[0];               }
                    136: 
                    137: %%
                    138: /*
                    139:  * kw_lookup
                    140:  *     Look up a string in the keyword table.  Returns a -1 if the
                    141:  *     string is not a keyword otherwise it returns the keyword number
                    142:  */
                    143: 
                    144: kw_lookup(word)
                    145: register char *word;
                    146: {
                    147:        register struct kt *kp;
                    148: 
                    149:        for (kp = key_words; kp->kt_name != 0; kp++)
                    150:                if (eq(word, kp->kt_name))
                    151:                        return kp->kt_val;
                    152:        return -1;
                    153: }
                    154: 
                    155: /*
                    156:  * Number conversion routines
                    157:  */
                    158: 
                    159: octal(str)
                    160: char *str;
                    161: {
                    162:        int num;
                    163: 
                    164:        (void) sscanf(str, "%o", &num);
                    165:        return num;
                    166: }
                    167: 
                    168: hex(str)
                    169: char *str;
                    170: {
                    171:        int num;
                    172: 
                    173:        (void) sscanf(str+2, "%x", &num);
                    174:        return num;
                    175: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.