Annotation of OpenXM_contrib2/asir2000/parse/lex.c, Revision 1.38
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.38 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/lex.c,v 1.37 2005/12/10 14:14:16 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.7 noro 469: #if defined(__FreeBSD__)
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(); ; ) {
540: c1 = Getc();
541: if ( (c == '*') && (c1 == '/') )
542: return Getc();
543: else
544: c = c1;
545: }
546: }
547:
1.18 noro 548: int myatoi(char *s)
1.1 noro 549: {
550: int i,r;
551: for ( i = 0, r = 0; i < DLENGTH; i++ ) r = r * 10 + ( s[i] - '0' );
552: return ( r );
553: }
554:
555: extern int ox_do_copy;
1.30 noro 556: extern int I_am_server;
557: extern JMP_BUF main_env;
1.1 noro 558:
1.18 noro 559: void yyerror(char *s)
1.1 noro 560: {
1.31 noro 561: if ( main_parser ) {
562: if ( ox_do_copy ) {
1.1 noro 563: /* push errors to DebugStack */
564: } else {
565: if ( asir_infile->fp == stdin )
566: fprintf(stderr,"%s\n",s);
567: else
568: fprintf(stderr,"\"%s\", near line %d: %s\n",asir_infile->name,asir_infile->ln,s);
569: }
1.31 noro 570: if ( I_am_server ) {
571: set_lasterror(s);
572: LONGJMP(main_env,1);
573: }
574: } else
1.1 noro 575: fprintf(stderr,"exprparse : %s\n",s);
576: }
577:
578: int echoback;
579:
1.38 ! noro 580: extern int do_fep, do_file;
1.1 noro 581:
582: unsigned char encrypt_char(unsigned char);
583: unsigned char decrypt_char(unsigned char);
584:
1.18 noro 585: int Egetc(FILE *fp)
1.1 noro 586: {
587: int c;
588:
589: if ( fp ) {
1.23 noro 590: #if FEP
1.13 noro 591: if ( do_fep && isatty(fileno(fp)) )
592: c = readline_getc();
593: else
594: #endif
595: c = getc(fp);
1.11 noro 596: #if defined(VISUAL)
597: if ( recv_intr ) {
598: #include <signal.h>
599: if ( recv_intr == 1 ) {
600: recv_intr = 0;
601: int_handler(SIGINT);
602: } else {
603: recv_intr = 0;
604: ox_usr1_handler(0);
605: }
606: }
607: #endif
1.1 noro 608: if ( c == EOF )
609: return c;
610: if ( asir_infile->encoded )
611: c = decrypt_char((unsigned char)c);
612: return c;
1.38 ! noro 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;
1.38 ! noro 651: } else if ( asir_infile->fp || do_file )
1.1 noro 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);
1.35 noro 725: for ( ; isspace((unsigned char)*line); line++ );
1.12 saito 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>