Annotation of OpenXM_contrib2/asir2000/parse/glob.c, Revision 1.45
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.45 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/glob.c,v 1.44 2004/02/04 07:42:07 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.43 ohara 57: #if !defined(VISUAL) && !defined(_PA_RISC1_1) && !defined(linux) && !defined(SYSV) && !defined(__CYGWIN__) && !defined(__INTERIX)
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 int GC_free_space_divisor;
81: extern int GC_free_space_numerator;
82: extern FILE *asir_out;
83:
1.24 noro 84: INFILE asir_infile;
1.26 noro 85: JMP_BUF main_env,debug_env,timer_env,exec_env;
1.1 noro 86: int little_endian,debug_mode;
87: char *asir_libdir;
88: char *asir_pager;
89:
90: NODE usrf,sysf,noargsysf,ubinf,parif;
91: NODE ONENODE;
1.29 noro 92: int main_parser, allow_create_var, ox_do_copy, ox_do_count, ox_count_length;
1.1 noro 93: int ox_file_io, ox_need_conv;
94: char *ox_copy_bptr;
95: char *parse_strp;
96: SNODE parse_snode;
97: FUNC parse_targetf;
98: FILE *ox_istream,*ox_ostream;
99: int do_server_in_X11;
100: Obj LastVal;
101: char LastError[BUFSIZ];
1.15 noro 102: int timer_is_set;
103:
1.1 noro 104:
105: struct oV oVAR[] = {
106: {"x",0,0}, {"y",0,0}, {"z",0,0}, {"u",0,0},
107: {"v",0,0}, {"w",0,0}, {"p",0,0}, {"q",0,0},
108: {"r",0,0}, {"s",0,0}, {"t",0,0}, {"a",0,0},
109: {"b",0,0}, {"c",0,0}, {"d",0,0}, {"e",0,0},
110: {"f",0,0}, {"g",0,0}, {"h",0,0}, {"i",0,0},
111: {"j",0,0}, {"k",0,0}, {"l",0,0}, {"m",0,0},
112: {"n",0,0}, {"o",0,0},
113: {"_x",0,0}, {"_y",0,0}, {"_z",0,0}, {"_u",0,0},
114: {"_v",0,0}, {"_w",0,0}, {"_p",0,0}, {"_q",0,0},
115: {"_r",0,0}, {"_s",0,0}, {"_t",0,0}, {"_a",0,0},
116: {"_b",0,0}, {"_c",0,0}, {"_d",0,0}, {"_e",0,0},
117: {"_f",0,0}, {"_g",0,0}, {"_h",0,0}, {"_i",0,0},
118: {"_j",0,0}, {"_k",0,0}, {"_l",0,0}, {"_m",0,0},
119: {"_n",0,0}, {"_o",0,0}
120: };
121:
122: struct oVL oVLIST[52];
123:
124: VL CO = oVLIST;
125: VL ALG;
126:
127: struct oVS oGPVS,oAPVS,oEPVS;
128: VS GPVS = &oGPVS;
129: VS APVS = &oAPVS;
130: VS EPVS = &oEPVS;
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.44 noro 137: struct oSymbol oGrlex, oGlex, oLex;
138: Symbol Symbol_grlex = &oGrlex;
139: Symbol Symbol_glex = &oGlex;
140: Symbol Symbol_lex = &oLex;;
141:
1.1 noro 142: struct oF oF_TRUE,oF_FALSE;
143: F F_TRUE = &oF_TRUE;
144: F F_FALSE = &oF_FALSE;
145:
146: #if defined(VISUAL)
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.38 ohara 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));
166: CPVS = GPVS;
167: MKNODE(ONENODE,mkfnode(1,I_FORMULA,ONE),0);
168: OID(F_TRUE)=O_F; FOP(F_TRUE)=AL_TRUE; F_TRUE->arg.dummy = 0;
169: OID(F_FALSE)=O_F; FOP(F_FALSE)=AL_FALSE; F_FALSE->arg.dummy = 0;
1.44 noro 170: OID(Symbol_grlex) = O_SYMBOL; Symbol_grlex->name = "@grlex";
171: Symbol_grlex->value = 0;
172: OID(Symbol_glex) = O_SYMBOL; Symbol_glex->name = "@glex";
173: Symbol_glex->value = 1;
1.45 ! noro 174: OID(Symbol_lex) = O_SYMBOL; Symbol_lex->name = "@lex";
! 175: Symbol_lex->value = 2;
1.1 noro 176: sprintf(asirname,"%s/asir_symtab",asir_libdir);
177: }
178:
1.24 noro 179: void input_init(FILE *fp,char *name)
1.1 noro 180: {
1.24 noro 181: asir_infile = (INFILE)CALLOC(sizeof(struct oINFILE),1);
1.1 noro 182: asir_infile->name = name; asir_infile->fp = fp;
183: asir_infile->ln = 1; NEXT(asir_infile) = 0;
184: }
185:
1.24 noro 186: void notdef(VL vl,Obj a,Obj b,Obj *c)
1.1 noro 187: {
188: error("undefined arithmetic operation.");
189: }
190:
191: int do_asirrc;
192: int do_file;
1.42 ohara 193: char *do_filename;
1.1 noro 194: int do_message;
195: int do_fep;
196: int read_exec_file;
1.42 ohara 197: int asir_setenv;
1.1 noro 198: static int buserr_sav;
199: static char asir_history[BUFSIZ];
200:
201: extern int mpi_myid;
202:
1.5 noro 203: #if !defined(VISUAL_LIB)
204: void ExitAsir() {
205: exit(0);
206: }
207: #endif
208:
1.1 noro 209: /*
210: * status = 1 abnormal termination (error() etc.)
211: * status = 2 normal termination (end(), quit() etc.)
212: */
213:
1.24 noro 214: void asir_terminate(int status)
1.1 noro 215: {
1.21 noro 216: int t;
217:
1.1 noro 218: if ( read_exec_file ) {
1.21 noro 219: t = read_exec_file;
220: read_exec_file = 0;
221: if ( t == 1 )
1.26 noro 222: LONGJMP(main_env,status);
1.21 noro 223: else
1.26 noro 224: LONGJMP(exec_env,status);
1.1 noro 225: } else {
226: tty_reset();
1.33 noro 227: #if defined(MPI)
1.1 noro 228: if ( !mpi_myid )
229: close_allconnections();
230: mpi_finalize();
231: #else
1.20 noro 232: #if defined(SIGPIPE)
233: signal(SIGPIPE,SIG_IGN);
234: #endif
1.1 noro 235: close_allconnections();
236: #endif
237: if ( asir_out )
238: fflush(asir_out);
1.32 noro 239: #if FEP
1.13 saito 240: if ( do_fep ) {
241: stifle_history(MAXHIST);
242: write_history(asir_history);
243: }
244: #endif
1.1 noro 245: ExitAsir();
246: }
247: }
248:
249: void param_init() {
250: unsigned int et = 0xff;
251: extern int paristack;
252: if ( *((char *)&et) )
253: little_endian = 1;
254: else
255: little_endian = 0;
256: }
1.39 noro 257:
258: Obj user_defined_prompt;
259:
1.1 noro 260: void prompt() {
1.39 noro 261: if ( !do_quiet && !do_fep && asir_infile->fp == stdin )
1.21 noro 262: fprintf(asir_out,"[%d] ",APVS->n);
1.39 noro 263: else if ( do_quiet && user_defined_prompt
264: && OID(user_defined_prompt)==O_STR) {
265: fprintf(asir_out,BDY((STRING)user_defined_prompt),APVS->n);
266: }
1.1 noro 267: fflush(asir_out);
268: }
269:
1.24 noro 270: void sprompt(char *ptr)
1.1 noro 271: {
1.21 noro 272: sprintf(ptr,"[%d] ",APVS->n);
1.34 ohara 273: }
274:
275: #if !defined(VISUAL)
276: static int which(char *prog, char *path, char *buf, size_t size)
277: {
278: char *tok;
279: char delim[] = ":";
280: char *path2 = malloc(strlen(path)+1);
281: char *name = malloc(size);
282: int proglen = strlen(prog)+3; /* "/" + prog + " \0" */
283:
284: if (!name || !path2) {
285: return 0;
286: }
287: strcpy(path2, path);
288: tok = strtok(path2, delim);
289: while (tok != NULL) {
290: if (size >= strlen(tok)) {
291: sprintf(name, "%s/%s", tok, prog);
292: if (access(name, X_OK&R_OK) == 0) {
293: strcpy(buf, name);
294: strcat(buf, " ");
295: free(path2); free(name);
296: return 1;
297: }
298: tok = strtok(NULL, delim);
299: }
300: }
301: free(path2); free(name);
302: return 0;
303: }
304: #endif
305:
306: void cppname_init()
307: {
308: #if !defined(VISUAL)
309: if (access(cppname, X_OK&R_OK) != 0) {
310: which("cpp", "/lib:/usr/ccs/lib:/usr/bin", cppname, BUFSIZ) ||
311: which("cpp", getenv("PATH"), cppname, BUFSIZ);
312: }
313: #endif
1.1 noro 314: }
315:
316: FILE *in_fp;
317:
1.24 noro 318: void process_args(int ac,char **av)
1.1 noro 319: {
320: do_asirrc = 1;
1.33 noro 321: #if !defined(MPI)
1.1 noro 322: do_message = 1;
323: #endif
1.38 ohara 324: do_quiet = 0;
1.1 noro 325: while ( ac > 0 ) {
326: if ( !strcmp(*av,"-heap") && (ac >= 2) ) {
327: void GC_expand_hp(int);
328:
329: GC_expand_hp(atoi(*(av+1))); av += 2; ac -= 2;
330: } else if ( !strcmp(*av,"-adj") && (ac >= 2) ) {
331: char *slash;
332:
333: slash = strrchr(*(av+1),'/');
334: if ( slash ) {
335: *slash = 0;
336: GC_free_space_numerator = atoi(slash+1);
337: }
338: GC_free_space_divisor = atoi(*(av+1));
339: av += 2; ac -= 2;
340: } else if ( !strcmp(*av,"-cpp") && (ac >= 2) ) {
341: strcpy(cppname,*(av+1)); av += 2; ac -= 2;
342: } else if ( !strcmp(*av,"-f") && (ac >= 2) ) {
1.38 ohara 343: do_quiet = 1;
1.1 noro 344: in_fp = fopen(*(av+1),"r");
345: if ( !in_fp ) {
346: fprintf(stderr,"%s does not exist!",*(av+1));
347: asir_terminate(1);
348: }
349: do_file = 1;
1.42 ohara 350: do_filename = *(av+1);
1.1 noro 351: av += 2; ac -= 2;
1.42 ohara 352: } else if ( !strcmp(*av,"-E") ) {
353: asir_setenv = 1; av++; ac--;
1.38 ohara 354: } else if ( !strcmp(*av,"-quiet") ) {
1.39 noro 355: do_quiet = 1; av++; ac--;
1.1 noro 356: } else if ( !strcmp(*av,"-norc") ) {
357: do_asirrc = 0; av++; ac--;
358: } else if ( !strcmp(*av,"-nomessage") ) {
359: do_message = 0; av++; ac--;
1.11 noro 360: } else if ( !strcmp(*av,"-rootdir") && (ac >= 2) ) {
361: set_rootdir(*(av+1)); av += 2; ac -= 2;
1.1 noro 362: } else if ( !strcmp(*av,"-maxheap") && (ac >= 2) ) {
363: void GC_set_max_heap_size(int);
364:
365: GC_set_max_heap_size(atoi(*(av+1))); av += 2; ac -= 2;
366: #if !defined(VISUAL)
367: } else if ( !strcmp(*av,"-display") && (ac >= 2) ) {
368: strcpy(displayname,*(av+1)); av += 2; ac -= 2;
369: #endif
1.32 noro 370: #if FEP
1.13 saito 371: } else if ( !strcmp(*av,"-fep") ) {
372: do_fep = 1; av++; ac--;
373: #endif
1.31 ohara 374: #if defined(PARI)
1.1 noro 375: } else if ( !strcmp(*av,"-paristack") ) {
376: extern int paristack;
377:
378: paristack = atoi(*(av+1)); av += 2; ac -= 2;
379: #endif
380: } else {
381: fprintf(stderr,"%s : unknown option.\n",*av);
382: asir_terminate(1);
383: }
384: }
1.32 noro 385: #if FEP
1.13 saito 386: if ( do_fep ) {
387: char *home;
388: home = (char *)getenv("HOME");
389: if (!home)
390: home = ".";
391: sprintf (asir_history, "%s/.asir_history",home);
392: read_history(asir_history);
393: using_history();
394: }
395: #endif
1.1 noro 396: }
397:
398: #include <signal.h>
399:
400: void sig_init() {
401: #if !defined(VISUAL)
402: signal(SIGINT,int_handler);
403: #else
1.24 noro 404: void register_ctrlc_handler();
405:
1.1 noro 406: register_ctrlc_handler();
407: #endif
408: signal(SIGSEGV,segv_handler);
409:
1.23 noro 410: #if defined(SIGFPE)
1.1 noro 411: signal(SIGFPE,fpe_handler);
412: #endif
413:
1.23 noro 414: #if defined(SIGPIPE)
1.1 noro 415: signal(SIGPIPE,pipe_handler);
416: #endif
417:
1.23 noro 418: #if defined(SIGILL)
1.1 noro 419: signal(SIGILL,ill_handler);
420: #endif
421:
422: #if !defined(VISUAL)
423: signal(SIGBUS,bus_handler);
424: #endif
425: }
426:
427: static void (*old_int)(int);
428:
429: void asir_save_handler() {
430: old_int = signal(SIGINT,SIG_IGN);
431: signal(SIGINT,old_int);
432: }
433:
434: void asir_set_handler() {
435: signal(SIGINT,int_handler);
436: }
437:
438: void asir_reset_handler() {
439: signal(SIGINT,old_int);
440: }
441:
1.24 noro 442: void resetenv(char *s)
1.1 noro 443: {
444: extern FILE *outfile;
445:
446: fprintf(stderr,"%s\n",s);
447: while ( NEXT(asir_infile) )
448: closecurrentinput();
449: resetpvs();
450: #if !defined(VISUAL)
451: if ( do_server_in_X11 )
452: #endif
453: show_debug_window(0);
454: #if defined(VISUAL_LIB)
455: w_noflush_stderr(0);
456: #endif
457: asir_out = stdout;
1.31 ohara 458: #if defined(PARI)
1.1 noro 459: pari_outfile = stdout;
460: #endif
461: /* restore states */
462: reset_engine();
463: reset_io();
1.16 noro 464: #if !defined(VISUAL)
1.15 noro 465: reset_timer();
1.16 noro 466: #endif
1.26 noro 467: LONGJMP(main_env,1);
1.1 noro 468: }
469:
1.24 noro 470: void fatal(int n)
1.1 noro 471: {
472: resetenv("return to toplevel");
473: }
474:
475: FUNC registered_handler;
476: extern int ox_int_received, critical_when_signal;
477:
1.24 noro 478: void int_handler(int sig)
1.1 noro 479: {
480: extern NODE PVSS;
481:
482: if ( do_file ) {
483: ExitAsir();
484: }
485: if ( critical_when_signal ) {
486: ox_int_received = 1;
487: return;
488: }
1.12 noro 489: #if defined(VISUAL)
1.19 noro 490: suspend_timer();
1.1 noro 491: #endif
492: signal(SIGINT,SIG_IGN);
1.3 noro 493: #if !defined(VISUAL)
494: if ( do_server_in_X11 ) {
495: debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
496: restore_handler();
497: return;
498: }
1.1 noro 499: #endif
500: #if defined(linux)
501: #if 1
502: while ( stdin->_IO_read_ptr < stdin->_IO_read_end )
503: #else
504: while ( stdin->_gptr < stdin->_egptr )
505: #endif
506: getchar();
507: #endif
508: while ( 1 ) {
509: char buf[BUFSIZ];
510: char c;
511:
512: fprintf(stderr,"interrupt ?(q/t/c/d/u/w/?) "); fflush(stderr);
513: buf[0] = '\n';
514: while ( buf[0] == '\n' )
515: fgets(buf,BUFSIZ,stdin);
516: switch ( c = buf[0] ) {
517: case 'q':
518: while ( 1 ) {
519: fprintf(stderr,"Abort this session? (y or n) "); fflush(stderr);
520: fgets(buf,BUFSIZ,stdin);
521: if ( !strncmp(buf,"y",1) ) {
522: read_exec_file = 0;
523: fprintf(stderr,"Bye\n"); asir_terminate(1);
524: } else if ( !strncmp(buf,"n",1) ) {
525: restore_handler();
526: return;
527: }
528: }
529: break;
530: case 't':
531: case 'u':
532: while ( 1 ) {
533: fprintf(stderr,"Abort this computation? (y or n) "); fflush(stderr);
534: fgets(buf,BUFSIZ,stdin);
535: if ( !strncmp(buf,"y",1) )
536: break;
537: else if ( !strncmp(buf,"n",1) ) {
538: restore_handler();
539: return;
540: }
541: }
542: if ( debug_mode )
543: debug_mode = 0;
544: restore_handler();
545: if ( c == 'u' ) {
546: if ( registered_handler ) {
547: fprintf(stderr,
548: "Calling the registered exception handler...");
549: bevalf(registered_handler,0);
550: fprintf(stderr, "done.\n");
551: }
552: }
553: if ( read_exec_file ) {
554: read_exec_file = 0;
555: resetenv("initialization aborted; return to toplevel");
556: } else
557: resetenv("return to toplevel");
558: break;
559: case 'd':
560: #if 0
561: nextbp = 1; nextbplevel = -1;
562: #endif
563: debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
564: restore_handler();
565: return;
566: case 'c':
567: restore_handler();
568: return; break;
569: case 'w':
570: showpos(); break;
571: case '?':
572: fprintf(stderr, "q:quit t:toplevel c:continue d:debug u:call registered handler w:where\n");
573: break;
574: default:
575: break;
576: }
577: }
578: }
579:
580: void restore_handler() {
1.12 noro 581: #if defined(VISUAL)
1.19 noro 582: resume_timer();
1.1 noro 583: #endif
1.19 noro 584: #if defined(SIGINT)
1.1 noro 585: signal(SIGINT,int_handler);
586: #endif
587: }
588:
1.24 noro 589: void segv_handler(int sig)
1.1 noro 590: {
1.19 noro 591: #if defined(SIGSEGV)
1.1 noro 592: signal(SIGSEGV,segv_handler);
1.19 noro 593: error("internal error (SEGV)");
1.1 noro 594: #endif
595: }
596:
1.24 noro 597: void ill_handler(int sig)
1.1 noro 598: {
1.19 noro 599: #if defined(SIGILL)
1.1 noro 600: signal(SIGILL,ill_handler);
1.19 noro 601: error("illegal instruction (ILL)");
1.1 noro 602: #endif
603: }
604:
1.24 noro 605: void alrm_handler(int sig)
1.1 noro 606: {
607: fprintf(stderr,"interval timer expired (VTALRM)\n");
1.26 noro 608: LONGJMP(timer_env,1);
1.1 noro 609: }
610:
1.24 noro 611: void bus_handler(int sig)
1.1 noro 612: {
613: #if defined(SIGBUS)
614: signal(SIGBUS,bus_handler);
615: error("internal error (BUS ERROR)");
616: #endif
617: }
618:
1.24 noro 619: void fpe_handler(int sig)
1.1 noro 620: {
1.19 noro 621: #if defined(SIGFPE)
1.1 noro 622: signal(SIGFPE,fpe_handler);
1.19 noro 623: error("internal error (FPE)");
1.1 noro 624: #endif
625: }
626:
1.24 noro 627: void pipe_handler(int sig)
1.1 noro 628: {
629: #if defined(SIGPIPE)
630: signal(SIGPIPE,pipe_handler);
1.20 noro 631: end_critical();
1.1 noro 632: error("internal error (BROKEN PIPE)");
633: #endif
634: }
635:
636: void resize_buffer()
637: {
638: }
639:
640: void tty_init() {
641: }
642:
643: void tty_reset() {
644: }
645:
646: extern int evalstatline;
647:
1.24 noro 648: void set_lasterror(char *s)
1.1 noro 649: {
650: strncpy(LastError,s,BUFSIZ);
651: LastError[BUFSIZ-1] = 0;
652: }
653:
654: SNODE error_snode;
655:
1.24 noro 656: void error(char *s)
1.1 noro 657: {
1.37 noro 658: SNODE *snp=0;
1.1 noro 659:
1.16 noro 660: #if !defined(VISUAL)
1.15 noro 661: if ( timer_is_set )
662: alrm_handler(SIGVTALRM);
1.16 noro 663: #endif
1.1 noro 664: fprintf(stderr,"%s\n",s);
665: set_lasterror(s);
666: if ( CPVS != GPVS ) {
1.37 noro 667: if ( CPVS && CPVS->usrf && CPVS->usrf->f.usrf )
1.7 noro 668: searchsn(&BDY(CPVS->usrf->f.usrf),evalstatline,&snp);
1.6 noro 669: if ( snp )
670: error_snode = *snp;
671: else
672: error_snode = 0;
1.1 noro 673: } else
674: error_snode = 0;
675: if ( do_file ) {
676: char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
677:
678: sprintf(errbuf,"%s\n",s);
679: showpos_to_string(errbuf+strlen(errbuf));
680: set_lasterror(errbuf);
681: ExitAsir();
682: }
683: if ( debug_mode )
1.26 noro 684: LONGJMP(debug_env,1);
1.1 noro 685: if ( CPVS != GPVS )
686: if ( do_server_in_X11 || isatty(0) )
687: bp(error_snode);
1.40 noro 688: if ( read_exec_file )
689: read_exec_file = 0;
690: resetenv("return to toplevel");
691: }
692:
693: void toplevel(char *s)
694: {
695: SNODE *snp=0;
696:
697: #if !defined(VISUAL)
698: if ( timer_is_set )
699: alrm_handler(SIGVTALRM);
700: #endif
701: fprintf(stderr,"%s\n",s);
702: if ( do_file ) {
703: char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
704:
705: sprintf(errbuf,"%s\n",s);
706: showpos_to_string(errbuf+strlen(errbuf));
707: ExitAsir();
708: }
1.1 noro 709: if ( read_exec_file )
710: read_exec_file = 0;
711: resetenv("return to toplevel");
712: }
713:
714: #if !defined(VISUAL)
715: #include <sys/time.h>
716:
1.24 noro 717: void set_timer(int interval)
1.1 noro 718: {
719: struct itimerval it;
720:
721: it.it_interval.tv_sec = interval;
722: it.it_interval.tv_usec = 0;
723: it.it_value.tv_sec = interval;
724: it.it_value.tv_usec = 0;
725: setitimer(ITIMER_VIRTUAL,&it,0);
726: signal(SIGVTALRM,alrm_handler);
1.15 noro 727: timer_is_set = 1;
1.1 noro 728: }
729:
730: void reset_timer()
731: {
732: struct itimerval it;
733:
734: it.it_interval.tv_sec = 0;
735: it.it_interval.tv_usec = 0;
736: it.it_value.tv_sec = 0;
737: it.it_value.tv_usec = 0;
738: setitimer(ITIMER_VIRTUAL,&it,0);
739: signal(SIGVTALRM,SIG_IGN);
1.15 noro 740: timer_is_set = 0;
1.1 noro 741: }
742: #endif
743:
744: unsigned int get_asir_version();
1.14 noro 745: char *get_asir_distribution();
1.1 noro 746:
747: void copyright() {
1.17 noro 748: #if defined(INTERVAL)
749: printf("This is Risa/Asir + Interval Arithmetic, Version %d (%s Distribution).\n",
750: get_asir_version(), get_asir_distribution());
751: #else
1.14 noro 752: printf("This is Risa/Asir, Version %d (%s Distribution).\n",
753: get_asir_version(), get_asir_distribution());
1.17 noro 754: #endif
1.14 noro 755: printf("Copyright (C) 1994-2000, all rights reserved, FUJITSU LABORATORIES LIMITED.\n");
1.30 noro 756: printf("Copyright 2000-2003, Risa/Asir committers, http://www.openxm.org/.\n");
1.41 noro 757: printf("GC 6.2(alpha6) copyright 1988-2003, H-J. Boehm, A. J. Demers, Xerox, SGI, HP.\n");
1.32 noro 758: #if PARI
759: #if 0
1.28 noro 760: printf("PARI 2.2.4, copyright (C) 2002 The PARI Group.\n");
1.32 noro 761: #endif
762: printf("PARI 2.0.17, copyright 1989-1999, C. Batut, K. Belabas, D. Bernardi,\n");
763: printf(" H. Cohen and M. Olivier.\n");
764: #endif
1.1 noro 765: }
1.14 noro 766:
1.5 noro 767:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>