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

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.39    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/glob.c,v 1.38 2003/10/19 02:54:41 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.36      noro      135: char *CUR_FUNC;
1.1       noro      136:
                    137: struct oF oF_TRUE,oF_FALSE;
                    138: F F_TRUE = &oF_TRUE;
                    139: F F_FALSE = &oF_FALSE;
                    140:
                    141: #if defined(VISUAL)
1.4       noro      142: char cppname[BUFSIZ] = "c:\\asir\\stdlib\\cpp ";
1.1       noro      143: #else
1.4       noro      144: char cppname[BUFSIZ] = "/lib/cpp ";
1.1       noro      145: #endif
1.4       noro      146: char asirname[BUFSIZ];
1.1       noro      147: char displayname[BUFSIZ];
                    148:
                    149: int Verbose;
1.38      ohara     150: int do_quiet;
1.1       noro      151:
                    152: void glob_init() {
                    153:        int i;
                    154:
                    155:        for ( i = 0; i < 51; i++ ) {
                    156:                VR(&oVLIST[i]) = &oVAR[i]; NEXT(&oVLIST[i]) = &oVLIST[i+1];
                    157:        }
                    158:        VR(&oVLIST[i]) = &oVAR[i]; NEXT(&oVLIST[i]) = 0;
                    159:        reallocarray((char **)&GPVS->va,(int *)&GPVS->asize,(int *)&GPVS->n,(int)sizeof(struct oPV));
                    160:        reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
                    161:        CPVS = GPVS;
                    162:        MKNODE(ONENODE,mkfnode(1,I_FORMULA,ONE),0);
                    163:        OID(F_TRUE)=O_F; FOP(F_TRUE)=AL_TRUE; F_TRUE->arg.dummy = 0;
                    164:        OID(F_FALSE)=O_F; FOP(F_FALSE)=AL_FALSE; F_FALSE->arg.dummy = 0;
                    165:        sprintf(asirname,"%s/asir_symtab",asir_libdir);
                    166: }
                    167:
1.24      noro      168: void input_init(FILE *fp,char *name)
1.1       noro      169: {
1.24      noro      170:        asir_infile = (INFILE)CALLOC(sizeof(struct oINFILE),1);
1.1       noro      171:        asir_infile->name = name; asir_infile->fp = fp;
                    172:        asir_infile->ln = 1; NEXT(asir_infile) = 0;
                    173: }
                    174:
1.24      noro      175: void notdef(VL vl,Obj a,Obj b,Obj *c)
1.1       noro      176: {
                    177:        error("undefined arithmetic operation.");
                    178: }
                    179:
                    180: int do_asirrc;
                    181: int do_file;
                    182: int do_message;
                    183: int do_fep;
                    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: }
1.39    ! noro      244:
        !           245: Obj user_defined_prompt;
        !           246:
1.1       noro      247: void prompt() {
1.39    ! noro      248:        if ( !do_quiet && !do_fep && asir_infile->fp == stdin )
1.21      noro      249:                fprintf(asir_out,"[%d] ",APVS->n);
1.39    ! noro      250:        else if ( do_quiet && user_defined_prompt
        !           251:                && OID(user_defined_prompt)==O_STR) {
        !           252:                fprintf(asir_out,BDY((STRING)user_defined_prompt),APVS->n);
        !           253:        }
1.1       noro      254:        fflush(asir_out);
                    255: }
                    256:
