Annotation of 43BSDTahoe/new/dipress/src/bin/texttoip/textlex.l, revision 1.1.1.1

1.1       root        1: %{
                      2: /*
                      3:  * Copyright (c) 1984, 1985, 1986 Xerox Corp.
                      4:  *
                      5:  *  texttoip - convert a textual representation of interpress to a real
                      6:  *            interpress file.  The text produced by "iptotext" is the input
                      7:  *            that is recognized.
                      8:  *
                      9:  *  This is the lex specification of the input scanner.
                     10:  *
                     11:  *  Written for Xerox Corporation by William LeFebvre
                     12:  *
                     13:  *  6-May-1984
                     14:  *
                     15:  * HISTORY
                     16:  * 15-Jul-86  Lee Moore (lee) at Xerox Webster Research Center
                     17:  *     Escaped characters (as octal numbers) are no longer processed
                     18:  *     here.  The popular null was causing problems.  Processing
                     19:  *     of these escapes has been moved to AppendString1 in libip.a .
                     20:  *
                     21:  * 01-Dec-85  lee at Xerox, WRC
                     22:  *     Linted.
                     23:  *
                     24:  * 28-apr-85  ed flint
                     25:  *     add conditional compilation for vax11-c (vms)
                     26:  *
                     27:  *
                     28:  * if using this file on vms, you must edit this file and add the following 
                     29:  * lines around the #include "stdio.h" line which is at the top of the file
                     30:  *
                     31:  *             #ifdef vax11c
                     32:  *             # include stdio
                     33:  *             #else
                     34:  *             # include "stdio.h"
                     35:  *             #endif
                     36:  */
                     37: 
                     38: 
                     39: #ifdef vax11c
                     40: # include ctype
                     41: #else
                     42: # include <ctype.h>
                     43: #endif
                     44: 
                     45: # include "iptokens.h"
                     46: # include "texttoken.h"
                     47: # include "ipnames.h"
                     48: 
                     49: # define    short_or_long(ch)  (ch != '>' ? 1 : 2)
                     50: 
                     51: extern long yylval_long;
                     52: extern char *yylval_charP;
                     53: char *buffptr;
                     54: char string_buffer[1024];
                     55: %}
                     56: 
                     57: %%
                     58: 
                     59: ^"File: "      {
                     60:                    return(T_file);
                     61:                }
                     62: 
                     63: ^"Header: "    {
                     64:                    return(T_header);
                     65:                }
                     66: 
                     67: ^>[> ]"Comment: "      {
                     68:                            yylval_long = short_or_long(yytext[1]);
                     69:                            return(T_seq_comment);
                     70:                        }
                     71: 
                     72: ^>[> ]"Identifier: "   {
                     73:                            yylval_long = short_or_long(yytext[1]);
                     74:                            return(T_seq_identifier);
                     75:                        }
                     76: 
                     77: ^>[> ]"Insert file: "  {
                     78:                            yylval_long = short_or_long(yytext[1]);
                     79:                            return(T_seq_insert_file);
                     80:                        }
                     81: 
                     82: ^>[> ]"Integer: "      {
                     83:                            yylval_long = short_or_long(yytext[1]);
                     84:                            return(T_seq_integer);
                     85:                        }
                     86: 
                     87: ^>[> ]"Rational: "     {
                     88:                            yylval_long = short_or_long(yytext[1]);
                     89:                            return(T_seq_rational);
                     90:                        }
                     91: 
                     92: ^>[> ]"String: "       {
                     93:                            yylval_long = short_or_long(yytext[1]);
                     94:                            return(T_seq_string);
                     95:                        }
                     96: 
                     97: ^>[> ]"Adaptive Pixel Vector: "        {
                     98:                            yylval_long = short_or_long(yytext[1]);
                     99:                            return(T_seq_apv);
                    100:                        }
                    101: 
                    102: ^>[> ]"Compressed Pixel Vector: "      {
                    103:                            yylval_long = short_or_long(yytext[1]);
                    104:                            return(T_seq_cpv);
                    105:                        }
                    106: 
                    107: ^>[> ]"Packed Pixel Vector: "  {
                    108:                            yylval_long = short_or_long(yytext[1]);
                    109:                            return(T_seq_ppv);
                    110:                        }
                    111: 
                    112: [+-]?[0-9A-Fa-f][0-9A-Fa-f]*   {
                    113:                            yylval_long = getnum(yytext);
                    114:                            return(T_number);
                    115:                        }
                    116: 
                    117: ^[a-zA-Z{}][a-zA-Z]*   {
                    118:                            register char *ptr;
                    119: 
                    120:                            for (ptr = yytext; *ptr; ptr++)
                    121:                            {
                    122:                                if (isupper(*ptr))
                    123:                                {
                    124:                                    *ptr = tolower(*ptr);
                    125:                                }
                    126:                            }
                    127:                            for (yylval_long = 0; yylval_long <= OP_LIMIT;
                    128:                                        yylval_long++)
                    129:                            {
                    130:                                if (strcmp(yytext, op_names[yylval_long]) == 0)
                    131:                                {
                    132:                                    return(T_operator);
                    133:                                }
                    134:                            }
                    135:                            return(T_operator);
                    136:                        }
                    137: 
                    138: \"                     {
                    139:                            unsigned char ch;
                    140:                            int val = 0;
                    141:                            int cnt = 0;
                    142: 
                    143:                            yylval_charP = buffptr = string_buffer;
                    144: 
                    145:                            while ((ch = input()) != '"')
                    146:                            {
                    147:                                if (ch == '\\')
                    148:                                {
                    149:                                    ch = input();
                    150:                                    if (ch >= '0' && ch <= '9')
                    151:                                    {
                    152:                                        *buffptr++ = '\\';
                    153:                                    }
                    154:                                }
                    155:                                *buffptr++ = ch;
                    156:                            }
                    157:                            *buffptr = '\0';
                    158:                            return(T_string);
                    159:                        }
                    160: 
                    161: [a-zA-Z][a-zA-Z0-9\-]* {
                    162:                            yylval_charP = yytext;
                    163:                            return(T_identifier);
                    164:                        }
                    165: 
                    166: [ \t][ \t]*            {
                    167:                            yyleng = 0;         /* gobble white space */
                    168:                            yymore();
                    169:                        }
                    170: 
                    171: \(.*\)                 {
                    172:                            yyleng = 0;         /* gobble comments */
                    173:                            yymore();
                    174:                        }
                    175: 
                    176: ^\(.*\)\n              {
                    177:                            /* comment that spans the whole line */
                    178:                            yyleng = 0;
                    179:                            yymore();
                    180:                        }
                    181: 
                    182: \n                     {
                    183:                            return(T_newline);
                    184:                        }
                    185: 
                    186: .                      {
                    187:                            yylval_long = yytext[yyleng-1];
                    188:                            return(T_character);
                    189:                        }
                    190: 
                    191: %%
                    192: 
                    193: extern int radix;
                    194: 
                    195: getnum(str)
                    196: 
                    197: char *str;
                    198: 
                    199: {
                    200:     register int val;
                    201:     register int digit;
                    202: 
                    203:     /* take the easy and fast way out for base 10 */
                    204:     if (radix == 10)
                    205:     {
                    206:        return(atoi(str));
                    207:     }
                    208: 
                    209:     /* otherwise this is a standard "convert any radix" algorithm */
                    210:     val = 0;
                    211:     while ((digit = *str++) != '\0')
                    212:     {
                    213:        if ((digit -= '0') > 9)
                    214:        {
                    215:            /* it is a letter */
                    216:            if ((digit -= ('A' - '0' - 10)) > 15)
                    217:            {
                    218:                /* it is a lower case digit */
                    219:                digit -= ('a' - 'A');
                    220:            }
                    221:        }
                    222:        if (digit >= radix)
                    223:        {
                    224:            /* this is really too much!  give up at this point */
                    225:            return(val);
                    226:        }
                    227:        val *= radix;
                    228:        val += digit;
                    229:     }
                    230:     return(val);
                    231: }

unix.superglobalmegacorp.com

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