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