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

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.32    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/lex.c,v 1.31 2004/03/04 07:11:01 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();
1.27      ohara     189:                                        if ( c1 == 'n' ) {
1.1       noro      190:                                                c1 = '\n';
1.27      ohara     191:                     }else if ( c1 == 't' ) {
                    192:                         c1 = '\t';
                    193:                     }else if ( isdigit(c1) ){
                    194:                         d = c1 - '0';
                    195:                         c1 = Getc();
                    196:                         if ( isdigit(c1) ) {
                    197:                              d = 8*d + (c1 - '0');
                    198:                              c1 = Getc();
                    199:                              if ( isdigit(c1) ) {
                    200:                                  d = 8*d + (c1 - '0');
                    201:                              }else {
                    202:                                  Ungetc(c1);
                    203:                              }
                    204:                         }else {
                    205:                             Ungetc(c1);
                    206:                         }
                    207:                         c1 = d;
                    208:                     }
1.2       noro      209:                                        REALLOC_NBUF nbuf[i++] = c1;
                    210:                                } else {
                    211:                                        REALLOC_NBUF nbuf[i++] = c;
                    212:                                }
1.1       noro      213:                        } while ( c != '"' );
1.2       noro      214:                        nbuf[i-1] = 0; /* REALLOC_NBUF is not necessary */
1.1       noro      215:                        cptr = (char *)MALLOC(strlen(nbuf)+1);
                    216:                        strcpy(cptr,nbuf); yylvalp->p = (pointer) cptr;
                    217:                        return ( STR ); break;
                    218:                case '>': case '<': case '=': case '!':
                    219:                        if ( (c1 = Getc()) == '=' )
                    220:                                switch ( c ) {
                    221:                                        case '>': yylvalp->i = (int)C_GE; break;
                    222:                                        case '<': yylvalp->i = (int)C_LE; break;
                    223:                                        case '=': yylvalp->i = (int)C_EQ; break;
                    224:                                        case '!': yylvalp->i = (int)C_NE; break;
                    225:                                        default: break;
                    226:                                }
                    227:                        else if ( (c == '<' && c1 == '<') || (c == '>' && c1 == '>') )
                    228:                                return c;
                    229:                        else {
                    230:                                Ungetc(c1);
                    231:                                switch ( c ) {
                    232:                                        case '>': yylvalp->i = (int)C_GT; break;
                    233:                                        case '<': yylvalp->i = (int)C_LT; break;
                    234:                                        default: return c; break;
                    235:                                }
                    236:                        }
                    237:                        return CMP; break;
                    238:                case '+': case '-': case '*': case '/': case '%': case '^':
                    239:                case '|': case '&':
                    240:                        switch ( c ) {
                    241:                                case '+': yylvalp->p = (pointer)addfs; break;
                    242:                                case '-': yylvalp->p = (pointer)subfs; break;
                    243:                                case '*': yylvalp->p = (pointer)mulfs; break;
                    244:                                case '/': yylvalp->p = (pointer)divfs; break;
                    245:                                case '%': yylvalp->p = (pointer)remfs; break;
                    246:                                case '^': yylvalp->p = (pointer)pwrfs; break;
                    247:                                default: break;
                    248:                        }
                    249:                        if ( (c1 = Getc()) == c )
                    250:                                switch ( c ) {
                    251:                                        case '+': case '-': return SELF; break;
                    252:                                        case '|': return OR; break;
                    253:                                        case '&': return AND; break;
                    254:                                        default: Ungetc(c1); return c; break;
                    255:                                }
                    256:                        else if ( c1 == '=' )
                    257:                                return BOPASS;
                    258:                        else if ( (c == '-') && (c1 == '>') )
                    259:                                return POINT;
                    260:                        else {
                    261:                                Ungetc(c1); return c;
                    262:                        }
                    263:                        break;
                    264:                default :
                    265:                        break;
                    266:        }
                    267:        if ( isdigit(c) ) {
                    268:                for ( i = 0; i < DLENGTH; i++ )
                    269:                        nbuf[i] = '0';
1.2       noro      270:                REALLOC_NBUF nbuf[i++] = c;
                    271:                READ_DIGIT_NBUF
1.1       noro      272:                if ( c == '.' ) {
1.20      kondoh    273:                        floatingpoint = 1;
1.1       noro      274:
1.2       noro      275:                        REALLOC_NBUF nbuf[i++] = c;
                    276:                        READ_DIGIT_NBUF
1.21      noro      277:                        if ( c == 'e' || c == 'E' ) {
1.2       noro      278:                                REALLOC_NBUF nbuf[i++] = c;
                    279:                                c = Getc();
                    280:                                if ( (c == '+') || (c == '-') ) {
                    281:                                        REALLOC_NBUF nbuf[i++] = c;
                    282:                                } else
                    283:                                        Ungetc(c);
                    284:                                READ_DIGIT_NBUF
1.1       noro      285:                        }
1.21      noro      286:                } else if ( c == 'e' || c == 'E' ) {
1.20      kondoh    287:                        floatingpoint = 1;
                    288:                        REALLOC_NBUF nbuf[i++] = c;
                    289:                        c = Getc();
                    290:                        if ( (c == '+') || (c == '-') ) {
                    291:                                REALLOC_NBUF nbuf[i++] = c;
                    292:                        } else
                    293:                                Ungetc(c);
                    294:                        READ_DIGIT_NBUF
                    295:                }
                    296:                if ( floatingpoint ) {
1.2       noro      297:                        Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
1.22      ohara     298: #if defined(PARI)
1.1       noro      299:                        if ( !bigfloat ) {
                    300:                                dbl = (double)atof(nbuf+DLENGTH);
                    301:                                MKReal(dbl,real); r = (Obj)real;
                    302:                        } else
                    303:                                strtobf(nbuf,(BF *)&r);
                    304: #else
                    305:                        dbl = (double)atof(nbuf+DLENGTH);
                    306:                        MKReal(dbl,real); r = (Obj)real;
                    307: #endif
                    308:                } else {
                    309:                        Ungetc(c);
                    310:                        i -= DLENGTH; d = (i%DLENGTH?i/DLENGTH+1:i/DLENGTH);
                    311:                        n = NALLOC(d); PL(n) = d;
                    312:                        for ( j = 0, ptr = BD(n); j < d; j++ ,i -= DLENGTH )
                    313:                                ptr[j] = myatoi(nbuf+i);
                    314:                        bnton(DBASE,n,&n1);
                    315:                        NTOQ(n1,1,q); r = (Obj)q;
                    316: /*                     optobj(&r); */
                    317:                }
                    318:                yylvalp->p = (pointer)r;
                    319:                return ( FORMULA );
1.25      noro      320:        } else if ( isalpha(c) || c == ':' ) {
                    321:                if ( c == ':' ) {
                    322:                        c1 = Getc();
                    323:                        if ( c1 != ':' ) {
                    324:                                Ungetc(c1);
                    325:                                return c;
                    326:                        }
                    327:                        c1 = Getc();
                    328:                        if ( !isalpha(c1) ) {
                    329:                                Ungetc(c1);
                    330:                                return COLONCOLON;
                    331:                        }
                    332:                        i = 0;
                    333:                        tbuf[i++] = ':';
                    334:                        tbuf[i++] = ':';
                    335:                        tbuf[i++] = c1;
                    336:                } else {
                    337:                        i = 0;
                    338:                        tbuf[i++] = c;
                    339:                }
1.2       noro      340:                while ( 1 ) {
                    341:                        c = Getc();
1.24      noro      342:                        if ( isalpha(c)||isdigit(c)||(c=='_')||(c=='.') ) {
1.2       noro      343:                                REALLOC_TBUF tbuf[i++] = c;
                    344:                        } else
                    345:                                break;
                    346:                }
                    347:                REALLOC_TBUF tbuf[i] = 0; Ungetc(c);
1.1       noro      348:                if ( isupper(tbuf[0]) ) {
                    349:                        cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    350:                        yylvalp->p = (pointer)cptr;
                    351:                        return UCASE;
                    352:                } else {
                    353:                        for ( i = 0; kwd[i].name && strcmp(tbuf,kwd[i].name); i++ );
                    354:                        if ( kwd[i].name ) {
                    355:                                yylvalp->i = asir_infile->ln;
                    356:                                return kwd[i].token;
                    357:                        } else {
                    358:                                cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    359:                                yylvalp->p = (pointer)cptr;
                    360:                                return LCASE;
                    361:                        }
                    362:                }
                    363:        } else if ( c == '@' ) {
                    364:                if ( isdigit(c = Getc()) ) {
1.2       noro      365:                        i = 0;
                    366:                        nbuf[i++] = c;
                    367:                        READ_DIGIT_NBUF
                    368:                        Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
                    369:                        yylvalp->i = atoi(nbuf);
1.1       noro      370:                        return ANS;
                    371:                } else if ( c == '@' ) {
                    372:                        yylvalp->i = MAX(0,APVS->n-1);
                    373:                        return ANS;
                    374:                } else if ( c == '>' ||  c == '<' ||  c == '=' || c == '!' ) {
                    375:                        if ( (c1 = Getc()) == '=' )
                    376:                                switch ( c ) {
                    377:                                        case '>': yylvalp->i = (int)L_GE; break;
                    378:                                        case '<': yylvalp->i = (int)L_LE; break;
                    379:                                        case '=': yylvalp->i = (int)L_EQ; break;
                    380:                                        case '!': yylvalp->i = (int)L_NE; break;
                    381:                                        default: break;
                    382:                                }
                    383:                        else {
                    384:                                Ungetc(c1);
                    385:                                switch ( c ) {
                    386:                                        case '>': yylvalp->i = (int)L_GT; break;
                    387:                                        case '<': yylvalp->i = (int)L_LT; break;
                    388:                                        case '=': yylvalp->i = (int)L_EQ; break;
                    389:                                        case '!': yylvalp->i = (int)L_NOT; return FOP_NOT; break;
                    390:                                        default: break;
                    391:                                }
                    392:                        }
                    393:                        return LOP;
                    394:                } else if ( c == '|' ||  c == '&' ) {
                    395:                        if ( (c1 = Getc()) != c )
                    396:                                Ungetc(c1);
                    397:                        switch ( c ) {
                    398:                                case '|': yylvalp->i = (int)L_OR;
                    399:                                        return FOP_OR; break;
                    400:                                case '&': yylvalp->i = (int)L_AND;
                    401:                                        return FOP_AND; break;
                    402:                        }
                    403:                } else if ( isalpha(c) ) {
1.2       noro      404:                        i = 0;
                    405:                        tbuf[i++] = '@';
                    406:                        tbuf[i++] = c;
                    407:                        while ( 1 ) {
                    408:                                c = Getc();
                    409:                                if ( isalpha(c) ) {
                    410:                                        REALLOC_TBUF tbuf[i++] = c;
                    411:                                } else
                    412:                                        break;
                    413:                        }
                    414:                        Ungetc(c); REALLOC_TBUF tbuf[i] = 0;
1.1       noro      415:                        if ( !strcmp(tbuf,"@p") )
                    416:                                return GFPNGEN;
1.17      noro      417:                        else if ( !strcmp(tbuf,"@s") )
                    418:                                return GFSNGEN;
1.1       noro      419:                        else if ( !strcmp(tbuf,"@i") ) {
                    420:                                extern pointer IU;
                    421:
                    422:                                yylvalp->p = IU;
                    423:                                return FORMULA;
                    424:                        } else if ( !strcmp(tbuf,"@true") ) {
                    425:                                yylvalp->p = F_TRUE;
                    426:                                return FORMULA;
                    427:                        } else if ( !strcmp(tbuf,"@false") ) {
                    428:                                yylvalp->p = F_FALSE;
                    429:                                return FORMULA;
                    430:                        } else if ( !strcmp(tbuf,"@impl") ) {
                    431:                                yylvalp->i = (int)L_IMPL;
                    432:                                return FOP_IMPL;
                    433:                        } else if ( !strcmp(tbuf,"@repl") ) {
                    434:                                yylvalp->i = (int)L_REPL;
                    435:                                return FOP_REPL;
                    436:                        } else if ( !strcmp(tbuf,"@equiv") ) {
                    437:                                yylvalp->i = (int)L_EQUIV;
                    438:                                return FOP_EQUIV;
1.29      noro      439:                        } else if ( !strcmp(tbuf,"@grlex") ) {
                    440:                                yylvalp->p = Symbol_grlex;
                    441:                                return FORMULA;
                    442:                        } else if ( !strcmp(tbuf,"@glex") ) {
                    443:                                yylvalp->p = Symbol_glex;
                    444:                                return FORMULA;
                    445:                        } else if ( !strcmp(tbuf,"@lex") ) {
                    446:                                yylvalp->p = Symbol_lex;
                    447:                                return FORMULA;
1.1       noro      448:                        } else {
                    449:                                cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    450:                                yylvalp->p = (pointer)cptr;
                    451:                                return LCASE;
                    452:                        }
                    453:                } else {
                    454:                        Ungetc(c);
                    455:                        return GF2NGEN;
                    456:                }
                    457:        } else
                    458:                return ( c );
