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