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

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

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