1.24      noro      257: void sprompt(char *ptr)
1.1       noro      258: {
1.21      noro      259:        sprintf(ptr,"[%d] ",APVS->n);
1.34      ohara     260: }
                    261:
                    262: #if !defined(VISUAL)
                    263: static int which(char *prog, char *path, char *buf, size_t size)
                    264: {
                    265:     char *tok;
                    266:     char delim[] = ":";
                    267:     char *path2  = malloc(strlen(path)+1);
                    268:     char *name   = malloc(size);
                    269:     int  proglen = strlen(prog)+3; /* "/" + prog + " \0" */
                    270:
                    271:     if (!name || !path2) {
                    272:         return 0;
                    273:     }
                    274:     strcpy(path2, path);
                    275:     tok = strtok(path2, delim);
                    276:     while (tok != NULL) {
                    277:         if (size >= strlen(tok)) {
                    278:             sprintf(name, "%s/%s", tok, prog);
                    279:             if (access(name, X_OK&R_OK) == 0) {
                    280:                 strcpy(buf, name);
                    281:                 strcat(buf, " ");
                    282:                 free(path2); free(name);
                    283:                 return 1;
                    284:             }
                    285:             tok = strtok(NULL, delim);
                    286:         }
                    287:     }
                    288:     free(path2); free(name);
                    289:     return 0;
                    290: }
                    291: #endif
                    292:
                    293: void cppname_init()
                    294: {
                    295: #if !defined(VISUAL)
                    296:     if (access(cppname, X_OK&R_OK) != 0) {
                    297:         which("cpp", "/lib:/usr/ccs/lib:/usr/bin", cppname, BUFSIZ) ||
                    298:         which("cpp", getenv("PATH"), cppname, BUFSIZ);
                    299:     }
                    300: #endif
1.1       noro      301: }
                    302:
                    303: FILE *in_fp;
                    304:
