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