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