1.24      noro      305: void process_args(int ac,char **av)
1.1       noro      306: {
                    307:        do_asirrc = 1;
1.33      noro      308: #if !defined(MPI)
1.1       noro      309:        do_message = 1;
                    310: #endif
1.38      ohara     311:        do_quiet = 0;
1.1       noro      312:        while ( ac > 0 ) {
                    313:                if ( !strcmp(*av,"-heap") && (ac >= 2) ) {
                    314:                        void GC_expand_hp(int);
                    315:
                    316:                        GC_expand_hp(atoi(*(av+1))); av += 2; ac -= 2;
                    317:                } else if ( !strcmp(*av,"-adj") && (ac >= 2) ) {
                    318:                        char *slash;
                    319:
                    320:                        slash = strrchr(*(av+1),'/');
                    321:                        if ( slash ) {
                    322:                                *slash = 0;
                    323:                                GC_free_space_numerator = atoi(slash+1);
                    324:                        }
                    325:                        GC_free_space_divisor = atoi(*(av+1));
                    326:                        av += 2; ac -= 2;
                    327:                } else if ( !strcmp(*av,"-cpp") && (ac >= 2) ) {
                    328:                        strcpy(cppname,*(av+1)); av += 2; ac -= 2;
                    329:                } else if ( !strcmp(*av,"-f") && (ac >= 2) ) {
1.38      ohara     330:                        do_quiet = 1;
1.1       noro      331:                        in_fp = fopen(*(av+1),"r");
                    332:                        if ( !in_fp ) {
                    333:                                fprintf(stderr,"%s does not exist!",*(av+1));
                    334:                                asir_terminate(1);
                    335:                        }
                    336:                        do_file = 1;
                    337:                        av += 2; ac -= 2;
1.38      ohara     338:                } else if ( !strcmp(*av,"-quiet") ) {
1.39    ! noro      339:                        do_quiet = 1; av++; ac--;
1.1       noro      340:                } else if ( !strcmp(*av,"-norc") ) {
                    341:                        do_asirrc = 0; av++; ac--;
                    342:                } else if ( !strcmp(*av,"-nomessage") ) {
                    343:                        do_message = 0; av++; ac--;
1.11      noro      344:                } else if ( !strcmp(*av,"-rootdir") && (ac >= 2) ) {
                    345:                        set_rootdir(*(av+1)); av += 2; ac -= 2;
1.1       noro      346:                } else if ( !strcmp(*av,"-maxheap") && (ac >= 2) ) {
                    347:                        void GC_set_max_heap_size(int);
                    348:
                    349:                        GC_set_max_heap_size(atoi(*(av+1))); av += 2; ac -= 2;
                    350: #if !defined(VISUAL)
                    351:                } else if ( !strcmp(*av,"-display") && (ac >= 2) ) {
                    352:                        strcpy(displayname,*(av+1)); av += 2; ac -= 2;
                    353: #endif
1.32      noro      354: #if FEP
1.13      saito     355:                } else if ( !strcmp(*av,"-fep") ) {
                    356:                        do_fep = 1; av++; ac--;
                    357: #endif
1.31      ohara     358: #if defined(PARI)
1.1       noro      359:                } else if ( !strcmp(*av,"-paristack") ) {
                    360:                        extern int paristack;
                    361:
                    362:                        paristack = atoi(*(av+1)); av += 2; ac -= 2;
                    363: #endif
                    364:                } else {
                    365:                        fprintf(stderr,"%s : unknown option.\n",*av);
                    366:                        asir_terminate(1);
                    367:                }
                    368:        }
1.32      noro      369: #if FEP
1.13      saito     370:        if ( do_fep ) {
                    371:                char *home;
                    372:                home = (char *)getenv("HOME");
                    373:                if (!home)
                    374:                        home = ".";
                    375:                sprintf (asir_history, "%s/.asir_history",home);
                    376:                read_history(asir_history);
                    377:                using_history();
                    378:        }
                    379: #endif
1.1       noro      380: }
                    381:
                    382: #include <signal.h>
                    383:
                    384: void sig_init() {
                    385: #if !defined(VISUAL)
                    386:        signal(SIGINT,int_handler);
                    387: #else
1.24      noro      388:        void register_ctrlc_handler();
                    389:
1.1       noro      390:        register_ctrlc_handler();
                    391: #endif
                    392:        signal(SIGSEGV,segv_handler);
                    393:
1.23      noro      394: #if defined(SIGFPE)
1.1       noro      395:        signal(SIGFPE,fpe_handler);
                    396: #endif
                    397:
1.23      noro      398: #if defined(SIGPIPE)
1.1       noro      399:        signal(SIGPIPE,pipe_handler);
                    400: #endif
                    401:
1.23      noro      402: #if defined(SIGILL)
1.1       noro      403:        signal(SIGILL,ill_handler);
                    404: #endif
                    405:
                    406: #if !defined(VISUAL)
                    407:        signal(SIGBUS,bus_handler);
                    408: #endif
                    409: }
                    410:
                    411: static void (*old_int)(int);
                    412:
                    413: void asir_save_handler() {
                    414:        old_int = signal(SIGINT,SIG_IGN);
                    415:        signal(SIGINT,old_int);
                    416: }
                    417:
                    418: void asir_set_handler() {
                    419:        signal(SIGINT,int_handler);
                    420: }
                    421:
                    422: void asir_reset_handler() {
                    423:        signal(SIGINT,old_int);
                    424: }
                    425:
1.24      noro      426: void resetenv(char *s)
1.1       noro      427: {
                    428:        extern FILE *outfile;
                    429:
                    430:        fprintf(stderr,"%s\n",s);
                    431:        while ( NEXT(asir_infile) )
                    432:                closecurrentinput();
                    433:        resetpvs();
                    434: #if !defined(VISUAL)
                    435:        if ( do_server_in_X11 )
                    436: #endif
                    437:                show_debug_window(0);
                    438: #if defined(VISUAL_LIB)
                    439:        w_noflush_stderr(0);
                    440: #endif
                    441:        asir_out = stdout;
1.31      ohara     442: #if defined(PARI)
1.1       noro      443:        pari_outfile = stdout;
                    444: #endif
                    445:        /* restore states */
                    446:        reset_engine();
                    447:        reset_io();
1.16      noro      448: #if !defined(VISUAL)
1.15      noro      449:        reset_timer();
1.16      noro      450: #endif
1.26      noro      451:        LONGJMP(main_env,1);
1.1       noro      452: }
                    453:
