Annotation of 42BSD/etc/config/config.l, revision 1.1

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

unix.superglobalmegacorp.com

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