Annotation of OpenXM_contrib2/asir2000/parse/glob.c, Revision 1.89
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.89 ! fujimoto 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/glob.c,v 1.88 2015/08/06 10:01:53 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.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.89 ! fujimoto 234: #if defined(__MINGW32__) || defined(__MINGW64__)
! 235: fflush(stderr);
! 236: #endif
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:
1.88 fujimoto 288: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.34 ohara 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: {
1.88 fujimoto 321: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
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.89 ! fujimoto 376: #if defined(__MINGW32__) || defined(__MINGW64__)
! 377: fflush(stderr);
! 378: #endif
1.1 noro 379: asir_terminate(1);
380: }
381: do_file = 1;
1.42 ohara 382: do_filename = *(av+1);
1.1 noro 383: av += 2; ac -= 2;
1.42 ohara 384: } else if ( !strcmp(*av,"-E") ) {
385: asir_setenv = 1; av++; ac--;
1.38 ohara 386: } else if ( !strcmp(*av,"-quiet") ) {
1.39 noro 387: do_quiet = 1; av++; ac--;
1.1 noro 388: } else if ( !strcmp(*av,"-norc") ) {
389: do_asirrc = 0; av++; ac--;
390: } else if ( !strcmp(*av,"-nomessage") ) {
391: do_message = 0; av++; ac--;
1.11 noro 392: } else if ( !strcmp(*av,"-rootdir") && (ac >= 2) ) {
393: set_rootdir(*(av+1)); av += 2; ac -= 2;
1.1 noro 394: } else if ( !strcmp(*av,"-maxheap") && (ac >= 2) ) {
395: void GC_set_max_heap_size(int);
396:
397: GC_set_max_heap_size(atoi(*(av+1))); av += 2; ac -= 2;
1.88 fujimoto 398: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.1 noro 399: } else if ( !strcmp(*av,"-display") && (ac >= 2) ) {
400: strcpy(displayname,*(av+1)); av += 2; ac -= 2;
401: #endif
1.32 noro 402: #if FEP
1.13 saito 403: } else if ( !strcmp(*av,"-fep") ) {
404: do_fep = 1; av++; ac--;
405: #endif
1.1 noro 406: } else {
407: fprintf(stderr,"%s : unknown option.\n",*av);
1.89 ! fujimoto 408: #if defined(__MINGW32__) || defined(__MINGW64__)
! 409: fflush(stderr);
! 410: #endif
1.1 noro 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() {
1.88 fujimoto 430: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.1 noro 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:
1.88 fujimoto 451: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.1 noro 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.89 ! fujimoto 478: #if defined(__MINGW32__) || defined(__MINGW64__)
! 479: fflush(stderr);
! 480: #endif
1.1 noro 481: while ( NEXT(asir_infile) )
482: closecurrentinput();
483: resetpvs();
1.88 fujimoto 484: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.1 noro 485: if ( do_server_in_X11 )
486: #endif
487: show_debug_window(0);
488: #if defined(VISUAL_LIB)
489: w_noflush_stderr(0);
490: #endif
491: asir_out = stdout;
492: /* restore states */
493: reset_engine();
494: reset_io();
1.88 fujimoto 495: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
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.88 fujimoto 526: #if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__)
1.19 noro 527: suspend_timer();
1.1 noro 528: #endif
529: signal(SIGINT,SIG_IGN);
1.88 fujimoto 530: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.3 noro 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.89 ! fujimoto 597: #if defined(__MINGW32__) || defined(__MINGW64__)
! 598: fflush(stderr);
! 599: #endif
1.1 noro 600: }
601: }
1.62 noro 602: resetenv("return to toplevel");
1.1 noro 603: break;
604: case 'd':
605: #if 0
606: nextbp = 1; nextbplevel = -1;
607: #endif
608: debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
609: restore_handler();
610: return;
611: case 'c':
612: restore_handler();
613: return; break;
614: case 'w':
1.48 noro 615: showpos();
616: break;
1.1 noro 617: case '?':
1.53 noro 618: fprintf(stderr, "q:quit t:toplevel c:continue d:debug u:call registered handler w:where\n");
1.89 ! fujimoto 619: #if defined(__MINGW32__) || defined(__MINGW64__)
! 620: fflush(stderr);
! 621: #endif
1.1 noro 622: break;
623: default:
624: break;
625: }
626: }
627: }
628:
629: void restore_handler() {
1.88 fujimoto 630: #if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__)
1.19 noro 631: resume_timer();
1.1 noro 632: #endif
1.19 noro 633: #if defined(SIGINT)
1.1 noro 634: signal(SIGINT,int_handler);
635: #endif
636: }
637:
1.24 noro 638: void segv_handler(int sig)
1.1 noro 639: {
1.19 noro 640: #if defined(SIGSEGV)
1.1 noro 641: signal(SIGSEGV,segv_handler);
1.19 noro 642: error("internal error (SEGV)");
1.1 noro 643: #endif
644: }
645:
1.24 noro 646: void ill_handler(int sig)
1.1 noro 647: {
1.19 noro 648: #if defined(SIGILL)
1.1 noro 649: signal(SIGILL,ill_handler);
1.19 noro 650: error("illegal instruction (ILL)");
1.1 noro 651: #endif
652: }
653:
1.69 noro 654: #if defined(__DARWIN__)
655: #define SIGNAL_FOR_TIMER SIGALRM
656: #define ITIMER_TYPE ITIMER_REAL
657: #else
658: #define SIGNAL_FOR_TIMER SIGVTALRM
659: #define ITIMER_TYPE ITIMER_VIRTUAL
660: #endif
661:
1.24 noro 662: void alrm_handler(int sig)
1.1 noro 663: {
664: fprintf(stderr,"interval timer expired (VTALRM)\n");
1.89 ! fujimoto 665: #if defined(__MINGW32__) || defined(__MINGW64__)
! 666: fflush(stderr);
! 667: #endif
1.26 noro 668: LONGJMP(timer_env,1);
1.1 noro 669: }
670:
1.24 noro 671: void bus_handler(int sig)
1.1 noro 672: {
673: #if defined(SIGBUS)
674: signal(SIGBUS,bus_handler);
675: error("internal error (BUS ERROR)");
676: #endif
677: }
678:
1.24 noro 679: void fpe_handler(int sig)
1.1 noro 680: {
1.19 noro 681: #if defined(SIGFPE)
1.1 noro 682: signal(SIGFPE,fpe_handler);
1.19 noro 683: error("internal error (FPE)");
1.1 noro 684: #endif
685: }
686:
1.24 noro 687: void pipe_handler(int sig)
1.1 noro 688: {
689: #if defined(SIGPIPE)
690: signal(SIGPIPE,pipe_handler);
1.20 noro 691: end_critical();
1.1 noro 692: error("internal error (BROKEN PIPE)");
693: #endif
694: }
695:
696: void resize_buffer()
697: {
698: }
699:
700: void tty_init() {
701: }
702:
703: void tty_reset() {
704: }
705:
706: extern int evalstatline;
707:
1.24 noro 708: void set_lasterror(char *s)
1.1 noro 709: {
710: strncpy(LastError,s,BUFSIZ);
711: LastError[BUFSIZ-1] = 0;
712: }
713:
714: SNODE error_snode;
1.51 noro 715: int error_in_timer;
1.1 noro 716:
1.24 noro 717: void error(char *s)
1.1 noro 718: {
1.37 noro 719: SNODE *snp=0;
1.1 noro 720:
1.88 fujimoto 721: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.51 noro 722: if ( !error_in_timer && timer_is_set )
1.69 noro 723: alrm_handler(SIGNAL_FOR_TIMER);
1.16 noro 724: #endif
1.1 noro 725: fprintf(stderr,"%s\n",s);
1.89 ! fujimoto 726: #if defined(__MINGW32__) || defined(__MINGW64__)
! 727: fflush(stderr);
! 728: #endif
1.1 noro 729: set_lasterror(s);
730: if ( CPVS != GPVS ) {
1.37 noro 731: if ( CPVS && CPVS->usrf && CPVS->usrf->f.usrf )
1.7 noro 732: searchsn(&BDY(CPVS->usrf->f.usrf),evalstatline,&snp);
1.6 noro 733: if ( snp )
734: error_snode = *snp;
735: else
736: error_snode = 0;
1.1 noro 737: } else
738: error_snode = 0;
739: if ( do_file ) {
740: char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
741:
742: sprintf(errbuf,"%s\n",s);
743: showpos_to_string(errbuf+strlen(errbuf));
744: set_lasterror(errbuf);
745: ExitAsir();
746: }
747: if ( debug_mode )
1.26 noro 748: LONGJMP(debug_env,1);
1.1 noro 749: if ( CPVS != GPVS )
1.52 noro 750: if ( !no_debug_on_error && (do_server_in_X11 || isatty(0)) )
1.1 noro 751: bp(error_snode);
1.62 noro 752: if ( I_am_server )
753: showpos_to_list(&LastStackTrace);
1.40 noro 754: resetenv("return to toplevel");
755: }
756:
1.86 noro 757: void goto_toplevel(char *s)
1.40 noro 758: {
759: SNODE *snp=0;
760:
1.88 fujimoto 761: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.40 noro 762: if ( timer_is_set )
1.69 noro 763: alrm_handler(SIGNAL_FOR_TIMER);
1.40 noro 764: #endif
765: fprintf(stderr,"%s\n",s);
1.89 ! fujimoto 766: #if defined(__MINGW32__) || defined(__MINGW64__)
! 767: fflush(stderr);
! 768: #endif
1.40 noro 769: if ( do_file ) {
770: char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
771:
772: sprintf(errbuf,"%s\n",s);
773: showpos_to_string(errbuf+strlen(errbuf));
774: ExitAsir();
775: }
1.1 noro 776: resetenv("return to toplevel");
777: }
778:
1.88 fujimoto 779: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.1 noro 780: #include <sys/time.h>
781:
1.24 noro 782: void set_timer(int interval)
1.1 noro 783: {
784: struct itimerval it;
785:
786: it.it_interval.tv_sec = interval;
787: it.it_interval.tv_usec = 0;
788: it.it_value.tv_sec = interval;
789: it.it_value.tv_usec = 0;
1.69 noro 790: setitimer(ITIMER_TYPE,&it,0);
791: signal(SIGNAL_FOR_TIMER,alrm_handler);
1.15 noro 792: timer_is_set = 1;
1.1 noro 793: }
794:
795: void reset_timer()
796: {
797: struct itimerval it;
798:
799: it.it_interval.tv_sec = 0;
800: it.it_interval.tv_usec = 0;
801: it.it_value.tv_sec = 0;
802: it.it_value.tv_usec = 0;
1.69 noro 803: setitimer(ITIMER_TYPE,&it,0);
804: signal(SIGNAL_FOR_TIMER,SIG_IGN);
1.15 noro 805: timer_is_set = 0;
1.1 noro 806: }
807: #endif
808:
809: unsigned int get_asir_version();
1.14 noro 810: char *get_asir_distribution();
1.1 noro 811:
1.72 ohara 812: char *get_gcversion()
813: {
1.82 ohara 814: return "GC 7.2 copyright 1988-2012, H-J. Boehm, A. J. Demers, Xerox, SGI, HP.\n";
1.72 ohara 815: }
816:
1.47 ohara 817: char *get_pariversion()
818: {
819: return "";
1.1 noro 820: }
1.14 noro 821:
1.47 ohara 822: char *get_intervalversion()
823: {
824: #if defined(INTERVAL)
825: return " + Interval Arithmetic";
826: #else
827: return "";
828: #endif
829: }
830:
831: void copyright()
832: {
1.72 ohara 833: char *scopyright();
834: fputs(scopyright(), stdout);
1.47 ohara 835: }
1.5 noro 836:
1.47 ohara 837: char *scopyright()
838: {
839: static char *notice;
1.72 ohara 840: char *s1, *s2, *s3, *s4;
1.47 ohara 841: int d, len;
1.72 ohara 842: 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 843: if (!notice) {
844: s1 = get_intervalversion();
845: s2 = get_asir_distribution();
1.72 ohara 846: s3 = get_gcversion();
847: s4 = get_pariversion();
1.47 ohara 848: d = get_asir_version();
1.72 ohara 849: len = (strlen(format)-8)+strlen(s1)+strlen(s2)+strlen(s3)+strlen(s4)+sizeof(int)*3;
1.47 ohara 850: notice = MALLOC(len+1);
1.72 ohara 851: sprintf(notice, format, s1, d, s2, s3, s4);
1.47 ohara 852: }
853: return notice;
854: }
1.84 noro 855:
1.88 fujimoto 856: #if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__)
1.84 noro 857: void check_intr()
858: {
859: extern int recv_intr;
860: if ( recv_intr ) {
861: if ( recv_intr == 1 ) {
862: recv_intr = 0;
863: int_handler(0);
864: } else {
865: recv_intr = 0;
866: ox_usr1_handler(0);
867: }
868: }
869: }
870: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>