Annotation of OpenXM_contrib2/asir2000/parse/glob.c, Revision 1.8
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
! 26: * e-mail at risa-admin@flab.fujitsu.co.jp of the detailed specification
! 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: *
! 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/glob.c,v 1.7 2000/07/13 05:09:03 noro Exp $
! 49: */
1.1 noro 50: #include "ca.h"
51: #include "al.h"
52: #include "parse.h"
53: #if PARI
54: #include "genpari.h"
55: #endif
56: #if !defined(THINK_C) && !defined(VISUAL) && !defined(_PA_RISC1_1) && !defined(linux) && !defined(SYSV)
57: #include <sgtty.h>
58: #else
59: #if defined(THINK_C) && !defined(__MWERKS__)
60: #include <console.h>
61: #endif
62: #endif
63:
64: #if defined(VISUAL)
65: #include <io.h>
66: #include <direct.h>
67: #endif
68:
69: #if defined(SYSV)
70: #include <sys/ttold.h>
71: #endif
72:
73: #if defined(THINK_C) || defined(VISUAL)
74: #if defined(VISUAL)
75: #define HISTORY asir_history
76: #else
77: #define HISTORY "history"
78: #endif
79: #endif
80: #define MAXHIST 100
81:
82: extern int GC_free_space_divisor;
83: extern int GC_free_space_numerator;
84: extern FILE *asir_out;
85:
86: IN asir_infile;
87: jmp_buf env,debug_env,timer_env;
88: int little_endian,debug_mode;
89: char *asir_libdir;
90: char *asir_pager;
91:
92: NODE usrf,sysf,noargsysf,ubinf,parif;
93: NODE ONENODE;
94: int main_parser, ox_do_copy, ox_do_count, ox_count_length;
95: int ox_file_io, ox_need_conv;
96: char *ox_copy_bptr;
97: char *parse_strp;
98: SNODE parse_snode;
99: FUNC parse_targetf;
100: FILE *ox_istream,*ox_ostream;
101: int do_server_in_X11;
102: Obj LastVal;
103: char LastError[BUFSIZ];
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;
131: VS CPVS;
132:
133: struct oF oF_TRUE,oF_FALSE;
134: F F_TRUE = &oF_TRUE;
135: F F_FALSE = &oF_FALSE;
136:
137: #if defined(__SVR4) && defined(sun)
1.4 noro 138: char cppname[BUFSIZ] = "/usr/ccs/lib/cpp ";
1.1 noro 139: #else
140: #if defined(__FreeBSD__) || defined(__NetBSD__)
1.4 noro 141: char cppname[BUFSIZ] = "/usr/bin/cpp ";
1.1 noro 142: #else
143: #if defined(VISUAL)
1.4 noro 144: char cppname[BUFSIZ] = "c:\\asir\\stdlib\\cpp ";
1.1 noro 145: #else
1.4 noro 146: char cppname[BUFSIZ] = "/lib/cpp ";
1.1 noro 147: #endif
148: #endif
149: #endif
1.4 noro 150: char asirname[BUFSIZ];
1.1 noro 151: char displayname[BUFSIZ];
152:
153: int Verbose;
154:
155: void glob_init() {
156: int i;
157:
158: for ( i = 0; i < 51; i++ ) {
159: VR(&oVLIST[i]) = &oVAR[i]; NEXT(&oVLIST[i]) = &oVLIST[i+1];
160: }
161: VR(&oVLIST[i]) = &oVAR[i]; NEXT(&oVLIST[i]) = 0;
162: reallocarray((char **)&GPVS->va,(int *)&GPVS->asize,(int *)&GPVS->n,(int)sizeof(struct oPV));
163: reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
164: CPVS = GPVS;
165: MKNODE(ONENODE,mkfnode(1,I_FORMULA,ONE),0);
166: OID(F_TRUE)=O_F; FOP(F_TRUE)=AL_TRUE; F_TRUE->arg.dummy = 0;
167: OID(F_FALSE)=O_F; FOP(F_FALSE)=AL_FALSE; F_FALSE->arg.dummy = 0;
168: sprintf(asirname,"%s/asir_symtab",asir_libdir);
169: #if defined(THINK_C)
170: initVol();
171: #endif
172: }
173:
174: void input_init(fp,name)
175: FILE *fp;
176: char *name;
177: {
178: asir_infile = (IN)CALLOC(sizeof(struct oIN),1);
179: asir_infile->name = name; asir_infile->fp = fp;
180: asir_infile->ln = 1; NEXT(asir_infile) = 0;
181: }
182:
183: void notdef(vl,a,b,c)
184: VL vl;
185: Obj a,b,*c;
186: {
187: *c = 0;
188: error("undefined arithmetic operation.");
189: }
190:
191: int kernelmode;
192: int do_asirrc;
193: int do_file;
194: int do_message;
195: int do_fep;
196: int no_prompt;
197: int read_exec_file;
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:
214: void asir_terminate(status)
215: int status;
216: {
217: if ( read_exec_file ) {
218: read_exec_file = 0; longjmp(env,status);
219: } else {
220: tty_reset();
221: #if INET && !defined(THINK_C)
222: #if MPI
223: if ( !mpi_myid )
224: close_allconnections();
225: mpi_finalize();
226: #else
227: close_allconnections();
228: #endif
229: #endif
230: if ( kernelmode )
231: fputc(0xff,asir_out);
232: if ( asir_out )
233: fflush(asir_out);
234: #if defined(THINK_C) && !defined(__MWERKS__)
235: *((int *)0x8) = buserr_sav;
236: while ( NEXT(asir_infile) )
237: closecurrentinput();
238: console_options.pause_atexit = 0;
239: resetDir();
240: write_hist(HISTORY);
241: #endif
242: ExitAsir();
243: }
244: }
245:
246: void param_init() {
247: unsigned int et = 0xff;
248: extern int paristack;
249: #if defined(THINK_C)
250: char name[BUFSIZ];
251: int c;
252: int val;
253: FILE *fp;
254: int stacksize;
255:
256: #include <Memory.h>
257: GC_free_space_divisor = 4; stacksize = 0x40000;
258: if ( fp = fopen("params","r") ) {
259: while ( 1 ) {
260: c = fgetc(fp);
261: if ( c == EOF )
262: break;
263: else
264: ungetc(c,fp);
265: fscanf(fp,"%s %d",name,&val);
266: if ( !strcmp(name,"stacksize") )
267: stacksize = val;
268: else if ( !strcmp(name,"adj") )
269: GC_free_space_divisor = val;
270: #if PARI
271: else if ( !strcmp(name,"paristack") )
272: paristack = val;
273: #endif
274: }
275: fclose(fp);
276: }
277: #if defined(__MWERKS__)
278: {
279: Ptr al;
280: al = LMGetApplLimit();
281: LMSetApplLimit(al-stacksize);
282: }
283: #else
284: ApplLimit = (Ptr)((char *)ApplLimit-stacksize);
285: console_options.title = "\pAsir";
286: #endif
287: #endif
288: if ( *((char *)&et) )
289: little_endian = 1;
290: else
291: little_endian = 0;
292: }
293:
294: void prompt() {
295: if ( !no_prompt && !do_fep && asir_infile->fp == stdin )
296: fprintf(asir_out,"[%d]%c",APVS->n,kernelmode?0xfe:' ');
297: fflush(asir_out);
298: }
299:
300: void sprompt(ptr)
301: char *ptr;
302: {
303: sprintf(ptr,"[%d]%c",APVS->n,kernelmode?0xfe:' ');
304: }
305:
306: #if 0 && !defined(THINK_C) && !defined(VISUAL) && !defined(_PA_RISC1_1)
307: static struct tchars tc;
308: static char oldeof;
309: struct winsize wsize;
310: int ttywidth;
311: char *upperbuf,*lowerbuf;
312: #endif
313:
314: FILE *in_fp;
315:
316: void process_args(ac,av)
317: int ac;
318: char **av;
319: {
320: #if !defined(THINK_C)
321: do_asirrc = 1;
322: #if !MPI
323: do_message = 1;
324: #endif
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) ) {
343: in_fp = fopen(*(av+1),"r");
344: if ( !in_fp ) {
345: fprintf(stderr,"%s does not exist!",*(av+1));
346: asir_terminate(1);
347: }
348: do_file = 1;
349: av += 2; ac -= 2;
350: } else if ( !strcmp(*av,"-kernel") ) {
351: kernelmode = 1; av++; ac--;
352: } else if ( !strcmp(*av,"-norc") ) {
353: do_asirrc = 0; av++; ac--;
354: } else if ( !strcmp(*av,"-nomessage") ) {
355: do_message = 0; av++; ac--;
356: } else if ( !strcmp(*av,"-terse") ) {
357: no_prompt = 0; av++; ac--;
358: } else if ( !strcmp(*av,"-maxheap") && (ac >= 2) ) {
359: void GC_set_max_heap_size(int);
360:
361: GC_set_max_heap_size(atoi(*(av+1))); av += 2; ac -= 2;
362: #if !defined(VISUAL)
363: } else if ( !strcmp(*av,"-display") && (ac >= 2) ) {
364: strcpy(displayname,*(av+1)); av += 2; ac -= 2;
365: #endif
366: #if PARI
367: } else if ( !strcmp(*av,"-paristack") ) {
368: extern int paristack;
369:
370: paristack = atoi(*(av+1)); av += 2; ac -= 2;
371: #endif
372: } else {
373: fprintf(stderr,"%s : unknown option.\n",*av);
374: asir_terminate(1);
375: }
376: }
377: #endif
378: #if (defined(THINK_C) && !defined(__MWERKS__))
379: init_hist(MAXHIST);
380: read_hist(HISTORY);
381: #endif
382: }
383:
384: #include <signal.h>
385:
386: void sig_init() {
387: #if !defined(VISUAL)
388: signal(SIGINT,int_handler);
389: #else
390: register_ctrlc_handler();
391: #endif
392: signal(SIGSEGV,segv_handler);
393:
394: #if defined SIGFPE
395: signal(SIGFPE,fpe_handler);
396: #endif
397:
398: #if defined SIGPIPE
399: signal(SIGPIPE,pipe_handler);
400: #endif
401:
402: #if defined SIGILL
403: signal(SIGILL,ill_handler);
404: #endif
405:
406: #if defined(THINK_C)
407: buserr_sav = *((int *)0x8);
408: *((int *)0x8) = (int)bus_handler;
409: #else /* THINK_C */
410:
411: #if !defined(VISUAL)
412: signal(SIGBUS,bus_handler);
413: #endif
414:
415: #if 0
416: #if !defined(VISUAL) && !defined(_PA_RISC1_1)
417: signal(SIGWINCH,winch_handler);
418: #endif
419: #endif
420:
421: #endif /* THINK_C */
422: }
423:
424: static void (*old_int)(int);
425:
426: void asir_save_handler() {
427: old_int = signal(SIGINT,SIG_IGN);
428: signal(SIGINT,old_int);
429: }
430:
431: void asir_set_handler() {
432: signal(SIGINT,int_handler);
433: }
434:
435: void asir_reset_handler() {
436: signal(SIGINT,old_int);
437: }
438:
439: void resetenv(s)
440: char *s;
441: {
442: extern FILE *outfile;
443:
444: fprintf(stderr,"%s\n",s);
445: while ( NEXT(asir_infile) )
446: closecurrentinput();
447: resetpvs();
448: #if !defined(VISUAL)
449: if ( do_server_in_X11 )
450: #endif
451: show_debug_window(0);
452: #if defined(VISUAL_LIB)
453: w_noflush_stderr(0);
454: #endif
455: asir_out = stdout;
456: #if PARI
457: pari_outfile = stdout;
458: #endif
459: /* restore states */
460: reset_engine();
461: reset_io();
462: longjmp(env,1);
463: }
464:
465: void fatal(n)
466: int n;
467: {
468: resetenv("return to toplevel");
469: }
470:
471: FUNC registered_handler;
472: extern int ox_int_received, critical_when_signal;
473:
474: void int_handler(sig)
475: int sig;
476: {
477: extern NODE PVSS;
478:
479: if ( do_file ) {
480: ExitAsir();
481: }
482: if ( critical_when_signal ) {
483: ox_int_received = 1;
484: return;
485: }
486: #if defined(THINK_C) || defined(VISUAL)
487: suspend_timer(); signal(SIGINT,SIG_IGN);
488: #endif
489: #if defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
490: signal(SIGINT,SIG_IGN);
1.3 noro 491: #endif
492: #if !defined(VISUAL)
493: if ( do_server_in_X11 ) {
494: debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
495: restore_handler();
496: return;
497: }
1.1 noro 498: #endif
499: #if defined(linux)
500: #if 1
501: while ( stdin->_IO_read_ptr < stdin->_IO_read_end )
502: #else
503: while ( stdin->_gptr < stdin->_egptr )
504: #endif
505: getchar();
506: #endif
507: while ( 1 ) {
508: char buf[BUFSIZ];
509: char c;
510:
511: fprintf(stderr,"interrupt ?(q/t/c/d/u/w/?) "); fflush(stderr);
512: if ( kernelmode )
513: fputc('\0',stderr);
514: buf[0] = '\n';
515: while ( buf[0] == '\n' )
516: fgets(buf,BUFSIZ,stdin);
517: switch ( c = buf[0] ) {
518: case 'q':
519: while ( 1 ) {
520: fprintf(stderr,"Abort this session? (y or n) "); fflush(stderr);
521: fgets(buf,BUFSIZ,stdin);
522: if ( !strncmp(buf,"y",1) ) {
523: read_exec_file = 0;
524: fprintf(stderr,"Bye\n"); asir_terminate(1);
525: } else if ( !strncmp(buf,"n",1) ) {
526: restore_handler();
527: return;
528: }
529: }
530: break;
531: case 't':
532: case 'u':
533: while ( 1 ) {
534: fprintf(stderr,"Abort this computation? (y or n) "); fflush(stderr);
535: fgets(buf,BUFSIZ,stdin);
536: if ( !strncmp(buf,"y",1) )
537: break;
538: else if ( !strncmp(buf,"n",1) ) {
539: restore_handler();
540: return;
541: }
542: }
543: if ( debug_mode )
544: debug_mode = 0;
545: if ( kernelmode )
546: fputc('\0',stderr);
547: restore_handler();
548: if ( c == 'u' ) {
549: if ( registered_handler ) {
550: fprintf(stderr,
551: "Calling the registered exception handler...");
552: bevalf(registered_handler,0);
553: fprintf(stderr, "done.\n");
554: }
555: }
556: if ( read_exec_file ) {
557: read_exec_file = 0;
558: resetenv("initialization aborted; return to toplevel");
559: } else
560: resetenv("return to toplevel");
561: break;
562: case 'd':
563: #if 0
564: nextbp = 1; nextbplevel = -1;
565: #endif
566: debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
567: restore_handler();
568: return;
569: case 'c':
570: if ( kernelmode )
571: fputc('\0',stderr);
572: restore_handler();
573: return; break;
574: case 'w':
575: showpos(); break;
576: case '?':
577: fprintf(stderr, "q:quit t:toplevel c:continue d:debug u:call registered handler w:where\n");
578: break;
579: default:
580: break;
581: }
582: }
583: }
584:
585: void restore_handler() {
586: #if defined(THINK_C) || defined(VISUAL)
587: resume_timer(); signal(SIGINT,int_handler);
588: #endif
589: #if defined(_PA_RISC1_1) || defined(linux) || defined(__svr4__)
590: signal(SIGINT,int_handler);
591: #endif
592: }
593:
594: void segv_handler(sig)
595: int sig;
596: {
597: #if defined(THINK_C) || defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
598: signal(SIGSEGV,segv_handler);
599: #endif
600: error("internal error (SEGV)");
601: }
602:
603: void ill_handler(sig)
604: int sig;
605: {
606: #if defined(THINK_C) || defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
607: signal(SIGILL,ill_handler);
608: #endif
609: error("illegal instruction (ILL)");
610: }
611:
612: void alrm_handler(sig)
613: int sig;
614: {
615: fprintf(stderr,"interval timer expired (VTALRM)\n");
616: longjmp(timer_env,1);
617: }
618:
619: void bus_handler(sig)
620: int sig;
621: {
622: #if defined(SIGBUS)
623: signal(SIGBUS,bus_handler);
624: error("internal error (BUS ERROR)");
625: #endif
626: }
627:
628: void fpe_handler(sig)
629: int sig;
630: {
631: #if defined(THINK_C) || defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
632: signal(SIGFPE,fpe_handler);
633: #endif
634: error("internal error (FPE)");
635: }
636:
637: void winch_handler(sig)
638: int sig;
639: {
640: #if 0
641: #if !defined(THINK_C) && !defined(VISUAL) && !defined(_PA_RISC1_1) && !defined(__svr4__)
642: if ( isatty(1) ) {
643: struct winsize t;
644:
645: if ( ioctl(1,TIOCGWINSZ,&t) == -1 )
646: perror("TIOCGWINSZ");
647: if ( t.ws_col != wsize.ws_col || t.ws_row != wsize.ws_row ) {
648: resize_buffer();
649: if ( killpg(getpgrp(0),SIGWINCH) == -1 )
650: perror("killpg");
651: }
652: }
653: #endif
654: #endif
655: }
656:
657: void pipe_handler(sig)
658: int sig;
659: {
660: #if defined(SIGPIPE)
661: signal(SIGPIPE,pipe_handler);
662: error("internal error (BROKEN PIPE)");
663: #endif
664: }
665:
666: void resize_buffer()
667: {
668: #if 0 && !defined(THINK_C) && !defined(VISUAL) && !defined(_PA_RISC1_1)
669: if ( isatty(1) ) {
670: if ( ioctl(1,TIOCGWINSZ,&wsize) == -1 )
671: perror("TIOCGWINSZ");
672: if ( wsize.ws_col > 2 ) {
673: ttywidth = wsize.ws_col - 2;
674: upperbuf = (char *)MALLOC(wsize.ws_col);
675: lowerbuf = (char *)MALLOC(wsize.ws_col);
676: }
677: }
678: #endif
679: }
680:
681: void tty_init() {
682: #if 0 && !defined(THINK_C) && !defined(VISUAL) && !defined(_PA_RISC1_1)
683: if ( isatty(0) ) {
684: if ( ioctl(0,TIOCGETC,&tc) == -1 )
685: perror("TIOCGETC");
686: oldeof = tc.t_eofc; tc.t_eofc = 0xff;
687: if ( ioctl(0,TIOCSETC,&tc) == -1 )
688: perror("TIOCSETC");
689: setpgrp(0, getpid());
690: }
691: resize_buffer();
692: #endif
693: }
694:
695: void tty_reset() {
696: #if 0 && !defined(THINK_C) && !defined(VISUAL) && !defined(_PA_RISC1_1)
697: if ( oldeof ) {
698: tc.t_eofc = oldeof;
699: if ( ioctl(0,TIOCSETC,&tc) == -1 )
700: perror("TIOCSETC");
701: }
702: #endif
703: }
704:
705: extern int evalstatline;
706:
707: void set_lasterror(s)
708: char *s;
709: {
710: strncpy(LastError,s,BUFSIZ);
711: LastError[BUFSIZ-1] = 0;
712: }
713:
714: SNODE error_snode;
715:
716: void error(s)
717: char *s;
718: {
719: SNODE *snp;
720:
721: fprintf(stderr,"%s\n",s);
722: set_lasterror(s);
723: if ( CPVS != GPVS ) {
1.7 noro 724: if ( CPVS->usrf && CPVS->usrf && CPVS->usrf->f.usrf )
725: searchsn(&BDY(CPVS->usrf->f.usrf),evalstatline,&snp);
1.6 noro 726: if ( snp )
727: error_snode = *snp;
728: else
729: error_snode = 0;
1.1 noro 730: } else
731: error_snode = 0;
732: if ( do_file ) {
733: char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
734:
735: sprintf(errbuf,"%s\n",s);
736: showpos_to_string(errbuf+strlen(errbuf));
737: set_lasterror(errbuf);
738: ExitAsir();
739: }
740: if ( debug_mode )
741: longjmp(debug_env,1);
742: if ( CPVS != GPVS )
743: if ( do_server_in_X11 || isatty(0) )
744: bp(error_snode);
745: if ( read_exec_file )
746: read_exec_file = 0;
747: resetenv("return to toplevel");
748: }
749:
750: #if !defined(VISUAL)
751: #include <sys/time.h>
752:
753: void set_timer(interval)
754: int interval;
755: {
756: struct itimerval it;
757:
758: it.it_interval.tv_sec = interval;
759: it.it_interval.tv_usec = 0;
760: it.it_value.tv_sec = interval;
761: it.it_value.tv_usec = 0;
762: setitimer(ITIMER_VIRTUAL,&it,0);
763: signal(SIGVTALRM,alrm_handler);
764: }
765:
766: void reset_timer()
767: {
768: struct itimerval it;
769:
770: it.it_interval.tv_sec = 0;
771: it.it_interval.tv_usec = 0;
772: it.it_value.tv_sec = 0;
773: it.it_value.tv_usec = 0;
774: setitimer(ITIMER_VIRTUAL,&it,0);
775: signal(SIGVTALRM,SIG_IGN);
776: }
777: #endif
778:
779: unsigned int get_asir_version();
780:
781: void copyright() {
1.2 noro 782: printf("This is Risa/Asir, Version %d.\n",get_asir_version());
1.1 noro 783: printf("Copyright (C) FUJITSU LABORATORIES LIMITED.\n");
1.2 noro 784: printf("1994-1999. All rights reserved.\n");
1.1 noro 785: }
1.5 noro 786:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>