Annotation of OpenXM_contrib2/asir2000/parse/glob.c, Revision 1.54
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.54 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/glob.c,v 1.53 2004/12/17 03:09:08 noro Exp $
1.8 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "al.h"
52: #include "parse.h"
1.24 noro 53: #include "ox.h"
1.31 ohara 54: #if defined(PARI)
1.1 noro 55: #include "genpari.h"
56: #endif
1.43 ohara 57: #if !defined(VISUAL) && !defined(_PA_RISC1_1) && !defined(linux) && !defined(SYSV) && !defined(__CYGWIN__) && !defined(__INTERIX)
1.1 noro 58: #include <sgtty.h>
59: #endif
60:
61: #if defined(VISUAL)
62: #include <io.h>
63: #include <direct.h>
1.34 ohara 64: #else
65: #include <unistd.h>
66: #include <string.h>
67: #include <stdio.h>
1.1 noro 68: #endif
69:
1.19 noro 70: #if defined(SYSV) && !defined(_IBMR2)
1.1 noro 71: #include <sys/ttold.h>
72: #endif
73:
74: #if defined(VISUAL)
75: #define HISTORY asir_history
76: #endif
1.12 noro 77:
1.1 noro 78: #define MAXHIST 100
79:
80: extern int GC_free_space_divisor;
81: extern int GC_free_space_numerator;
82: extern FILE *asir_out;
83:
1.24 noro 84: INFILE asir_infile;
1.26 noro 85: JMP_BUF main_env,debug_env,timer_env,exec_env;
1.52 noro 86: int little_endian,debug_mode,no_debug_on_error;
1.1 noro 87: char *asir_libdir;
88: char *asir_pager;
89:
90: NODE usrf,sysf,noargsysf,ubinf,parif;
91: NODE ONENODE;
1.29 noro 92: int main_parser, allow_create_var, ox_do_copy, ox_do_count, ox_count_length;
1.1 noro 93: int ox_file_io, ox_need_conv;
94: char *ox_copy_bptr;
95: char *parse_strp;
96: SNODE parse_snode;
97: FUNC parse_targetf;
98: FILE *ox_istream,*ox_ostream;
99: int do_server_in_X11;
100: Obj LastVal;
101: char LastError[BUFSIZ];
1.15 noro 102: int timer_is_set;
1.49 noro 103: NODE current_option;
1.53 noro 104: NODE user_int_handler, user_quit_handler;
1.1 noro 105:
106: struct oV oVAR[] = {
107: {"x",0,0}, {"y",0,0}, {"z",0,0}, {"u",0,0},
108: {"v",0,0}, {"w",0,0}, {"p",0,0}, {"q",0,0},
109: {"r",0,0}, {"s",0,0}, {"t",0,0}, {"a",0,0},
110: {"b",0,0}, {"c",0,0}, {"d",0,0}, {"e",0,0},
111: {"f",0,0}, {"g",0,0}, {"h",0,0}, {"i",0,0},
112: {"j",0,0}, {"k",0,0}, {"l",0,0}, {"m",0,0},
113: {"n",0,0}, {"o",0,0},
114: {"_x",0,0}, {"_y",0,0}, {"_z",0,0}, {"_u",0,0},
115: {"_v",0,0}, {"_w",0,0}, {"_p",0,0}, {"_q",0,0},
116: {"_r",0,0}, {"_s",0,0}, {"_t",0,0}, {"_a",0,0},
117: {"_b",0,0}, {"_c",0,0}, {"_d",0,0}, {"_e",0,0},
118: {"_f",0,0}, {"_g",0,0}, {"_h",0,0}, {"_i",0,0},
119: {"_j",0,0}, {"_k",0,0}, {"_l",0,0}, {"_m",0,0},
120: {"_n",0,0}, {"_o",0,0}
121: };
122:
123: struct oVL oVLIST[52];
124:
125: VL CO = oVLIST;
126: VL ALG;
127:
128: struct oVS oGPVS,oAPVS,oEPVS;
129: VS GPVS = &oGPVS;
130: VS APVS = &oAPVS;
131: VS EPVS = &oEPVS;
1.35 noro 132: VS CPVS,MPVS;
133:
134: NODE MODULE_LIST;
135: MODULE CUR_MODULE;
1.36 noro 136: char *CUR_FUNC;
1.1 noro 137:
1.46 noro 138: struct oSYMBOL oGrlex, oGlex, oLex;
139: SYMBOL Symbol_grlex = &oGrlex;
140: SYMBOL Symbol_glex = &oGlex;
141: SYMBOL Symbol_lex = &oLex;;
1.44 noro 142:
1.1 noro 143: struct oF oF_TRUE,oF_FALSE;
144: F F_TRUE = &oF_TRUE;
145: F F_FALSE = &oF_FALSE;
146:
147: #if defined(VISUAL)
1.4 noro 148: char cppname[BUFSIZ] = "c:\\asir\\stdlib\\cpp ";
1.1 noro 149: #else
1.4 noro 150: char cppname[BUFSIZ] = "/lib/cpp ";
1.1 noro 151: #endif
1.4 noro 152: char asirname[BUFSIZ];
1.1 noro 153: char displayname[BUFSIZ];
154:
155: int Verbose;
1.38 ohara 156: int do_quiet;
1.1 noro 157:
158: void glob_init() {
159: int i;
160:
161: for ( i = 0; i < 51; i++ ) {
162: VR(&oVLIST[i]) = &oVAR[i]; NEXT(&oVLIST[i]) = &oVLIST[i+1];
163: }
164: VR(&oVLIST[i]) = &oVAR[i]; NEXT(&oVLIST[i]) = 0;
165: reallocarray((char **)&GPVS->va,(int *)&GPVS->asize,(int *)&GPVS->n,(int)sizeof(struct oPV));
166: reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
167: CPVS = GPVS;
168: MKNODE(ONENODE,mkfnode(1,I_FORMULA,ONE),0);
169: OID(F_TRUE)=O_F; FOP(F_TRUE)=AL_TRUE; F_TRUE->arg.dummy = 0;
170: OID(F_FALSE)=O_F; FOP(F_FALSE)=AL_FALSE; F_FALSE->arg.dummy = 0;
1.44 noro 171: OID(Symbol_grlex) = O_SYMBOL; Symbol_grlex->name = "@grlex";
172: Symbol_grlex->value = 0;
173: OID(Symbol_glex) = O_SYMBOL; Symbol_glex->name = "@glex";
174: Symbol_glex->value = 1;
1.45 noro 175: OID(Symbol_lex) = O_SYMBOL; Symbol_lex->name = "@lex";
176: Symbol_lex->value = 2;
1.1 noro 177: sprintf(asirname,"%s/asir_symtab",asir_libdir);
178: }
179:
1.24 noro 180: void input_init(FILE *fp,char *name)
1.1 noro 181: {
1.24 noro 182: asir_infile = (INFILE)CALLOC(sizeof(struct oINFILE),1);
1.1 noro 183: asir_infile->name = name; asir_infile->fp = fp;
184: asir_infile->ln = 1; NEXT(asir_infile) = 0;
185: }
186:
1.24 noro 187: void notdef(VL vl,Obj a,Obj b,Obj *c)
1.1 noro 188: {
189: error("undefined arithmetic operation.");
190: }
191:
192: int do_asirrc;
193: int do_file;
1.42 ohara 194: char *do_filename;
1.1 noro 195: int do_message;
196: int do_fep;
197: int read_exec_file;
1.42 ohara 198: int asir_setenv;
1.1 noro 199: static int buserr_sav;
200: static char asir_history[BUFSIZ];
201:
202: extern int mpi_myid;
203:
1.5 noro 204: #if !defined(VISUAL_LIB)
205: void ExitAsir() {
206: exit(0);
207: }
208: #endif
209:
1.1 noro 210: /*
211: * status = 1 abnormal termination (error() etc.)
212: * status = 2 normal termination (end(), quit() etc.)
213: */
214:
1.24 noro 215: void asir_terminate(int status)
1.1 noro 216: {
1.21 noro 217: int t;
1.53 noro 218: NODE n;
1.21 noro 219:
1.1 noro 220: if ( read_exec_file ) {
1.21 noro 221: t = read_exec_file;
222: read_exec_file = 0;
223: if ( t == 1 )
1.26 noro 224: LONGJMP(main_env,status);
1.21 noro 225: else
1.26 noro 226: LONGJMP(exec_env,status);
1.1 noro 227: } else {
1.54 ! noro 228: if ( user_quit_handler ) {
! 229: fprintf(stderr,"Calling the registered quit callbacks...");
! 230: for ( n = user_quit_handler; n; n = NEXT(n) )
! 231: bevalf((FUNC)BDY(n),0);
! 232: fprintf(stderr, "done.\n");
! 233: }
1.1 noro 234: tty_reset();
1.33 noro 235: #if defined(MPI)
1.1 noro 236: if ( !mpi_myid )
237: close_allconnections();
238: mpi_finalize();
239: #else
1.20 noro 240: #if defined(SIGPIPE)
241: signal(SIGPIPE,SIG_IGN);
242: #endif
1.1 noro 243: close_allconnections();
244: #endif
245: if ( asir_out )
246: fflush(asir_out);
1.32 noro 247: #if FEP
1.13 saito 248: if ( do_fep ) {
249: stifle_history(MAXHIST);
250: write_history(asir_history);
251: }
252: #endif
1.1 noro 253: ExitAsir();
254: }
255: }
256:
257: void param_init() {
258: unsigned int et = 0xff;
259: extern int paristack;
260: if ( *((char *)&et) )
261: little_endian = 1;
262: else
263: little_endian = 0;
264: }
1.39 noro 265:
266: Obj user_defined_prompt;
267:
1.1 noro 268: void prompt() {
1.48 noro 269: if ( !do_quiet && !do_fep && asir_infile->fp == stdin ) {
1.21 noro 270: fprintf(asir_out,"[%d] ",APVS->n);
1.48 noro 271: fflush(asir_out);
272: } else if ( do_quiet && user_defined_prompt
1.39 noro 273: && OID(user_defined_prompt)==O_STR) {
274: fprintf(asir_out,BDY((STRING)user_defined_prompt),APVS->n);
1.48 noro 275: fflush(asir_out);
1.39 noro 276: }
1.1 noro 277: }
278:
1.24 noro 279: void sprompt(char *ptr)
1.1 noro 280: {
1.21 noro 281: sprintf(ptr,"[%d] ",APVS->n);
1.34 ohara 282: }
283:
284: #if !defined(VISUAL)
285: static int which(char *prog, char *path, char *buf, size_t size)
286: {
287: char *tok;
288: char delim[] = ":";
289: char *path2 = malloc(strlen(path)+1);
290: char *name = malloc(size);
291: int proglen = strlen(prog)+3; /* "/" + prog + " \0" */
292:
293: if (!name || !path2) {
294: return 0;
295: }
296: strcpy(path2, path);
297: tok = strtok(path2, delim);
298: while (tok != NULL) {
299: if (size >= strlen(tok)) {
300: sprintf(name, "%s/%s", tok, prog);
301: if (access(name, X_OK&R_OK) == 0) {
302: strcpy(buf, name);
303: strcat(buf, " ");
304: free(path2); free(name);
305: return 1;
306: }
307: tok = strtok(NULL, delim);
308: }
309: }
310: free(path2); free(name);
311: return 0;
312: }
313: #endif
314:
315: void cppname_init()
316: {
317: #if !defined(VISUAL)
318: if (access(cppname, X_OK&R_OK) != 0) {
319: which("cpp", "/lib:/usr/ccs/lib:/usr/bin", cppname, BUFSIZ) ||
320: which("cpp", getenv("PATH"), cppname, BUFSIZ);
321: }
322: #endif
1.1 noro 323: }
324:
325: FILE *in_fp;
326:
1.24 noro 327: void process_args(int ac,char **av)
1.1 noro 328: {
329: do_asirrc = 1;
1.33 noro 330: #if !defined(MPI)
1.1 noro 331: do_message = 1;
332: #endif
1.38 ohara 333: do_quiet = 0;
1.1 noro 334: while ( ac > 0 ) {
335: if ( !strcmp(*av,"-heap") && (ac >= 2) ) {
336: void GC_expand_hp(int);
337:
338: GC_expand_hp(atoi(*(av+1))); av += 2; ac -= 2;
339: } else if ( !strcmp(*av,"-adj") && (ac >= 2) ) {
340: char *slash;
341:
342: slash = strrchr(*(av+1),'/');
343: if ( slash ) {
344: *slash = 0;
345: GC_free_space_numerator = atoi(slash+1);
346: }
347: GC_free_space_divisor = atoi(*(av+1));
348: av += 2; ac -= 2;
349: } else if ( !strcmp(*av,"-cpp") && (ac >= 2) ) {
350: strcpy(cppname,*(av+1)); av += 2; ac -= 2;
351: } else if ( !strcmp(*av,"-f") && (ac >= 2) ) {
1.38 ohara 352: do_quiet = 1;
1.1 noro 353: in_fp = fopen(*(av+1),"r");
354: if ( !in_fp ) {
355: fprintf(stderr,"%s does not exist!",*(av+1));
356: asir_terminate(1);
357: }
358: do_file = 1;
1.42 ohara 359: do_filename = *(av+1);
1.1 noro 360: av += 2; ac -= 2;
1.42 ohara 361: } else if ( !strcmp(*av,"-E") ) {
362: asir_setenv = 1; av++; ac--;
1.38 ohara 363: } else if ( !strcmp(*av,"-quiet") ) {
1.39 noro 364: do_quiet = 1; av++; ac--;
1.1 noro 365: } else if ( !strcmp(*av,"-norc") ) {
366: do_asirrc = 0; av++; ac--;
367: } else if ( !strcmp(*av,"-nomessage") ) {
368: do_message = 0; av++; ac--;
1.11 noro 369: } else if ( !strcmp(*av,"-rootdir") && (ac >= 2) ) {
370: set_rootdir(*(av+1)); av += 2; ac -= 2;
1.1 noro 371: } else if ( !strcmp(*av,"-maxheap") && (ac >= 2) ) {
372: void GC_set_max_heap_size(int);
373:
374: GC_set_max_heap_size(atoi(*(av+1))); av += 2; ac -= 2;
375: #if !defined(VISUAL)
376: } else if ( !strcmp(*av,"-display") && (ac >= 2) ) {
377: strcpy(displayname,*(av+1)); av += 2; ac -= 2;
378: #endif
1.32 noro 379: #if FEP
1.13 saito 380: } else if ( !strcmp(*av,"-fep") ) {
381: do_fep = 1; av++; ac--;
382: #endif
1.31 ohara 383: #if defined(PARI)
1.1 noro 384: } else if ( !strcmp(*av,"-paristack") ) {
385: extern int paristack;
386:
387: paristack = atoi(*(av+1)); av += 2; ac -= 2;
388: #endif
389: } else {
390: fprintf(stderr,"%s : unknown option.\n",*av);
391: asir_terminate(1);
392: }
393: }
1.32 noro 394: #if FEP
1.13 saito 395: if ( do_fep ) {
396: char *home;
397: home = (char *)getenv("HOME");
398: if (!home)
399: home = ".";
400: sprintf (asir_history, "%s/.asir_history",home);
401: read_history(asir_history);
402: using_history();
403: }
404: #endif
1.1 noro 405: }
406:
407: #include <signal.h>
408:
409: void sig_init() {
410: #if !defined(VISUAL)
411: signal(SIGINT,int_handler);
412: #else
1.24 noro 413: void register_ctrlc_handler();
414:
1.1 noro 415: register_ctrlc_handler();
416: #endif
417: signal(SIGSEGV,segv_handler);
418:
1.23 noro 419: #if defined(SIGFPE)
1.1 noro 420: signal(SIGFPE,fpe_handler);
421: #endif
422:
1.23 noro 423: #if defined(SIGPIPE)
1.1 noro 424: signal(SIGPIPE,pipe_handler);
425: #endif
426:
1.23 noro 427: #if defined(SIGILL)
1.1 noro 428: signal(SIGILL,ill_handler);
429: #endif
430:
431: #if !defined(VISUAL)
432: signal(SIGBUS,bus_handler);
433: #endif
434: }
435:
436: static void (*old_int)(int);
437:
438: void asir_save_handler() {
439: old_int = signal(SIGINT,SIG_IGN);
440: signal(SIGINT,old_int);
441: }
442:
443: void asir_set_handler() {
444: signal(SIGINT,int_handler);
445: }
446:
447: void asir_reset_handler() {
448: signal(SIGINT,old_int);
449: }
450:
1.24 noro 451: void resetenv(char *s)
1.1 noro 452: {
453: extern FILE *outfile;
454:
1.53 noro 455: fprintf(stderr,"%s\n",s);
1.1 noro 456: while ( NEXT(asir_infile) )
457: closecurrentinput();
458: resetpvs();
459: #if !defined(VISUAL)
460: if ( do_server_in_X11 )
461: #endif
462: show_debug_window(0);
463: #if defined(VISUAL_LIB)
464: w_noflush_stderr(0);
465: #endif
466: asir_out = stdout;
1.31 ohara 467: #if defined(PARI)
1.1 noro 468: pari_outfile = stdout;
469: #endif
470: /* restore states */
471: reset_engine();
472: reset_io();
1.16 noro 473: #if !defined(VISUAL)
1.15 noro 474: reset_timer();
1.16 noro 475: #endif
1.26 noro 476: LONGJMP(main_env,1);
1.1 noro 477: }
478:
1.24 noro 479: void fatal(int n)
1.1 noro 480: {
481: resetenv("return to toplevel");
482: }
483:
484: extern int ox_int_received, critical_when_signal;
485:
1.24 noro 486: void int_handler(int sig)
1.1 noro 487: {
488: extern NODE PVSS;
1.53 noro 489: NODE t;
1.48 noro 490:
1.1 noro 491:
492: if ( do_file ) {
493: ExitAsir();
494: }
495: if ( critical_when_signal ) {
496: ox_int_received = 1;
497: return;
498: }
1.12 noro 499: #if defined(VISUAL)
1.19 noro 500: suspend_timer();
1.1 noro 501: #endif
502: signal(SIGINT,SIG_IGN);
1.3 noro 503: #if !defined(VISUAL)
504: if ( do_server_in_X11 ) {
505: debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
506: restore_handler();
507: return;
508: }
1.1 noro 509: #endif
510: #if defined(linux)
511: #if 1
512: while ( stdin->_IO_read_ptr < stdin->_IO_read_end )
513: #else
514: while ( stdin->_gptr < stdin->_egptr )
515: #endif
516: getchar();
517: #endif
518: while ( 1 ) {
519: char buf[BUFSIZ];
520: char c;
521:
1.53 noro 522: fprintf(stderr,"interrupt ?(q/t/c/d/u/w/?) "); fflush(stderr);
1.1 noro 523: buf[0] = '\n';
524: while ( buf[0] == '\n' )
525: fgets(buf,BUFSIZ,stdin);
526: switch ( c = buf[0] ) {
527: case 'q':
528: while ( 1 ) {
1.53 noro 529: fprintf(stderr,"Abort this session? (y or n) "); fflush(stderr);
1.1 noro 530: fgets(buf,BUFSIZ,stdin);
531: if ( !strncmp(buf,"y",1) ) {
532: read_exec_file = 0;
1.53 noro 533: fprintf(stderr,"Bye\n");
1.48 noro 534: asir_terminate(1);
1.1 noro 535: } else if ( !strncmp(buf,"n",1) ) {
536: restore_handler();
537: return;
538: }
539: }
540: break;
541: case 't':
542: case 'u':
543: while ( 1 ) {
1.53 noro 544: fprintf(stderr,"Abort this computation? (y or n) "); fflush(stderr);
1.1 noro 545: fgets(buf,BUFSIZ,stdin);
546: if ( !strncmp(buf,"y",1) )
547: break;
548: else if ( !strncmp(buf,"n",1) ) {
549: restore_handler();
550: return;
551: }
552: }
553: if ( debug_mode )
554: debug_mode = 0;
555: restore_handler();
556: if ( c == 'u' ) {
1.53 noro 557: if ( user_int_handler ) {
558: fprintf(stderr,
559: "Calling the registered exception callbacks...");
560: for ( t = user_int_handler; t; t = NEXT(t) )
561: bevalf((FUNC)BDY(t),0);
562: fprintf(stderr, "done.\n");
1.1 noro 563: }
564: }
565: if ( read_exec_file ) {
566: read_exec_file = 0;
567: resetenv("initialization aborted; return to toplevel");
568: } else
569: resetenv("return to toplevel");
570: break;
571: case 'd':
572: #if 0
573: nextbp = 1; nextbplevel = -1;
574: #endif
575: debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
576: restore_handler();
577: return;
578: case 'c':
579: restore_handler();
580: return; break;
581: case 'w':
1.48 noro 582: showpos();
583: break;
1.1 noro 584: case '?':
1.53 noro 585: fprintf(stderr, "q:quit t:toplevel c:continue d:debug u:call registered handler w:where\n");
1.1 noro 586: break;
587: default:
588: break;
589: }
590: }
591: }
592:
593: void restore_handler() {
1.12 noro 594: #if defined(VISUAL)
1.19 noro 595: resume_timer();
1.1 noro 596: #endif
1.19 noro 597: #if defined(SIGINT)
1.1 noro 598: signal(SIGINT,int_handler);
599: #endif
600: }
601:
1.24 noro 602: void segv_handler(int sig)
1.1 noro 603: {
1.19 noro 604: #if defined(SIGSEGV)
1.1 noro 605: signal(SIGSEGV,segv_handler);
1.19 noro 606: error("internal error (SEGV)");
1.1 noro 607: #endif
608: }
609:
1.24 noro 610: void ill_handler(int sig)
1.1 noro 611: {
1.19 noro 612: #if defined(SIGILL)
1.1 noro 613: signal(SIGILL,ill_handler);
1.19 noro 614: error("illegal instruction (ILL)");
1.1 noro 615: #endif
616: }
617:
1.24 noro 618: void alrm_handler(int sig)
1.1 noro 619: {
620: fprintf(stderr,"interval timer expired (VTALRM)\n");
1.26 noro 621: LONGJMP(timer_env,1);
1.1 noro 622: }
623:
1.24 noro 624: void bus_handler(int sig)
1.1 noro 625: {
626: #if defined(SIGBUS)
627: signal(SIGBUS,bus_handler);
628: error("internal error (BUS ERROR)");
629: #endif
630: }
631:
1.24 noro 632: void fpe_handler(int sig)
1.1 noro 633: {
1.19 noro 634: #if defined(SIGFPE)
1.1 noro 635: signal(SIGFPE,fpe_handler);
1.19 noro 636: error("internal error (FPE)");
1.1 noro 637: #endif
638: }
639:
1.24 noro 640: void pipe_handler(int sig)
1.1 noro 641: {
642: #if defined(SIGPIPE)
643: signal(SIGPIPE,pipe_handler);
1.20 noro 644: end_critical();
1.1 noro 645: error("internal error (BROKEN PIPE)");
646: #endif
647: }
648:
649: void resize_buffer()
650: {
651: }
652:
653: void tty_init() {
654: }
655:
656: void tty_reset() {
657: }
658:
659: extern int evalstatline;
660:
1.24 noro 661: void set_lasterror(char *s)
1.1 noro 662: {
663: strncpy(LastError,s,BUFSIZ);
664: LastError[BUFSIZ-1] = 0;
665: }
666:
667: SNODE error_snode;
1.51 noro 668: int error_in_timer;
1.1 noro 669:
1.24 noro 670: void error(char *s)
1.1 noro 671: {
1.37 noro 672: SNODE *snp=0;
1.1 noro 673:
1.16 noro 674: #if !defined(VISUAL)
1.51 noro 675: if ( !error_in_timer && timer_is_set )
1.15 noro 676: alrm_handler(SIGVTALRM);
1.16 noro 677: #endif
1.1 noro 678: fprintf(stderr,"%s\n",s);
679: set_lasterror(s);
680: if ( CPVS != GPVS ) {
1.37 noro 681: if ( CPVS && CPVS->usrf && CPVS->usrf->f.usrf )
1.7 noro 682: searchsn(&BDY(CPVS->usrf->f.usrf),evalstatline,&snp);
1.6 noro 683: if ( snp )
684: error_snode = *snp;
685: else
686: error_snode = 0;
1.1 noro 687: } else
688: error_snode = 0;
689: if ( do_file ) {
690: char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
691:
692: sprintf(errbuf,"%s\n",s);
693: showpos_to_string(errbuf+strlen(errbuf));
694: set_lasterror(errbuf);
695: ExitAsir();
696: }
697: if ( debug_mode )
1.26 noro 698: LONGJMP(debug_env,1);
1.1 noro 699: if ( CPVS != GPVS )
1.52 noro 700: if ( !no_debug_on_error && (do_server_in_X11 || isatty(0)) )
1.1 noro 701: bp(error_snode);
1.40 noro 702: if ( read_exec_file )
703: read_exec_file = 0;
704: resetenv("return to toplevel");
705: }
706:
707: void toplevel(char *s)
708: {
709: SNODE *snp=0;
710:
711: #if !defined(VISUAL)
712: if ( timer_is_set )
713: alrm_handler(SIGVTALRM);
714: #endif
715: fprintf(stderr,"%s\n",s);
716: if ( do_file ) {
717: char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
718:
719: sprintf(errbuf,"%s\n",s);
720: showpos_to_string(errbuf+strlen(errbuf));
721: ExitAsir();
722: }
1.1 noro 723: if ( read_exec_file )
724: read_exec_file = 0;
725: resetenv("return to toplevel");
726: }
727:
728: #if !defined(VISUAL)
729: #include <sys/time.h>
730:
1.24 noro 731: void set_timer(int interval)
1.1 noro 732: {
733: struct itimerval it;
734:
735: it.it_interval.tv_sec = interval;
736: it.it_interval.tv_usec = 0;
737: it.it_value.tv_sec = interval;
738: it.it_value.tv_usec = 0;
739: setitimer(ITIMER_VIRTUAL,&it,0);
740: signal(SIGVTALRM,alrm_handler);
1.15 noro 741: timer_is_set = 1;
1.1 noro 742: }
743:
744: void reset_timer()
745: {
746: struct itimerval it;
747:
748: it.it_interval.tv_sec = 0;
749: it.it_interval.tv_usec = 0;
750: it.it_value.tv_sec = 0;
751: it.it_value.tv_usec = 0;
752: setitimer(ITIMER_VIRTUAL,&it,0);
753: signal(SIGVTALRM,SIG_IGN);
1.15 noro 754: timer_is_set = 0;
1.1 noro 755: }
756: #endif
757:
758: unsigned int get_asir_version();
1.14 noro 759: char *get_asir_distribution();
1.1 noro 760:
1.47 ohara 761: char *get_pariversion()
762: {
1.32 noro 763: #if PARI
764: #if 0
1.47 ohara 765: return "PARI 2.2.4, copyright (C) 2002 The PARI Group.\nPARI 2.0.17, copyright 1989-1999, C. Batut, K. Belabas, D. Bernardi,\n H. Cohen and M. Olivier.\n";
1.32 noro 766: #endif
1.47 ohara 767: return "PARI 2.0.17, copyright 1989-1999, C. Batut, K. Belabas, D. Bernardi,\n H. Cohen and M. Olivier.\n";
1.32 noro 768: #endif
1.47 ohara 769: return "";
1.1 noro 770: }
1.14 noro 771:
1.47 ohara 772: char *get_intervalversion()
773: {
774: #if defined(INTERVAL)
775: return " + Interval Arithmetic";
776: #else
777: return "";
778: #endif
779: }
780:
781: void copyright()
782: {
1.50 fujiwara 783: char *format = "This is Risa/Asir%s, Version %d (%s Distribution).\nCopyright (C) 1994-2000, all rights reserved, FUJITSU LABORATORIES LIMITED.\nCopyright 2000-2004, Risa/Asir committers, http://www.openxm.org/.\nGC 6.2(alpha6) copyright 1988-2003, H-J. Boehm, A. J. Demers, Xerox, SGI, HP.\n%s";
1.47 ohara 784: printf(format, get_intervalversion(), get_asir_version(), get_asir_distribution(), get_pariversion());
785: }
1.5 noro 786:
1.47 ohara 787: char *scopyright()
788: {
789: static char *notice;
790: char *s1, *s2, *s3;
791: int d, len;
792: char *format = "This is Risa/Asir%s, Version %d (%s Distribution).\nCopyright (C) 1994-2000, all rights reserved, FUJITSU LABORATORIES LIMITED.\nCopyright 2000-2003, Risa/Asir committers, http://www.openxm.org/.\nGC 6.2(alpha6) copyright 1988-2003, H-J. Boehm, A. J. Demers, Xerox, SGI, HP.\n%s";
793: if (!notice) {
794: s1 = get_intervalversion();
795: s2 = get_asir_distribution();
796: s3 = get_pariversion();
797: d = get_asir_version();
798: len = (strlen(format)-8)+strlen(s1)+strlen(s2)+strlen(s3)+sizeof(int)*3;
799: notice = MALLOC(len+1);
800: sprintf(notice, format, s1, d, s2, s3);
801: }
802: return notice;
803: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>