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

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.26    ! saito      48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/lex.c,v 1.25 2003/05/30 00:47:24 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:
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 );
1.25      noro      302:        } else if ( isalpha(c) || c == ':' ) {
                    303:                if ( c == ':' ) {
                    304:                        c1 = Getc();
                    305:                        if ( c1 != ':' ) {
                    306:                                Ungetc(c1);
                    307:                                return c;
                    308:                        }
                    309:                        c1 = Getc();
                    310:                        if ( !isalpha(c1) ) {
                    311:                                Ungetc(c1);
                    312:                                return COLONCOLON;
                    313:                        }
                    314:                        i = 0;
                    315:                        tbuf[i++] = ':';
                    316:                        tbuf[i++] = ':';
                    317:                        tbuf[i++] = c1;
                    318:                } else {
                    319:                        i = 0;
                    320:                        tbuf[i++] = c;
                    321:                }
1.2       noro      322:                while ( 1 ) {
                    323:                        c = Getc();
1.24      noro      324:                        if ( isalpha(c)||isdigit(c)||(c=='_')||(c=='.') ) {
1.2       noro      325:                                REALLOC_TBUF tbuf[i++] = c;
                    326:                        } else
                    327:                                break;
                    328:                }
                    329:                REALLOC_TBUF tbuf[i] = 0; Ungetc(c);
1.1       noro      330:                if ( isupper(tbuf[0]) ) {
                    331:                        cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    332:                        yylvalp->p = (pointer)cptr;
                    333:                        return UCASE;
                    334:                } else {
                    335:                        for ( i = 0; kwd[i].name && strcmp(tbuf,kwd[i].name); i++ );
                    336:                        if ( kwd[i].name ) {
                    337:                                yylvalp->i = asir_infile->ln;
                    338:                                return kwd[i].token;
                    339:                        } else {
                    340:                                cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    341:                                yylvalp->p = (pointer)cptr;
                    342:                                return LCASE;
                    343:                        }
                    344:                }
                    345:        } else if ( c == '@' ) {
                    346:                if ( isdigit(c = Getc()) ) {
1.2       noro      347:                        i = 0;
                    348:                        nbuf[i++] = c;
                    349:                        READ_DIGIT_NBUF
                    350:                        Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
                    351:                        yylvalp->i = atoi(nbuf);
1.1       noro      352:                        return ANS;
                    353:                } else if ( c == '@' ) {
                    354:                        yylvalp->i = MAX(0,APVS->n-1);
                    355:                        return ANS;
                    356:                } else if ( c == '>' ||  c == '<' ||  c == '=' || c == '!' ) {
                    357:                        if ( (c1 = Getc()) == '=' )
                    358:                                switch ( c ) {
                    359:                                        case '>': yylvalp->i = (int)L_GE; break;
                    360:                                        case '<': yylvalp->i = (int)L_LE; break;
                    361:                                        case '=': yylvalp->i = (int)L_EQ; break;
                    362:                                        case '!': yylvalp->i = (int)L_NE; break;
                    363:                                        default: break;
                    364:                                }
                    365:                        else {
                    366:                                Ungetc(c1);
                    367:                                switch ( c ) {
                    368:                                        case '>': yylvalp->i = (int)L_GT; break;
                    369:                                        case '<': yylvalp->i = (int)L_LT; break;
                    370:                                        case '=': yylvalp->i = (int)L_EQ; break;
                    371:                                        case '!': yylvalp->i = (int)L_NOT; return FOP_NOT; break;
                    372:                                        default: break;
                    373:                                }
                    374:                        }
                    375:                        return LOP;
                    376:                } else if ( c == '|' ||  c == '&' ) {
                    377:                        if ( (c1 = Getc()) != c )
                    378:                                Ungetc(c1);
                    379:                        switch ( c ) {
                    380:                                case '|': yylvalp->i = (int)L_OR;
                    381:                                        return FOP_OR; break;
                    382:                                case '&': yylvalp->i = (int)L_AND;
                    383:                                        return FOP_AND; break;
                    384:                        }
                    385:                } else if ( isalpha(c) ) {
1.2       noro      386:                        i = 0;
                    387:                        tbuf[i++] = '@';
                    388:                        tbuf[i++] = c;
                    389:                        while ( 1 ) {
                    390:                                c = Getc();
                    391:                                if ( isalpha(c) ) {
                    392:                                        REALLOC_TBUF tbuf[i++] = c;
                    393:                                } else
                    394:                                        break;
                    395:                        }
                    396:                        Ungetc(c); REALLOC_TBUF tbuf[i] = 0;
1.1       noro      397:                        if ( !strcmp(tbuf,"@p") )
                    398:                                return GFPNGEN;
1.17      noro      399:                        else if ( !strcmp(tbuf,"@s") )
                    400:                                return GFSNGEN;
1.1       noro      401:                        else if ( !strcmp(tbuf,"@i") ) {
                    402:                                extern pointer IU;
                    403:
                    404:                                yylvalp->p = IU;
                    405:                                return FORMULA;
                    406:                        } else if ( !strcmp(tbuf,"@true") ) {
                    407:                                yylvalp->p = F_TRUE;
                    408:                                return FORMULA;
                    409:                        } else if ( !strcmp(tbuf,"@false") ) {
                    410:                                yylvalp->p = F_FALSE;
                    411:                                return FORMULA;
                    412:                        } else if ( !strcmp(tbuf,"@impl") ) {
                    413:                                yylvalp->i = (int)L_IMPL;
                    414:                                return FOP_IMPL;
                    415:                        } else if ( !strcmp(tbuf,"@repl") ) {
                    416:                                yylvalp->i = (int)L_REPL;
                    417:                                return FOP_REPL;
                    418:                        } else if ( !strcmp(tbuf,"@equiv") ) {
                    419:                                yylvalp->i = (int)L_EQUIV;
                    420:                                return FOP_EQUIV;
                    421:                        } else {
                    422:                                cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    423:                                yylvalp->p = (pointer)cptr;
                    424:                                return LCASE;
                    425:                        }
                    426:                } else {
                    427:                        Ungetc(c);
                    428:                        return GF2NGEN;
                    429:                }
                    430:        } else
                    431:                return ( c );
