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