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

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

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