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