[BACK]Return to glob.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / parse

Annotation of OpenXM_contrib2/asir2000/parse/glob.c, Revision 1.11

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.11    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/glob.c,v 1.10 2000/08/28 06:13:15 noro Exp $
1.8       noro       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--;
1.11    ! noro      358:                } else if ( !strcmp(*av,"-rootdir") && (ac >= 2) ) {
        !           359:                        set_rootdir(*(av+1)); av += 2; ac -= 2;
1.1       noro      360:                } else if ( !strcmp(*av,"-maxheap") && (ac >= 2) ) {
                    361:                        void GC_set_max_heap_size(int);
                    362:
                    363:                        GC_set_max_heap_size(atoi(*(av+1))); av += 2; ac -= 2;
                    364: #if !defined(VISUAL)
                    365:                } else if ( !strcmp(*av,"-display") && (ac >= 2) ) {
                    366:                        strcpy(displayname,*(av+1)); av += 2; ac -= 2;
                    367: #endif
                    368: #if PARI
                    369:                } else if ( !strcmp(*av,"-paristack") ) {
                    370:                        extern int paristack;
                    371:
                    372:                        paristack = atoi(*(av+1)); av += 2; ac -= 2;
                    373: #endif
                    374:                } else {
                    375:                        fprintf(stderr,"%s : unknown option.\n",*av);
                    376:                        asir_terminate(1);
                    377:                }
                    378:        }
                    379: #endif
                    380: #if (defined(THINK_C) && !defined(__MWERKS__))
                    381:        init_hist(MAXHIST);
                    382:        read_hist(HISTORY);
                    383: #endif
                    384: }
                    385:
                    386: #include <signal.h>
                    387:
                    388: void sig_init() {
                    389: #if !defined(VISUAL)
                    390:        signal(SIGINT,int_handler);
                    391: #else
                    392:        register_ctrlc_handler();
                    393: #endif
                    394:        signal(SIGSEGV,segv_handler);
                    395:
                    396: #if defined SIGFPE
                    397:        signal(SIGFPE,fpe_handler);
                    398: #endif
                    399:
                    400: #if defined SIGPIPE
                    401:        signal(SIGPIPE,pipe_handler);
                    402: #endif
                    403:
                    404: #if defined SIGILL
                    405:        signal(SIGILL,ill_handler);
                    406: #endif
                    407:
                    408: #if defined(THINK_C)
                    409:        buserr_sav = *((int *)0x8);
                    410:        *((int *)0x8) = (int)bus_handler;
                    411: #else /* THINK_C */
                    412:
                    413: #if !defined(VISUAL)
                    414:        signal(SIGBUS,bus_handler);
                    415: #endif
                    416:
                    417: #if 0
                    418: #if !defined(VISUAL) && !defined(_PA_RISC1_1)
                    419:        signal(SIGWINCH,winch_handler);
                    420: #endif
                    421: #endif
                    422:
                    423: #endif /* THINK_C */
                    424: }
                    425:
                    426: static void (*old_int)(int);
                    427:
                    428: void asir_save_handler() {
                    429:        old_int = signal(SIGINT,SIG_IGN);
                    430:        signal(SIGINT,old_int);
                    431: }
                    432:
                    433: void asir_set_handler() {
                    434:        signal(SIGINT,int_handler);
                    435: }
                    436:
                    437: void asir_reset_handler() {
                    438:        signal(SIGINT,old_int);
                    439: }
                    440:
                    441: void resetenv(s)
                    442: char *s;
                    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;
                    458: #if PARI
                    459:        pari_outfile = stdout;
                    460: #endif
                    461:        /* restore states */
                    462:        reset_engine();
                    463:        reset_io();
                    464:        longjmp(env,1);
                    465: }
                    466:
                    467: void fatal(n)
                    468: int n;
                    469: {
                    470:        resetenv("return to toplevel");
                    471: }
                    472:
                    473: FUNC registered_handler;
                    474: extern int ox_int_received, critical_when_signal;
                    475:
                    476: void int_handler(sig)
                    477: int sig;
                    478: {
                    479:        extern NODE PVSS;
                    480:
                    481:        if ( do_file ) {
                    482:                ExitAsir();
                    483:        }
                    484:        if ( critical_when_signal ) {
                    485:                ox_int_received = 1;
                    486:                return;
                    487:        }
                    488: #if defined(THINK_C) || defined(VISUAL)
                    489:        suspend_timer(); signal(SIGINT,SIG_IGN);
                    490: #endif
                    491: #if defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
                    492:        signal(SIGINT,SIG_IGN);
1.3       noro      493: #endif
                    494: #if !defined(VISUAL)
                    495:     if ( do_server_in_X11 ) {
                    496:                debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
                    497:                restore_handler();
                    498:                return;
                    499:        }
1.1       noro      500: #endif
                    501: #if defined(linux)
                    502: #if 1
                    503:        while ( stdin->_IO_read_ptr < stdin->_IO_read_end )
                    504: #else
                    505:        while ( stdin->_gptr < stdin->_egptr )
                    506: #endif
                    507:                getchar();
                    508: #endif
                    509:        while ( 1 ) {
                    510:                char buf[BUFSIZ];
                    511:                char c;
                    512:
                    513:                fprintf(stderr,"interrupt ?(q/t/c/d/u/w/?) "); fflush(stderr);
                    514:                if ( kernelmode )
                    515:                        fputc('\0',stderr);
                    516:                buf[0] = '\n';
                    517:                while ( buf[0] == '\n' )
                    518:                        fgets(buf,BUFSIZ,stdin);
                    519:                switch ( c = buf[0] ) {
                    520:                        case 'q':
                    521:                                while ( 1 ) {
                    522:                                        fprintf(stderr,"Abort this session? (y or n) "); fflush(stderr);
                    523:                                        fgets(buf,BUFSIZ,stdin);
                    524:                                        if ( !strncmp(buf,"y",1) ) {
                    525:                                                read_exec_file = 0;
                    526:                                                fprintf(stderr,"Bye\n"); asir_terminate(1);
                    527:                                        } else if ( !strncmp(buf,"n",1) ) {
                    528:                                                restore_handler();
                    529:                                                return;
                    530:                                        }
                    531:                                }
                    532:                                break;
                    533:                        case 't':
                    534:                        case 'u':
                    535:                                while ( 1 ) {
                    536:                                        fprintf(stderr,"Abort this computation? (y or n) "); fflush(stderr);
                    537:                                        fgets(buf,BUFSIZ,stdin);
                    538:                                        if ( !strncmp(buf,"y",1) )
                    539:                                                break;
                    540:                                        else if ( !strncmp(buf,"n",1) ) {
                    541:                                                restore_handler();
                    542:                                                return;
                    543:                                        }
                    544:                                }
                    545:                                if ( debug_mode )
                    546:                                        debug_mode = 0;
                    547:                                if ( kernelmode )
                    548:                                        fputc('\0',stderr);
                    549:                                restore_handler();
                    550:                                if ( c == 'u' ) {
                    551:                                        if ( registered_handler ) {
                    552:                                                fprintf(stderr,
                    553:                                                        "Calling the registered exception handler...");
                    554:                                                bevalf(registered_handler,0);
                    555:                                                fprintf(stderr, "done.\n");
                    556:                                        }
                    557:                                }
                    558:                                if ( read_exec_file ) {
                    559:                                        read_exec_file = 0;
                    560:                                        resetenv("initialization aborted; return to toplevel");
                    561:                                } else
                    562:                                        resetenv("return to toplevel");
                    563:                                break;
                    564:                        case 'd':
                    565: #if 0
                    566:                                nextbp = 1; nextbplevel = -1;
                    567: #endif
                    568:                                debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
                    569:                                restore_handler();
                    570:                                return;
                    571:                        case 'c':
                    572:                                if ( kernelmode )
                    573:                                        fputc('\0',stderr);
                    574:                                restore_handler();
                    575:                                return; break;
                    576:                        case 'w':
                    577:                                showpos(); break;
                    578:                        case '?':
                    579:                                fprintf(stderr, "q:quit t:toplevel c:continue d:debug u:call registered handler w:where\n");
                    580:                                break;
                    581:                        default:
                    582:                                break;
                    583:                }
                    584:        }
                    585: }
                    586:
                    587: void restore_handler() {
                    588: #if defined(THINK_C) || defined(VISUAL)
                    589:        resume_timer(); signal(SIGINT,int_handler);
                    590: #endif
                    591: #if defined(_PA_RISC1_1) || defined(linux) || defined(__svr4__)
                    592:        signal(SIGINT,int_handler);
                    593: #endif
                    594: }
                    595:
                    596: void segv_handler(sig)
                    597: int sig;
                    598: {
                    599: #if defined(THINK_C) || defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
                    600:        signal(SIGSEGV,segv_handler);
                    601: #endif
                    602:        error("internal error (SEGV)");
                    603: }
                    604:
                    605: void ill_handler(sig)
                    606: int sig;
                    607: {
                    608: #if defined(THINK_C) || defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
                    609:        signal(SIGILL,ill_handler);
                    610: #endif
                    611:        error("illegal instruction (ILL)");
                    612: }
                    613:
                    614: void alrm_handler(sig)
                    615: int sig;
                    616: {
                    617:        fprintf(stderr,"interval timer expired (VTALRM)\n");
                    618:        longjmp(timer_env,1);
                    619: }
                    620:
                    621: void bus_handler(sig)
                    622: int sig;
                    623: {
                    624: #if defined(SIGBUS)
                    625:        signal(SIGBUS,bus_handler);
                    626:        error("internal error (BUS ERROR)");
                    627: #endif
                    628: }
                    629:
                    630: void fpe_handler(sig)
                    631: int sig;
                    632: {
                    633: #if defined(THINK_C) || defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
                    634:        signal(SIGFPE,fpe_handler);
                    635: #endif
                    636:        error("internal error (FPE)");
                    637: }
                    638:
                    639: void winch_handler(sig)
                    640: int sig;
                    641: {
                    642: #if 0
                    643: #if !defined(THINK_C) && !defined(VISUAL) && !defined(_PA_RISC1_1) && !defined(__svr4__)
                    644:        if ( isatty(1) ) {
                    645:                struct winsize t;
                    646:
                    647:                if ( ioctl(1,TIOCGWINSZ,&t) == -1 )
                    648:                        perror("TIOCGWINSZ");
                    649:                if ( t.ws_col != wsize.ws_col || t.ws_row != wsize.ws_row ) {
                    650:                        resize_buffer();
                    651:                        if ( killpg(getpgrp(0),SIGWINCH) == -1 )
                    652:                                perror("killpg");
                    653:                }
                    654:        }
                    655: #endif
                    656: #endif
                    657: }
                    658:
                    659: void pipe_handler(sig)
                    660: int sig;
                    661: {
                    662: #if defined(SIGPIPE)
                    663:        signal(SIGPIPE,pipe_handler);
                    664:        error("internal error (BROKEN PIPE)");
                    665: #endif
                    666: }
                    667:
                    668: void resize_buffer()
                    669: {
                    670: #if 0 && !defined(THINK_C) && !defined(VISUAL) && !defined(_PA_RISC1_1)
                    671:        if ( isatty(1) ) {
                    672:                if ( ioctl(1,TIOCGWINSZ,&wsize) == -1 )
                    673:                        perror("TIOCGWINSZ");
                    674:                if ( wsize.ws_col > 2 ) {
                    675:                        ttywidth = wsize.ws_col - 2;
                    676:                        upperbuf = (char *)MALLOC(wsize.ws_col);
                    677:                        lowerbuf = (char *)MALLOC(wsize.ws_col);
                    678:                }
                    679:        }
                    680: #endif
                    681: }
                    682:
                    683: void tty_init() {
                    684: #if 0 && !defined(THINK_C) && !defined(VISUAL) && !defined(_PA_RISC1_1)
                    685:        if ( isatty(0) ) {
                    686:                if ( ioctl(0,TIOCGETC,&tc) == -1 )
                    687:                        perror("TIOCGETC");
                    688:                oldeof = tc.t_eofc; tc.t_eofc = 0xff;
                    689:                if ( ioctl(0,TIOCSETC,&tc) == -1 )
                    690:                        perror("TIOCSETC");
                    691:                setpgrp(0, getpid());
                    692:        }
                    693:        resize_buffer();
                    694: #endif
                    695: }
                    696:
                    697: void tty_reset() {
                    698: #if 0 && !defined(THINK_C) && !defined(VISUAL) && !defined(_PA_RISC1_1)
                    699:        if ( oldeof ) {
                    700:                tc.t_eofc = oldeof;
                    701:                if ( ioctl(0,TIOCSETC,&tc) == -1 )
                    702:                        perror("TIOCSETC");
                    703:        }
                    704: #endif
                    705: }
                    706:
                    707: extern int evalstatline;
                    708:
                    709: void set_lasterror(s)
                    710: char *s;
                    711: {
                    712:        strncpy(LastError,s,BUFSIZ);
                    713:        LastError[BUFSIZ-1] = 0;
                    714: }
                    715:
                    716: SNODE error_snode;
                    717:
                    718: void error(s)
                    719: char *s;
                    720: {
                    721:        SNODE *snp;
                    722:
                    723:        fprintf(stderr,"%s\n",s);
                    724:        set_lasterror(s);
                    725:        if ( CPVS != GPVS ) {
1.7       noro      726:                if ( CPVS->usrf && CPVS->usrf && CPVS->usrf->f.usrf )
                    727:                        searchsn(&BDY(CPVS->usrf->f.usrf),evalstatline,&snp);
1.6       noro      728:                if ( snp )
                    729:                        error_snode = *snp;
                    730:                else
                    731:                        error_snode = 0;
1.1       noro      732:        } else
                    733:                error_snode = 0;
                    734:        if ( do_file ) {
                    735:                char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
                    736:
                    737:                sprintf(errbuf,"%s\n",s);
                    738:                showpos_to_string(errbuf+strlen(errbuf));
                    739:                set_lasterror(errbuf);
                    740:                ExitAsir();
                    741:        }
                    742:        if ( debug_mode )
                    743:                longjmp(debug_env,1);
                    744:        if ( CPVS != GPVS )
                    745:                if ( do_server_in_X11 || isatty(0) )
                    746:                        bp(error_snode);
                    747:        if ( read_exec_file )
                    748:                read_exec_file = 0;
                    749:        resetenv("return to toplevel");
                    750: }
                    751:
                    752: #if !defined(VISUAL)
                    753: #include <sys/time.h>
                    754:
                    755: void set_timer(interval)
                    756: int interval;
                    757: {
                    758:        struct itimerval it;
                    759:
                    760:        it.it_interval.tv_sec = interval;
                    761:        it.it_interval.tv_usec = 0;
                    762:        it.it_value.tv_sec = interval;
                    763:        it.it_value.tv_usec = 0;
                    764:        setitimer(ITIMER_VIRTUAL,&it,0);
                    765:        signal(SIGVTALRM,alrm_handler);
                    766: }
                    767:
                    768: void reset_timer()
                    769: {
                    770:        struct itimerval it;
                    771:
                    772:        it.it_interval.tv_sec = 0;
                    773:        it.it_interval.tv_usec = 0;
                    774:        it.it_value.tv_sec = 0;
                    775:        it.it_value.tv_usec = 0;
                    776:        setitimer(ITIMER_VIRTUAL,&it,0);
                    777:        signal(SIGVTALRM,SIG_IGN);
                    778: }
                    779: #endif
                    780:
                    781: unsigned int get_asir_version();
                    782:
                    783: void copyright() {
1.2       noro      784:        printf("This is Risa/Asir, Version %d.\n",get_asir_version());
1.1       noro      785:        printf("Copyright (C) FUJITSU LABORATORIES LIMITED.\n");
1.10      noro      786:        printf("1994-2000. All rights reserved.\n");
1.1       noro      787: }
1.5       noro      788:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>