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

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

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