Annotation of 43BSDReno/usr.sbin/config/lang.l, revision 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:  *     @(#)lang.l      5.6 (Berkeley) 5/16/90
        !            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: #if MACHINE_HP300
        !            64:        { "scode",      NEXUS },
        !            65: #endif
        !            66:        { "size",       SIZE },
        !            67:        { "slave",      SLAVE },
        !            68:        { "swap",       SWAP },
        !            69:        { "tape",       DEVICE },
        !            70:        { "timezone",   TIMEZONE },
        !            71:        { "trace",      TRACE },
        !            72:        { "vector",     VECTOR },
        !            73:        { 0, 0 },
        !            74: };
        !            75: %}
        !            76: WORD   [A-Za-z_][-A-Za-z_]*
        !            77: %%
        !            78: {WORD}         {
        !            79:                        int i;
        !            80: 
        !            81:                        if ((i = kw_lookup(yytext)) == -1)
        !            82:                        {
        !            83:                                yylval.str = yytext;
        !            84:                                tprintf("id(%s) ", yytext);
        !            85:                                return ID;
        !            86:                        }
        !            87:                        tprintf("(%s) ", yytext);
        !            88:                        return i;
        !            89:                }
        !            90: \"[^"]+\"      {
        !            91:                        yytext[strlen(yytext)-1] = '\0';
        !            92:                        yylval.str = yytext + 1;
        !            93:                        return ID;
        !            94:                }
        !            95: 0[0-7]*                {
        !            96:                        yylval.val = octal(yytext);
        !            97:                        tprintf("#O:%o ", yylval.val);
        !            98:                        return NUMBER;
        !            99:                }
        !           100: 0x[0-9a-fA-F]+ {
        !           101:                        yylval.val = hex(yytext);
        !           102:                        tprintf("#X:%x ", yylval.val);
        !           103:                        return NUMBER;
        !           104:                }
        !           105: [1-9][0-9]*    {
        !           106:                        yylval.val = atoi(yytext);
        !           107:                        tprintf("#D:%d ", yylval.val);
        !           108:                        return NUMBER;
        !           109:                }
        !           110: [0-9]"."[0-9]* {
        !           111:                        double atof();
        !           112:                        yylval.val = (int) (60 * atof(yytext) + 0.5);
        !           113:                        return FPNUMBER;
        !           114:                }
        !           115: "-"            {
        !           116:                        return MINUS;
        !           117:                }
        !           118: "?"            {
        !           119:                        yylval.val = -1;
        !           120:                        tprintf("? ");
        !           121:                        return NUMBER;
        !           122:                }
        !           123: \n/[ \t]       {
        !           124:                        yyline++;
        !           125:                        tprintf("\n... ");
        !           126:                }
        !           127: \n             {
        !           128:                        yyline++;
        !           129:                        tprintf("\n");
        !           130:                        return SEMICOLON;
        !           131:                }
        !           132: #.*            {       /* Ignored (comment) */;        }
        !           133: [ \t]*         {       /* Ignored (white space) */;    }
        !           134: ";"            {       return SEMICOLON;               }
        !           135: ","            {       return COMMA;                   }
        !           136: "="            {       return EQUALS;                  }
        !           137: "@"            {       return AT;                      }
        !           138: .              {       return yytext[0];               }
        !           139: 
        !           140: %%
        !           141: /*
        !           142:  * kw_lookup
        !           143:  *     Look up a string in the keyword table.  Returns a -1 if the
        !           144:  *     string is not a keyword otherwise it returns the keyword number
        !           145:  */
        !           146: 
        !           147: kw_lookup(word)
        !           148: register char *word;
        !           149: {
        !           150:        register struct kt *kp;
        !           151: 
        !           152:        for (kp = key_words; kp->kt_name != 0; kp++)
        !           153:                if (eq(word, kp->kt_name))
        !           154:                        return kp->kt_val;
        !           155:        return -1;
        !           156: }
        !           157: 
        !           158: /*
        !           159:  * Number conversion routines
        !           160:  */
        !           161: 
        !           162: octal(str)
        !           163: char *str;
        !           164: {
        !           165:        int num;
        !           166: 
        !           167:        (void) sscanf(str, "%o", &num);
        !           168:        return num;
        !           169: }
        !           170: 
        !           171: hex(str)
        !           172: char *str;
        !           173: {
        !           174:        int num;
        !           175: 
        !           176:        (void) sscanf(str+2, "%x", &num);
        !           177:        return num;
        !           178: }

unix.superglobalmegacorp.com

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