[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.16

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.16    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/glob.c,v 1.15 2001/03/16 01:54:55 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
1.12      noro       56: #if !defined(VISUAL) && !defined(_PA_RISC1_1) && !defined(linux) && !defined(SYSV)
1.1       noro       57: #include <sgtty.h>
                     58: #endif
                     59:
                     60: #if defined(VISUAL)
                     61: #include <io.h>
                     62: #include <direct.h>
                     63: #endif
                     64:
                     65: #if defined(SYSV)
                     66: #include <sys/ttold.h>
                     67: #endif
                     68:
                     69: #if defined(VISUAL)
                     70: #define HISTORY asir_history
                     71: #endif
1.12      noro       72:
1.1       noro       73: #define MAXHIST 100
                     74:
                     75: extern int GC_free_space_divisor;
                     76: extern int GC_free_space_numerator;
                     77: extern FILE *asir_out;
                     78:
                     79: IN asir_infile;
                     80: jmp_buf env,debug_env,timer_env;
                     81: int little_endian,debug_mode;
                     82: char *asir_libdir;
                     83: char *asir_pager;
                     84:
                     85: NODE usrf,sysf,noargsysf,ubinf,parif;
                     86: NODE ONENODE;
                     87: int main_parser, ox_do_copy, ox_do_count, ox_count_length;
                     88: int ox_file_io, ox_need_conv;
                     89: char *ox_copy_bptr;
                     90: char *parse_strp;
                     91: SNODE parse_snode;
                     92: FUNC parse_targetf;
                     93: FILE *ox_istream,*ox_ostream;
                     94: int do_server_in_X11;
                     95: Obj LastVal;
                     96: char LastError[BUFSIZ];
1.15      noro       97: int timer_is_set;
                     98:
1.1       noro       99:
                    100: struct oV oVAR[] = {
                    101:        {"x",0,0}, {"y",0,0}, {"z",0,0}, {"u",0,0},
                    102:        {"v",0,0}, {"w",0,0}, {"p",0,0}, {"q",0,0},
                    103:        {"r",0,0}, {"s",0,0}, {"t",0,0}, {"a",0,0},
                    104:        {"b",0,0}, {"c",0,0}, {"d",0,0}, {"e",0,0},
                    105:        {"f",0,0}, {"g",0,0}, {"h",0,0}, {"i",0,0},
                    106:        {"j",0,0}, {"k",0,0}, {"l",0,0}, {"m",0,0},
                    107:        {"n",0,0}, {"o",0,0},
                    108:        {"_x",0,0}, {"_y",0,0}, {"_z",0,0}, {"_u",0,0},
                    109:        {"_v",0,0}, {"_w",0,0}, {"_p",0,0}, {"_q",0,0},
                    110:        {"_r",0,0}, {"_s",0,0}, {"_t",0,0}, {"_a",0,0},
                    111:        {"_b",0,0}, {"_c",0,0}, {"_d",0,0}, {"_e",0,0},
                    112:        {"_f",0,0}, {"_g",0,0}, {"_h",0,0}, {"_i",0,0},
                    113:        {"_j",0,0}, {"_k",0,0}, {"_l",0,0}, {"_m",0,0},
                    114:        {"_n",0,0}, {"_o",0,0}
                    115: };
                    116:
                    117: struct oVL oVLIST[52];
                    118:
                    119: VL CO = oVLIST;
                    120: VL ALG;
                    121:
                    122: struct oVS oGPVS,oAPVS,oEPVS;
                    123: VS GPVS = &oGPVS;
                    124: VS APVS = &oAPVS;
                    125: VS EPVS = &oEPVS;
                    126: VS CPVS;
                    127:
                    128: struct oF oF_TRUE,oF_FALSE;
                    129: F F_TRUE = &oF_TRUE;
                    130: F F_FALSE = &oF_FALSE;
                    131:
                    132: #if defined(__SVR4) && defined(sun)
1.4       noro      133: char cppname[BUFSIZ] = "/usr/ccs/lib/cpp ";
1.1       noro      134: #else
                    135: #if defined(__FreeBSD__) || defined(__NetBSD__)
1.4       noro      136: char cppname[BUFSIZ] = "/usr/bin/cpp ";
1.1       noro      137: #else
                    138: #if defined(VISUAL)
1.4       noro      139: char cppname[BUFSIZ] = "c:\\asir\\stdlib\\cpp ";
1.1       noro      140: #else
1.4       noro      141: char cppname[BUFSIZ] = "/lib/cpp ";
1.1       noro      142: #endif
                    143: #endif
                    144: #endif
1.4       noro      145: char asirname[BUFSIZ];
1.1       noro      146: char displayname[BUFSIZ];
                    147:
                    148: int Verbose;
                    149:
                    150: void glob_init() {
                    151:        int i;
                    152:
                    153:        for ( i = 0; i < 51; i++ ) {
                    154:                VR(&oVLIST[i]) = &oVAR[i]; NEXT(&oVLIST[i]) = &oVLIST[i+1];
                    155:        }
                    156:        VR(&oVLIST[i]) = &oVAR[i]; NEXT(&oVLIST[i]) = 0;
                    157:        reallocarray((char **)&GPVS->va,(int *)&GPVS->asize,(int *)&GPVS->n,(int)sizeof(struct oPV));
                    158:        reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
                    159:        CPVS = GPVS;
                    160:        MKNODE(ONENODE,mkfnode(1,I_FORMULA,ONE),0);
                    161:        OID(F_TRUE)=O_F; FOP(F_TRUE)=AL_TRUE; F_TRUE->arg.dummy = 0;
                    162:        OID(F_FALSE)=O_F; FOP(F_FALSE)=AL_FALSE; F_FALSE->arg.dummy = 0;
                    163:        sprintf(asirname,"%s/asir_symtab",asir_libdir);
                    164: }
                    165:
                    166: void input_init(fp,name)
                    167: FILE *fp;
                    168: char *name;
                    169: {
                    170:        asir_infile = (IN)CALLOC(sizeof(struct oIN),1);
                    171:        asir_infile->name = name; asir_infile->fp = fp;
                    172:        asir_infile->ln = 1; NEXT(asir_infile) = 0;
                    173: }
                    174:
                    175: void notdef(vl,a,b,c)
                    176: VL vl;
                    177: Obj a,b,*c;
                    178: {
                    179:        *c = 0;
                    180:        error("undefined arithmetic operation.");
                    181: }
                    182:
                    183: int kernelmode;
                    184: int do_asirrc;
                    185: int do_file;
                    186: int do_message;
                    187: int do_fep;
                    188: int no_prompt;
                    189: int read_exec_file;
                    190: static int buserr_sav;
                    191: static char asir_history[BUFSIZ];
                    192:
                    193: extern int mpi_myid;
                    194:
1.5       noro      195: #if !defined(VISUAL_LIB)
                    196: void ExitAsir() {
                    197:        exit(0);
                    198: }
                    199: #endif
                    200:
1.1       noro      201: /*
                    202:  * status = 1 abnormal termination (error() etc.)
                    203:  * status = 2 normal termination (end(), quit() etc.)
                    204:  */
                    205:
                    206: void asir_terminate(status)
                    207: int status;
                    208: {
                    209:        if ( read_exec_file ) {
                    210:                read_exec_file = 0; longjmp(env,status);
                    211:        } else {
                    212:                tty_reset();
                    213: #if MPI
                    214:                if ( !mpi_myid )
                    215:                        close_allconnections();
                    216:                mpi_finalize();
                    217: #else
                    218:                close_allconnections();
                    219: #endif
                    220:                if ( kernelmode )
                    221:                        fputc(0xff,asir_out);
                    222:                if ( asir_out )
                    223:                        fflush(asir_out);
1.13      saito     224: #if FEP
                    225:                if ( do_fep ) {
                    226:                        stifle_history(MAXHIST);
                    227:                        write_history(asir_history);
                    228:                }
                    229: #endif
1.1       noro      230:                ExitAsir();
                    231:        }
                    232: }
                    233:
                    234: void param_init() {
                    235:        unsigned int et = 0xff;
                    236:        extern int paristack;
                    237:        if ( *((char *)&et) )
                    238:                little_endian = 1;
                    239:        else
                    240:                little_endian = 0;
                    241: }
                    242:
                    243: void prompt() {
                    244:        if ( !no_prompt && !do_fep && asir_infile->fp == stdin )
                    245:                fprintf(asir_out,"[%d]%c",APVS->n,kernelmode?0xfe:' ');
                    246:        fflush(asir_out);
                    247: }
                    248:
                    249: void sprompt(ptr)
                    250: char *ptr;
                    251: {
                    252:        sprintf(ptr,"[%d]%c",APVS->n,kernelmode?0xfe:' ');
                    253: }
                    254:
                    255: FILE *in_fp;
                    256:
                    257: void process_args(ac,av)
                    258: int ac;
                    259: char **av;
                    260: {
                    261:        do_asirrc = 1;
                    262: #if !MPI
                    263:        do_message = 1;
                    264: #endif
                    265:        while ( ac > 0 ) {
                    266:                if ( !strcmp(*av,"-heap") && (ac >= 2) ) {
                    267:                        void GC_expand_hp(int);
                    268:
                    269:                        GC_expand_hp(atoi(*(av+1))); av += 2; ac -= 2;
                    270:                } else if ( !strcmp(*av,"-adj") && (ac >= 2) ) {
                    271:                        char *slash;
                    272:
                    273:                        slash = strrchr(*(av+1),'/');
                    274:                        if ( slash ) {
                    275:                                *slash = 0;
                    276:                                GC_free_space_numerator = atoi(slash+1);
                    277:                        }
                    278:                        GC_free_space_divisor = atoi(*(av+1));
                    279:                        av += 2; ac -= 2;
                    280:                } else if ( !strcmp(*av,"-cpp") && (ac >= 2) ) {
                    281:                        strcpy(cppname,*(av+1)); av += 2; ac -= 2;
                    282:                } else if ( !strcmp(*av,"-f") && (ac >= 2) ) {
                    283:                        in_fp = fopen(*(av+1),"r");
                    284:                        if ( !in_fp ) {
                    285:                                fprintf(stderr,"%s does not exist!",*(av+1));
                    286:                                asir_terminate(1);
                    287:                        }
                    288:                        do_file = 1;
                    289:                        av += 2; ac -= 2;
                    290:                } else if ( !strcmp(*av,"-kernel") ) {
                    291:                        kernelmode = 1; av++; ac--;
                    292:                } else if ( !strcmp(*av,"-norc") ) {
                    293:                        do_asirrc = 0; av++; ac--;
                    294:                } else if ( !strcmp(*av,"-nomessage") ) {
                    295:                        do_message = 0; av++; ac--;
                    296:                } else if ( !strcmp(*av,"-terse") ) {
                    297:                        no_prompt = 0; av++; ac--;
1.11      noro      298:                } else if ( !strcmp(*av,"-rootdir") && (ac >= 2) ) {
                    299:                        set_rootdir(*(av+1)); av += 2; ac -= 2;
1.1       noro      300:                } else if ( !strcmp(*av,"-maxheap") && (ac >= 2) ) {
                    301:                        void GC_set_max_heap_size(int);
                    302:
                    303:                        GC_set_max_heap_size(atoi(*(av+1))); av += 2; ac -= 2;
                    304: #if !defined(VISUAL)
                    305:                } else if ( !strcmp(*av,"-display") && (ac >= 2) ) {
                    306:                        strcpy(displayname,*(av+1)); av += 2; ac -= 2;
                    307: #endif
1.13      saito     308: #if FEP
                    309:                } else if ( !strcmp(*av,"-fep") ) {
                    310:                        do_fep = 1; av++; ac--;
                    311: #endif
1.1       noro      312: #if PARI
                    313:                } else if ( !strcmp(*av,"-paristack") ) {
                    314:                        extern int paristack;
                    315:
                    316:                        paristack = atoi(*(av+1)); av += 2; ac -= 2;
                    317: #endif
                    318:                } else {
                    319:                        fprintf(stderr,"%s : unknown option.\n",*av);
                    320:                        asir_terminate(1);
                    321:                }
                    322:        }
1.13      saito     323: #if FEP
                    324:        if ( do_fep ) {
                    325:                char *home;
                    326:                home = (char *)getenv("HOME");
                    327:                if (!home)
                    328:                        home = ".";
                    329:                sprintf (asir_history, "%s/.asir_history",home);
                    330:                read_history(asir_history);
                    331:                using_history();
                    332:        }
                    333: #endif
1.1       noro      334: }
                    335:
                    336: #include <signal.h>
                    337:
                    338: void sig_init() {
                    339: #if !defined(VISUAL)
                    340:        signal(SIGINT,int_handler);
                    341: #else
                    342:        register_ctrlc_handler();
                    343: #endif
                    344:        signal(SIGSEGV,segv_handler);
                    345:
                    346: #if defined SIGFPE
                    347:        signal(SIGFPE,fpe_handler);
                    348: #endif
                    349:
                    350: #if defined SIGPIPE
                    351:        signal(SIGPIPE,pipe_handler);
                    352: #endif
                    353:
                    354: #if defined SIGILL
                    355:        signal(SIGILL,ill_handler);
                    356: #endif
                    357:
                    358: #if !defined(VISUAL)
                    359:        signal(SIGBUS,bus_handler);
                    360: #endif
                    361: }
                    362:
                    363: static void (*old_int)(int);
                    364:
                    365: void asir_save_handler() {
                    366:        old_int = signal(SIGINT,SIG_IGN);
                    367:        signal(SIGINT,old_int);
                    368: }
                    369:
                    370: void asir_set_handler() {
                    371:        signal(SIGINT,int_handler);
                    372: }
                    373:
                    374: void asir_reset_handler() {
                    375:        signal(SIGINT,old_int);
                    376: }
                    377:
                    378: void resetenv(s)
                    379: char *s;
                    380: {
                    381:        extern FILE *outfile;
                    382:
                    383:        fprintf(stderr,"%s\n",s);
                    384:        while ( NEXT(asir_infile) )
                    385:                closecurrentinput();
                    386:        resetpvs();
                    387: #if !defined(VISUAL)
                    388:        if ( do_server_in_X11 )
                    389: #endif
                    390:                show_debug_window(0);
                    391: #if defined(VISUAL_LIB)
                    392:        w_noflush_stderr(0);
                    393: #endif
                    394:        asir_out = stdout;
                    395: #if PARI
                    396:        pari_outfile = stdout;
                    397: #endif
                    398:        /* restore states */
                    399:        reset_engine();
                    400:        reset_io();
1.16    ! noro      401: #if !defined(VISUAL)
1.15      noro      402:        reset_timer();
1.16    ! noro      403: #endif
1.1       noro      404:        longjmp(env,1);
                    405: }
                    406:
                    407: void fatal(n)
                    408: int n;
                    409: {
                    410:        resetenv("return to toplevel");
                    411: }
                    412:
                    413: FUNC registered_handler;
                    414: extern int ox_int_received, critical_when_signal;
                    415:
                    416: void int_handler(sig)
                    417: int sig;
                    418: {
                    419:        extern NODE PVSS;
                    420:
                    421:        if ( do_file ) {
                    422:                ExitAsir();
                    423:        }
                    424:        if ( critical_when_signal ) {
                    425:                ox_int_received = 1;
                    426:                return;
                    427:        }
1.12      noro      428: #if defined(VISUAL)
1.1       noro      429:        suspend_timer(); signal(SIGINT,SIG_IGN);
                    430: #endif
                    431: #if defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
                    432:        signal(SIGINT,SIG_IGN);
1.3       noro      433: #endif
                    434: #if !defined(VISUAL)
                    435:     if ( do_server_in_X11 ) {
                    436:                debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
                    437:                restore_handler();
                    438:                return;
                    439:        }
1.1       noro      440: #endif
                    441: #if defined(linux)
                    442: #if 1
                    443:        while ( stdin->_IO_read_ptr < stdin->_IO_read_end )
                    444: #else
                    445:        while ( stdin->_gptr < stdin->_egptr )
                    446: #endif
                    447:                getchar();
                    448: #endif
                    449:        while ( 1 ) {
                    450:                char buf[BUFSIZ];
                    451:                char c;
                    452:
                    453:                fprintf(stderr,"interrupt ?(q/t/c/d/u/w/?) "); fflush(stderr);
                    454:                if ( kernelmode )
                    455:                        fputc('\0',stderr);
                    456:                buf[0] = '\n';
                    457:                while ( buf[0] == '\n' )
                    458:                        fgets(buf,BUFSIZ,stdin);
                    459:                switch ( c = buf[0] ) {
                    460:                        case 'q':
                    461:                                while ( 1 ) {
                    462:                                        fprintf(stderr,"Abort this session? (y or n) "); fflush(stderr);
                    463:                                        fgets(buf,BUFSIZ,stdin);
                    464:                                        if ( !strncmp(buf,"y",1) ) {
                    465:                                                read_exec_file = 0;
                    466:                                                fprintf(stderr,"Bye\n"); asir_terminate(1);
                    467:                                        } else if ( !strncmp(buf,"n",1) ) {
                    468:                                                restore_handler();
                    469:                                                return;
                    470:                                        }
                    471:                                }
                    472:                                break;
                    473:                        case 't':
                    474:                        case 'u':
                    475:                                while ( 1 ) {
                    476:                                        fprintf(stderr,"Abort this computation? (y or n) "); fflush(stderr);
                    477:                                        fgets(buf,BUFSIZ,stdin);
                    478:                                        if ( !strncmp(buf,"y",1) )
                    479:                                                break;
                    480:                                        else if ( !strncmp(buf,"n",1) ) {
                    481:                                                restore_handler();
                    482:                                                return;
                    483:                                        }
                    484:                                }
                    485:                                if ( debug_mode )
                    486:                                        debug_mode = 0;
                    487:                                if ( kernelmode )
                    488:                                        fputc('\0',stderr);
                    489:                                restore_handler();
                    490:                                if ( c == 'u' ) {
                    491:                                        if ( registered_handler ) {
                    492:                                                fprintf(stderr,
                    493:                                                        "Calling the registered exception handler...");
                    494:                                                bevalf(registered_handler,0);
                    495:                                                fprintf(stderr, "done.\n");
                    496:                                        }
                    497:                                }
                    498:                                if ( read_exec_file ) {
                    499:                                        read_exec_file = 0;
                    500:                                        resetenv("initialization aborted; return to toplevel");
                    501:                                } else
                    502:                                        resetenv("return to toplevel");
                    503:                                break;
                    504:                        case 'd':
                    505: #if 0
                    506:                                nextbp = 1; nextbplevel = -1;
                    507: #endif
                    508:                                debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
                    509:                                restore_handler();
                    510:                                return;
                    511:                        case 'c':
                    512:                                if ( kernelmode )
                    513:                                        fputc('\0',stderr);
                    514:                                restore_handler();
                    515:                                return; break;
                    516:                        case 'w':
                    517:                                showpos(); break;
                    518:                        case '?':
                    519:                                fprintf(stderr, "q:quit t:toplevel c:continue d:debug u:call registered handler w:where\n");
                    520:                                break;
                    521:                        default:
                    522:                                break;
                    523:                }
                    524:        }
                    525: }
                    526:
                    527: void restore_handler() {
1.12      noro      528: #if defined(VISUAL)
1.1       noro      529:        resume_timer(); signal(SIGINT,int_handler);
                    530: #endif
                    531: #if defined(_PA_RISC1_1) || defined(linux) || defined(__svr4__)
                    532:        signal(SIGINT,int_handler);
                    533: #endif
                    534: }
                    535:
                    536: void segv_handler(sig)
                    537: int sig;
                    538: {
1.12      noro      539: #if defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
1.1       noro      540:        signal(SIGSEGV,segv_handler);
                    541: #endif
                    542:        error("internal error (SEGV)");
                    543: }
                    544:
                    545: void ill_handler(sig)
                    546: int sig;
                    547: {
1.12      noro      548: #if defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
1.1       noro      549:        signal(SIGILL,ill_handler);
                    550: #endif
                    551:        error("illegal instruction (ILL)");
                    552: }
                    553:
                    554: void alrm_handler(sig)
                    555: int sig;
                    556: {
                    557:        fprintf(stderr,"interval timer expired (VTALRM)\n");
                    558:        longjmp(timer_env,1);
                    559: }
                    560:
                    561: void bus_handler(sig)
                    562: int sig;
                    563: {
                    564: #if defined(SIGBUS)
                    565:        signal(SIGBUS,bus_handler);
                    566:        error("internal error (BUS ERROR)");
                    567: #endif
                    568: }
                    569:
                    570: void fpe_handler(sig)
                    571: int sig;
                    572: {
1.12      noro      573: #if defined(_PA_RISC1_1) || defined(linux) || defined(VISUAL) || defined(__svr4__)
1.1       noro      574:        signal(SIGFPE,fpe_handler);
                    575: #endif
                    576:        error("internal error (FPE)");
                    577: }
                    578:
                    579: void pipe_handler(sig)
                    580: int sig;
                    581: {
                    582: #if defined(SIGPIPE)
                    583:        signal(SIGPIPE,pipe_handler);
                    584:        error("internal error (BROKEN PIPE)");
                    585: #endif
                    586: }
                    587:
                    588: void resize_buffer()
                    589: {
                    590: }
                    591:
                    592: void tty_init() {
                    593: }
                    594:
                    595: void tty_reset() {
                    596: }
                    597:
                    598: extern int evalstatline;
                    599:
                    600: void set_lasterror(s)
                    601: char *s;
                    602: {
                    603:        strncpy(LastError,s,BUFSIZ);
                    604:        LastError[BUFSIZ-1] = 0;
                    605: }
                    606:
                    607: SNODE error_snode;
                    608:
                    609: void error(s)
                    610: char *s;
                    611: {
                    612:        SNODE *snp;
                    613:
1.16    ! noro      614: #if !defined(VISUAL)
1.15      noro      615:        if ( timer_is_set )
                    616:                alrm_handler(SIGVTALRM);
1.16    ! noro      617: #endif
1.1       noro      618:        fprintf(stderr,"%s\n",s);
                    619:        set_lasterror(s);
                    620:        if ( CPVS != GPVS ) {
1.7       noro      621:                if ( CPVS->usrf && CPVS->usrf && CPVS->usrf->f.usrf )
                    622:                        searchsn(&BDY(CPVS->usrf->f.usrf),evalstatline,&snp);
1.6       noro      623:                if ( snp )
                    624:                        error_snode = *snp;
                    625:                else
                    626:                        error_snode = 0;
1.1       noro      627:        } else
                    628:                error_snode = 0;
                    629:        if ( do_file ) {
                    630:                char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
                    631:
                    632:                sprintf(errbuf,"%s\n",s);
                    633:                showpos_to_string(errbuf+strlen(errbuf));
                    634:                set_lasterror(errbuf);
                    635:                ExitAsir();
                    636:        }
                    637:        if ( debug_mode )
                    638:                longjmp(debug_env,1);
                    639:        if ( CPVS != GPVS )
                    640:                if ( do_server_in_X11 || isatty(0) )
                    641:                        bp(error_snode);
                    642:        if ( read_exec_file )
                    643:                read_exec_file = 0;
                    644:        resetenv("return to toplevel");
                    645: }
                    646:
                    647: #if !defined(VISUAL)
                    648: #include <sys/time.h>
                    649:
                    650: void set_timer(interval)
                    651: int interval;
                    652: {
                    653:        struct itimerval it;
                    654:
                    655:        it.it_interval.tv_sec = interval;
                    656:        it.it_interval.tv_usec = 0;
                    657:        it.it_value.tv_sec = interval;
                    658:        it.it_value.tv_usec = 0;
                    659:        setitimer(ITIMER_VIRTUAL,&it,0);
                    660:        signal(SIGVTALRM,alrm_handler);
1.15      noro      661:        timer_is_set = 1;
1.1       noro      662: }
                    663:
                    664: void reset_timer()
                    665: {
                    666:        struct itimerval it;
                    667:
                    668:        it.it_interval.tv_sec = 0;
                    669:        it.it_interval.tv_usec = 0;
                    670:        it.it_value.tv_sec = 0;
                    671:        it.it_value.tv_usec = 0;
                    672:        setitimer(ITIMER_VIRTUAL,&it,0);
                    673:        signal(SIGVTALRM,SIG_IGN);
1.15      noro      674:        timer_is_set = 0;
1.1       noro      675: }
                    676: #endif
                    677:
                    678: unsigned int get_asir_version();
1.14      noro      679: char *get_asir_distribution();
1.1       noro      680:
                    681: void copyright() {
1.14      noro      682:        printf("This is Risa/Asir, Version %d (%s Distribution).\n",
                    683:                get_asir_version(), get_asir_distribution());
                    684:        printf("Copyright (C) 1994-2000, all rights reserved, FUJITSU LABORATORIES LIMITED.\n");
                    685:        printf("Copyright 2000,2001, Risa/Asir committers, http://www.openxm.org/.\n");
                    686:        printf("GC 5.3, copyright 1999, H-J. Boehm, A. J. Demers, Xerox, SGI, HP.\n");
                    687:        printf("PARI 2.0.17(beta), copyright (C) 1989-1999,\n");
                    688:        printf("     C. Batut, K. Belabas, D. Bernardi, H. Cohen and M. Olivier.\n");
1.1       noro      689: }
1.14      noro      690:
1.5       noro      691:

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