1.6       noro      432: }
                    433:
                    434: void purge_stdin()
                    435: {
1.7       noro      436: #if defined(__FreeBSD__)
1.6       noro      437:        fpurge(stdin);
                    438: #elif defined(linux)
                    439:        stdin->_IO_read_end = stdin->_IO_read_base;
                    440:        stdin->_IO_read_ptr = stdin->_IO_read_base;
1.10      noro      441: #elif defined(VISUAL_LIB)
1.18      noro      442:        void w_purge_stdin();
                    443:
1.10      noro      444:        w_purge_stdin();
1.16      noro      445: #elif defined(sparc) || defined(__alpha) || defined(__SVR4) || defined(mips) || defined(VISUAL) || defined(_IBMR2)
1.6       noro      446:        stdin->_ptr = stdin->_base; stdin->_cnt = 0;
1.26    ! saito     447: #elif (defined(__MACH__) && defined(__ppc__)) || defined(__CYGWIN__) || defined(__FreeBSD__)
1.15      noro      448:        stdin->_r = 0; stdin->_p = stdin->_bf._base;
1.6       noro      449: #else
                    450: --->FIXIT
                    451: #endif
1.1       noro      452: }
                    453:
                    454: static int skipspace() {
                    455:        int c,c1;
                    456:
                    457:        for ( c = Getc(); ; )
                    458:                switch ( c ) {
1.14      noro      459:                        case ' ': case '\t': case '\r':
1.1       noro      460:                                c = Getc(); break;
                    461:                        case '\n':
                    462:                                c = afternl();  break;
                    463:                        case '/':
                    464:                                if ( (c1 = Getc()) == '*' )
                    465:                                        c = aftercomment();
                    466:                                else {
                    467:                                        Ungetc(c1); return c;
                    468:                                }
                    469:                                break;
                    470:                        default:
                    471:                                return c; break;
                    472:                }
                    473: }
                    474:
                    475: int afternl() {
                    476:        int c,ac,i,quote;
                    477:        char *ptr;
                    478:        char *av[BUFSIZ];
                    479:        static int ilevel = 0;
                    480:        char buf[BUFSIZ];
                    481:
                    482:        if ( !ilevel )
                    483:                asir_infile->ln++;
                    484:        while ( (c = Getc()) == '#' ) {
                    485:                Gets(buf);
                    486:                for ( quote = 0, ptr = buf; *ptr; ptr++ )
                    487:                        if ( *ptr == '"' )
                    488:                                quote = quote ? 0 : 1;
                    489:                        else if ( quote && (*ptr == ' ') )
                    490:                                *ptr = '_';
                    491:                stoarg(buf,&ac,av);
                    492:                if ( ac == 3 )
                    493:                        if ( (i = atoi(av[2])) == 1 )
                    494:                                ilevel++;
                    495:                        else if ( i == 2 )
                    496:                                ilevel--;
                    497:                if ( !ilevel )
                    498:                        asir_infile->ln = atoi(av[0]);
                    499:        }
                    500:        return c;
                    501: }
                    502:
                    503: int aftercomment() {
                    504:        int c,c1;
                    505:
                    506:        for ( c = Getc(); ; ) {
                    507:                c1 = Getc();
                    508:                if ( (c == '*') && (c1 == '/') )
                    509:                        return Getc();
                    510:                else
                    511:                        c = c1;
                    512:        }
                    513: }
                    514:
