Annotation of researchv9/sys.vax/conf/src/config/config.l, revision 1.1

1.1     ! root        1: %{
        !             2: /*     config.l        1.8     81/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: YYSTYPE yylval;
        !            11: 
        !            12: /*
        !            13:  * Key word table
        !            14:  */
        !            15: 
        !            16: struct kt {
        !            17:        char *kt_name;
        !            18:        int kt_val;
        !            19: } key_words[] = {
        !            20:        "cpu", CPU, "ident", IDENT, "config", CONFIG, "options", OPTIONS,
        !            21:        "device", DEVICE, "controller", CONTROLLER, "uba", UBA, "mba", MBA,
        !            22:        "csr", CSR, "nexus", NEXUS, "drive", DRIVE, "vector", VECTOR,
        !            23:        "pseudo-device", PSEUDO_DEVICE, "flags", FLAGS, "trace", TRACE,
        !            24:        "disk", DISK, "tape", DEVICE, "slave", SLAVE, "at", AT,
        !            25:        "hz", HZ, "timezone", TIMEZONE, "dst", DST, "maxusers", MAXUSERS,
        !            26:        "master", MASTER, "mkfile", MAKEFILE,
        !            27:        0,0,
        !            28: };
        !            29: %}
        !            30: WORD   [A-Za-z_][-A-Za-z_]*
        !            31: %%
        !            32: {WORD}         {
        !            33:                        int i;
        !            34: 
        !            35:                        if ((i = kw_lookup(yytext)) == -1)
        !            36:                        {
        !            37:                                yylval.cp = yytext;
        !            38:                                tprintf("id(%s) ", yytext);
        !            39:                                return ID;
        !            40:                        }
        !            41:                        tprintf("(%s) ", yytext);
        !            42:                        return i;
        !            43:                }
        !            44: \"[^"]+\"      {
        !            45:                        yytext[strlen(yytext)-1] = '\0';
        !            46:                        yylval.cp = yytext + 1;
        !            47:                        return ID;
        !            48:                }
        !            49: 0[0-7]*                {
        !            50:                        yylval.i = octal(yytext);
        !            51:                        tprintf("#O:%o ", yylval.i);
        !            52:                        return NUMBER;
        !            53:                }
        !            54: 0x[0-9a-f]+    {
        !            55:                        yylval.i = hex(yytext);
        !            56:                        tprintf("#X:%x ", yylval.i);
        !            57:                        return NUMBER;
        !            58:                }
        !            59: [1-9][0-9]*    {
        !            60:                        yylval.i = atoi(yytext);
        !            61:                        tprintf("#D:%d ", yylval.i);
        !            62:                        return NUMBER;
        !            63:                }
        !            64: [0-9]"."[0-9]* {
        !            65:                        double atof();
        !            66:                        yylval.i = (int) (60 * atof(yytext) + 0.5);
        !            67:                        return FPNUMBER;
        !            68:                }
        !            69: "-"            {
        !            70:                        return MINUS;
        !            71:                }
        !            72: "?"            {
        !            73:                        yylval.i = QUES;
        !            74:                        tprintf("? ");
        !            75:                        return NUMBER;
        !            76:                }
        !            77: \n/[ \t]       {
        !            78:                        yyline++;
        !            79:                        tprintf("\n... ");
        !            80:                }
        !            81: \n             {
        !            82:                        yyline++;
        !            83:                        tprintf("\n");
        !            84:                        return SEMICOLON;
        !            85:                }
        !            86: ^#.*           {       /* Ignored (comment) */;        }
        !            87: [ \t]*         {       /* Ignored (white space) */;    }
        !            88: ";"            {       return SEMICOLON;               }
        !            89: ","            {       return COMMA;                   }
        !            90: %%
        !            91: /*
        !            92:  * kw_lookup
        !            93:  *     Look up a string in the keyword table.  Returns a -1 if the
        !            94:  *     string is not a keyword otherwise it returns the keyword number
        !            95:  */
        !            96: 
        !            97: kw_lookup(word)
        !            98: register char *word;
        !            99: {
        !           100:        register struct kt *kp;
        !           101: 
        !           102:        for (kp = key_words; kp->kt_name != 0; kp++)
        !           103:                if (eq(word, kp->kt_name))
        !           104:                        return kp->kt_val;
        !           105:        return -1;
        !           106: }
        !           107: 
        !           108: /*
        !           109:  * Number conversion routines
        !           110:  */
        !           111: 
        !           112: octal(str)
        !           113: char *str;
        !           114: {
        !           115:        int num;
        !           116: 
        !           117:        sscanf(str, "%o", &num);
        !           118:        return num;
        !           119: }
        !           120: 
        !           121: hex(str)
        !           122: char *str;
        !           123: {
        !           124:        int num;
        !           125: 
        !           126:        sscanf(str+2, "%x", &num);
        !           127:        return num;
        !           128: }

unix.superglobalmegacorp.com

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