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