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

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.35    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/lex.c,v 1.34 2004/12/17 03:09:08 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.33      noro      191:                                        }else if ( c1 == 'r' ) {
                    192:                                                c1 = '\r';
1.27      ohara     193:                     }else if ( c1 == 't' ) {
                    194:                         c1 = '\t';
                    195:                     }else if ( isdigit(c1) ){
                    196:                         d = c1 - '0';
                    197:                         c1 = Getc();
                    198:                         if ( isdigit(c1) ) {
                    199:                              d = 8*d + (c1 - '0');
                    200:                              c1 = Getc();
                    201:                              if ( isdigit(c1) ) {
                    202:                                  d = 8*d + (c1 - '0');
                    203:                              }else {
                    204:                                  Ungetc(c1);
                    205:                              }
                    206:                         }else {
                    207:                             Ungetc(c1);
                    208:                         }
                    209:                         c1 = d;
                    210:                     }
1.2       noro      211:                                        REALLOC_NBUF nbuf[i++] = c1;
                    212:                                } else {
                    213:                                        REALLOC_NBUF nbuf[i++] = c;
                    214:                                }
1.1       noro      215:                        } while ( c != '"' );
1.2       noro      216:                        nbuf[i-1] = 0; /* REALLOC_NBUF is not necessary */
1.1       noro      217:                        cptr = (char *)MALLOC(strlen(nbuf)+1);
                    218:                        strcpy(cptr,nbuf); yylvalp->p = (pointer) cptr;
                    219:                        return ( STR ); break;
                    220:                case '>': case '<': case '=': case '!':
                    221:                        if ( (c1 = Getc()) == '=' )
                    222:                                switch ( c ) {
                    223:                                        case '>': yylvalp->i = (int)C_GE; break;
                    224:                                        case '<': yylvalp->i = (int)C_LE; break;
                    225:                                        case '=': yylvalp->i = (int)C_EQ; break;
                    226:                                        case '!': yylvalp->i = (int)C_NE; break;
                    227:                                        default: break;
                    228:                                }
                    229:                        else if ( (c == '<' && c1 == '<') || (c == '>' && c1 == '>') )
                    230:                                return c;
                    231:                        else {
                    232:                                Ungetc(c1);
                    233:                                switch ( c ) {
                    234:                                        case '>': yylvalp->i = (int)C_GT; break;
                    235:                                        case '<': yylvalp->i = (int)C_LT; break;
                    236:                                        default: return c; break;
                    237:                                }
                    238:                        }
                    239:                        return CMP; break;
                    240:                case '+': case '-': case '*': case '/': case '%': case '^':
                    241:                case '|': case '&':
                    242:                        switch ( c ) {
                    243:                                case '+': yylvalp->p = (pointer)addfs; break;
                    244:                                case '-': yylvalp->p = (pointer)subfs; break;
                    245:                                case '*': yylvalp->p = (pointer)mulfs; break;
                    246:                                case '/': yylvalp->p = (pointer)divfs; break;
                    247:                                case '%': yylvalp->p = (pointer)remfs; break;
                    248:                                case '^': yylvalp->p = (pointer)pwrfs; break;
                    249:                                default: break;
                    250:                        }
                    251:                        if ( (c1 = Getc()) == c )
                    252:                                switch ( c ) {
                    253:                                        case '+': case '-': return SELF; break;
                    254:                                        case '|': return OR; break;
                    255:                                        case '&': return AND; break;
                    256:                                        default: Ungetc(c1); return c; break;
                    257:                                }
                    258:                        else if ( c1 == '=' )
                    259:                                return BOPASS;
                    260:                        else if ( (c == '-') && (c1 == '>') )
                    261:                                return POINT;
                    262:                        else {
                    263:                                Ungetc(c1); return c;
                    264:                        }
                    265:                        break;
                    266:                default :
                    267:                        break;
                    268:        }
                    269:        if ( isdigit(c) ) {
                    270:                for ( i = 0; i < DLENGTH; i++ )
                    271:                        nbuf[i] = '0';
1.2       noro      272:                REALLOC_NBUF nbuf[i++] = c;
                    273:                READ_DIGIT_NBUF
1.1       noro      274:                if ( c == '.' ) {
1.20      kondoh    275:                        floatingpoint = 1;
1.1       noro      276:
1.2       noro      277:                        REALLOC_NBUF nbuf[i++] = c;
                    278:                        READ_DIGIT_NBUF
1.21      noro      279:                        if ( c == 'e' || c == 'E' ) {
1.2       noro      280:                                REALLOC_NBUF nbuf[i++] = c;
                    281:                                c = Getc();
                    282:                                if ( (c == '+') || (c == '-') ) {
                    283:                                        REALLOC_NBUF nbuf[i++] = c;
                    284:                                } else
                    285:                                        Ungetc(c);
                    286:                                READ_DIGIT_NBUF
1.1       noro      287:                        }
1.21      noro      288:                } else if ( c == 'e' || c == 'E' ) {
1.20      kondoh    289:                        floatingpoint = 1;
                    290:                        REALLOC_NBUF nbuf[i++] = c;
                    291:                        c = Getc();
                    292:                        if ( (c == '+') || (c == '-') ) {
                    293:                                REALLOC_NBUF nbuf[i++] = c;
                    294:                        } else
                    295:                                Ungetc(c);
                    296:                        READ_DIGIT_NBUF
                    297:                }
                    298:                if ( floatingpoint ) {
1.2       noro      299:                        Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
1.22      ohara     300: #if defined(PARI)
1.1       noro      301:                        if ( !bigfloat ) {
                    302:                                dbl = (double)atof(nbuf+DLENGTH);
                    303:                                MKReal(dbl,real); r = (Obj)real;
                    304:                        } else
                    305:                                strtobf(nbuf,(BF *)&r);
                    306: #else
                    307:                        dbl = (double)atof(nbuf+DLENGTH);
                    308:                        MKReal(dbl,real); r = (Obj)real;
                    309: #endif
                    310:                } else {
                    311:                        Ungetc(c);
                    312:                        i -= DLENGTH; d = (i%DLENGTH?i/DLENGTH+1:i/DLENGTH);
                    313:                        n = NALLOC(d); PL(n) = d;
                    314:                        for ( j = 0, ptr = BD(n); j < d; j++ ,i -= DLENGTH )
                    315:                                ptr[j] = myatoi(nbuf+i);
                    316:                        bnton(DBASE,n,&n1);
                    317:                        NTOQ(n1,1,q); r = (Obj)q;
                    318: /*                     optobj(&r); */
                    319:                }
                    320:                yylvalp->p = (pointer)r;
                    321:                return ( FORMULA );
1.25      noro      322:        } else if ( isalpha(c) || c == ':' ) {
                    323:                if ( c == ':' ) {
                    324:                        c1 = Getc();
                    325:                        if ( c1 != ':' ) {
                    326:                                Ungetc(c1);
                    327:                                return c;
                    328:                        }
                    329:                        c1 = Getc();
                    330:                        if ( !isalpha(c1) ) {
                    331:                                Ungetc(c1);
                    332:                                return COLONCOLON;
                    333:                        }
                    334:                        i = 0;
                    335:                        tbuf[i++] = ':';
                    336:                        tbuf[i++] = ':';
                    337:                        tbuf[i++] = c1;
                    338:                } else {
                    339:                        i = 0;
                    340:                        tbuf[i++] = c;
                    341:                }
1.2       noro      342:                while ( 1 ) {
                    343:                        c = Getc();
1.24      noro      344:                        if ( isalpha(c)||isdigit(c)||(c=='_')||(c=='.') ) {
1.2       noro      345:                                REALLOC_TBUF tbuf[i++] = c;
                    346:                        } else
                    347:                                break;
                    348:                }
                    349:                REALLOC_TBUF tbuf[i] = 0; Ungetc(c);
1.1       noro      350:                if ( isupper(tbuf[0]) ) {
                    351:                        cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    352:                        yylvalp->p = (pointer)cptr;
                    353:                        return UCASE;
                    354:                } else {
                    355:                        for ( i = 0; kwd[i].name && strcmp(tbuf,kwd[i].name); i++ );
                    356:                        if ( kwd[i].name ) {
                    357:                                yylvalp->i = asir_infile->ln;
                    358:                                return kwd[i].token;
                    359:                        } else {
                    360:                                cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    361:                                yylvalp->p = (pointer)cptr;
                    362:                                return LCASE;
                    363:                        }
                    364:                }
                    365:        } else if ( c == '@' ) {
                    366:                if ( isdigit(c = Getc()) ) {
1.2       noro      367:                        i = 0;
                    368:                        nbuf[i++] = c;
                    369:                        READ_DIGIT_NBUF
                    370:                        Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
                    371:                        yylvalp->i = atoi(nbuf);
1.1       noro      372:                        return ANS;
                    373:                } else if ( c == '@' ) {
                    374:                        yylvalp->i = MAX(0,APVS->n-1);
                    375:                        return ANS;
                    376:                } else if ( c == '>' ||  c == '<' ||  c == '=' || c == '!' ) {
                    377:                        if ( (c1 = Getc()) == '=' )
                    378:                                switch ( c ) {
                    379:                                        case '>': yylvalp->i = (int)L_GE; break;
                    380:                                        case '<': yylvalp->i = (int)L_LE; break;
                    381:                                        case '=': yylvalp->i = (int)L_EQ; break;
                    382:                                        case '!': yylvalp->i = (int)L_NE; break;
                    383:                                        default: break;
                    384:                                }
                    385:                        else {
                    386:                                Ungetc(c1);
                    387:                                switch ( c ) {
                    388:                                        case '>': yylvalp->i = (int)L_GT; break;
                    389:                                        case '<': yylvalp->i = (int)L_LT; break;
                    390:                                        case '=': yylvalp->i = (int)L_EQ; break;
                    391:                                        case '!': yylvalp->i = (int)L_NOT; return FOP_NOT; break;
                    392:                                        default: break;
                    393:                                }
                    394:                        }
                    395:                        return LOP;
                    396:                } else if ( c == '|' ||  c == '&' ) {
                    397:                        if ( (c1 = Getc()) != c )
                    398:                                Ungetc(c1);
                    399:                        switch ( c ) {
                    400:                                case '|': yylvalp->i = (int)L_OR;
                    401:                                        return FOP_OR; break;
                    402:                                case '&': yylvalp->i = (int)L_AND;
                    403:                                        return FOP_AND; break;
                    404:                        }
                    405:                } else if ( isalpha(c) ) {
1.2       noro      406:                        i = 0;
                    407:                        tbuf[i++] = '@';
                    408:                        tbuf[i++] = c;
                    409:                        while ( 1 ) {
                    410:                                c = Getc();
                    411:                                if ( isalpha(c) ) {
                    412:                                        REALLOC_TBUF tbuf[i++] = c;
                    413:                                } else
                    414:                                        break;
                    415:                        }
                    416:                        Ungetc(c); REALLOC_TBUF tbuf[i] = 0;
1.1       noro      417:                        if ( !strcmp(tbuf,"@p") )
                    418:                                return GFPNGEN;
1.17      noro      419:                        else if ( !strcmp(tbuf,"@s") )
                    420:                                return GFSNGEN;
1.1       noro      421:                        else if ( !strcmp(tbuf,"@i") ) {
                    422:                                extern pointer IU;
                    423:
                    424:                                yylvalp->p = IU;
                    425:                                return FORMULA;
                    426:                        } else if ( !strcmp(tbuf,"@true") ) {
                    427:                                yylvalp->p = F_TRUE;
                    428:                                return FORMULA;
                    429:                        } else if ( !strcmp(tbuf,"@false") ) {
                    430:                                yylvalp->p = F_FALSE;
                    431:                                return FORMULA;
                    432:                        } else if ( !strcmp(tbuf,"@impl") ) {
                    433:                                yylvalp->i = (int)L_IMPL;
                    434:                                return FOP_IMPL;
                    435:                        } else if ( !strcmp(tbuf,"@repl") ) {
                    436:                                yylvalp->i = (int)L_REPL;
                    437:                                return FOP_REPL;
                    438:                        } else if ( !strcmp(tbuf,"@equiv") ) {
                    439:                                yylvalp->i = (int)L_EQUIV;
                    440:                                return FOP_EQUIV;
1.29      noro      441:                        } else if ( !strcmp(tbuf,"@grlex") ) {
                    442:                                yylvalp->p = Symbol_grlex;
                    443:                                return FORMULA;
                    444:                        } else if ( !strcmp(tbuf,"@glex") ) {
                    445:                                yylvalp->p = Symbol_glex;
                    446:                                return FORMULA;
                    447:                        } else if ( !strcmp(tbuf,"@lex") ) {
                    448:                                yylvalp->p = Symbol_lex;
                    449:                                return FORMULA;
1.1       noro      450:                        } else {
                    451:                                cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
                    452:                                yylvalp->p = (pointer)cptr;
                    453:                                return LCASE;
                    454:                        }
                    455:                } else {
                    456:                        Ungetc(c);
                    457:                        return GF2NGEN;
                    458:                }
                    459:        } else
                    460:                return ( c );
