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

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

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