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

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

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