Annotation of OpenXM_contrib2/asir2000/parse/glob.c, Revision 1.85
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.85 ! ohara 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/glob.c,v 1.84 2013/11/29 08:21:29 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.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.85 ! ohara 87: char *asir_private_dir;
1.1 noro 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;
1.62 noro 101: LIST LastStackTrace;
1.1 noro 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.67 noro 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;
1.80 noro 171: MKNODE(ONENODE,mkfnode(1,I_FORMULA,ONE),NULLP);
1.1 noro 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;
1.42 ohara 201: int asir_setenv;
1.1 noro 202: static int buserr_sav;
203: static char asir_history[BUFSIZ];
204:
205: extern int mpi_myid;
206:
1.5 noro 207: #if !defined(VISUAL_LIB)
208: void ExitAsir() {
209: exit(0);
210: }
211: #endif
212:
1.1 noro 213: /*
214: * status = 1 abnormal termination (error() etc.)
215: * status = 2 normal termination (end(), quit() etc.)
1.63 noro 216: * status = 3 absolute termination
1.1 noro 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.63 noro 223:
224: /* called from engine in Windows */
225: if ( status == 3 ) asir_infile = 0;
1.21 noro 226:
1.62 noro 227: if ( asir_infile && asir_infile->ready_for_longjmp )
228: LONGJMP(asir_infile->jmpbuf,status);
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)
1.79 noro 322: char *oxhome;
323: char oxcpp[BUFSIZ];
324: #define OXCPP "/bin/ox_cpp"
325:
326: if ( oxhome = getenv("OpenXM_HOME") ) {
327: if ( strlen(oxhome)+strlen(OXCPP)<BUFSIZ ) {
328: sprintf(oxcpp,"%s%s",oxhome,OXCPP);
329: if ( access(oxcpp,X_OK&R_OK) == 0 ) {
330: strcpy(cppname,oxcpp);
331: return;
332: }
333: }
334: }
335: if (access(cppname, X_OK&R_OK) != 0) {
1.34 ohara 336: which("cpp", "/lib:/usr/ccs/lib:/usr/bin", cppname, BUFSIZ) ||
337: which("cpp", getenv("PATH"), cppname, BUFSIZ);
338: }
339: #endif
1.1 noro 340: }
341:
342: FILE *in_fp;
343:
1.24 noro 344: void process_args(int ac,char **av)
1.1 noro 345: {
1.75 ohara 346: int nm,dv;
1.1 noro 347: do_asirrc = 1;
1.33 noro 348: #if !defined(MPI)
1.1 noro 349: do_message = 1;
350: #endif
1.38 ohara 351: do_quiet = 0;
1.1 noro 352: while ( ac > 0 ) {
353: if ( !strcmp(*av,"-heap") && (ac >= 2) ) {
354: void GC_expand_hp(int);
355:
356: GC_expand_hp(atoi(*(av+1))); av += 2; ac -= 2;
357: } else if ( !strcmp(*av,"-adj") && (ac >= 2) ) {
358: char *slash;
359: slash = strrchr(*(av+1),'/');
360: if ( slash ) {
361: *slash = 0;
1.75 ohara 362: nm = atoi(slash+1);
363: }else {
364: nm = 1;
1.1 noro 365: }
1.75 ohara 366: dv = atoi(*(av+1));
367: Risa_GC_set_adj(nm,dv);
1.1 noro 368: av += 2; ac -= 2;
369: } else if ( !strcmp(*av,"-cpp") && (ac >= 2) ) {
370: strcpy(cppname,*(av+1)); av += 2; ac -= 2;
371: } else if ( !strcmp(*av,"-f") && (ac >= 2) ) {
1.38 ohara 372: do_quiet = 1;
1.1 noro 373: in_fp = fopen(*(av+1),"r");
374: if ( !in_fp ) {
1.62 noro 375: fprintf(stderr,"%s does not exist!\n",*(av+1));
1.1 noro 376: asir_terminate(1);
377: }
378: do_file = 1;
1.42 ohara 379: do_filename = *(av+1);
1.1 noro 380: av += 2; ac -= 2;
1.42 ohara 381: } else if ( !strcmp(*av,"-E") ) {
382: asir_setenv = 1; av++; ac--;
1.38 ohara 383: } else if ( !strcmp(*av,"-quiet") ) {
1.39 noro 384: do_quiet = 1; av++; ac--;
1.1 noro 385: } else if ( !strcmp(*av,"-norc") ) {
386: do_asirrc = 0; av++; ac--;
387: } else if ( !strcmp(*av,"-nomessage") ) {
388: do_message = 0; av++; ac--;
1.11 noro 389: } else if ( !strcmp(*av,"-rootdir") && (ac >= 2) ) {
390: set_rootdir(*(av+1)); av += 2; ac -= 2;
1.1 noro 391: } else if ( !strcmp(*av,"-maxheap") && (ac >= 2) ) {
392: void GC_set_max_heap_size(int);
393:
394: GC_set_max_heap_size(atoi(*(av+1))); av += 2; ac -= 2;
395: #if !defined(VISUAL)
396: } else if ( !strcmp(*av,"-display") && (ac >= 2) ) {
397: strcpy(displayname,*(av+1)); av += 2; ac -= 2;
398: #endif
1.32 noro 399: #if FEP
1.13 saito 400: } else if ( !strcmp(*av,"-fep") ) {
401: do_fep = 1; av++; ac--;
402: #endif
1.31 ohara 403: #if defined(PARI)
1.1 noro 404: } else if ( !strcmp(*av,"-paristack") ) {
405: extern int paristack;
406:
407: paristack = atoi(*(av+1)); av += 2; ac -= 2;
408: #endif
409: } else {
410: fprintf(stderr,"%s : unknown option.\n",*av);
411: asir_terminate(1);
412: }
413: }
1.32 noro 414: #if FEP
1.13 saito 415: if ( do_fep ) {
416: char *home;
417: home = (char *)getenv("HOME");
418: if (!home)
419: home = ".";
420: sprintf (asir_history, "%s/.asir_history",home);
421: read_history(asir_history);
422: using_history();
423: }
424: #endif
1.1 noro 425: }
426:
427: #include <signal.h>
428:
429: void sig_init() {
430: #if !defined(VISUAL)
431: signal(SIGINT,int_handler);
432: #else
1.24 noro 433: void register_ctrlc_handler();
434:
1.1 noro 435: register_ctrlc_handler();
436: #endif
437: signal(SIGSEGV,segv_handler);
438:
1.23 noro 439: #if defined(SIGFPE)
1.1 noro 440: signal(SIGFPE,fpe_handler);
441: #endif
442:
1.23 noro 443: #if defined(SIGPIPE)
1.1 noro 444: signal(SIGPIPE,pipe_handler);
445: #endif
446:
1.23 noro 447: #if defined(SIGILL)
1.1 noro 448: signal(SIGILL,ill_handler);
449: #endif
450:
451: #if !defined(VISUAL)
452: signal(SIGBUS,bus_handler);
453: #endif
454: }
455:
456: static void (*old_int)(int);
457:
458: void asir_save_handler() {
459: old_int = signal(SIGINT,SIG_IGN);
460: signal(SIGINT,old_int);
461: }
462:
463: void asir_set_handler() {
464: signal(SIGINT,int_handler);
465: }
466:
467: void asir_reset_handler() {
468: signal(SIGINT,old_int);
469: }
470:
1.62 noro 471: extern int I_am_server;
472:
1.24 noro 473: void resetenv(char *s)
1.1 noro 474: {
475: extern FILE *outfile;
476:
1.53 noro 477: fprintf(stderr,"%s\n",s);
1.1 noro 478: while ( NEXT(asir_infile) )
479: closecurrentinput();
480: resetpvs();
481: #if !defined(VISUAL)
482: if ( do_server_in_X11 )
483: #endif
484: show_debug_window(0);
485: #if defined(VISUAL_LIB)
486: w_noflush_stderr(0);
487: #endif
488: asir_out = stdout;
1.31 ohara 489: #if defined(PARI)
1.1 noro 490: pari_outfile = stdout;
491: #endif
492: /* restore states */
493: reset_engine();
494: reset_io();
1.16 noro 495: #if !defined(VISUAL)
1.15 noro 496: reset_timer();
1.16 noro 497: #endif
1.62 noro 498: LONGJMP(main_env,1);
1.1 noro 499: }
500:
1.24 noro 501: void fatal(int n)
1.1 noro 502: {
503: resetenv("return to toplevel");
504: }
505:
506: extern int ox_int_received, critical_when_signal;
1.83 noro 507: extern int in_gc, caught_intr;
1.1 noro 508:
1.24 noro 509: void int_handler(int sig)
1.1 noro 510: {
511: extern NODE PVSS;
1.53 noro 512: NODE t;
1.48 noro 513:
1.1 noro 514:
515: if ( do_file ) {
516: ExitAsir();
517: }
518: if ( critical_when_signal ) {
519: ox_int_received = 1;
520: return;
521: }
1.83 noro 522: if ( in_gc ) {
523: caught_intr = 1;
524: return;
525: }
1.12 noro 526: #if defined(VISUAL)
1.19 noro 527: suspend_timer();
1.1 noro 528: #endif
529: signal(SIGINT,SIG_IGN);
1.3 noro 530: #if !defined(VISUAL)
531: if ( do_server_in_X11 ) {
532: debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
533: restore_handler();
534: return;
535: }
1.1 noro 536: #endif
537: #if defined(linux)
538: #if 1
539: while ( stdin->_IO_read_ptr < stdin->_IO_read_end )
540: #else
541: while ( stdin->_gptr < stdin->_egptr )
542: #endif
543: getchar();
544: #endif
545: while ( 1 ) {
546: char buf[BUFSIZ];
547: char c;
548:
1.53 noro 549: fprintf(stderr,"interrupt ?(q/t/c/d/u/w/?) "); fflush(stderr);
1.1 noro 550: buf[0] = '\n';
1.77 noro 551: while ( !feof(stdin) && buf[0] == '\n' )
1.1 noro 552: fgets(buf,BUFSIZ,stdin);
1.77 noro 553: if ( feof(stdin) ) {
554: clearerr(stdin);
555: continue;
556: }
1.1 noro 557: switch ( c = buf[0] ) {
558: case 'q':
559: while ( 1 ) {
1.53 noro 560: fprintf(stderr,"Abort this session? (y or n) "); fflush(stderr);
1.1 noro 561: fgets(buf,BUFSIZ,stdin);
562: if ( !strncmp(buf,"y",1) ) {
1.53 noro 563: fprintf(stderr,"Bye\n");
1.65 noro 564: /* for terminating myself */
565: asir_infile = 0;
1.48 noro 566: asir_terminate(1);
1.1 noro 567: } else if ( !strncmp(buf,"n",1) ) {
568: restore_handler();
569: return;
570: }
571: }
572: break;
573: case 't':
574: case 'u':
575: while ( 1 ) {
1.53 noro 576: fprintf(stderr,"Abort this computation? (y or n) "); fflush(stderr);
1.1 noro 577: fgets(buf,BUFSIZ,stdin);
578: if ( !strncmp(buf,"y",1) )
579: break;
580: else if ( !strncmp(buf,"n",1) ) {
581: restore_handler();
582: return;
583: }
584: }
585: if ( debug_mode )
586: debug_mode = 0;
587: restore_handler();
588: if ( c == 'u' ) {
1.53 noro 589: if ( user_int_handler ) {
1.58 noro 590: if ( !do_terse )
591: fprintf(stderr,
592: "Calling the registered exception callbacks...");
1.53 noro 593: for ( t = user_int_handler; t; t = NEXT(t) )
594: bevalf((FUNC)BDY(t),0);
1.58 noro 595: if ( !do_terse )
596: fprintf(stderr, "done.\n");
1.1 noro 597: }
598: }
1.62 noro 599: resetenv("return to toplevel");
1.1 noro 600: break;
601: case 'd':
602: #if 0
603: nextbp = 1; nextbplevel = -1;
604: #endif
605: debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
606: restore_handler();
607: return;
608: case 'c':
609: restore_handler();
610: return; break;
611: case 'w':
1.48 noro 612: showpos();
613: break;
1.1 noro 614: case '?':
1.53 noro 615: fprintf(stderr, "q:quit t:toplevel c:continue d:debug u:call registered handler w:where\n");
1.1 noro 616: break;
617: default:
618: break;
619: }
620: }
621: }
622:
623: void restore_handler() {
1.12 noro 624: #if defined(VISUAL)
1.19 noro 625: resume_timer();
1.1 noro 626: #endif
1.19 noro 627: #if defined(SIGINT)
1.1 noro 628: signal(SIGINT,int_handler);
629: #endif
630: }
631:
1.24 noro 632: void segv_handler(int sig)
1.1 noro 633: {
1.19 noro 634: #if defined(SIGSEGV)
1.1 noro 635: signal(SIGSEGV,segv_handler);
1.19 noro 636: error("internal error (SEGV)");
1.1 noro 637: #endif
638: }
639:
1.24 noro 640: void ill_handler(int sig)
1.1 noro 641: {
1.19 noro 642: #if defined(SIGILL)
1.1 noro 643: signal(SIGILL,ill_handler);
1.19 noro 644: error("illegal instruction (ILL)");
1.1 noro 645: #endif
646: }
647:
1.69 noro 648: #if defined(__DARWIN__)
649: #define SIGNAL_FOR_TIMER SIGALRM
650: #define ITIMER_TYPE ITIMER_REAL
651: #else
652: #define SIGNAL_FOR_TIMER SIGVTALRM
653: #define ITIMER_TYPE ITIMER_VIRTUAL
654: #endif
655:
1.24 noro 656: void alrm_handler(int sig)
1.1 noro 657: {
658: fprintf(stderr,"interval timer expired (VTALRM)\n");
1.26 noro 659: LONGJMP(timer_env,1);
1.1 noro 660: }
661:
1.24 noro 662: void bus_handler(int sig)
1.1 noro 663: {
664: #if defined(SIGBUS)
665: signal(SIGBUS,bus_handler);
666: error("internal error (BUS ERROR)");
667: #endif
668: }
669:
1.24 noro 670: void fpe_handler(int sig)
1.1 noro 671: {
1.19 noro 672: #if defined(SIGFPE)
1.1 noro 673: signal(SIGFPE,fpe_handler);
1.19 noro 674: error("internal error (FPE)");
1.1 noro 675: #endif
676: }
677:
1.24 noro 678: void pipe_handler(int sig)
1.1 noro 679: {
680: #if defined(SIGPIPE)
681: signal(SIGPIPE,pipe_handler);
1.20 noro 682: end_critical();
1.1 noro 683: error("internal error (BROKEN PIPE)");
684: #endif
685: }
686:
687: void resize_buffer()
688: {
689: }
690:
691: void tty_init() {
692: }
693:
694: void tty_reset() {
695: }
696:
697: extern int evalstatline;
698:
1.24 noro 699: void set_lasterror(char *s)
1.1 noro 700: {
701: strncpy(LastError,s,BUFSIZ);
702: LastError[BUFSIZ-1] = 0;
703: }
704:
705: SNODE error_snode;
1.51 noro 706: int error_in_timer;
1.1 noro 707:
1.24 noro 708: void error(char *s)
1.1 noro 709: {
1.37 noro 710: SNODE *snp=0;
1.1 noro 711:
1.16 noro 712: #if !defined(VISUAL)
1.51 noro 713: if ( !error_in_timer && timer_is_set )
1.69 noro 714: alrm_handler(SIGNAL_FOR_TIMER);
1.16 noro 715: #endif
1.1 noro 716: fprintf(stderr,"%s\n",s);
717: set_lasterror(s);
718: if ( CPVS != GPVS ) {
1.37 noro 719: if ( CPVS && CPVS->usrf && CPVS->usrf->f.usrf )
1.7 noro 720: searchsn(&BDY(CPVS->usrf->f.usrf),evalstatline,&snp);
1.6 noro 721: if ( snp )
722: error_snode = *snp;
723: else
724: error_snode = 0;
1.1 noro 725: } else
726: error_snode = 0;
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: set_lasterror(errbuf);
733: ExitAsir();
734: }
735: if ( debug_mode )
1.26 noro 736: LONGJMP(debug_env,1);
1.1 noro 737: if ( CPVS != GPVS )
1.52 noro 738: if ( !no_debug_on_error && (do_server_in_X11 || isatty(0)) )
1.1 noro 739: bp(error_snode);
1.62 noro 740: if ( I_am_server )
741: showpos_to_list(&LastStackTrace);
1.40 noro 742: resetenv("return to toplevel");
743: }
744:
745: void toplevel(char *s)
746: {
747: SNODE *snp=0;
748:
749: #if !defined(VISUAL)
750: if ( timer_is_set )
1.69 noro 751: alrm_handler(SIGNAL_FOR_TIMER);
1.40 noro 752: #endif
753: fprintf(stderr,"%s\n",s);
754: if ( do_file ) {
755: char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
756:
757: sprintf(errbuf,"%s\n",s);
758: showpos_to_string(errbuf+strlen(errbuf));
759: ExitAsir();
760: }
1.1 noro 761: resetenv("return to toplevel");
762: }
763:
764: #if !defined(VISUAL)
765: #include <sys/time.h>
766:
1.24 noro 767: void set_timer(int interval)
1.1 noro 768: {
769: struct itimerval it;
770:
771: it.it_interval.tv_sec = interval;
772: it.it_interval.tv_usec = 0;
773: it.it_value.tv_sec = interval;
774: it.it_value.tv_usec = 0;
1.69 noro 775: setitimer(ITIMER_TYPE,&it,0);
776: signal(SIGNAL_FOR_TIMER,alrm_handler);
1.15 noro 777: timer_is_set = 1;
1.1 noro 778: }
779:
780: void reset_timer()
781: {
782: struct itimerval it;
783:
784: it.it_interval.tv_sec = 0;
785: it.it_interval.tv_usec = 0;
786: it.it_value.tv_sec = 0;
787: it.it_value.tv_usec = 0;
1.69 noro 788: setitimer(ITIMER_TYPE,&it,0);
789: signal(SIGNAL_FOR_TIMER,SIG_IGN);
1.15 noro 790: timer_is_set = 0;
1.1 noro 791: }
792: #endif
793:
794: unsigned int get_asir_version();
1.14 noro 795: char *get_asir_distribution();
1.1 noro 796:
1.72 ohara 797: char *get_gcversion()
798: {
1.82 ohara 799: return "GC 7.2 copyright 1988-2012, H-J. Boehm, A. J. Demers, Xerox, SGI, HP.\n";
1.72 ohara 800: }
801:
1.47 ohara 802: char *get_pariversion()
803: {
1.32 noro 804: #if PARI
805: #if 0
1.59 saito 806: return PARIVERSION", Copyright (C) 2000-2005 The PARI Group.\n";
807: #else
808: return "PARI 2.0.17, copyright 1989-1999, C. Batut, K. Belabas, D. Bernardi,\n H. Cohen and M. Olivier.\n";
1.32 noro 809: #endif
810: #endif
1.47 ohara 811: return "";
1.1 noro 812: }
1.14 noro 813:
1.47 ohara 814: char *get_intervalversion()
815: {
816: #if defined(INTERVAL)
817: return " + Interval Arithmetic";
818: #else
819: return "";
820: #endif
821: }
822:
823: void copyright()
824: {
1.72 ohara 825: char *scopyright();
826: fputs(scopyright(), stdout);
1.47 ohara 827: }
1.5 noro 828:
1.47 ohara 829: char *scopyright()
830: {
831: static char *notice;
1.72 ohara 832: char *s1, *s2, *s3, *s4;
1.47 ohara 833: int d, len;
1.72 ohara 834: 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 835: if (!notice) {
836: s1 = get_intervalversion();
837: s2 = get_asir_distribution();
1.72 ohara 838: s3 = get_gcversion();
839: s4 = get_pariversion();
1.47 ohara 840: d = get_asir_version();
1.72 ohara 841: len = (strlen(format)-8)+strlen(s1)+strlen(s2)+strlen(s3)+strlen(s4)+sizeof(int)*3;
1.47 ohara 842: notice = MALLOC(len+1);
1.72 ohara 843: sprintf(notice, format, s1, d, s2, s3, s4);
1.47 ohara 844: }
845: return notice;
846: }
1.84 noro 847:
848: #if defined(VISUAL)
849: void check_intr()
850: {
851: extern int recv_intr;
852: if ( recv_intr ) {
853: if ( recv_intr == 1 ) {
854: recv_intr = 0;
855: int_handler(0);
856: } else {
857: recv_intr = 0;
858: ox_usr1_handler(0);
859: }
860: }
861: }
862: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>