1.18      noro      515: int myatoi(char *s)
1.1       noro      516: {
                    517:        int i,r;
                    518:        for ( i = 0, r = 0; i < DLENGTH; i++ ) r = r * 10 + ( s[i] - '0' );
                    519:        return ( r );
                    520: }
                    521:
                    522: extern int ox_do_copy;
                    523:
1.18      noro      524: void yyerror(char *s)
1.1       noro      525: {
                    526:        if ( main_parser )
                    527:                if ( ox_do_copy ) {
                    528:                        /* push errors to DebugStack */
                    529:                } else {
                    530:                        if ( asir_infile->fp == stdin )
                    531:                                fprintf(stderr,"%s\n",s);
                    532:                        else
                    533:                                fprintf(stderr,"\"%s\", near line %d: %s\n",asir_infile->name,asir_infile->ln,s);
                    534:                }
                    535:        else
                    536:                fprintf(stderr,"exprparse : %s\n",s);
                    537: }
                    538:
                    539: int echoback;
                    540:
                    541: extern int read_exec_file, do_fep, do_file;
                    542:
                    543: unsigned char encrypt_char(unsigned char);
                    544: unsigned char decrypt_char(unsigned char);
                    545:
1.18      noro      546: int Egetc(FILE *fp)
1.1       noro      547: {
                    548:        int c;
                    549:
                    550:        if ( fp ) {
1.23      noro      551: #if FEP
1.13      noro      552:                if ( do_fep && isatty(fileno(fp)) )
                    553:                        c = readline_getc();
                    554:                else
                    555: #endif
                    556:                        c = getc(fp);
1.11      noro      557: #if defined(VISUAL)
                    558:                if ( recv_intr ) {
                    559: #include <signal.h>
                    560:                        if ( recv_intr == 1 ) {
                    561:                                recv_intr = 0;
                    562:                                int_handler(SIGINT);
                    563:                        } else {
                    564:                                recv_intr = 0;
                    565:                                ox_usr1_handler(0);
                    566:                        }
                    567:                }
                    568: #endif
1.1       noro      569:                if ( c == EOF )
                    570:                        return c;
                    571:                if ( asir_infile->encoded )
                    572:                        c = decrypt_char((unsigned char)c);
                    573:                return c;
1.3       noro      574:        } else if ( read_exec_file )
                    575:                return EOF;
                    576:        else {
1.1       noro      577:                c = *parse_strp++;
                    578:                if ( !c )
                    579:                        return EOF;
                    580:                else
                    581:                        return c;
                    582:        }
                    583: }
                    584:
