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