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