Annotation of OpenXM_contrib2/asir2000/parse/lex.c, Revision 1.40
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.40 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/lex.c,v 1.39 2006/03/05 07:11:52 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(); ; ) {
1.39 noro 540: if ( c == '\n' ) asir_infile->ln++;
1.1 noro 541: c1 = Getc();
542: if ( (c == '*') && (c1 == '/') )
543: return Getc();
544: else
545: c = c1;
546: }
547: }
548:
1.18 noro 549: int myatoi(char *s)
1.1 noro 550: {
551: int i,r;
552: for ( i = 0, r = 0; i < DLENGTH; i++ ) r = r * 10 + ( s[i] - '0' );
553: return ( r );
554: }
555:
556: extern int ox_do_copy;
1.30 noro 557: extern int I_am_server;
558: extern JMP_BUF main_env;
1.40 ! noro 559: extern int at_root;
! 560: extern LIST LastStackTrace;
1.1 noro 561:
1.18 noro 562: void yyerror(char *s)
1.1 noro 563: {
1.40 ! noro 564: STRING fname;
! 565: Q q;
! 566: NODE t;
! 567: LIST l,l2;
! 568:
1.31 noro 569: if ( main_parser ) {
570: if ( ox_do_copy ) {
1.1 noro 571: /* push errors to DebugStack */
572: } else {
573: if ( asir_infile->fp == stdin )
574: fprintf(stderr,"%s\n",s);
575: else
576: fprintf(stderr,"\"%s\", near line %d: %s\n",asir_infile->name,asir_infile->ln,s);
577: }
1.31 noro 578: if ( I_am_server ) {
1.40 ! noro 579: if ( NEXT(asir_infile) ) {
! 580: /* error in a file; record the position */
! 581: MKSTR(fname,asir_infile->name); STOQ(asir_infile->ln,q);
! 582: t = mknode(2,fname,q); MKLIST(l,t);
! 583: /* line number at the toplevel */
! 584: MKSTR(fname,"toplevel"); STOQ(at_root,q);
! 585: t = mknode(2,fname,q); MKLIST(l2,t);
! 586: t = mknode(2,l2,l);
! 587: } else {
! 588: MKSTR(fname,"toplevel"); STOQ(asir_infile->ln,q);
! 589: t = mknode(2,fname,q); MKLIST(l,t);
! 590: t = mknode(1,l);
! 591: }
! 592: MKLIST(LastStackTrace,t);
1.31 noro 593: set_lasterror(s);
594: LONGJMP(main_env,1);
595: }
596: } else
1.1 noro 597: fprintf(stderr,"exprparse : %s\n",s);
598: }
599:
600: int echoback;
601:
1.38 noro 602: extern int do_fep, do_file;
1.1 noro 603:
604: unsigned char encrypt_char(unsigned char);
605: unsigned char decrypt_char(unsigned char);
606:
1.18 noro 607: int Egetc(FILE *fp)
1.1 noro 608: {
609: int c;
610:
611: if ( fp ) {
1.23 noro 612: #if FEP
1.13 noro 613: if ( do_fep && isatty(fileno(fp)) )
614: c = readline_getc();
615: else
616: #endif
617: c = getc(fp);
1.11 noro 618: #if defined(VISUAL)
619: if ( recv_intr ) {
620: #include <signal.h>
621: if ( recv_intr == 1 ) {
622: recv_intr = 0;
623: int_handler(SIGINT);
624: } else {
625: recv_intr = 0;
626: ox_usr1_handler(0);
627: }
628: }
629: #endif
1.1 noro 630: if ( c == EOF )
631: return c;
632: if ( asir_infile->encoded )
633: c = decrypt_char((unsigned char)c);
634: return c;
1.38 noro 635: } else {
1.1 noro 636: c = *parse_strp++;
637: if ( !c )
638: return EOF;
639: else
640: return c;
641: }
642: }
643:
1.18 noro 644: void Eungetc(int c,FILE *fp)
1.1 noro 645: {
646: if ( fp ) {
647: if ( asir_infile->encoded )
648: c = (int)encrypt_char((unsigned char)c);
1.23 noro 649: #if FEP
1.13 noro 650: if ( do_fep && isatty(fileno(fp)) )
651: readline_ungetc();
652: else
653: #endif
654: ungetc(c,fp);
1.1 noro 655: } else
656: *--parse_strp = c;
657: }
658:
659: static int Getc() {
660: int c;
661:
662: if ( main_parser ) {
663: while ( 1 ) {
664: if ((c = Egetc(asir_infile->fp)) == EOF)
665: if ( NEXT(asir_infile) ) {
666: closecurrentinput();
1.9 noro 667: /* if the input is the top level, generate error */
668: if ( !NEXT(asir_infile) )
669: error("end-of-file detected during parsing");
670: else
671: c = Getc();
1.1 noro 672: break;
1.38 noro 673: } else if ( asir_infile->fp || do_file )
1.1 noro 674: asir_terminate(2);
675: else {
676: if ( asir_infile->fp )
677: clearerr(asir_infile->fp);
678: }
679: else
680: break;
681: }
682: if ( echoback )
683: fputc(c,asir_out);
684: } else
685: c = *parse_strp++;
686: return ( c );
687: }
688:
1.18 noro 689: static void Ungetc(int c) {
1.1 noro 690: if ( main_parser ) {
691: Eungetc(c,asir_infile->fp);
692: if ( echoback )
693: fputc('',asir_out);
694: } else
695: *--parse_strp = c;
696: }
697:
1.18 noro 698: static void Gets(char *s)
1.1 noro 699: {
700: int c;
701:
702: while ( (c = Getc()) != '\n' )
703: *s++ = c;
704: *s = 0;
705: }
1.12 saito 706:
1.23 noro 707: #if FEP
1.12 saito 708:
709: static char *readline_line;
710: static int readline_nc,readline_index;
711: char *readline_console();
712:
713: int readline_getc()
714: {
715: char buf[BUFSIZ];
716:
717: if ( !readline_nc ) {
718: if ( readline_line )
719: free(readline_line);
720: sprompt(buf);
721: readline_line = readline_console(buf);
722: readline_nc = strlen(readline_line);
723: readline_index = 0;
724: }
725: readline_nc--;
726: return readline_line[readline_index++];
727: }
728:
729: void readline_ungetc()
730: {
731: readline_nc++; readline_index--;
732: }
733:
1.18 noro 734: char *readline_console(char *prompt)
1.12 saito 735: {
736: char *line;
737: int exp_result;
738: char *expansion;
739:
740: while ( 1 ) {
741: line = (char *)readline(prompt);
742: if ( line && *line ) {
743: using_history();
744: exp_result = history_expand(line,&expansion);
745: if ( !exp_result ) {
746: free(expansion);
1.35 noro 747: for ( ; isspace((unsigned char)*line); line++ );
1.12 saito 748: add_history(line);
749: break;
750: } else if ( exp_result > 0 ) {
751: free(line);
752: line = expansion;
753: break;
754: }
755: }
756: }
757: return line;
758: }
759: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>