1.6       noro      459: }
                    460:
                    461: void purge_stdin()
                    462: {
1.7       noro      463: #if defined(__FreeBSD__)
1.6       noro      464:        fpurge(stdin);
                    465: #elif defined(linux)
                    466:        stdin->_IO_read_end = stdin->_IO_read_base;
                    467:        stdin->_IO_read_ptr = stdin->_IO_read_base;
1.10      noro      468: #elif defined(VISUAL_LIB)
1.18      noro      469:        void w_purge_stdin();
                    470:
1.10      noro      471:        w_purge_stdin();
1.16      noro      472: #elif defined(sparc) || defined(__alpha) || defined(__SVR4) || defined(mips) || defined(VISUAL) || defined(_IBMR2)
1.6       noro      473:        stdin->_ptr = stdin->_base; stdin->_cnt = 0;
1.28      ohara     474: #elif (defined(__MACH__) && defined(__ppc__)) || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__INTERIX)
1.15      noro      475:        stdin->_r = 0; stdin->_p = stdin->_bf._base;
1.6       noro      476: #else
                    477: --->FIXIT
                    478: #endif
1.1       noro      479: }
                    480:
1.32    ! noro      481: extern int asir_texmacs;
        !           482:
1.1       noro      483: static int skipspace() {
                    484:        int c,c1;
                    485:
                    486:        for ( c = Getc(); ; )
                    487:                switch ( c ) {
1.14      noro      488:                        case ' ': case '\t': case '\r':
1.1       noro      489:                                c = Getc(); break;
                    490:                        case '\n':
1.32    ! noro      491:                                c = afternl(); break;
1.1       noro      492:                        case '/':
                    493:                                if ( (c1 = Getc()) == '*' )
                    494:                                        c = aftercomment();
                    495:                                else {
                    496:                                        Ungetc(c1); return c;
                    497:                                }
                    498:                                break;
                    499:                        default:
                    500:                                return c; break;
                    501:                }
                    502: }
                    503:
                    504: int afternl() {
                    505:        int c,ac,i,quote;
                    506:        char *ptr;
                    507:        char *av[BUFSIZ];
                    508:        static int ilevel = 0;
                    509:        char buf[BUFSIZ];
                    510:
                    511:        if ( !ilevel )
                    512:                asir_infile->ln++;
                    513:        while ( (c = Getc()) == '#' ) {
                    514:                Gets(buf);
                    515:                for ( quote = 0, ptr = buf; *ptr; ptr++ )
                    516:                        if ( *ptr == '"' )
                    517:                                quote = quote ? 0 : 1;
                    518:                        else if ( quote && (*ptr == ' ') )
                    519:                                *ptr = '_';
                    520:                stoarg(buf,&ac,av);
                    521:                if ( ac == 3 )
                    522:                        if ( (i = atoi(av[2])) == 1 )
                    523:                                ilevel++;
                    524:                        else if ( i == 2 )
                    525:                                ilevel--;
                    526:                if ( !ilevel )
                    527:                        asir_infile->ln = atoi(av[0]);
                    528:        }
                    529:        return c;
                    530: }
                    531:
                    532: int aftercomment() {
                    533:        int c,c1;
                    534:
                    535:        for ( c = Getc(); ; ) {
                    536:                c1 = Getc();
                    537:                if ( (c == '*') && (c1 == '/') )
                    538:                        return Getc();
                    539:                else
                    540:                        c = c1;
                    541:        }
                    542: }
                    543:
1.18      noro      544: int myatoi(char *s)
1.1       noro      545: {
                    546:        int i,r;
                    547:        for ( i = 0, r = 0; i < DLENGTH; i++ ) r = r * 10 + ( s[i] - '0' );
                    548:        return ( r );
                    549: }
                    550:
                    551: extern int ox_do_copy;
1.30      noro      552: extern int I_am_server;
                    553: extern JMP_BUF main_env;
1.1       noro      554:
1.18      noro      555: void yyerror(char *s)
1.1       noro      556: {
1.31      noro      557:        if ( main_parser ) {
                    558:                if ( ox_do_copy ) {
1.1       noro      559:                        /* push errors to DebugStack */
                    560:                } else {
                    561:                        if ( asir_infile->fp == stdin )
                    562:                                fprintf(stderr,"%s\n",s);
                    563:                        else
                    564:                                fprintf(stderr,"\"%s\", near line %d: %s\n",asir_infile->name,asir_infile->ln,s);
                    565:                }
1.31      noro      566:                if ( I_am_server ) {
                    567:                        set_lasterror(s);
                    568:                        LONGJMP(main_env,1);
                    569:                }
                    570:        } else
1.1       noro      571:                fprintf(stderr,"exprparse : %s\n",s);
                    572: }
                    573:
                    574: int echoback;
                    575:
                    576: extern int read_exec_file, do_fep, do_file;
                    577:
                    578: unsigned char encrypt_char(unsigned char);
                    579: unsigned char decrypt_char(unsigned char);
                    580:
