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

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.22    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/glob.c,v 1.21 2001/08/20 09:03:27 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:
1.19      noro       65: #if defined(SYSV) && !defined(_IBMR2)
1.1       noro       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;
1.21      noro       80: jmp_buf main_env,debug_env,timer_env,exec_env;
1.1       noro       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
1.18      noro      135: #if defined(__FreeBSD__) || defined(__NetBSD__) || (defined(__MACH__) && defined(__ppc__))
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:        error("undefined arithmetic operation.");
                    180: }
                    181:
                    182: int do_asirrc;
                    183: int do_file;
                    184: int do_message;
                    185: int do_fep;
                    186: int no_prompt;
                    187: int read_exec_file;
                    188: static int buserr_sav;
                    189: static char asir_history[BUFSIZ];
                    190:
                    191: extern int mpi_myid;
                    192:
1.5       noro      193: #if !defined(VISUAL_LIB)
                    194: void ExitAsir() {
                    195:        exit(0);
                    196: }
                    197: #endif
                    198:
1.1       noro      199: /*
                    200:  * status = 1 abnormal termination (error() etc.)
                    201:  * status = 2 normal termination (end(), quit() etc.)
                    202:  */
                    203:
                    204: void asir_terminate(status)
                    205: int status;
                    206: {
1.21      noro      207:        int t;
                    208:
1.1       noro      209:        if ( read_exec_file ) {
1.21      noro      210:                t = read_exec_file;
                    211:                read_exec_file = 0;
                    212:                if ( t == 1 )
                    213:                        longjmp(main_env,status);
                    214:                else
                    215:                        longjmp(exec_env,status);
1.1       noro      216:        } else {
                    217:                tty_reset();
                    218: #if MPI
                    219:                if ( !mpi_myid )
                    220:                        close_allconnections();
                    221:                mpi_finalize();
                    222: #else
1.20      noro      223: #if defined(SIGPIPE)
                    224:                signal(SIGPIPE,SIG_IGN);
                    225: #endif
1.1       noro      226:                close_allconnections();
                    227: #endif
                    228:                if ( asir_out )
                    229:                        fflush(asir_out);
1.13      saito     230: #if FEP
                    231:                if ( do_fep ) {
                    232:                        stifle_history(MAXHIST);
                    233:                        write_history(asir_history);
                    234:                }
                    235: #endif
1.1       noro      236:                ExitAsir();
                    237:        }
                    238: }
                    239:
                    240: void param_init() {
                    241:        unsigned int et = 0xff;
                    242:        extern int paristack;
                    243:        if ( *((char *)&et) )
                    244:                little_endian = 1;
                    245:        else
                    246:                little_endian = 0;
                    247: }
                    248:
                    249: void prompt() {
                    250:        if ( !no_prompt && !do_fep && asir_infile->fp == stdin )
1.21      noro      251:                fprintf(asir_out,"[%d] ",APVS->n);
1.1       noro      252:        fflush(asir_out);
                    253: }
                    254:
                    255: void sprompt(ptr)
                    256: char *ptr;
                    257: {
1.21      noro      258:        sprintf(ptr,"[%d] ",APVS->n);
1.1       noro      259: }
                    260:
                    261: FILE *in_fp;
                    262:
                    263: void process_args(ac,av)
                    264: int ac;
                    265: char **av;
                    266: {
                    267:        do_asirrc = 1;
                    268: #if !MPI
                    269:        do_message = 1;
                    270: #endif
                    271:        while ( ac > 0 ) {
                    272:                if ( !strcmp(*av,"-heap") && (ac >= 2) ) {
                    273:                        void GC_expand_hp(int);
                    274:
                    275:                        GC_expand_hp(atoi(*(av+1))); av += 2; ac -= 2;
                    276:                } else if ( !strcmp(*av,"-adj") && (ac >= 2) ) {
                    277:                        char *slash;
                    278:
                    279:                        slash = strrchr(*(av+1),'/');
                    280:                        if ( slash ) {
                    281:                                *slash = 0;
                    282:                                GC_free_space_numerator = atoi(slash+1);
                    283:                        }
                    284:                        GC_free_space_divisor = atoi(*(av+1));
                    285:                        av += 2; ac -= 2;
                    286:                } else if ( !strcmp(*av,"-cpp") && (ac >= 2) ) {
                    287:                        strcpy(cppname,*(av+1)); av += 2; ac -= 2;
                    288:                } else if ( !strcmp(*av,"-f") && (ac >= 2) ) {
                    289:                        in_fp = fopen(*(av+1),"r");
                    290:                        if ( !in_fp ) {
                    291:                                fprintf(stderr,"%s does not exist!",*(av+1));
                    292:                                asir_terminate(1);
                    293:                        }
                    294:                        do_file = 1;
                    295:                        av += 2; ac -= 2;
                    296:                } else if ( !strcmp(*av,"-norc") ) {
                    297:                        do_asirrc = 0; av++; ac--;
                    298:                } else if ( !strcmp(*av,"-nomessage") ) {
                    299:                        do_message = 0; av++; ac--;
                    300:                } else if ( !strcmp(*av,"-terse") ) {
                    301:                        no_prompt = 0; av++; ac--;
1.11      noro      302:                } else if ( !strcmp(*av,"-rootdir") && (ac >= 2) ) {
                    303:                        set_rootdir(*(av+1)); av += 2; ac -= 2;
1.1       noro      304:                } else if ( !strcmp(*av,"-maxheap") && (ac >= 2) ) {
                    305:                        void GC_set_max_heap_size(int);
                    306:
                    307:                        GC_set_max_heap_size(atoi(*(av+1))); av += 2; ac -= 2;
                    308: #if !defined(VISUAL)
                    309:                } else if ( !strcmp(*av,"-display") && (ac >= 2) ) {
                    310:                        strcpy(displayname,*(av+1)); av += 2; ac -= 2;
                    311: #endif
1.13      saito     312: #if FEP
                    313:                } else if ( !strcmp(*av,"-fep") ) {
                    314:                        do_fep = 1; av++; ac--;
                    315: #endif
1.1       noro      316: #if PARI
                    317:                } else if ( !strcmp(*av,"-paristack") ) {
                    318:                        extern int paristack;
                    319:
                    320:                        paristack = atoi(*(av+1)); av += 2; ac -= 2;
                    321: #endif
                    322:                } else {
                    323:                        fprintf(stderr,"%s : unknown option.\n",*av);
                    324:                        asir_terminate(1);
                    325:                }
                    326:        }
1.13      saito     327: #if FEP
                    328:        if ( do_fep ) {
                    329:                char *home;
                    330:                home = (char *)getenv("HOME");
                    331:                if (!home)
                    332:                        home = ".";
                    333:                sprintf (asir_history, "%s/.asir_history",home);
                    334:                read_history(asir_history);
                    335:                using_history();
                    336:        }
                    337: #endif
1.1       noro      338: }
                    339:
                    340: #include <signal.h>
                    341:
                    342: void sig_init() {
                    343: #if !defined(VISUAL)
                    344:        signal(SIGINT,int_handler);
                    345: #else
                    346:        register_ctrlc_handler();
                    347: #endif
                    348:        signal(SIGSEGV,segv_handler);
                    349:
                    350: #if defined SIGFPE
                    351:        signal(SIGFPE,fpe_handler);
                    352: #endif
                    353:
                    354: #if defined SIGPIPE
                    355:        signal(SIGPIPE,pipe_handler);
                    356: #endif
                    357:
                    358: #if defined SIGILL
                    359:        signal(SIGILL,ill_handler);
                    360: #endif
                    361:
                    362: #if !defined(VISUAL)
                    363:        signal(SIGBUS,bus_handler);
                    364: #endif
                    365: }
                    366:
                    367: static void (*old_int)(int);
                    368:
                    369: void asir_save_handler() {
                    370:        old_int = signal(SIGINT,SIG_IGN);
                    371:        signal(SIGINT,old_int);
                    372: }
                    373:
                    374: void asir_set_handler() {
                    375:        signal(SIGINT,int_handler);
                    376: }
                    377:
                    378: void asir_reset_handler() {
                    379:        signal(SIGINT,old_int);
                    380: }
                    381:
                    382: void resetenv(s)
                    383: char *s;
                    384: {
                    385:        extern FILE *outfile;
                    386:
                    387:        fprintf(stderr,"%s\n",s);
                    388:        while ( NEXT(asir_infile) )
                    389:                closecurrentinput();
                    390:        resetpvs();
                    391: #if !defined(VISUAL)
                    392:        if ( do_server_in_X11 )
                    393: #endif
                    394:                show_debug_window(0);
                    395: #if defined(VISUAL_LIB)
                    396:        w_noflush_stderr(0);
                    397: #endif
                    398:        asir_out = stdout;
                    399: #if PARI
                    400:        pari_outfile = stdout;
                    401: #endif
                    402:        /* restore states */
                    403:        reset_engine();
                    404:        reset_io();
1.16      noro      405: #if !defined(VISUAL)
1.15      noro      406:        reset_timer();
1.16      noro      407: #endif
1.21      noro      408:        longjmp(main_env,1);
1.1       noro      409: }
                    410:
                    411: void fatal(n)
                    412: int n;
                    413: {
                    414:        resetenv("return to toplevel");
                    415: }
                    416:
                    417: FUNC registered_handler;
                    418: extern int ox_int_received, critical_when_signal;
                    419:
                    420: void int_handler(sig)
                    421: int sig;
                    422: {
                    423:        extern NODE PVSS;
                    424:
                    425:        if ( do_file ) {
                    426:                ExitAsir();
                    427:        }
                    428:        if ( critical_when_signal ) {
                    429:                ox_int_received = 1;
                    430:                return;
                    431:        }
1.12      noro      432: #if defined(VISUAL)
1.19      noro      433:        suspend_timer();
1.1       noro      434: #endif
                    435:        signal(SIGINT,SIG_IGN);
1.3       noro      436: #if !defined(VISUAL)
                    437:     if ( do_server_in_X11 ) {
                    438:                debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
                    439:                restore_handler();
                    440:                return;
                    441:        }
1.1       noro      442: #endif
                    443: #if defined(linux)
                    444: #if 1
                    445:        while ( stdin->_IO_read_ptr < stdin->_IO_read_end )
                    446: #else
                    447:        while ( stdin->_gptr < stdin->_egptr )
                    448: #endif
                    449:                getchar();
                    450: #endif
                    451:        while ( 1 ) {
                    452:                char buf[BUFSIZ];
                    453:                char c;
                    454:
                    455:                fprintf(stderr,"interrupt ?(q/t/c/d/u/w/?) "); fflush(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:                                restore_handler();
                    488:                                if ( c == 'u' ) {
                    489:                                        if ( registered_handler ) {
                    490:                                                fprintf(stderr,
                    491:                                                        "Calling the registered exception handler...");
                    492:                                                bevalf(registered_handler,0);
                    493:                                                fprintf(stderr, "done.\n");
                    494:                                        }
                    495:                                }
                    496:                                if ( read_exec_file ) {
                    497:                                        read_exec_file = 0;
                    498:                                        resetenv("initialization aborted; return to toplevel");
                    499:                                } else
                    500:                                        resetenv("return to toplevel");
                    501:                                break;
                    502:                        case 'd':
                    503: #if 0
                    504:                                nextbp = 1; nextbplevel = -1;
                    505: #endif
                    506:                                debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
                    507:                                restore_handler();
                    508:                                return;
                    509:                        case 'c':
                    510:                                restore_handler();
                    511:                                return; break;
                    512:                        case 'w':
                    513:                                showpos(); break;
                    514:                        case '?':
                    515:                                fprintf(stderr, "q:quit t:toplevel c:continue d:debug u:call registered handler w:where\n");
                    516:                                break;
                    517:                        default:
                    518:                                break;
                    519:                }
                    520:        }
                    521: }
                    522:
                    523: void restore_handler() {
1.12      noro      524: #if defined(VISUAL)
1.19      noro      525:        resume_timer();
1.1       noro      526: #endif
1.19      noro      527: #if defined(SIGINT)
1.1       noro      528:        signal(SIGINT,int_handler);
                    529: #endif
                    530: }
                    531:
                    532: void segv_handler(sig)
                    533: int sig;
                    534: {
1.19      noro      535: #if defined(SIGSEGV)
1.1       noro      536:        signal(SIGSEGV,segv_handler);
1.19      noro      537:        error("internal error (SEGV)");
1.1       noro      538: #endif
                    539: }
                    540:
                    541: void ill_handler(sig)
                    542: int sig;
                    543: {
1.19      noro      544: #if defined(SIGILL)
1.1       noro      545:        signal(SIGILL,ill_handler);
1.19      noro      546:        error("illegal instruction (ILL)");
1.1       noro      547: #endif
                    548: }
                    549:
                    550: void alrm_handler(sig)
                    551: int sig;
                    552: {
                    553:        fprintf(stderr,"interval timer expired (VTALRM)\n");
                    554:        longjmp(timer_env,1);
                    555: }
                    556:
                    557: void bus_handler(sig)
                    558: int sig;
                    559: {
                    560: #if defined(SIGBUS)
                    561:        signal(SIGBUS,bus_handler);
                    562:        error("internal error (BUS ERROR)");
                    563: #endif
                    564: }
                    565:
                    566: void fpe_handler(sig)
                    567: int sig;
                    568: {
1.19      noro      569: #if defined(SIGFPE)
1.1       noro      570:        signal(SIGFPE,fpe_handler);
1.19      noro      571:        error("internal error (FPE)");
1.1       noro      572: #endif
                    573: }
                    574:
                    575: void pipe_handler(sig)
                    576: int sig;
                    577: {
                    578: #if defined(SIGPIPE)
                    579:        signal(SIGPIPE,pipe_handler);
1.20      noro      580:        end_critical();
1.1       noro      581:        error("internal error (BROKEN PIPE)");
                    582: #endif
                    583: }
                    584:
                    585: void resize_buffer()
                    586: {
                    587: }
                    588:
                    589: void tty_init() {
                    590: }
                    591:
                    592: void tty_reset() {
                    593: }
                    594:
                    595: extern int evalstatline;
                    596:
                    597: void set_lasterror(s)
                    598: char *s;
                    599: {
                    600:        strncpy(LastError,s,BUFSIZ);
                    601:        LastError[BUFSIZ-1] = 0;
                    602: }
                    603:
                    604: SNODE error_snode;
                    605:
                    606: void error(s)
                    607: char *s;
                    608: {
                    609:        SNODE *snp;
                    610:
1.16      noro      611: #if !defined(VISUAL)
1.15      noro      612:        if ( timer_is_set )
                    613:                alrm_handler(SIGVTALRM);
1.16      noro      614: #endif
1.1       noro      615:        fprintf(stderr,"%s\n",s);
                    616:        set_lasterror(s);
                    617:        if ( CPVS != GPVS ) {
1.7       noro      618:                if ( CPVS->usrf && CPVS->usrf && CPVS->usrf->f.usrf )
                    619:                        searchsn(&BDY(CPVS->usrf->f.usrf),evalstatline,&snp);
1.6       noro      620:                if ( snp )
                    621:                        error_snode = *snp;
                    622:                else
                    623:                        error_snode = 0;
1.1       noro      624:        } else
                    625:                error_snode = 0;
                    626:        if ( do_file ) {
                    627:                char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
                    628:
                    629:                sprintf(errbuf,"%s\n",s);
                    630:                showpos_to_string(errbuf+strlen(errbuf));
                    631:                set_lasterror(errbuf);
                    632:                ExitAsir();
                    633:        }
                    634:        if ( debug_mode )
                    635:                longjmp(debug_env,1);
                    636:        if ( CPVS != GPVS )
                    637:                if ( do_server_in_X11 || isatty(0) )
                    638:                        bp(error_snode);
                    639:        if ( read_exec_file )
                    640:                read_exec_file = 0;
                    641:        resetenv("return to toplevel");
                    642: }
                    643:
                    644: #if !defined(VISUAL)
                    645: #include <sys/time.h>
                    646:
                    647: void set_timer(interval)
                    648: int interval;
                    649: {
                    650:        struct itimerval it;
                    651:
                    652:        it.it_interval.tv_sec = interval;
                    653:        it.it_interval.tv_usec = 0;
                    654:        it.it_value.tv_sec = interval;
                    655:        it.it_value.tv_usec = 0;
                    656:        setitimer(ITIMER_VIRTUAL,&it,0);
                    657:        signal(SIGVTALRM,alrm_handler);
1.15      noro      658:        timer_is_set = 1;
1.1       noro      659: }
                    660:
                    661: void reset_timer()
                    662: {
                    663:        struct itimerval it;
                    664:
                    665:        it.it_interval.tv_sec = 0;
                    666:        it.it_interval.tv_usec = 0;
                    667:        it.it_value.tv_sec = 0;
                    668:        it.it_value.tv_usec = 0;
                    669:        setitimer(ITIMER_VIRTUAL,&it,0);
                    670:        signal(SIGVTALRM,SIG_IGN);
1.15      noro      671:        timer_is_set = 0;
1.1       noro      672: }
                    673: #endif
                    674:
                    675: unsigned int get_asir_version();
1.14      noro      676: char *get_asir_distribution();
1.1       noro      677:
                    678: void copyright() {
1.17      noro      679: #if defined(INTERVAL)
                    680:        printf("This is Risa/Asir + Interval Arithmetic, Version %d (%s Distribution).\n",
                    681:                get_asir_version(), get_asir_distribution());
                    682: #else
1.14      noro      683:        printf("This is Risa/Asir, Version %d (%s Distribution).\n",
                    684:                get_asir_version(), get_asir_distribution());
1.17      noro      685: #endif
1.14      noro      686:        printf("Copyright (C) 1994-2000, all rights reserved, FUJITSU LABORATORIES LIMITED.\n");
                    687:        printf("Copyright 2000,2001, Risa/Asir committers, http://www.openxm.org/.\n");
                    688:        printf("GC 5.3, copyright 1999, H-J. Boehm, A. J. Demers, Xerox, SGI, HP.\n");
                    689:        printf("PARI 2.0.17(beta), copyright (C) 1989-1999,\n");
                    690:        printf("     C. Batut, K. Belabas, D. Bernardi, H. Cohen and M. Olivier.\n");
1.1       noro      691: }
1.14      noro      692:
1.5       noro      693:

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