1.24      noro      454: void fatal(int n)
1.1       noro      455: {
                    456:        resetenv("return to toplevel");
                    457: }
                    458:
                    459: FUNC registered_handler;
                    460: extern int ox_int_received, critical_when_signal;
                    461:
1.24      noro      462: void int_handler(int sig)
1.1       noro      463: {
                    464:        extern NODE PVSS;
                    465:
                    466:        if ( do_file ) {
                    467:                ExitAsir();
                    468:        }
                    469:        if ( critical_when_signal ) {
                    470:                ox_int_received = 1;
                    471:                return;
                    472:        }
1.12      noro      473: #if defined(VISUAL)
1.19      noro      474:        suspend_timer();
1.1       noro      475: #endif
                    476:        signal(SIGINT,SIG_IGN);
1.3       noro      477: #if !defined(VISUAL)
                    478:     if ( do_server_in_X11 ) {
                    479:                debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
                    480:                restore_handler();
                    481:                return;
                    482:        }
1.1       noro      483: #endif
                    484: #if defined(linux)
                    485: #if 1
                    486:        while ( stdin->_IO_read_ptr < stdin->_IO_read_end )
                    487: #else
                    488:        while ( stdin->_gptr < stdin->_egptr )
                    489: #endif
                    490:                getchar();
                    491: #endif
                    492:        while ( 1 ) {
                    493:                char buf[BUFSIZ];
                    494:                char c;
                    495:
                    496:                fprintf(stderr,"interrupt ?(q/t/c/d/u/w/?) "); fflush(stderr);
                    497:                buf[0] = '\n';
                    498:                while ( buf[0] == '\n' )
                    499:                        fgets(buf,BUFSIZ,stdin);
                    500:                switch ( c = buf[0] ) {
                    501:                        case 'q':
                    502:                                while ( 1 ) {
                    503:                                        fprintf(stderr,"Abort this session? (y or n) "); fflush(stderr);
                    504:                                        fgets(buf,BUFSIZ,stdin);
                    505:                                        if ( !strncmp(buf,"y",1) ) {
                    506:                                                read_exec_file = 0;
                    507:                                                fprintf(stderr,"Bye\n"); asir_terminate(1);
                    508:                                        } else if ( !strncmp(buf,"n",1) ) {
                    509:                                                restore_handler();
                    510:                                                return;
                    511:                                        }
                    512:                                }
                    513:                                break;
                    514:                        case 't':
                    515:                        case 'u':
                    516:                                while ( 1 ) {
                    517:                                        fprintf(stderr,"Abort this computation? (y or n) "); fflush(stderr);
                    518:                                        fgets(buf,BUFSIZ,stdin);
                    519:                                        if ( !strncmp(buf,"y",1) )
                    520:                                                break;
                    521:                                        else if ( !strncmp(buf,"n",1) ) {
                    522:                                                restore_handler();
                    523:                                                return;
                    524:                                        }
                    525:                                }
                    526:                                if ( debug_mode )
                    527:                                        debug_mode = 0;
                    528:                                restore_handler();
                    529:                                if ( c == 'u' ) {
                    530:                                        if ( registered_handler ) {
                    531:                                                fprintf(stderr,
                    532:                                                        "Calling the registered exception handler...");
                    533:                                                bevalf(registered_handler,0);
                    534:                                                fprintf(stderr, "done.\n");
                    535:                                        }
                    536:                                }
                    537:                                if ( read_exec_file ) {
                    538:                                        read_exec_file = 0;
                    539:                                        resetenv("initialization aborted; return to toplevel");
                    540:                                } else
                    541:                                        resetenv("return to toplevel");
                    542:                                break;
                    543:                        case 'd':
                    544: #if 0
                    545:                                nextbp = 1; nextbplevel = -1;
                    546: #endif
                    547:                                debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
                    548:                                restore_handler();
                    549:                                return;
                    550:                        case 'c':
                    551:                                restore_handler();
                    552:                                return; break;
                    553:                        case 'w':
                    554:                                showpos(); break;
                    555:                        case '?':
                    556:                                fprintf(stderr, "q:quit t:toplevel c:continue d:debug u:call registered handler w:where\n");
                    557:                                break;
                    558:                        default:
                    559:                                break;
                    560:                }
                    561:        }
                    562: }
                    563:
                    564: void restore_handler() {
1.12      noro      565: #if defined(VISUAL)
1.19      noro      566:        resume_timer();
1.1       noro      567: #endif
1.19      noro      568: #if defined(SIGINT)
1.1       noro      569:        signal(SIGINT,int_handler);
                    570: #endif
                    571: }
                    572:
1.24      noro      573: void segv_handler(int sig)
1.1       noro      574: {
1.19      noro      575: #if defined(SIGSEGV)
1.1       noro      576:        signal(SIGSEGV,segv_handler);
1.19      noro      577:        error("internal error (SEGV)");
1.1       noro      578: #endif
                    579: }
                    580:
1.24      noro      581: void ill_handler(int sig)
1.1       noro      582: {
1.19      noro      583: #if defined(SIGILL)
1.1       noro      584:        signal(SIGILL,ill_handler);
1.19      noro      585:        error("illegal instruction (ILL)");
1.1       noro      586: #endif
                    587: }
                    588:
1.24      noro      589: void alrm_handler(int sig)
1.1       noro      590: {
                    591:        fprintf(stderr,"interval timer expired (VTALRM)\n");
1.26      noro      592:        LONGJMP(timer_env,1);
1.1       noro      593: }
                    594:
1.24      noro      595: void bus_handler(int sig)
1.1       noro      596: {
                    597: #if defined(SIGBUS)
                    598:        signal(SIGBUS,bus_handler);
                    599:        error("internal error (BUS ERROR)");
                    600: #endif
                    601: }
                    602:
1.24      noro      603: void fpe_handler(int sig)
1.1       noro      604: {
1.19      noro      605: #if defined(SIGFPE)
1.1       noro      606:        signal(SIGFPE,fpe_handler);
1.19      noro      607:        error("internal error (FPE)");
1.1       noro      608: #endif
                    609: }
                    610:
1.24      noro      611: void pipe_handler(int sig)
1.1       noro      612: {
                    613: #if defined(SIGPIPE)
                    614:        signal(SIGPIPE,pipe_handler);
1.20      noro      615:        end_critical();
1.1       noro      616:        error("internal error (BROKEN PIPE)");
                    617: #endif
                    618: }
                    619:
                    620: void resize_buffer()
                    621: {
                    622: }
                    623:
                    624: void tty_init() {
                    625: }
                    626:
                    627: void tty_reset() {
                    628: }
                    629:
                    630: extern int evalstatline;
                    631:
1.24      noro      632: void set_lasterror(char *s)
1.1       noro      633: {
                    634:        strncpy(LastError,s,BUFSIZ);
                    635:        LastError[BUFSIZ-1] = 0;
                    636: }
                    637:
                    638: SNODE error_snode;
                    639:
1.24      noro      640: void error(char *s)
1.1       noro      641: {
1.37      noro      642:        SNODE *snp=0;
1.1       noro      643:
1.16      noro      644: #if !defined(VISUAL)
1.15      noro      645:        if ( timer_is_set )
                    646:                alrm_handler(SIGVTALRM);
1.16      noro      647: #endif
1.1       noro      648:        fprintf(stderr,"%s\n",s);
                    649:        set_lasterror(s);
                    650:        if ( CPVS != GPVS ) {
1.37      noro      651:                if ( CPVS && CPVS->usrf && CPVS->usrf->f.usrf )
1.7       noro      652:                        searchsn(&BDY(CPVS->usrf->f.usrf),evalstatline,&snp);
1.6       noro      653:                if ( snp )
                    654:                        error_snode = *snp;
                    655:                else
                    656:                        error_snode = 0;
1.1       noro      657:        } else
                    658:                error_snode = 0;
                    659:        if ( do_file ) {
                    660:                char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
                    661:
                    662:                sprintf(errbuf,"%s\n",s);
                    663:                showpos_to_string(errbuf+strlen(errbuf));
                    664:                set_lasterror(errbuf);
                    665:                ExitAsir();
                    666:        }
                    667:        if ( debug_mode )
1.26      noro      668:                LONGJMP(debug_env,1);
1.1       noro      669:        if ( CPVS != GPVS )
                    670:                if ( do_server_in_X11 || isatty(0) )
                    671:                        bp(error_snode);
                    672:        if ( read_exec_file )
                    673:                read_exec_file = 0;
                    674:        resetenv("return to toplevel");
                    675: }
                    676:
                    677: #if !defined(VISUAL)
                    678: #include <sys/time.h>
                    679:
1.24      noro      680: void set_timer(int interval)
1.1       noro      681: {
                    682:        struct itimerval it;
                    683:
                    684:        it.it_interval.tv_sec = interval;
                    685:        it.it_interval.tv_usec = 0;
                    686:        it.it_value.tv_sec = interval;
                    687:        it.it_value.tv_usec = 0;
                    688:        setitimer(ITIMER_VIRTUAL,&it,0);
                    689:        signal(SIGVTALRM,alrm_handler);
1.15      noro      690:        timer_is_set = 1;
1.1       noro      691: }
                    692:
                    693: void reset_timer()
                    694: {
                    695:        struct itimerval it;
                    696:
                    697:        it.it_interval.tv_sec = 0;
                    698:        it.it_interval.tv_usec = 0;
                    699:        it.it_value.tv_sec = 0;
                    700:        it.it_value.tv_usec = 0;
                    701:        setitimer(ITIMER_VIRTUAL,&it,0);
                    702:        signal(SIGVTALRM,SIG_IGN);
1.15      noro      703:        timer_is_set = 0;
1.1       noro      704: }
                    705: #endif
                    706:
                    707: unsigned int get_asir_version();
1.14      noro      708: char *get_asir_distribution();
1.1       noro      709:
                    710: void copyright() {
1.17      noro      711: #if defined(INTERVAL)
                    712:        printf("This is Risa/Asir + Interval Arithmetic, Version %d (%s Distribution).\n",
                    713:                get_asir_version(), get_asir_distribution());
                    714: #else
1.14      noro      715:        printf("This is Risa/Asir, Version %d (%s Distribution).\n",
                    716:                get_asir_version(), get_asir_distribution());
1.17      noro      717: #endif
1.14      noro      718:        printf("Copyright (C) 1994-2000, all rights reserved, FUJITSU LABORATORIES LIMITED.\n");
1.30      noro      719:        printf("Copyright 2000-2003, Risa/Asir committers, http://www.openxm.org/.\n");
1.27      noro      720:        printf("GC 6.1(alpha5) copyright 2001, H-J. Boehm, A. J. Demers, Xerox, SGI, HP.\n");
1.32      noro      721: #if PARI
                    722: #if 0
1.28      noro      723:        printf("PARI 2.2.4, copyright (C) 2002 The PARI Group.\n");
1.32      noro      724: #endif
                    725:        printf("PARI 2.0.17, copyright 1989-1999, C. Batut, K. Belabas, D. Bernardi,\n");
                    726:        printf("   H. Cohen and M. Olivier.\n");
                    727: #endif
1.1       noro      728: }
1.14      noro      729:
1.5       noro      730:

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