1.6       noro      461: }
                    462:
                    463: void purge_stdin()
                    464: {
1.7       noro      465: #if defined(__FreeBSD__)
1.6       noro      466:        fpurge(stdin);
                    467: #elif defined(linux)
                    468:        stdin->_IO_read_end = stdin->_IO_read_base;
                    469:        stdin->_IO_read_ptr = stdin->_IO_read_base;
1.10      noro      470: #elif defined(VISUAL_LIB)
1.18      noro      471:        void w_purge_stdin();
                    472:
1.10      noro      473:        w_purge_stdin();
1.16      noro      474: #elif defined(sparc) || defined(__alpha) || defined(__SVR4) || defined(mips) || defined(VISUAL) || defined(_IBMR2)
1.6       noro      475:        stdin->_ptr = stdin->_base; stdin->_cnt = 0;
1.28      ohara     476: #elif (defined(__MACH__) && defined(__ppc__)) || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__INTERIX)
1.15      noro      477:        stdin->_r = 0; stdin->_p = stdin->_bf._base;
1.6       noro      478: #else
                    479: --->FIXIT
                    480: #endif
1.1       noro      481: }
1.32      noro      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);
1.35    ! noro      723:                                 for ( ; isspace((unsigned char)*line); line++ );
1.12      saito     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>