1.18      noro      581: int Egetc(FILE *fp)
1.1       noro      582: {
                    583:        int c;
                    584:
                    585:        if ( fp ) {
1.23      noro      586: #if FEP
1.13      noro      587:                if ( do_fep && isatty(fileno(fp)) )
                    588:                        c = readline_getc();
                    589:                else
                    590: #endif
                    591:                        c = getc(fp);
1.11      noro      592: #if defined(VISUAL)
                    593:                if ( recv_intr ) {
                    594: #include <signal.h>
                    595:                        if ( recv_intr == 1 ) {
                    596:                                recv_intr = 0;
                    597:                                int_handler(SIGINT);
                    598:                        } else {
                    599:                                recv_intr = 0;
                    600:                                ox_usr1_handler(0);
                    601:                        }
                    602:                }
                    603: #endif
1.1       noro      604:                if ( c == EOF )
                    605:                        return c;
                    606:                if ( asir_infile->encoded )
                    607:                        c = decrypt_char((unsigned char)c);
                    608:                return c;
1.3       noro      609:        } else if ( read_exec_file )
                    610:                return EOF;
                    611:        else {
1.1       noro      612:                c = *parse_strp++;
                    613:                if ( !c )
                    614:                        return EOF;
                    615:                else
                    616:                        return c;
                    617:        }
                    618: }
                    619:
1.18      noro      620: void Eungetc(int c,FILE *fp)
1.1       noro      621: {
                    622:        if ( fp ) {
                    623:                if ( asir_infile->encoded )
                    624:                        c = (int)encrypt_char((unsigned char)c);
1.23      noro      625: #if FEP
1.13      noro      626:                if ( do_fep && isatty(fileno(fp)) )
                    627:                        readline_ungetc();
                    628:                else
                    629: #endif
                    630:                        ungetc(c,fp);
1.1       noro      631:        } else
                    632:                *--parse_strp = c;
                    633: }
                    634:
                    635: static int Getc() {
                    636:        int c;
                    637:
                    638:        if ( main_parser ) {
                    639:                while ( 1 ) {
                    640:                        if ((c = Egetc(asir_infile->fp)) == EOF)
                    641:                                if ( NEXT(asir_infile) ) {
                    642:                                        closecurrentinput();
1.9       noro      643:                                        /* if the input is the top level, generate error */
                    644:                                        if ( !NEXT(asir_infile) )
                    645:                                                error("end-of-file detected during parsing");
                    646:                                        else
                    647:                                                c = Getc();
1.1       noro      648:                                        break;
                    649:                                } else if ( read_exec_file || do_file )
                    650:                                        asir_terminate(2);
                    651:                                else {
                    652:                                        if ( asir_infile->fp )
                    653:                                                clearerr(asir_infile->fp);
                    654:                                }
                    655:                        else
                    656:                                break;
                    657:                }
                    658:                if ( echoback )
                    659:                        fputc(c,asir_out);
                    660:        } else
                    661:                c = *parse_strp++;
                    662:        return ( c );
                    663: }
                    664:
1.18      noro      665: static void Ungetc(int c) {
1.1       noro      666:        if ( main_parser ) {
                    667:                Eungetc(c,asir_infile->fp);
                    668:                if ( echoback )
                    669:                        fputc('',asir_out);
                    670:        } else
                    671:                *--parse_strp = c;
                    672: }
                    673:
1.18      noro      674: static void Gets(char *s)
1.1       noro      675: {
                    676:        int c;
                    677:
                    678:        while ( (c = Getc()) != '\n' )
                    679:                *s++ = c;
                    680:        *s = 0;
                    681: }
1.12      saito     682:
1.23      noro      683: #if FEP
1.12      saito     684:
                    685: static char *readline_line;
                    686: static int readline_nc,readline_index;
                    687: char *readline_console();
                    688:
                    689: int readline_getc()
                    690: {
                    691:         char buf[BUFSIZ];
                    692:
                    693:         if ( !readline_nc ) {
                    694:                 if ( readline_line )
                    695:                         free(readline_line);
                    696:                 sprompt(buf);
                    697:                 readline_line = readline_console(buf);
                    698:                 readline_nc = strlen(readline_line);
                    699:                 readline_index = 0;
                    700:         }
                    701:         readline_nc--;
                    702:         return readline_line[readline_index++];
                    703: }
                    704:
                    705: void readline_ungetc()
                    706: {
                    707:         readline_nc++; readline_index--;
                    708: }
                    709:
1.18      noro      710: char *readline_console(char *prompt)
1.12      saito     711: {
                    712:         char *line;
                    713:         int exp_result;
                    714:         char *expansion;
                    715:
                    716:         while ( 1 ) {
                    717:                 line = (char *)readline(prompt);
                    718:                 if ( line && *line ) {
                    719:                         using_history();
                    720:                         exp_result = history_expand(line,&expansion);
                    721:                         if ( !exp_result ) {
                    722:                                 free(expansion);
                    723:                                 for ( ; isspace(*line); line++ );
                    724:                                 add_history(line);
                    725:                                 break;
                    726:                         } else if ( exp_result > 0 ) {
                    727:                                 free(line);
                    728:                                 line = expansion;
                    729:                                 break;
                    730:                         }
                    731:                 }
                    732:         }
                    733:         return line;
                    734: }
                    735: #endif

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