1.18      noro      585: void Eungetc(int c,FILE *fp)
1.1       noro      586: {
                    587:        if ( fp ) {
                    588:                if ( asir_infile->encoded )
                    589:                        c = (int)encrypt_char((unsigned char)c);
1.23      noro      590: #if FEP
1.13      noro      591:                if ( do_fep && isatty(fileno(fp)) )
                    592:                        readline_ungetc();
                    593:                else
                    594: #endif
                    595:                        ungetc(c,fp);
1.1       noro      596:        } else
                    597:                *--parse_strp = c;
                    598: }
                    599:
                    600: static int Getc() {
                    601:        int c;
                    602:
                    603:        if ( main_parser ) {
                    604:                while ( 1 ) {
                    605:                        if ((c = Egetc(asir_infile->fp)) == EOF)
                    606:                                if ( NEXT(asir_infile) ) {
                    607:                                        closecurrentinput();
1.9       noro      608:                                        /* if the input is the top level, generate error */
                    609:                                        if ( !NEXT(asir_infile) )
                    610:                                                error("end-of-file detected during parsing");
                    611:                                        else
                    612:                                                c = Getc();
1.1       noro      613:                                        break;
                    614:                                } else if ( read_exec_file || do_file )
                    615:                                        asir_terminate(2);
                    616:                                else {
                    617:                                        if ( asir_infile->fp )
                    618:                                                clearerr(asir_infile->fp);
                    619:                                }
                    620:                        else
                    621:                                break;
                    622:                }
                    623:                if ( echoback )
                    624:                        fputc(c,asir_out);
                    625:        } else
                    626:                c = *parse_strp++;
                    627:        return ( c );
                    628: }
                    629:
1.18      noro      630: static void Ungetc(int c) {
1.1       noro      631:        if ( main_parser ) {
                    632:                Eungetc(c,asir_infile->fp);
                    633:                if ( echoback )
                    634:                        fputc('',asir_out);
                    635:        } else
                    636:                *--parse_strp = c;
                    637: }
                    638:
1.18      noro      639: static void Gets(char *s)
1.1       noro      640: {
                    641:        int c;
                    642:
                    643:        while ( (c = Getc()) != '\n' )
                    644:                *s++ = c;
                    645:        *s = 0;
                    646: }
1.12      saito     647:
1.23      noro      648: #if FEP
1.12      saito     649:
                    650: static char *readline_line;
                    651: static int readline_nc,readline_index;
                    652: char *readline_console();
                    653:
                    654: int readline_getc()
                    655: {
                    656:         char buf[BUFSIZ];
                    657:
                    658:         if ( !readline_nc ) {
                    659:                 if ( readline_line )
                    660:                         free(readline_line);
                    661:                 sprompt(buf);
                    662:                 readline_line = readline_console(buf);
                    663:                 readline_nc = strlen(readline_line);
                    664:                 readline_index = 0;
                    665:         }
                    666:         readline_nc--;
                    667:         return readline_line[readline_index++];
                    668: }
                    669:
                    670: void readline_ungetc()
                    671: {
                    672:         readline_nc++; readline_index--;
                    673: }
                    674:
1.18      noro      675: char *readline_console(char *prompt)
1.12      saito     676: {
                    677:         char *line;
                    678:         int exp_result;
                    679:         char *expansion;
                    680:
                    681:         while ( 1 ) {
                    682:                 line = (char *)readline(prompt);
                    683:                 if ( line && *line ) {
                    684:                         using_history();
                    685:                         exp_result = history_expand(line,&expansion);
                    686:                         if ( !exp_result ) {
                    687:                                 free(expansion);
                    688:                                 for ( ; isspace(*line); line++ );
                    689:                                 add_history(line);
                    690:                                 break;
                    691:                         } else if ( exp_result > 0 ) {
                    692:                                 free(line);
                    693:                                 line = expansion;
                    694:                                 break;
                    695:                         }
                    696:                 }
                    697:         }
                    698:         return line;
                    699: }
                    700: #endif

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