[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.14

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.14    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/lex.c,v 1.13 2000/12/26 05:17:47 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: #include <sys/types.h>
                     56: #include <sys/stat.h>
1.10      noro       57: #if defined(VISUAL)
                     58: #include "ytab.h"
                     59: #else
1.1       noro       60: #include "y.tab.h"
1.10      noro       61: #endif
1.1       noro       62:
                     63: extern IN asir_infile;
                     64: extern struct oTKWD kwd[];
                     65:
                     66: int afternl();
                     67: int myatoi();
                     68: int aftercomment();
                     69:
                     70: extern int main_parser;
                     71: extern char *parse_strp;
1.11      noro       72: extern int recv_intr;
1.1       noro       73:
                     74: static int skipspace();
                     75: static int Getc();
                     76: static void Ungetc();
                     77: static void Gets();
                     78:
1.2       noro       79: #define NBUFSIZ (BUFSIZ*10)
                     80: #define TBUFSIZ (BUFSIZ)
                     81:
                     82: #define REALLOC_NBUF \
                     83: if ( i >= nbufsize ) {\
                     84:        nbufsize += NBUFSIZ;\
                     85:        if ( nbuf == nbuf0 ) {\
                     86:                nbuf = (char *)MALLOC_ATOMIC(nbufsize);\
                     87:                bcopy(nbuf0,nbuf,nbufsize-NBUFSIZ);\
                     88:        } else\
                     89:                nbuf = REALLOC(nbuf,nbufsize);\
                     90: }
                     91:
                     92: #define REALLOC_TBUF \
                     93: if ( i >= tbufsize ) {\
                     94:        tbufsize += TBUFSIZ;\
                     95:        if ( tbuf == tbuf0 ) {\
                     96:                tbuf = (char *)MALLOC_ATOMIC(tbufsize);\
                     97:                bcopy(tbuf0,tbuf,tbufsize-TBUFSIZ);\
                     98:        } else\
                     99:                tbuf = REALLOC(tbuf,tbufsize);\
                    100: }
                    101:
                    102: #define READ_ALNUM_NBUF \
                    103: while ( 1 ) {\
                    104:        c = Getc();\
                    105:        if ( isalnum(c) ) {\
                    106:                REALLOC_NBUF nbuf[i++] = c;\
                    107:        } else\
                    108:                break;\
                    109: }
                    110:
                    111: #define READ_DIGIT_NBUF \
                    112: while ( 1 ) {\
                    113:        c = Getc();\
                    114:        if ( isdigit(c) ) {\
                    115:                REALLOC_NBUF nbuf[i++] = c;\
                    116:        } else\
                    117:                break;\
                    118: }
                    119:
1.1       noro      120: yylex()
                    121: {
                    122: #define yylvalp (&yylval)
                    123:        register int c,c1;
                    124:        register int *ptr;
                    125:        char *cptr;
                    126:        int d,i,j;
1.2       noro      127:        char nbuf0[NBUFSIZ],tbuf0[TBUFSIZ];
                    128:        char *nbuf, *tbuf;
                    129:        int nbufsize, tbufsize;
1.1       noro      130:        N n,n1;
                    131:        Q q;
                    132:        Obj r;
                    133:
1.2       noro      134:        /* initialize buffer pointers */
                    135:        nbuf = nbuf0; tbuf = tbuf0;
                    136:        nbufsize = NBUFSIZ; tbufsize = TBUFSIZ;
                    137:
1.1       noro      138:        switch ( c = skipspace() ) {
                    139:                case EOF :
                    140:                        asir_terminate(2); break;
                    141:                case '0' :
                    142:                        while ( ( c = Getc() ) == '0' );
                    143:                        if ( c == '.' ) {
                    144:                                Ungetc(c); c = '0';
                    145:                        } else if ( c == 'x' ) {
                    146:                                for ( i = 0; i < 8; i++ )
                    147:                                        nbuf[i] = '0';
1.2       noro      148:                                READ_ALNUM_NBUF
                    149:                                Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
1.1       noro      150:                                hexton(nbuf,&n1);
                    151:                                NTOQ(n1,1,q); r = (Obj)q;
                    152:                                yylvalp->p = (pointer)r;
                    153:                                return ( FORMULA );
                    154:                        } else if ( c == 'b' ) {
                    155:                                for ( i = 0; i < 32; i++ )
                    156:                                        nbuf[i] = '0';
1.2       noro      157:                                READ_ALNUM_NBUF
                    158:                                Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
1.1       noro      159:                                binaryton(nbuf,&n1);
                    160:                                NTOQ(n1,1,q); r = (Obj)q;
                    161:                                yylvalp->p = (pointer)r;
                    162:                                return ( FORMULA );
                    163:                        } else if ( !isdigit(c) ) {
                    164:                                yylvalp->p = 0; Ungetc(c);
                    165:                                return ( FORMULA );
                    166:                        }
                    167:                        break;
                    168:                case '\'' :
                    169:                        for ( i = 0; ; i++ ) {
                    170:                                c = Getc();
                    171:                                if ( c == '\'' )
                    172:                                        break;
                    173:                                if ( c == '\\' )
                    174:                                        c = Getc();
1.2       noro      175:                                REALLOC_TBUF tbuf[i] = c;
1.1       noro      176:                        }
1.2       noro      177:                        REALLOC_TBUF tbuf[i] = 0;
1.1       noro      178:                        cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    179:                        yylvalp->p = (pointer)cptr;
                    180:                        return LCASE; break;
                    181:                case '"' :
                    182:                        i = 0;
                    183:                        do {
                    184:                                c = Getc();
                    185:                                if ( c == '\\' ) {
                    186:                                        c1 = Getc();
                    187:                                        if ( c1 == 'n' )
                    188:                                                c1 = '\n';
1.2       noro      189:                                        REALLOC_NBUF nbuf[i++] = c1;
                    190:                                } else {
                    191:                                        REALLOC_NBUF nbuf[i++] = c;
                    192:                                }
1.1       noro      193:                        } while ( c != '"' );
1.2       noro      194:                        nbuf[i-1] = 0; /* REALLOC_NBUF is not necessary */
1.1       noro      195:                        cptr = (char *)MALLOC(strlen(nbuf)+1);
                    196:                        strcpy(cptr,nbuf); yylvalp->p = (pointer) cptr;
                    197:                        return ( STR ); break;
                    198:                case '>': case '<': case '=': case '!':
                    199:                        if ( (c1 = Getc()) == '=' )
                    200:                                switch ( c ) {
                    201:                                        case '>': yylvalp->i = (int)C_GE; break;
                    202:                                        case '<': yylvalp->i = (int)C_LE; break;
                    203:                                        case '=': yylvalp->i = (int)C_EQ; break;
                    204:                                        case '!': yylvalp->i = (int)C_NE; break;
                    205:                                        default: break;
                    206:                                }
                    207:                        else if ( (c == '<' && c1 == '<') || (c == '>' && c1 == '>') )
                    208:                                return c;
                    209:                        else {
                    210:                                Ungetc(c1);
                    211:                                switch ( c ) {
                    212:                                        case '>': yylvalp->i = (int)C_GT; break;
                    213:                                        case '<': yylvalp->i = (int)C_LT; break;
                    214:                                        default: return c; break;
                    215:                                }
                    216:                        }
                    217:                        return CMP; break;
                    218:                case '+': case '-': case '*': case '/': case '%': case '^':
                    219:                case '|': case '&':
                    220:                        switch ( c ) {
                    221:                                case '+': yylvalp->p = (pointer)addfs; break;
                    222:                                case '-': yylvalp->p = (pointer)subfs; break;
                    223:                                case '*': yylvalp->p = (pointer)mulfs; break;
                    224:                                case '/': yylvalp->p = (pointer)divfs; break;
                    225:                                case '%': yylvalp->p = (pointer)remfs; break;
                    226:                                case '^': yylvalp->p = (pointer)pwrfs; break;
                    227:                                default: break;
                    228:                        }
                    229:                        if ( (c1 = Getc()) == c )
                    230:                                switch ( c ) {
                    231:                                        case '+': case '-': return SELF; break;
                    232:                                        case '|': return OR; break;
                    233:                                        case '&': return AND; break;
                    234:                                        default: Ungetc(c1); return c; break;
                    235:                                }
                    236:                        else if ( c1 == '=' )
                    237:                                return BOPASS;
                    238:                        else if ( (c == '-') && (c1 == '>') )
                    239:                                return POINT;
                    240:                        else {
                    241:                                Ungetc(c1); return c;
                    242:                        }
                    243:                        break;
                    244:                default :
                    245:                        break;
                    246:        }
                    247:        if ( isdigit(c) ) {
                    248:                for ( i = 0; i < DLENGTH; i++ )
                    249:                        nbuf[i] = '0';
1.2       noro      250:                REALLOC_NBUF nbuf[i++] = c;
                    251:                READ_DIGIT_NBUF
1.1       noro      252:                if ( c == '.' ) {
                    253:                        double dbl;
                    254:                        Real real;
                    255:                        double atof();
                    256:                        extern int bigfloat;
                    257:
1.2       noro      258:                        REALLOC_NBUF nbuf[i++] = c;
                    259:                        READ_DIGIT_NBUF
1.1       noro      260:                        if ( c == 'e' ) {
1.2       noro      261:                                REALLOC_NBUF nbuf[i++] = c;
                    262:                                c = Getc();
                    263:                                if ( (c == '+') || (c == '-') ) {
                    264:                                        REALLOC_NBUF nbuf[i++] = c;
                    265:                                } else
                    266:                                        Ungetc(c);
                    267:                                READ_DIGIT_NBUF
1.1       noro      268:                        }
1.2       noro      269:                        Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
1.1       noro      270: #if PARI
                    271:                        if ( !bigfloat ) {
                    272:                                dbl = (double)atof(nbuf+DLENGTH);
                    273:                                MKReal(dbl,real); r = (Obj)real;
                    274:                        } else
                    275:                                strtobf(nbuf,(BF *)&r);
                    276: #else
                    277:                        dbl = (double)atof(nbuf+DLENGTH);
                    278:                        MKReal(dbl,real); r = (Obj)real;
                    279: #endif
                    280:                } else {
                    281:                        Ungetc(c);
                    282:                        i -= DLENGTH; d = (i%DLENGTH?i/DLENGTH+1:i/DLENGTH);
                    283:                        n = NALLOC(d); PL(n) = d;
                    284:                        for ( j = 0, ptr = BD(n); j < d; j++ ,i -= DLENGTH )
                    285:                                ptr[j] = myatoi(nbuf+i);
                    286:                        bnton(DBASE,n,&n1);
                    287:                        NTOQ(n1,1,q); r = (Obj)q;
                    288: /*                     optobj(&r); */
                    289:                }
                    290:                yylvalp->p = (pointer)r;
                    291:                return ( FORMULA );
                    292:        } else if ( isalpha(c) ) {
1.2       noro      293:                i = 0;
                    294:                tbuf[i++] = c;
                    295:                while ( 1 ) {
                    296:                        c = Getc();
                    297:                        if ( isalpha(c)||isdigit(c)||(c=='_') ) {
                    298:                                REALLOC_TBUF tbuf[i++] = c;
                    299:                        } else
                    300:                                break;
                    301:                }
                    302:                REALLOC_TBUF tbuf[i] = 0; Ungetc(c);
1.1       noro      303:                if ( isupper(tbuf[0]) ) {
                    304:                        cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    305:                        yylvalp->p = (pointer)cptr;
                    306:                        return UCASE;
                    307:                } else {
                    308:                        for ( i = 0; kwd[i].name && strcmp(tbuf,kwd[i].name); i++ );
                    309:                        if ( kwd[i].name ) {
                    310:                                yylvalp->i = asir_infile->ln;
                    311:                                return kwd[i].token;
                    312:                        } else {
                    313:                                cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    314:                                yylvalp->p = (pointer)cptr;
                    315:                                return LCASE;
                    316:                        }
                    317:                }
                    318:        } else if ( c == '@' ) {
                    319:                if ( isdigit(c = Getc()) ) {
1.2       noro      320:                        i = 0;
                    321:                        nbuf[i++] = c;
                    322:                        READ_DIGIT_NBUF
                    323:                        Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
                    324:                        yylvalp->i = atoi(nbuf);
1.1       noro      325:                        return ANS;
                    326:                } else if ( c == '@' ) {
                    327:                        yylvalp->i = MAX(0,APVS->n-1);
                    328:                        return ANS;
                    329:                } else if ( c == '>' ||  c == '<' ||  c == '=' || c == '!' ) {
                    330:                        if ( (c1 = Getc()) == '=' )
                    331:                                switch ( c ) {
                    332:                                        case '>': yylvalp->i = (int)L_GE; break;
                    333:                                        case '<': yylvalp->i = (int)L_LE; break;
                    334:                                        case '=': yylvalp->i = (int)L_EQ; break;
                    335:                                        case '!': yylvalp->i = (int)L_NE; break;
                    336:                                        default: break;
                    337:                                }
                    338:                        else {
                    339:                                Ungetc(c1);
                    340:                                switch ( c ) {
                    341:                                        case '>': yylvalp->i = (int)L_GT; break;
                    342:                                        case '<': yylvalp->i = (int)L_LT; break;
                    343:                                        case '=': yylvalp->i = (int)L_EQ; break;
                    344:                                        case '!': yylvalp->i = (int)L_NOT; return FOP_NOT; break;
                    345:                                        default: break;
                    346:                                }
                    347:                        }
                    348:                        return LOP;
                    349:                } else if ( c == '|' ||  c == '&' ) {
                    350:                        if ( (c1 = Getc()) != c )
                    351:                                Ungetc(c1);
                    352:                        switch ( c ) {
                    353:                                case '|': yylvalp->i = (int)L_OR;
                    354:                                        return FOP_OR; break;
                    355:                                case '&': yylvalp->i = (int)L_AND;
                    356:                                        return FOP_AND; break;
                    357:                        }
                    358:                } else if ( isalpha(c) ) {
1.2       noro      359:                        i = 0;
                    360:                        tbuf[i++] = '@';
                    361:                        tbuf[i++] = c;
                    362:                        while ( 1 ) {
                    363:                                c = Getc();
                    364:                                if ( isalpha(c) ) {
                    365:                                        REALLOC_TBUF tbuf[i++] = c;
                    366:                                } else
                    367:                                        break;
                    368:                        }
                    369:                        Ungetc(c); REALLOC_TBUF tbuf[i] = 0;
1.1       noro      370:                        if ( !strcmp(tbuf,"@p") )
                    371:                                return GFPNGEN;
                    372:                        else if ( !strcmp(tbuf,"@i") ) {
                    373:                                extern pointer IU;
                    374:
                    375:                                yylvalp->p = IU;
                    376:                                return FORMULA;
                    377:                        } else if ( !strcmp(tbuf,"@true") ) {
                    378:                                yylvalp->p = F_TRUE;
                    379:                                return FORMULA;
                    380:                        } else if ( !strcmp(tbuf,"@false") ) {
                    381:                                yylvalp->p = F_FALSE;
                    382:                                return FORMULA;
                    383:                        } else if ( !strcmp(tbuf,"@impl") ) {
                    384:                                yylvalp->i = (int)L_IMPL;
                    385:                                return FOP_IMPL;
                    386:                        } else if ( !strcmp(tbuf,"@repl") ) {
                    387:                                yylvalp->i = (int)L_REPL;
                    388:                                return FOP_REPL;
                    389:                        } else if ( !strcmp(tbuf,"@equiv") ) {
                    390:                                yylvalp->i = (int)L_EQUIV;
                    391:                                return FOP_EQUIV;
                    392:                        } else {
                    393:                                cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    394:                                yylvalp->p = (pointer)cptr;
                    395:                                return LCASE;
                    396:                        }
                    397:                } else {
                    398:                        Ungetc(c);
                    399:                        return GF2NGEN;
                    400:                }
                    401:        } else
                    402:                return ( c );
1.6       noro      403: }
                    404:
                    405: void purge_stdin()
                    406: {
1.7       noro      407: #if defined(__FreeBSD__)
1.6       noro      408:        fpurge(stdin);
                    409: #elif defined(linux)
                    410:        stdin->_IO_read_end = stdin->_IO_read_base;
                    411:        stdin->_IO_read_ptr = stdin->_IO_read_base;
1.10      noro      412: #elif defined(VISUAL_LIB)
                    413:        w_purge_stdin();
                    414: #elif defined(sparc) || defined(__alpha) || defined(__SVR4) || defined(mips) || defined(VISUAL)
1.6       noro      415:        stdin->_ptr = stdin->_base; stdin->_cnt = 0;
                    416: #else
                    417: --->FIXIT
                    418: #endif
1.1       noro      419: }
                    420:
                    421: static int skipspace() {
                    422:        int c,c1;
                    423:
                    424:        for ( c = Getc(); ; )
                    425:                switch ( c ) {
1.14    ! noro      426:                        case ' ': case '\t': case '\r':
1.1       noro      427:                                c = Getc(); break;
                    428:                        case '\n':
                    429:                                c = afternl();  break;
                    430:                        case '/':
                    431:                                if ( (c1 = Getc()) == '*' )
                    432:                                        c = aftercomment();
                    433:                                else {
                    434:                                        Ungetc(c1); return c;
                    435:                                }
                    436:                                break;
                    437:                        default:
                    438:                                return c; break;
                    439:                }
                    440: }
                    441:
                    442: int afternl() {
                    443:        int c,ac,i,quote;
                    444:        char *ptr;
                    445:        char *av[BUFSIZ];
                    446:        static int ilevel = 0;
                    447:        char buf[BUFSIZ];
                    448:
                    449:        if ( !ilevel )
                    450:                asir_infile->ln++;
                    451:        while ( (c = Getc()) == '#' ) {
                    452:                Gets(buf);
                    453:                for ( quote = 0, ptr = buf; *ptr; ptr++ )
                    454:                        if ( *ptr == '"' )
                    455:                                quote = quote ? 0 : 1;
                    456:                        else if ( quote && (*ptr == ' ') )
                    457:                                *ptr = '_';
                    458:                stoarg(buf,&ac,av);
                    459:                if ( ac == 3 )
                    460:                        if ( (i = atoi(av[2])) == 1 )
                    461:                                ilevel++;
                    462:                        else if ( i == 2 )
                    463:                                ilevel--;
                    464:                if ( !ilevel )
                    465:                        asir_infile->ln = atoi(av[0]);
                    466:        }
                    467:        return c;
                    468: }
                    469:
                    470: int aftercomment() {
                    471:        int c,c1;
                    472:
                    473:        for ( c = Getc(); ; ) {
                    474:                c1 = Getc();
                    475:                if ( (c == '*') && (c1 == '/') )
                    476:                        return Getc();
                    477:                else
                    478:                        c = c1;
                    479:        }
                    480: }
                    481:
                    482: int myatoi(s)
                    483: char *s;
                    484: {
                    485:        int i,r;
                    486:        for ( i = 0, r = 0; i < DLENGTH; i++ ) r = r * 10 + ( s[i] - '0' );
                    487:        return ( r );
                    488: }
                    489:
                    490: extern int ox_do_copy;
                    491:
                    492: void yyerror(s)
                    493: char *s;
                    494: {
                    495:        if ( main_parser )
                    496:                if ( ox_do_copy ) {
                    497:                        /* push errors to DebugStack */
                    498:                } else {
                    499:                        if ( asir_infile->fp == stdin )
                    500:                                fprintf(stderr,"%s\n",s);
                    501:                        else
                    502:                                fprintf(stderr,"\"%s\", near line %d: %s\n",asir_infile->name,asir_infile->ln,s);
                    503:                }
                    504:        else
                    505:                fprintf(stderr,"exprparse : %s\n",s);
                    506: }
                    507:
                    508: int echoback;
                    509:
                    510: extern int read_exec_file, do_fep, do_file;
                    511:
                    512: int readline_getc();
                    513: void readline_ungetc();
                    514: int Egetc();
                    515: void Eungetc();
                    516:
                    517: unsigned char encrypt_char(unsigned char);
                    518: unsigned char decrypt_char(unsigned char);
                    519:
                    520: int Egetc(fp)
                    521: FILE *fp;
                    522: {
                    523:        int c;
                    524:
                    525:        if ( fp ) {
1.13      noro      526: #if FEP
                    527:                if ( do_fep && isatty(fileno(fp)) )
                    528:                        c = readline_getc();
                    529:                else
                    530: #endif
                    531:                        c = getc(fp);
1.11      noro      532: #if defined(VISUAL)
                    533:                if ( recv_intr ) {
                    534: #include <signal.h>
                    535:                        if ( recv_intr == 1 ) {
                    536:                                recv_intr = 0;
                    537:                                int_handler(SIGINT);
                    538:                        } else {
                    539:                                recv_intr = 0;
                    540:                                ox_usr1_handler(0);
                    541:                        }
                    542:                }
                    543: #endif
1.1       noro      544:                if ( c == EOF )
                    545:                        return c;
                    546:                if ( asir_infile->encoded )
                    547:                        c = decrypt_char((unsigned char)c);
                    548:                return c;
1.3       noro      549:        } else if ( read_exec_file )
                    550:                return EOF;
                    551:        else {
1.1       noro      552:                c = *parse_strp++;
                    553:                if ( !c )
                    554:                        return EOF;
                    555:                else
                    556:                        return c;
                    557:        }
                    558: }
                    559:
                    560: void Eungetc(c,fp)
                    561: int c;
                    562: FILE *fp;
                    563: {
                    564:        if ( fp ) {
                    565:                if ( asir_infile->encoded )
                    566:                        c = (int)encrypt_char((unsigned char)c);
1.13      noro      567: #if FEP
                    568:                if ( do_fep && isatty(fileno(fp)) )
                    569:                        readline_ungetc();
                    570:                else
                    571: #endif
                    572:                        ungetc(c,fp);
1.1       noro      573:        } else
                    574:                *--parse_strp = c;
                    575: }
                    576:
                    577: static int Getc() {
                    578:        int c;
                    579:
                    580:        if ( main_parser ) {
                    581:                while ( 1 ) {
                    582:                        if ((c = Egetc(asir_infile->fp)) == EOF)
                    583:                                if ( NEXT(asir_infile) ) {
                    584:                                        closecurrentinput();
1.9       noro      585:                                        /* if the input is the top level, generate error */
                    586:                                        if ( !NEXT(asir_infile) )
                    587:                                                error("end-of-file detected during parsing");
                    588:                                        else
                    589:                                                c = Getc();
1.1       noro      590:                                        break;
                    591:                                } else if ( read_exec_file || do_file )
                    592:                                        asir_terminate(2);
                    593:                                else {
                    594:                                        if ( asir_infile->fp )
                    595:                                                clearerr(asir_infile->fp);
                    596:                                }
                    597:                        else
                    598:                                break;
                    599:                }
                    600:                if ( echoback )
                    601:                        fputc(c,asir_out);
                    602:        } else
                    603:                c = *parse_strp++;
                    604:        return ( c );
                    605: }
                    606:
                    607: static void Ungetc(c) {
                    608:        if ( main_parser ) {
                    609:                Eungetc(c,asir_infile->fp);
                    610:                if ( echoback )
                    611:                        fputc('',asir_out);
                    612:        } else
                    613:                *--parse_strp = c;
                    614: }
                    615:
                    616: static void Gets(s)
                    617: char *s;
                    618: {
                    619:        int c;
                    620:
                    621:        while ( (c = Getc()) != '\n' )
                    622:                *s++ = c;
                    623:        *s = 0;
                    624: }
1.12      saito     625:
                    626: #if FEP
                    627:
                    628: static char *readline_line;
                    629: static int readline_nc,readline_index;
                    630: char *readline_console();
                    631:
                    632: int readline_getc()
                    633: {
                    634:         char buf[BUFSIZ];
                    635:
                    636:         if ( !readline_nc ) {
                    637:                 if ( readline_line )
                    638:                         free(readline_line);
                    639:                 sprompt(buf);
                    640:                 readline_line = readline_console(buf);
                    641:                 readline_nc = strlen(readline_line);
                    642:                 readline_index = 0;
                    643:         }
                    644:         readline_nc--;
                    645:         return readline_line[readline_index++];
                    646: }
                    647:
                    648: void readline_ungetc()
                    649: {
                    650:         readline_nc++; readline_index--;
                    651: }
                    652:
                    653: char *readline_console(prompt)
                    654: char *prompt;
                    655: {
                    656:         char *line;
                    657:         int exp_result;
                    658:         char *expansion;
                    659:
                    660:         while ( 1 ) {
                    661:                 line = (char *)readline(prompt);
                    662:                 if ( line && *line ) {
                    663:                         using_history();
                    664:                         exp_result = history_expand(line,&expansion);
                    665:                         if ( !exp_result ) {
                    666:                                 free(expansion);
                    667:                                 for ( ; isspace(*line); line++ );
                    668:                                 add_history(line);
                    669:                                 break;
                    670:                         } else if ( exp_result > 0 ) {
                    671:                                 free(line);
                    672:                                 line = expansion;
                    673:                                 break;
                    674:                         }
                    675:                 }
                    676:         }
                    677:         return line;
                    678: }
                    679: #endif

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