Annotation of OpenXM_contrib2/asir2000/parse/glob.c, Revision 1.12
1.8 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.9 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.8 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.12 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/glob.c,v 1.11 2000/11/08 06:21:18 noro Exp $
1.8 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "al.h"
52: #include "parse.h"
53: #if PARI
54: #include "genpari.h"
55: #endif
1.12 ! noro 56: #if !defined(VISUAL) && !defined(_PA_RISC1_1) && !defined(linux) && !defined(SYSV)
1.1 noro 57: #include <sgtty.h>
58: #endif
59:
60: #if defined(VISUAL)
61: #include <io.h>
62: #include <direct.h>
63: #endif
64:
65: #if defined(SYSV)
66: #include <sys/ttold.h>
67: #endif
68:
69: #if defined(VISUAL)
70: #define HISTORY asir_history
71: #endif
1.12 ! noro 72:
1.1 noro 73: #define MAXHIST 100
74:
75: extern int GC_free_space_divisor;
76: extern int GC_free_space_numerator;
77: extern FILE *asir_out;
78:
79: IN asir_infile;
80: jmp_buf env,debug_env,timer_env;
81: int little_endian,debug_mode;
82: char *asir_libdir;
83: char *asir_pager;
84:
85: NODE usrf,sysf,noargsysf,ubinf,parif;
86: NODE ONENODE;
87: int main_parser, ox_do_copy, ox_do_count, ox_count_length;
88: int ox_file_io, ox_need_conv;
89: char *ox_copy_bptr;
90: char *parse_strp;
91: SNODE parse_snode;
92: FUNC parse_targetf;
93: FILE *ox_istream,*ox_ostream;
94: int do_server_in_X11;
95: Obj LastVal;
96: char LastError[BUFSIZ];
97:
98: struct oV oVAR[] = {
99: {"x",0,0}, {"y",0,0}, {"z",0,0}, {"u",0,0},
100: {"v",0,0}, {"w",0,0}, {"p",0,0}, {"q",0,0},
101: {"r",0,0}, {"s",0,0}, {"t",0,0}, {"a",0,0},
102: {"b",0,0}, {"c",0,0}, {"d",0,0}, {"e",0,0},
103: {"f",0,0}, {"g",0,0}, {"h",0,0}, {"i",0,0},
104: {"j",0,0}, {"k",0,0}, {"l",0,0}, {"m",0,0},
105: {"n",0,0}, {"o",0,0},
106: {"_x",0,0}, {"_y",0,0}, {"_z",0,0}, {"_u",0,0},
107: {"_v",0,0}, {"_w",0,0}, {"_p",0,0}, {"_q",0,0},
108: {"_r",0,0}, {"_s",0,0}, {"_t",0,0}, {"_a",0,0},
109: {"_b",0,0}, {"_c",0,0}, {"_d",0,0}, {"_e",0,0},
110: {"_f",0,0}, {"_g",0,0}, {"_h",0,0}, {"_i",0,0},
111: {"_j",0,0}, {"_k",0,0}, {"_l",0,0}, {"_m",0,0},
112: {"_n",0,0}, {"_o",0,0}
113: };
114:
115: struct oVL oVLIST[52];
116:
117: VL CO = oVLIST;
118: VL ALG;
119:
120: struct oVS oGPVS,oAPVS,oEPVS;
121: VS GPVS = &oGPVS;
122: VS APVS = &oAPVS;
123: VS EPVS = &oEPVS;
124: VS CPVS;
125:
126: struct oF oF_TRUE,oF_FALSE;
127: F F_TRUE = &oF_TRUE;
128: F F_FALSE = &oF_FALSE;
129:
130: #if defined(__SVR4) && defined(sun)
1.4 noro 131: char cppname[BUFSIZ] = "/usr/ccs/lib/cpp ";
1.1 noro 132: #else
133: #if defined(__FreeBSD__) || defined(__NetBSD__)
1.4 noro 134: char cppname[BUFSIZ] = "/usr/bin/cpp ";
1.1 noro 135: #else
136: #if defined(VISUAL)
1.4 noro 137: char cppname[BUFSIZ] = "c:\\asir\\stdlib\\cpp ";
1.1 noro 138: #else
1.4 noro 139: char cppname[BUFSIZ] = "/lib/cpp ";
1.1 noro 140: #endif
141: #endif
142: #endif
1.4 noro 143: char asirname[BUFSIZ];
1.1 noro 144: char displayname[BUFSIZ];
145:
146: int Verbose;
147:
148: void glob_init() {
149: int i;
150:
151: for ( i = 0; i < 51; i++ ) {
152: VR(&oVLIST[i]) = &oVAR[i]; NEXT(&oVLIST[i]) = &oVLIST[i+1];
153: }
154: VR(&oVLIST[i]) = &oVAR[i]; NEXT(&oVLIST[i]) = 0;
155: reallocarray((char **)&GPVS->va,(int *)&GPVS->asize,(int *)&GPVS->n,(int)sizeof(struct oPV));
156: reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
157: CPVS = GPVS;
158: MKNODE(ONENODE,mkfnode(1,I_FORMULA,ONE),0);
159: OID(F_TRUE)=O_F; FOP(F_TRUE)=AL_TRUE; F_TRUE->arg.dummy = 0;
160: OID(F_FALSE)=O_F; FOP(F_FALSE)=AL_FALSE; F_FALSE->arg.dummy = 0;
161: sprintf(asirname,"%s/asir_symtab",asir_libdir);
162: }
163:
164: void input_init(fp,name)
165: FILE *fp;
166: char *name;
167: {
168: asir_infile = (IN)CALLOC(sizeof(struct oIN),1);
169: asir_infile->name = name; asir_infile->fp = fp;
170: asir_infile->ln = 1; NEXT(asir_infile) = 0;
171: }
172:
173: void notdef(vl,a,b,c)
174: VL vl;
175: Obj a,b,*c;
176: {
177: *c = 0;
178: error("undefined arithmetic operation.");
179: }
180:
181: int kernelmode;
182: int do_asirrc;
183: int do_file;
184: int do_message;
185: int do_fep;
186: int no_prompt;
187: int read_exec_file;
188: static int buserr_sav;
189: static char asir_history[BUFSIZ];
190:
191: extern int mpi_myid;
192:
1.5 noro 193: #if !defined(VISUAL_LIB)
194: void ExitAsir() {
195: exit(0);
196: }
197: #endif
198:
1.1 noro 199: /*
200: * status = 1 abnormal termination (error() etc.)
201: * status = 2 normal termination (end(), quit() etc.)
202: */
203:
204: void asir_terminate(status)
205: int status;
206: {
207: if ( read_exec_file ) {
208: read_exec_file = 0; longjmp(env,status);
209: } else {
210: tty_reset();
211: #if MPI
212: if ( !mpi_myid )
213: close_allconnections();
214: mpi_finalize();
215: #else
216: close_allconnections();
217: #endif
218: if ( kernelmode )
219: fputc(0xff,asir_out);
220: if ( asir_out )
221: fflush(asir_out);
222: ExitAsir();
223: }
224: }
225:
226: void param_init() {
227: unsigned int et = 0xff;
228: extern int paristack;
229: if ( *((char *)&et) )
230: little_endian = 1;
231: else
232: little_endian = 0;
233: }
234:
235: void prompt() {
236: if ( !no_prompt && !do_fep && asir_infile->fp == stdin )
237: fprintf(asir_out,"[%d]%c",APVS->n,kernelmode?0xfe:' ');
238: fflush(asir_out);
239: }
240:
241: void sprompt(ptr)
242: char *ptr;
243: {
244: sprintf(ptr,"[%d]%c",APVS->n,kernelmode?0xfe:' ');
245: }
246:
247: FILE *in_fp;
248:
249: void process_args(ac,av)
250: int ac;
251: char **av;
252: {
253: do_asirrc = 1;
254: #if !MPI
255: do_message = 1;
256: #endif
257: while ( ac > 0 ) {
258: if ( !strcmp(*av,"-heap") && (ac >= 2) ) {
259: void GC_expand_hp(int);
260:
261: GC_expand_hp(atoi(*(av+1))); av += 2; ac -= 2;
262: } else if ( !strcmp(*av,"-adj") && (ac >= 2) ) {
263: char *slash;
264:
265: slash = strrchr(*(av+1),'/');
266: if ( slash ) {
267: *slash = 0;
268: GC_free_space_numerator = atoi(slash+1);
269: }
270: GC_free_space_divisor = atoi(*(av+1));
271: av += 2; ac -= 2;
272: } else if ( !strcmp(*av,"-cpp") && (ac >= 2) ) {
273: strcpy(cppname,*(av+1)); av += 2; ac -= 2;
274: } else if ( !strcmp(*av,"-f") && (ac >= 2) ) {
275: in_fp = fopen(*(av+1),"r");
276: if ( !in_fp ) {
277: fprintf(stderr,"%s does not exist!",*(av+1));
278: asir_terminate(1);
279: }
280: do_file = 1;
281: av += 2; ac -= 2;
282: } else if ( !strcmp(*av,"-kernel") ) {
283: kernelmode = 1; av++; ac--;
284: } else if ( !strcmp(*av,"-norc") ) {
285: do_asirrc = 0; av++; ac--;
286: } else if ( !strcmp(*av,"-nomessage") ) {
287: do_message = 0; av++; ac--;
288: } else if ( !strcmp(*av,"-terse") ) {
289: no_prompt = 0; av++; ac--;
1.11 noro 290: } else if ( !strcmp(*av,"-rootdir") && (ac >= 2) ) {
291: set_rootdir(*(av+1)); av += 2; ac -= 2;
1.1 noro 292: } else if ( !strcmp(*av,"-maxheap") && (ac >= 2) ) {
293: void GC_set_max_heap_size(int);
294:
295: GC_set_max_heap_size(atoi(*(av+1))); av += 2; ac -= 2;
296: #if !defined(VISUAL)
297: } else if ( !strcmp(*av,"-display") && (ac >= 2) ) {
298: strcpy(displayname,*(av+1)); av += 2; ac -= 2;
299: #endif
300: #if PARI
301: } else if ( !strcmp(*av,"-paristack") ) {
302: extern int paristack;
303:
304: paristack = atoi(*(av+1)); av += 2; ac -= 2;
305: #endif
306: } else {
307: fprintf(stderr,"%s : unknown option.\n",*av);
308: asir_terminate(1);
309: }
310: }
311: }
312:
313: #include <signal.h>
314:
315: void sig_init() {
316: #if !defined(VISUAL)
317: signal(SIGINT,int_handler);
318: #else
319: register_ctrlc_handler();
320: #endif
321: signal(SIGSEGV,segv_handler);
322:
323: #if defined SIGFPE
324: signal(SIGFPE,fpe_handler);
325: #endif
326:
327: #if defined SIGPIPE
328: signal(SIGPIPE,pipe_handler);
329: #endif
330:
331: #if defined SIGILL
332: signal(SIGILL,ill_handler);
333: #endif
334:
335: #if !defined(VISUAL)
336: signal(SIGBUS,bus_handler);
337: #endif
338: }
339:
340: static void (*old_int)(int);
341:
342: void asir_save_handler() {
343: old_int = signal(SIGINT,SIG_IGN);
344: signal(SIGINT,old_int);
345: }
346:
347: void asir_set_handler() {
348: signal(SIGINT,int_handler);
349: }
350:
351: void asir_reset_handler() {
352: signal(SIGINT,old_int);
353: }
354:
355: void resetenv(s)
356: char *s;
357: {
358: extern FILE *outfile;
359:
360: fprintf(stderr,"%s\n",s);
361: while ( NEXT(asir_infile) )
362: closecurrentinput();
363: resetpvs();
364: #if !defined(VISUAL)
365: if ( do_server_in_X11 )
366: #endif
367: show_debug_window(0);
368: #if defined(VISUAL_LIB)
369: w_noflush_stderr(0);
370: #endif
371: asir_out = stdout;
372: #if PARI
373: pari_outfile = stdout;
374: #endif
375: /* restore states */
376: reset_engine();
377: reset_io();
378: longjmp(env,1);
379: }
380:
381: void fatal(n)
382: int n;
383: {
384: resetenv("return to toplevel");
385: }
386:
387: FUNC registered_handler;
388: extern int ox_int_received, critical_when_signal;
389:
390: void int_handler(sig)
391: int sig;
392: {
393: extern NODE PVSS;
394:
395: if ( do_file ) {
396: ExitAsir();
397: }
398: if ( critical_when_signal ) {
399: ox_int_received = 1;
400: return;
401: }
1.12 ! noro 402: #if defined(VISUAL)
1.1 noro 403: suspend_timer(); signal(SIGINT,SIG_IGN);
404: #endif
405: #if defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
406: signal(SIGINT,SIG_IGN);
1.3 noro 407: #endif
408: #if !defined(VISUAL)
409: if ( do_server_in_X11 ) {
410: debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
411: restore_handler();
412: return;
413: }
1.1 noro 414: #endif
415: #if defined(linux)
416: #if 1
417: while ( stdin->_IO_read_ptr < stdin->_IO_read_end )
418: #else
419: while ( stdin->_gptr < stdin->_egptr )
420: #endif
421: getchar();
422: #endif
423: while ( 1 ) {
424: char buf[BUFSIZ];
425: char c;
426:
427: fprintf(stderr,"interrupt ?(q/t/c/d/u/w/?) "); fflush(stderr);
428: if ( kernelmode )
429: fputc('\0',stderr);
430: buf[0] = '\n';
431: while ( buf[0] == '\n' )
432: fgets(buf,BUFSIZ,stdin);
433: switch ( c = buf[0] ) {
434: case 'q':
435: while ( 1 ) {
436: fprintf(stderr,"Abort this session? (y or n) "); fflush(stderr);
437: fgets(buf,BUFSIZ,stdin);
438: if ( !strncmp(buf,"y",1) ) {
439: read_exec_file = 0;
440: fprintf(stderr,"Bye\n"); asir_terminate(1);
441: } else if ( !strncmp(buf,"n",1) ) {
442: restore_handler();
443: return;
444: }
445: }
446: break;
447: case 't':
448: case 'u':
449: while ( 1 ) {
450: fprintf(stderr,"Abort this computation? (y or n) "); fflush(stderr);
451: fgets(buf,BUFSIZ,stdin);
452: if ( !strncmp(buf,"y",1) )
453: break;
454: else if ( !strncmp(buf,"n",1) ) {
455: restore_handler();
456: return;
457: }
458: }
459: if ( debug_mode )
460: debug_mode = 0;
461: if ( kernelmode )
462: fputc('\0',stderr);
463: restore_handler();
464: if ( c == 'u' ) {
465: if ( registered_handler ) {
466: fprintf(stderr,
467: "Calling the registered exception handler...");
468: bevalf(registered_handler,0);
469: fprintf(stderr, "done.\n");
470: }
471: }
472: if ( read_exec_file ) {
473: read_exec_file = 0;
474: resetenv("initialization aborted; return to toplevel");
475: } else
476: resetenv("return to toplevel");
477: break;
478: case 'd':
479: #if 0
480: nextbp = 1; nextbplevel = -1;
481: #endif
482: debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
483: restore_handler();
484: return;
485: case 'c':
486: if ( kernelmode )
487: fputc('\0',stderr);
488: restore_handler();
489: return; break;
490: case 'w':
491: showpos(); break;
492: case '?':
493: fprintf(stderr, "q:quit t:toplevel c:continue d:debug u:call registered handler w:where\n");
494: break;
495: default:
496: break;
497: }
498: }
499: }
500:
501: void restore_handler() {
1.12 ! noro 502: #if defined(VISUAL)
1.1 noro 503: resume_timer(); signal(SIGINT,int_handler);
504: #endif
505: #if defined(_PA_RISC1_1) || defined(linux) || defined(__svr4__)
506: signal(SIGINT,int_handler);
507: #endif
508: }
509:
510: void segv_handler(sig)
511: int sig;
512: {
1.12 ! noro 513: #if defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
1.1 noro 514: signal(SIGSEGV,segv_handler);
515: #endif
516: error("internal error (SEGV)");
517: }
518:
519: void ill_handler(sig)
520: int sig;
521: {
1.12 ! noro 522: #if defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
1.1 noro 523: signal(SIGILL,ill_handler);
524: #endif
525: error("illegal instruction (ILL)");
526: }
527:
528: void alrm_handler(sig)
529: int sig;
530: {
531: fprintf(stderr,"interval timer expired (VTALRM)\n");
532: longjmp(timer_env,1);
533: }
534:
535: void bus_handler(sig)
536: int sig;
537: {
538: #if defined(SIGBUS)
539: signal(SIGBUS,bus_handler);
540: error("internal error (BUS ERROR)");
541: #endif
542: }
543:
544: void fpe_handler(sig)
545: int sig;
546: {
1.12 ! noro 547: #if defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
1.1 noro 548: signal(SIGFPE,fpe_handler);
549: #endif
550: error("internal error (FPE)");
551: }
552:
553: void pipe_handler(sig)
554: int sig;
555: {
556: #if defined(SIGPIPE)
557: signal(SIGPIPE,pipe_handler);
558: error("internal error (BROKEN PIPE)");
559: #endif
560: }
561:
562: void resize_buffer()
563: {
564: }
565:
566: void tty_init() {
567: }
568:
569: void tty_reset() {
570: }
571:
572: extern int evalstatline;
573:
574: void set_lasterror(s)
575: char *s;
576: {
577: strncpy(LastError,s,BUFSIZ);
578: LastError[BUFSIZ-1] = 0;
579: }
580:
581: SNODE error_snode;
582:
583: void error(s)
584: char *s;
585: {
586: SNODE *snp;
587:
588: fprintf(stderr,"%s\n",s);
589: set_lasterror(s);
590: if ( CPVS != GPVS ) {
1.7 noro 591: if ( CPVS->usrf && CPVS->usrf && CPVS->usrf->f.usrf )
592: searchsn(&BDY(CPVS->usrf->f.usrf),evalstatline,&snp);
1.6 noro 593: if ( snp )
594: error_snode = *snp;
595: else
596: error_snode = 0;
1.1 noro 597: } else
598: error_snode = 0;
599: if ( do_file ) {
600: char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
601:
602: sprintf(errbuf,"%s\n",s);
603: showpos_to_string(errbuf+strlen(errbuf));
604: set_lasterror(errbuf);
605: ExitAsir();
606: }
607: if ( debug_mode )
608: longjmp(debug_env,1);
609: if ( CPVS != GPVS )
610: if ( do_server_in_X11 || isatty(0) )
611: bp(error_snode);
612: if ( read_exec_file )
613: read_exec_file = 0;
614: resetenv("return to toplevel");
615: }
616:
617: #if !defined(VISUAL)
618: #include <sys/time.h>
619:
620: void set_timer(interval)
621: int interval;
622: {
623: struct itimerval it;
624:
625: it.it_interval.tv_sec = interval;
626: it.it_interval.tv_usec = 0;
627: it.it_value.tv_sec = interval;
628: it.it_value.tv_usec = 0;
629: setitimer(ITIMER_VIRTUAL,&it,0);
630: signal(SIGVTALRM,alrm_handler);
631: }
632:
633: void reset_timer()
634: {
635: struct itimerval it;
636:
637: it.it_interval.tv_sec = 0;
638: it.it_interval.tv_usec = 0;
639: it.it_value.tv_sec = 0;
640: it.it_value.tv_usec = 0;
641: setitimer(ITIMER_VIRTUAL,&it,0);
642: signal(SIGVTALRM,SIG_IGN);
643: }
644: #endif
645:
646: unsigned int get_asir_version();
647:
648: void copyright() {
1.2 noro 649: printf("This is Risa/Asir, Version %d.\n",get_asir_version());
1.1 noro 650: printf("Copyright (C) FUJITSU LABORATORIES LIMITED.\n");
1.10 noro 651: printf("1994-2000. All rights reserved.\n");
1.1 noro 652: }
1.5 noro 653:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>