Annotation of OpenXM_contrib2/asir2000/parse/lex.c, Revision 1.45
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.45 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/lex.c,v 1.44 2007/08/06 08:15:26 saito 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.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.22 ohara 304: #if defined(PARI)
1.1 noro 305: if ( !bigfloat ) {
306: dbl = (double)atof(nbuf+DLENGTH);
307: MKReal(dbl,real); r = (Obj)real;
308: } else
309: strtobf(nbuf,(BF *)&r);
310: #else
311: dbl = (double)atof(nbuf+DLENGTH);
312: MKReal(dbl,real); r = (Obj)real;
313: #endif
314: } else {
315: Ungetc(c);
316: i -= DLENGTH; d = (i%DLENGTH?i/DLENGTH+1:i/DLENGTH);
317: n = NALLOC(d); PL(n) = d;
318: for ( j = 0, ptr = BD(n); j < d; j++ ,i -= DLENGTH )
319: ptr[j] = myatoi(nbuf+i);
320: bnton(DBASE,n,&n1);
321: NTOQ(n1,1,q); r = (Obj)q;
322: /* optobj(&r); */
323: }
324: yylvalp->p = (pointer)r;
325: return ( FORMULA );
1.36 noro 326: } else if ( isalpha(c) || c == ':' || c == '_' ) {
1.25 noro 327: if ( c == ':' ) {
328: c1 = Getc();
329: if ( c1 != ':' ) {
330: Ungetc(c1);
331: return c;
332: }
333: c1 = Getc();
334: if ( !isalpha(c1) ) {
335: Ungetc(c1);
336: return COLONCOLON;
337: }
338: i = 0;
339: tbuf[i++] = ':';
340: tbuf[i++] = ':';
341: tbuf[i++] = c1;
342: } else {
343: i = 0;
344: tbuf[i++] = c;
345: }
1.2 noro 346: while ( 1 ) {
347: c = Getc();
1.24 noro 348: if ( isalpha(c)||isdigit(c)||(c=='_')||(c=='.') ) {
1.2 noro 349: REALLOC_TBUF tbuf[i++] = c;
350: } else
351: break;
352: }
353: REALLOC_TBUF tbuf[i] = 0; Ungetc(c);
1.36 noro 354: if ( isupper(tbuf[0]) || (tbuf[0] == '_' && isupper(tbuf[1])) ) {
1.1 noro 355: cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
356: yylvalp->p = (pointer)cptr;
357: return UCASE;
358: } else {
359: for ( i = 0; kwd[i].name && strcmp(tbuf,kwd[i].name); i++ );
360: if ( kwd[i].name ) {
361: yylvalp->i = asir_infile->ln;
362: return kwd[i].token;
363: } else {
364: cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
365: yylvalp->p = (pointer)cptr;
366: return LCASE;
367: }
368: }
369: } else if ( c == '@' ) {
370: if ( isdigit(c = Getc()) ) {
1.2 noro 371: i = 0;
372: nbuf[i++] = c;
373: READ_DIGIT_NBUF
374: Ungetc(c); REALLOC_NBUF nbuf[i] = 0;
375: yylvalp->i = atoi(nbuf);
1.1 noro 376: return ANS;
377: } else if ( c == '@' ) {
378: yylvalp->i = MAX(0,APVS->n-1);
379: return ANS;
380: } else if ( c == '>' || c == '<' || c == '=' || c == '!' ) {
381: if ( (c1 = Getc()) == '=' )
382: switch ( c ) {
383: case '>': yylvalp->i = (int)L_GE; break;
384: case '<': yylvalp->i = (int)L_LE; break;
385: case '=': yylvalp->i = (int)L_EQ; break;
386: case '!': yylvalp->i = (int)L_NE; break;
387: default: break;
388: }
389: else {
390: Ungetc(c1);
391: switch ( c ) {
392: case '>': yylvalp->i = (int)L_GT; break;
393: case '<': yylvalp->i = (int)L_LT; break;
394: case '=': yylvalp->i = (int)L_EQ; break;
395: case '!': yylvalp->i = (int)L_NOT; return FOP_NOT; break;
396: default: break;
397: }
398: }
399: return LOP;
400: } else if ( c == '|' || c == '&' ) {
401: if ( (c1 = Getc()) != c )
402: Ungetc(c1);
403: switch ( c ) {
404: case '|': yylvalp->i = (int)L_OR;
405: return FOP_OR; break;
406: case '&': yylvalp->i = (int)L_AND;
407: return FOP_AND; break;
408: }
409: } else if ( isalpha(c) ) {
1.2 noro 410: i = 0;
411: tbuf[i++] = '@';
412: tbuf[i++] = c;
413: while ( 1 ) {
414: c = Getc();
415: if ( isalpha(c) ) {
416: REALLOC_TBUF tbuf[i++] = c;
417: } else
418: break;
419: }
420: Ungetc(c); REALLOC_TBUF tbuf[i] = 0;
1.1 noro 421: if ( !strcmp(tbuf,"@p") )
422: return GFPNGEN;
1.17 noro 423: else if ( !strcmp(tbuf,"@s") )
424: return GFSNGEN;
1.37 noro 425: else if ( !strcmp(tbuf,"@void") ) {
426: yylvalp->p = VOIDobj;
427: return FORMULA;
428: } else if ( !strcmp(tbuf,"@i") ) {
1.1 noro 429: extern pointer IU;
430:
431: yylvalp->p = IU;
432: return FORMULA;
433: } else if ( !strcmp(tbuf,"@true") ) {
434: yylvalp->p = F_TRUE;
435: return FORMULA;
436: } else if ( !strcmp(tbuf,"@false") ) {
437: yylvalp->p = F_FALSE;
438: return FORMULA;
439: } else if ( !strcmp(tbuf,"@impl") ) {
440: yylvalp->i = (int)L_IMPL;
441: return FOP_IMPL;
442: } else if ( !strcmp(tbuf,"@repl") ) {
443: yylvalp->i = (int)L_REPL;
444: return FOP_REPL;
445: } else if ( !strcmp(tbuf,"@equiv") ) {
446: yylvalp->i = (int)L_EQUIV;
447: return FOP_EQUIV;
1.29 noro 448: } else if ( !strcmp(tbuf,"@grlex") ) {
449: yylvalp->p = Symbol_grlex;
450: return FORMULA;
451: } else if ( !strcmp(tbuf,"@glex") ) {
452: yylvalp->p = Symbol_glex;
453: return FORMULA;
454: } else if ( !strcmp(tbuf,"@lex") ) {
455: yylvalp->p = Symbol_lex;
456: return FORMULA;
1.1 noro 457: } else {
458: cptr = (char *)MALLOC(strlen(tbuf)+1); strcpy(cptr,tbuf);
459: yylvalp->p = (pointer)cptr;
460: return LCASE;
461: }
462: } else {
463: Ungetc(c);
464: return GF2NGEN;
465: }
466: } else
467: return ( c );
1.6 noro 468: }
469:
470: void purge_stdin()
471: {
1.43 ohara 472: #if defined(__FreeBSD__) || defined(__DARWIN__)
1.6 noro 473: fpurge(stdin);
474: #elif defined(linux)
475: stdin->_IO_read_end = stdin->_IO_read_base;
476: stdin->_IO_read_ptr = stdin->_IO_read_base;
1.10 noro 477: #elif defined(VISUAL_LIB)
1.18 noro 478: void w_purge_stdin();
479:
1.10 noro 480: w_purge_stdin();
1.16 noro 481: #elif defined(sparc) || defined(__alpha) || defined(__SVR4) || defined(mips) || defined(VISUAL) || defined(_IBMR2)
1.6 noro 482: stdin->_ptr = stdin->_base; stdin->_cnt = 0;
1.28 ohara 483: #elif (defined(__MACH__) && defined(__ppc__)) || defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__INTERIX)
1.15 noro 484: stdin->_r = 0; stdin->_p = stdin->_bf._base;
1.6 noro 485: #else
486: --->FIXIT
487: #endif
1.1 noro 488: }
1.32 noro 489:
1.1 noro 490: static int skipspace() {
491: int c,c1;
492:
493: for ( c = Getc(); ; )
494: switch ( c ) {
1.14 noro 495: case ' ': case '\t': case '\r':
1.1 noro 496: c = Getc(); break;
497: case '\n':
1.32 noro 498: c = afternl(); break;
1.1 noro 499: case '/':
500: if ( (c1 = Getc()) == '*' )
501: c = aftercomment();
502: else {
503: Ungetc(c1); return c;
504: }
505: break;
506: default:
507: return c; break;
508: }
509: }
510:
511: int afternl() {
512: int c,ac,i,quote;
513: char *ptr;
514: char *av[BUFSIZ];
515: static int ilevel = 0;
516: char buf[BUFSIZ];
517:
518: if ( !ilevel )
519: asir_infile->ln++;
520: while ( (c = Getc()) == '#' ) {
521: Gets(buf);
522: for ( quote = 0, ptr = buf; *ptr; ptr++ )
523: if ( *ptr == '"' )
524: quote = quote ? 0 : 1;
525: else if ( quote && (*ptr == ' ') )
526: *ptr = '_';
527: stoarg(buf,&ac,av);
528: if ( ac == 3 )
529: if ( (i = atoi(av[2])) == 1 )
530: ilevel++;
531: else if ( i == 2 )
532: ilevel--;
533: if ( !ilevel )
534: asir_infile->ln = atoi(av[0]);
535: }
536: return c;
537: }
538:
539: int aftercomment() {
540: int c,c1;
541:
542: for ( c = Getc(); ; ) {
1.39 noro 543: if ( c == '\n' ) asir_infile->ln++;
1.1 noro 544: c1 = Getc();
545: if ( (c == '*') && (c1 == '/') )
546: return Getc();
547: else
548: c = c1;
549: }
550: }
551:
1.18 noro 552: int myatoi(char *s)
1.1 noro 553: {
554: int i,r;
555: for ( i = 0, r = 0; i < DLENGTH; i++ ) r = r * 10 + ( s[i] - '0' );
556: return ( r );
557: }
558:
559: extern int ox_do_copy;
1.30 noro 560: extern int I_am_server;
561: extern JMP_BUF main_env;
1.40 noro 562: extern int at_root;
563: extern LIST LastStackTrace;
1.41 noro 564: extern char *CUR_FUNC;
1.1 noro 565:
1.18 noro 566: void yyerror(char *s)
1.1 noro 567: {
1.41 noro 568: STRING fname,name,kwd;
1.42 noro 569: USINT u;
1.40 noro 570: NODE t;
571: LIST l,l2;
572:
1.31 noro 573: if ( main_parser ) {
574: if ( ox_do_copy ) {
1.1 noro 575: /* push errors to DebugStack */
576: } else {
577: if ( asir_infile->fp == stdin )
578: fprintf(stderr,"%s\n",s);
579: else
580: fprintf(stderr,"\"%s\", near line %d: %s\n",asir_infile->name,asir_infile->ln,s);
581: }
1.31 noro 582: if ( I_am_server ) {
1.40 noro 583: if ( NEXT(asir_infile) ) {
584: /* error in a file; record the position */
1.41 noro 585: MKSTR(fname,asir_infile->name);
586: if ( CPVS == GPVS )
587: MKSTR(name,"");
588: else
589: MKSTR(name,CUR_FUNC);
1.42 noro 590: MKUSINT(u,asir_infile->ln);
591: t = mknode(3,fname,name,u); MKLIST(l,t);
1.40 noro 592: /* line number at the toplevel */
1.42 noro 593: MKSTR(fname,"toplevel"); MKUSINT(u,at_root);
594: t = mknode(2,fname,u); MKLIST(l2,t);
1.40 noro 595: t = mknode(2,l2,l);
596: } else {
1.42 noro 597: MKSTR(fname,"toplevel"); MKUSINT(u,asir_infile->ln);
598: t = mknode(2,fname,u); MKLIST(l,t);
1.40 noro 599: t = mknode(1,l);
600: }
1.41 noro 601: MKLIST(l,t);
602: MKSTR(kwd,"asir_where"); t = mknode(2,kwd,l);
1.40 noro 603: MKLIST(LastStackTrace,t);
1.31 noro 604: set_lasterror(s);
605: LONGJMP(main_env,1);
606: }
607: } else
1.1 noro 608: fprintf(stderr,"exprparse : %s\n",s);
609: }
610:
611: int echoback;
612:
1.38 noro 613: extern int do_fep, do_file;
1.1 noro 614:
615: unsigned char encrypt_char(unsigned char);
616: unsigned char decrypt_char(unsigned char);
617:
1.18 noro 618: int Egetc(FILE *fp)
1.1 noro 619: {
620: int c;
621:
622: if ( fp ) {
1.23 noro 623: #if FEP
1.13 noro 624: if ( do_fep && isatty(fileno(fp)) )
625: c = readline_getc();
626: else
627: #endif
628: c = getc(fp);
1.11 noro 629: #if defined(VISUAL)
630: if ( recv_intr ) {
631: #include <signal.h>
632: if ( recv_intr == 1 ) {
633: recv_intr = 0;
634: int_handler(SIGINT);
635: } else {
636: recv_intr = 0;
637: ox_usr1_handler(0);
638: }
639: }
640: #endif
1.1 noro 641: if ( c == EOF )
642: return c;
643: if ( asir_infile->encoded )
644: c = decrypt_char((unsigned char)c);
645: return c;
1.38 noro 646: } else {
1.1 noro 647: c = *parse_strp++;
648: if ( !c )
649: return EOF;
650: else
651: return c;
652: }
653: }
654:
1.18 noro 655: void Eungetc(int c,FILE *fp)
1.1 noro 656: {
657: if ( fp ) {
658: if ( asir_infile->encoded )
659: c = (int)encrypt_char((unsigned char)c);
1.23 noro 660: #if FEP
1.13 noro 661: if ( do_fep && isatty(fileno(fp)) )
662: readline_ungetc();
663: else
664: #endif
665: ungetc(c,fp);
1.1 noro 666: } else
667: *--parse_strp = c;
668: }
669:
670: static int Getc() {
671: int c;
672:
673: if ( main_parser ) {
674: while ( 1 ) {
675: if ((c = Egetc(asir_infile->fp)) == EOF)
676: if ( NEXT(asir_infile) ) {
677: closecurrentinput();
1.9 noro 678: /* if the input is the top level, generate error */
679: if ( !NEXT(asir_infile) )
680: error("end-of-file detected during parsing");
681: else
682: c = Getc();
1.1 noro 683: break;
1.45 ! noro 684: } else if ( asir_infile->fp || do_file ) {
1.1 noro 685: if ( asir_infile->fp )
686: clearerr(asir_infile->fp);
1.45 ! noro 687: asir_terminate(2);
! 688: } else {
! 689: error("end-of-line detected during parsing");
1.1 noro 690: }
691: else
692: break;
693: }
694: if ( echoback )
695: fputc(c,asir_out);
696: } else
697: c = *parse_strp++;
698: return ( c );
699: }
700:
1.18 noro 701: static void Ungetc(int c) {
1.1 noro 702: if ( main_parser ) {
703: Eungetc(c,asir_infile->fp);
704: if ( echoback )
705: fputc('',asir_out);
706: } else
707: *--parse_strp = c;
708: }
709:
1.18 noro 710: static void Gets(char *s)
1.1 noro 711: {
712: int c;
713:
714: while ( (c = Getc()) != '\n' )
715: *s++ = c;
716: *s = 0;
717: }
1.12 saito 718:
1.23 noro 719: #if FEP
1.12 saito 720:
721: static char *readline_line;
722: static int readline_nc,readline_index;
723: char *readline_console();
724:
725: int readline_getc()
726: {
727: char buf[BUFSIZ];
728:
729: if ( !readline_nc ) {
730: if ( readline_line )
731: free(readline_line);
732: sprompt(buf);
733: readline_line = readline_console(buf);
734: readline_nc = strlen(readline_line);
735: readline_index = 0;
736: }
737: readline_nc--;
738: return readline_line[readline_index++];
739: }
740:
741: void readline_ungetc()
742: {
743: readline_nc++; readline_index--;
744: }
745:
1.18 noro 746: char *readline_console(char *prompt)
1.12 saito 747: {
748: char *line;
749: int exp_result;
750: char *expansion;
751:
752: while ( 1 ) {
753: line = (char *)readline(prompt);
754: if ( line && *line ) {
755: using_history();
756: exp_result = history_expand(line,&expansion);
757: if ( !exp_result ) {
758: free(expansion);
1.35 noro 759: for ( ; isspace((unsigned char)*line); line++ );
1.12 saito 760: add_history(line);
761: break;
762: } else if ( exp_result > 0 ) {
763: free(line);
764: line = expansion;
765: break;
766: }
767: }
768: }
769: return line;
770: }
771: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>