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

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

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