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

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

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