[BACK]Return to lex.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / parse

Annotation of OpenXM_contrib2/asir2000/parse/lex.c, Revision 1.6

1.4       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.5       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.4       noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.6     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/lex.c,v 1.5 2000/08/22 05:04:27 noro Exp $
1.4       noro       49: */
1.1       noro       50: #include <ctype.h>
                     51: #include "ca.h"
                     52: #include "al.h"
                     53: #include "base.h"
                     54: #include "parse.h"
                     55: #if !defined(THINK_C)
                     56: #include <sys/types.h>
                     57: #include <sys/stat.h>
                     58: #endif
                     59: #include "y.tab.h"
                     60:
                     61: extern IN asir_infile;
                     62: extern struct oTKWD kwd[];
                     63:
                     64: int afternl();
                     65: int myatoi();
                     66: int aftercomment();
                     67:
                     68: extern int main_parser;
                     69: extern char *parse_strp;
                     70:
                     71: static int skipspace();
                     72: static int Getc();
                     73: static void Ungetc();
                     74: static void Gets();
                     75:
1.2       noro       76: #define NBUFSIZ (BUFSIZ*10)
                     77: #define TBUFSIZ (BUFSIZ)
                     78:
                     79: #define REALLOC_NBUF \
                     80: if ( i >= nbufsize ) {\
                     81:        nbufsize += NBUFSIZ;\
                     82:        if ( nbuf == nbuf0 ) {\
                     83:                nbuf = (char *)MALLOC_ATOMIC(nbufsize);\
                     84:                bcopy(nbuf0,nbuf,nbufsize-NBUFSIZ);\
                     85:        } else\
                     86:                nbuf = REALLOC(nbuf,nbufsize);\
                     87: }
                     88:
                     89: #define REALLOC_TBUF \
                     90: if ( i >= tbufsize ) {\
                     91:        tbufsize += TBUFSIZ;\
                     92:        if ( tbuf == tbuf0 ) {\
                     93:                tbuf = (char *)MALLOC_ATOMIC(tbufsize);\
                     94:                bcopy(tbuf0,tbuf,tbufsize-TBUFSIZ);\
                     95:        } else\
                     96:                tbuf = REALLOC(tbuf,tbufsize);\
                     97: }
                     98:
                     99: #define READ_ALNUM_NBUF \
                    100: while ( 1 ) {\
                    101:        c = Getc();\
                    102:        if ( isalnum(c) ) {\
                    103:                REALLOC_NBUF nbuf[i++] = c;\
                    104:        } else\
                    105:                break;\
                    106: }
                    107:
                    108: #define READ_DIGIT_NBUF \
                    109: while ( 1 ) {\
                    110:        c = Getc();\
                    111:        if ( isdigit(c) ) {\
                    112:                REALLOC_NBUF nbuf[i++] = c;\
                    113:        } else\
                    114:                break;\
                    115: }
                    116:
1.1       noro      117: yylex()
                    118: {
                    119: #define yylvalp (&yylval)
                    120:        register int c,c1;
                    121:        register int *ptr;
                    122:        char *cptr;
                    123:        int d,i,j;
1.2       noro      124:        char nbuf0[NBUFSIZ],tbuf0[TBUFSIZ];
                    125:        char *nbuf, *tbuf;
                    126:        int nbufsize, tbufsize;
1.1       noro      127:        N n,n1;
                    128:        Q q;
                    129:        Obj r;
                    130:
1.2       noro      131:        /* initialize buffer pointers */
                    132:        nbuf = nbuf0; tbuf = tbuf0;
                    133:        nbufsize = NBUFSIZ; tbufsize = TBUFSIZ;
                    134:
1.1       noro      135:        switch ( c = skipspace() ) {
                    136:                case EOF :
                    137:                        asir_terminate(2); break;
                    138:                case '0' :
                    139:                        while ( ( c = Getc() ) == '0' );
                    140:                        if ( c == '.' ) {
                    141:                                Ungetc(c); c = '0';
                    142:                        } else if ( c == 'x' ) {
                    143:                                for ( i = 0; i < 8; i++ )
                    144:                                        nbuf[i] = '0';
1.2       noro      145:                                READ_ALNUM_NBUF
                    146:                                Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
1.1       noro      147:                                hexton(nbuf,&n1);
                    148:                                NTOQ(n1,1,q); r = (Obj)q;
                    149:                                yylvalp->p = (pointer)r;
                    150:                                return ( FORMULA );
                    151:                        } else if ( c == 'b' ) {
                    152:                                for ( i = 0; i < 32; i++ )
                    153:                                        nbuf[i] = '0';
1.2       noro      154:                                READ_ALNUM_NBUF
                    155:                                Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
1.1       noro      156:                                binaryton(nbuf,&n1);
                    157:                                NTOQ(n1,1,q); r = (Obj)q;
                    158:                                yylvalp->p = (pointer)r;
                    159:                                return ( FORMULA );
                    160:                        } else if ( !isdigit(c) ) {
                    161:                                yylvalp->p = 0; Ungetc(c);
                    162:                                return ( FORMULA );
                    163:                        }
                    164:                        break;
                    165:                case '\'' :
                    166:                        for ( i = 0; ; i++ ) {
                    167:                                c = Getc();
                    168:                                if ( c == '\'' )
                    169:                                        break;
                    170:                                if ( c == '\\' )
                    171:                                        c = Getc();
1.2       noro      172:                                REALLOC_TBUF tbuf[i] = c;
1.1       noro      173:                        }
1.2       noro      174:                        REALLOC_TBUF tbuf[i] = 0;
1.1       noro      175:                        cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    176:                        yylvalp->p = (pointer)cptr;
                    177:                        return LCASE; break;
                    178:                case '"' :
                    179:                        i = 0;
                    180:                        do {
                    181:                                c = Getc();
                    182:                                if ( c == '\\' ) {
                    183:                                        c1 = Getc();
                    184:                                        if ( c1 == 'n' )
                    185:                                                c1 = '\n';
1.2       noro      186:                                        REALLOC_NBUF nbuf[i++] = c1;
                    187:                                } else {
                    188:                                        REALLOC_NBUF nbuf[i++] = c;
                    189:                                }
1.1       noro      190:                        } while ( c != '"' );
1.2       noro      191:                        nbuf[i-1] = 0; /* REALLOC_NBUF is not necessary */
1.1       noro      192:                        cptr = (char *)MALLOC(strlen(nbuf)+1);
                    193:                        strcpy(cptr,nbuf); yylvalp->p = (pointer) cptr;
                    194:                        return ( STR ); break;
                    195:                case '>': case '<': case '=': case '!':
                    196:                        if ( (c1 = Getc()) == '=' )
                    197:                                switch ( c ) {
                    198:                                        case '>': yylvalp->i = (int)C_GE; break;
                    199:                                        case '<': yylvalp->i = (int)C_LE; break;
                    200:                                        case '=': yylvalp->i = (int)C_EQ; break;
                    201:                                        case '!': yylvalp->i = (int)C_NE; break;
                    202:                                        default: break;
                    203:                                }
                    204:                        else if ( (c == '<' && c1 == '<') || (c == '>' && c1 == '>') )
                    205:                                return c;
                    206:                        else {
                    207:                                Ungetc(c1);
                    208:                                switch ( c ) {
                    209:                                        case '>': yylvalp->i = (int)C_GT; break;
                    210:                                        case '<': yylvalp->i = (int)C_LT; break;
                    211:                                        default: return c; break;
                    212:                                }
                    213:                        }
                    214:                        return CMP; break;
                    215:                case '+': case '-': case '*': case '/': case '%': case '^':
                    216:                case '|': case '&':
                    217:                        switch ( c ) {
                    218:                                case '+': yylvalp->p = (pointer)addfs; break;
                    219:                                case '-': yylvalp->p = (pointer)subfs; break;
                    220:                                case '*': yylvalp->p = (pointer)mulfs; break;
                    221:                                case '/': yylvalp->p = (pointer)divfs; break;
                    222:                                case '%': yylvalp->p = (pointer)remfs; break;
                    223:                                case '^': yylvalp->p = (pointer)pwrfs; break;
                    224:                                default: break;
                    225:                        }
                    226:                        if ( (c1 = Getc()) == c )
                    227:                                switch ( c ) {
                    228:                                        case '+': case '-': return SELF; break;
                    229:                                        case '|': return OR; break;
                    230:                                        case '&': return AND; break;
                    231:                                        default: Ungetc(c1); return c; break;
                    232:                                }
                    233:                        else if ( c1 == '=' )
                    234:                                return BOPASS;
                    235:                        else if ( (c == '-') && (c1 == '>') )
                    236:                                return POINT;
                    237:                        else {
                    238:                                Ungetc(c1); return c;
                    239:                        }
                    240:                        break;
                    241:                default :
                    242:                        break;
                    243:        }
                    244:        if ( isdigit(c) ) {
                    245:                for ( i = 0; i < DLENGTH; i++ )
                    246:                        nbuf[i] = '0';
1.2       noro      247:                REALLOC_NBUF nbuf[i++] = c;
                    248:                READ_DIGIT_NBUF
1.1       noro      249:                if ( c == '.' ) {
                    250:                        double dbl;
                    251:                        Real real;
                    252:                        double atof();
                    253:                        extern int bigfloat;
                    254:
1.2       noro      255:                        REALLOC_NBUF nbuf[i++] = c;
                    256:                        READ_DIGIT_NBUF
1.1       noro      257:                        if ( c == 'e' ) {
1.2       noro      258:                                REALLOC_NBUF nbuf[i++] = c;
                    259:                                c = Getc();
                    260:                                if ( (c == '+') || (c == '-') ) {
                    261:                                        REALLOC_NBUF nbuf[i++] = c;
                    262:                                } else
                    263:                                        Ungetc(c);
                    264:                                READ_DIGIT_NBUF
1.1       noro      265:                        }
1.2       noro      266:                        Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
1.1       noro      267: #if PARI
                    268:                        if ( !bigfloat ) {
                    269:                                dbl = (double)atof(nbuf+DLENGTH);
                    270:                                MKReal(dbl,real); r = (Obj)real;
                    271:                        } else
                    272:                                strtobf(nbuf,(BF *)&r);
                    273: #else
                    274:                        dbl = (double)atof(nbuf+DLENGTH);
                    275:                        MKReal(dbl,real); r = (Obj)real;
                    276: #endif
                    277:                } else {
                    278:                        Ungetc(c);
                    279:                        i -= DLENGTH; d = (i%DLENGTH?i/DLENGTH+1:i/DLENGTH);
                    280:                        n = NALLOC(d); PL(n) = d;
                    281:                        for ( j = 0, ptr = BD(n); j < d; j++ ,i -= DLENGTH )
                    282:                                ptr[j] = myatoi(nbuf+i);
                    283:                        bnton(DBASE,n,&n1);
                    284:                        NTOQ(n1,1,q); r = (Obj)q;
                    285: /*                     optobj(&r); */
                    286:                }
                    287:                yylvalp->p = (pointer)r;
                    288:                return ( FORMULA );
                    289:        } else if ( isalpha(c) ) {
1.2       noro      290:                i = 0;
                    291:                tbuf[i++] = c;
                    292:                while ( 1 ) {
                    293:                        c = Getc();
                    294:                        if ( isalpha(c)||isdigit(c)||(c=='_') ) {
                    295:                                REALLOC_TBUF tbuf[i++] = c;
                    296:                        } else
                    297:                                break;
                    298:                }
                    299:                REALLOC_TBUF tbuf[i] = 0; Ungetc(c);
1.1       noro      300:                if ( isupper(tbuf[0]) ) {
                    301:                        cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    302:                        yylvalp->p = (pointer)cptr;
                    303:                        return UCASE;
                    304:                } else {
                    305:                        for ( i = 0; kwd[i].name && strcmp(tbuf,kwd[i].name); i++ );
                    306:                        if ( kwd[i].name ) {
                    307:                                yylvalp->i = asir_infile->ln;
                    308:                                return kwd[i].token;
                    309:                        } else {
                    310:                                cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    311:                                yylvalp->p = (pointer)cptr;
                    312:                                return LCASE;
                    313:                        }
                    314:                }
                    315:        } else if ( c == '@' ) {
                    316:                if ( isdigit(c = Getc()) ) {
1.2       noro      317:                        i = 0;
                    318:                        nbuf[i++] = c;
                    319:                        READ_DIGIT_NBUF
                    320:                        Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
                    321:                        yylvalp->i = atoi(nbuf);
1.1       noro      322:                        return ANS;
                    323:                } else if ( c == '@' ) {
                    324:                        yylvalp->i = MAX(0,APVS->n-1);
                    325:                        return ANS;
                    326:                } else if ( c == '>' ||  c == '<' ||  c == '=' || c == '!' ) {
                    327:                        if ( (c1 = Getc()) == '=' )
                    328:                                switch ( c ) {
                    329:                                        case '>': yylvalp->i = (int)L_GE; break;
                    330:                                        case '<': yylvalp->i = (int)L_LE; break;
                    331:                                        case '=': yylvalp->i = (int)L_EQ; break;
                    332:                                        case '!': yylvalp->i = (int)L_NE; break;
                    333:                                        default: break;
                    334:                                }
                    335:                        else {
                    336:                                Ungetc(c1);
                    337:                                switch ( c ) {
                    338:                                        case '>': yylvalp->i = (int)L_GT; break;
                    339:                                        case '<': yylvalp->i = (int)L_LT; break;
                    340:                                        case '=': yylvalp->i = (int)L_EQ; break;
                    341:                                        case '!': yylvalp->i = (int)L_NOT; return FOP_NOT; break;
                    342:                                        default: break;
                    343:                                }
                    344:                        }
                    345:                        return LOP;
                    346:                } else if ( c == '|' ||  c == '&' ) {
                    347:                        if ( (c1 = Getc()) != c )
                    348:                                Ungetc(c1);
                    349:                        switch ( c ) {
                    350:                                case '|': yylvalp->i = (int)L_OR;
                    351:                                        return FOP_OR; break;
                    352:                                case '&': yylvalp->i = (int)L_AND;
                    353:                                        return FOP_AND; break;
                    354:                        }
                    355:                } else if ( isalpha(c) ) {
1.2       noro      356:                        i = 0;
                    357:                        tbuf[i++] = '@';
                    358:                        tbuf[i++] = c;
                    359:                        while ( 1 ) {
                    360:                                c = Getc();
                    361:                                if ( isalpha(c) ) {
                    362:                                        REALLOC_TBUF tbuf[i++] = c;
                    363:                                } else
                    364:                                        break;
                    365:                        }
                    366:                        Ungetc(c); REALLOC_TBUF tbuf[i] = 0;
1.1       noro      367:                        if ( !strcmp(tbuf,"@p") )
                    368:                                return GFPNGEN;
                    369:                        else if ( !strcmp(tbuf,"@i") ) {
                    370:                                extern pointer IU;
                    371:
                    372:                                yylvalp->p = IU;
                    373:                                return FORMULA;
                    374:                        } else if ( !strcmp(tbuf,"@true") ) {
                    375:                                yylvalp->p = F_TRUE;
                    376:                                return FORMULA;
                    377:                        } else if ( !strcmp(tbuf,"@false") ) {
                    378:                                yylvalp->p = F_FALSE;
                    379:                                return FORMULA;
                    380:                        } else if ( !strcmp(tbuf,"@impl") ) {
                    381:                                yylvalp->i = (int)L_IMPL;
                    382:                                return FOP_IMPL;
                    383:                        } else if ( !strcmp(tbuf,"@repl") ) {
                    384:                                yylvalp->i = (int)L_REPL;
                    385:                                return FOP_REPL;
                    386:                        } else if ( !strcmp(tbuf,"@equiv") ) {
                    387:                                yylvalp->i = (int)L_EQUIV;
                    388:                                return FOP_EQUIV;
                    389:                        } else {
                    390:                                cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    391:                                yylvalp->p = (pointer)cptr;
                    392:                                return LCASE;
                    393:                        }
                    394:                } else {
                    395:                        Ungetc(c);
                    396:                        return GF2NGEN;
                    397:                }
                    398:        } else
                    399:                return ( c );
1.6     ! noro      400: }
        !           401:
        !           402: void purge_stdin()
        !           403: {
        !           404: #if defined(VISUAL)
        !           405: #elif defined(__FreeBSD__)
        !           406:        fpurge(stdin);
        !           407: #elif defined(linux)
        !           408:        stdin->_IO_read_end = stdin->_IO_read_base;
        !           409:        stdin->_IO_read_ptr = stdin->_IO_read_base;
        !           410: #elif defined(sparc) || defined(__alpha) || defined(__SVR4) || defined(mips)
        !           411:        stdin->_ptr = stdin->_base; stdin->_cnt = 0;
        !           412: #elif defined(VISUAL)
        !           413:        w_purge_stdin();
        !           414: #else
        !           415: --->FIXIT
        !           416: #endif
1.1       noro      417: }
                    418:
                    419: static int skipspace() {
                    420:        int c,c1;
                    421:
                    422:        for ( c = Getc(); ; )
                    423:                switch ( c ) {
                    424:                        case ' ': case '\t':
                    425:                                c = Getc(); break;
                    426:                        case '\n':
                    427:                                c = afternl();  break;
                    428:                        case '/':
                    429:                                if ( (c1 = Getc()) == '*' )
                    430:                                        c = aftercomment();
                    431:                                else {
                    432:                                        Ungetc(c1); return c;
                    433:                                }
                    434:                                break;
                    435:                        default:
                    436:                                return c; break;
                    437:                }
                    438: }
                    439:
                    440: int afternl() {
                    441:        int c,ac,i,quote;
                    442:        char *ptr;
                    443:        char *av[BUFSIZ];
                    444:        static int ilevel = 0;
                    445:        char buf[BUFSIZ];
                    446:
                    447:        if ( !ilevel )
                    448:                asir_infile->ln++;
                    449:        while ( (c = Getc()) == '#' ) {
                    450:                Gets(buf);
                    451:                for ( quote = 0, ptr = buf; *ptr; ptr++ )
                    452:                        if ( *ptr == '"' )
                    453:                                quote = quote ? 0 : 1;
                    454:                        else if ( quote && (*ptr == ' ') )
                    455:                                *ptr = '_';
                    456:                stoarg(buf,&ac,av);
                    457:                if ( ac == 3 )
                    458:                        if ( (i = atoi(av[2])) == 1 )
                    459:                                ilevel++;
                    460:                        else if ( i == 2 )
                    461:                                ilevel--;
                    462:                if ( !ilevel )
                    463:                        asir_infile->ln = atoi(av[0]);
                    464:        }
                    465:        return c;
                    466: }
                    467:
                    468: int aftercomment() {
                    469:        int c,c1;
                    470:
                    471:        for ( c = Getc(); ; ) {
                    472:                c1 = Getc();
                    473:                if ( (c == '*') && (c1 == '/') )
                    474:                        return Getc();
                    475:                else
                    476:                        c = c1;
                    477:        }
                    478: }
                    479:
                    480: int myatoi(s)
                    481: char *s;
                    482: {
                    483:        int i,r;
                    484:        for ( i = 0, r = 0; i < DLENGTH; i++ ) r = r * 10 + ( s[i] - '0' );
                    485:        return ( r );
                    486: }
                    487:
                    488: extern int ox_do_copy;
                    489:
                    490: void yyerror(s)
                    491: char *s;
                    492: {
                    493:        if ( main_parser )
                    494:                if ( ox_do_copy ) {
                    495:                        /* push errors to DebugStack */
                    496:                } else {
                    497:                        if ( asir_infile->fp == stdin )
                    498:                                fprintf(stderr,"%s\n",s);
                    499:                        else
                    500:                                fprintf(stderr,"\"%s\", near line %d: %s\n",asir_infile->name,asir_infile->ln,s);
                    501:                }
                    502:        else
                    503:                fprintf(stderr,"exprparse : %s\n",s);
                    504: }
                    505:
                    506: int echoback;
                    507:
                    508: extern int read_exec_file, do_fep, do_file;
                    509:
                    510: int readline_getc();
                    511: void readline_ungetc();
                    512: int Egetc();
                    513: void Eungetc();
                    514:
                    515: unsigned char encrypt_char(unsigned char);
                    516: unsigned char decrypt_char(unsigned char);
                    517:
                    518: int Egetc(fp)
                    519: FILE *fp;
                    520: {
                    521:        int c;
                    522:
                    523:        if ( fp ) {
                    524:                c = getc(fp);
                    525:                if ( c == EOF )
                    526:                        return c;
                    527:                if ( asir_infile->encoded )
                    528:                        c = decrypt_char((unsigned char)c);
                    529:                return c;
1.3       noro      530:        } else if ( read_exec_file )
                    531:                return EOF;
                    532:        else {
1.1       noro      533:                c = *parse_strp++;
                    534:                if ( !c )
                    535:                        return EOF;
                    536:                else
                    537:                        return c;
                    538:        }
                    539: }
                    540:
                    541: void Eungetc(c,fp)
                    542: int c;
                    543: FILE *fp;
                    544: {
                    545:        if ( fp ) {
                    546:                if ( asir_infile->encoded )
                    547:                        c = (int)encrypt_char((unsigned char)c);
                    548:                ungetc(c,fp);
                    549:        } else
                    550:                *--parse_strp = c;
                    551: }
                    552:
                    553: static int Getc() {
                    554:        int c;
                    555:
                    556:        if ( main_parser ) {
                    557:                while ( 1 ) {
                    558:                        if ((c = Egetc(asir_infile->fp)) == EOF)
                    559:                                if ( NEXT(asir_infile) ) {
                    560:                                        closecurrentinput();
                    561:                                        c = Getc();
                    562:                                        break;
                    563:                                } else if ( read_exec_file || do_file )
                    564:                                        asir_terminate(2);
                    565:                                else {
                    566:                                        if ( asir_infile->fp )
                    567:                                                clearerr(asir_infile->fp);
                    568:                                }
                    569:                        else
                    570:                                break;
                    571:                }
                    572:                if ( echoback )
                    573:                        fputc(c,asir_out);
                    574:        } else
                    575:                c = *parse_strp++;
                    576:        return ( c );
                    577: }
                    578:
                    579: static void Ungetc(c) {
                    580:        if ( main_parser ) {
                    581:                Eungetc(c,asir_infile->fp);
                    582:                if ( echoback )
                    583:                        fputc('',asir_out);
                    584:        } else
                    585:                *--parse_strp = c;
                    586: }
                    587:
                    588: static void Gets(s)
                    589: char *s;
                    590: {
                    591:        int c;
                    592:
                    593:        while ( (c = Getc()) != '\n' )
                    594:                *s++ = c;
                    595:        *s = 0;
                    596: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>