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

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.68    ! fujiwara   48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/glob.c,v 1.67 2006/09/28 07:43:45 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.43      ohara      57: #if !defined(VISUAL) && !defined(_PA_RISC1_1) && !defined(linux) && !defined(SYSV) && !defined(__CYGWIN__) && !defined(__INTERIX)
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.52      noro       86: int little_endian,debug_mode,no_debug_on_error;
1.1       noro       87: char *asir_libdir;
1.56      takayama   88: char *asir_contrib_dir;
1.1       noro       89: char *asir_pager;
                     90:
                     91: NODE usrf,sysf,noargsysf,ubinf,parif;
                     92: NODE ONENODE;
1.29      noro       93: int main_parser, allow_create_var, ox_do_copy, ox_do_count, ox_count_length;
1.1       noro       94: int ox_file_io, ox_need_conv;
                     95: char *ox_copy_bptr;
                     96: char *parse_strp;
                     97: SNODE parse_snode;
                     98: FUNC parse_targetf;
                     99: FILE *ox_istream,*ox_ostream;
                    100: int do_server_in_X11;
                    101: Obj LastVal;
1.62      noro      102: LIST LastStackTrace;
1.1       noro      103: char LastError[BUFSIZ];
1.15      noro      104: int timer_is_set;
1.49      noro      105: NODE current_option;
1.53      noro      106: NODE user_int_handler, user_quit_handler;
1.1       noro      107:
                    108: struct oV oVAR[] = {
                    109:        {"x",0,0}, {"y",0,0}, {"z",0,0}, {"u",0,0},
                    110:        {"v",0,0}, {"w",0,0}, {"p",0,0}, {"q",0,0},
                    111:        {"r",0,0}, {"s",0,0}, {"t",0,0}, {"a",0,0},
                    112:        {"b",0,0}, {"c",0,0}, {"d",0,0}, {"e",0,0},
                    113:        {"f",0,0}, {"g",0,0}, {"h",0,0}, {"i",0,0},
                    114:        {"j",0,0}, {"k",0,0}, {"l",0,0}, {"m",0,0},
                    115:        {"n",0,0}, {"o",0,0},
                    116:        {"_x",0,0}, {"_y",0,0}, {"_z",0,0}, {"_u",0,0},
                    117:        {"_v",0,0}, {"_w",0,0}, {"_p",0,0}, {"_q",0,0},
                    118:        {"_r",0,0}, {"_s",0,0}, {"_t",0,0}, {"_a",0,0},
                    119:        {"_b",0,0}, {"_c",0,0}, {"_d",0,0}, {"_e",0,0},
                    120:        {"_f",0,0}, {"_g",0,0}, {"_h",0,0}, {"_i",0,0},
                    121:        {"_j",0,0}, {"_k",0,0}, {"_l",0,0}, {"_m",0,0},
                    122:        {"_n",0,0}, {"_o",0,0}
                    123: };
                    124:
                    125: struct oVL oVLIST[52];
                    126:
                    127: VL CO = oVLIST;
                    128: VL ALG;
                    129:
1.60      noro      130: struct oVS oGPVS,oAPVS,oEPVS,oPPVS;
1.1       noro      131: VS GPVS = &oGPVS;
                    132: VS APVS = &oAPVS;
                    133: VS EPVS = &oEPVS;
1.60      noro      134: VS PPVS = &oPPVS;
1.35      noro      135: VS CPVS,MPVS;
                    136:
                    137: NODE MODULE_LIST;
                    138: MODULE CUR_MODULE;
1.36      noro      139: char *CUR_FUNC;
1.1       noro      140:
1.46      noro      141: struct oSYMBOL oGrlex, oGlex, oLex;
                    142: SYMBOL Symbol_grlex = &oGrlex;
                    143: SYMBOL Symbol_glex = &oGlex;
                    144: SYMBOL Symbol_lex = &oLex;;
1.44      noro      145:
1.1       noro      146: struct oF oF_TRUE,oF_FALSE;
                    147: F F_TRUE = &oF_TRUE;
                    148: F F_FALSE = &oF_FALSE;
                    149:
                    150: #if defined(VISUAL)
1.4       noro      151: char cppname[BUFSIZ] = "c:\\asir\\stdlib\\cpp ";
1.1       noro      152: #else
1.4       noro      153: char cppname[BUFSIZ] = "/lib/cpp ";
1.1       noro      154: #endif
1.4       noro      155: char asirname[BUFSIZ];
1.1       noro      156: char displayname[BUFSIZ];
                    157:
                    158: int Verbose;
1.67      noro      159: int do_quiet;
1.1       noro      160:
                    161: void glob_init() {
                    162:        int i;
                    163:
                    164:        for ( i = 0; i < 51; i++ ) {
                    165:                VR(&oVLIST[i]) = &oVAR[i]; NEXT(&oVLIST[i]) = &oVLIST[i+1];
                    166:        }
                    167:        VR(&oVLIST[i]) = &oVAR[i]; NEXT(&oVLIST[i]) = 0;
                    168:        reallocarray((char **)&GPVS->va,(int *)&GPVS->asize,(int *)&GPVS->n,(int)sizeof(struct oPV));
                    169:        reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
1.60      noro      170:        reallocarray((char **)&PPVS->va,(int *)&PPVS->asize,(int *)&PPVS->n,(int)sizeof(struct oPV));
1.1       noro      171:        CPVS = GPVS;
                    172:        MKNODE(ONENODE,mkfnode(1,I_FORMULA,ONE),0);
                    173:        OID(F_TRUE)=O_F; FOP(F_TRUE)=AL_TRUE; F_TRUE->arg.dummy = 0;
                    174:        OID(F_FALSE)=O_F; FOP(F_FALSE)=AL_FALSE; F_FALSE->arg.dummy = 0;
1.44      noro      175:        OID(Symbol_grlex) = O_SYMBOL; Symbol_grlex->name = "@grlex";
                    176:        Symbol_grlex->value = 0;
                    177:        OID(Symbol_glex) = O_SYMBOL; Symbol_glex->name = "@glex";
                    178:        Symbol_glex->value = 1;
1.45      noro      179:        OID(Symbol_lex) = O_SYMBOL; Symbol_lex->name = "@lex";
                    180:        Symbol_lex->value = 2;
1.1       noro      181:        sprintf(asirname,"%s/asir_symtab",asir_libdir);
                    182: }
                    183:
1.24      noro      184: void input_init(FILE *fp,char *name)
1.1       noro      185: {
1.24      noro      186:        asir_infile = (INFILE)CALLOC(sizeof(struct oINFILE),1);
1.1       noro      187:        asir_infile->name = name; asir_infile->fp = fp;
                    188:        asir_infile->ln = 1; NEXT(asir_infile) = 0;
                    189: }
                    190:
1.24      noro      191: void notdef(VL vl,Obj a,Obj b,Obj *c)
1.1       noro      192: {
                    193:        error("undefined arithmetic operation.");
                    194: }
                    195:
                    196: int do_asirrc;
                    197: int do_file;
1.42      ohara     198: char *do_filename;
1.1       noro      199: int do_message;
1.58      noro      200: int do_terse;
1.1       noro      201: int do_fep;
1.42      ohara     202: int asir_setenv;
1.1       noro      203: static int buserr_sav;
                    204: static char asir_history[BUFSIZ];
                    205:
                    206: extern int mpi_myid;
                    207:
1.5       noro      208: #if !defined(VISUAL_LIB)
                    209: void ExitAsir() {
                    210:        exit(0);
                    211: }
                    212: #endif
                    213:
1.1       noro      214: /*
                    215:  * status = 1 abnormal termination (error() etc.)
                    216:  * status = 2 normal termination (end(), quit() etc.)
1.63      noro      217:  * status = 3 absolute termination
1.1       noro      218:  */
                    219:
1.24      noro      220: void asir_terminate(int status)
1.1       noro      221: {
1.21      noro      222:        int t;
1.53      noro      223:        NODE n;
1.63      noro      224:
                    225:        /* called from engine in Windows */
                    226:        if ( status == 3 ) asir_infile = 0;
1.21      noro      227:
1.62      noro      228:        if ( asir_infile && asir_infile->ready_for_longjmp )
                    229:                LONGJMP(asir_infile->jmpbuf,status);
                    230:        else {
1.54      noro      231:                if ( user_quit_handler ) {
1.58      noro      232:                        if ( !do_terse )
                    233:                                fprintf(stderr,"Calling the registered quit callbacks...");
1.54      noro      234:                        for ( n = user_quit_handler; n; n = NEXT(n) )
                    235:                                bevalf((FUNC)BDY(n),0);
1.58      noro      236:                        if ( !do_terse )
                    237:                                fprintf(stderr, "done.\n");
1.54      noro      238:                }
1.1       noro      239:                tty_reset();
1.33      noro      240: #if defined(MPI)
1.1       noro      241:                if ( !mpi_myid )
                    242:                        close_allconnections();
                    243:                mpi_finalize();
                    244: #else
1.20      noro      245: #if defined(SIGPIPE)
                    246:                signal(SIGPIPE,SIG_IGN);
                    247: #endif
1.1       noro      248:                close_allconnections();
                    249: #endif
                    250:                if ( asir_out )
                    251:                        fflush(asir_out);
1.32      noro      252: #if FEP
1.13      saito     253:                if ( do_fep ) {
                    254:                        stifle_history(MAXHIST);
                    255:                        write_history(asir_history);
                    256:                }
                    257: #endif
1.1       noro      258:                ExitAsir();
                    259:        }
                    260: }
                    261:
                    262: void param_init() {
                    263:        unsigned int et = 0xff;
                    264:        extern int paristack;
                    265:        if ( *((char *)&et) )
                    266:                little_endian = 1;
                    267:        else
                    268:                little_endian = 0;
                    269: }
1.39      noro      270:
                    271: Obj user_defined_prompt;
                    272:
1.1       noro      273: void prompt() {
1.48      noro      274:        if ( !do_quiet && !do_fep && asir_infile->fp == stdin ) {
1.21      noro      275:                fprintf(asir_out,"[%d] ",APVS->n);
1.48      noro      276:                fflush(asir_out);
                    277:        } else if ( do_quiet && user_defined_prompt
1.39      noro      278:                && OID(user_defined_prompt)==O_STR) {
                    279:                fprintf(asir_out,BDY((STRING)user_defined_prompt),APVS->n);
1.48      noro      280:                fflush(asir_out);
1.39      noro      281:        }
1.1       noro      282: }
                    283:
1.24      noro      284: void sprompt(char *ptr)
1.1       noro      285: {
1.21      noro      286:        sprintf(ptr,"[%d] ",APVS->n);
1.34      ohara     287: }
                    288:
                    289: #if !defined(VISUAL)
                    290: static int which(char *prog, char *path, char *buf, size_t size)
                    291: {
                    292:     char *tok;
                    293:     char delim[] = ":";
                    294:     char *path2  = malloc(strlen(path)+1);
                    295:     char *name   = malloc(size);
                    296:     int  proglen = strlen(prog)+3; /* "/" + prog + " \0" */
                    297:
                    298:     if (!name || !path2) {
                    299:         return 0;
                    300:     }
                    301:     strcpy(path2, path);
                    302:     tok = strtok(path2, delim);
                    303:     while (tok != NULL) {
                    304:         if (size >= strlen(tok)) {
                    305:             sprintf(name, "%s/%s", tok, prog);
                    306:             if (access(name, X_OK&R_OK) == 0) {
                    307:                 strcpy(buf, name);
                    308:                 strcat(buf, " ");
                    309:                 free(path2); free(name);
                    310:                 return 1;
                    311:             }
                    312:             tok = strtok(NULL, delim);
                    313:         }
                    314:     }
                    315:     free(path2); free(name);
                    316:     return 0;
                    317: }
                    318: #endif
                    319:
                    320: void cppname_init()
                    321: {
                    322: #if !defined(VISUAL)
                    323:     if (access(cppname, X_OK&R_OK) != 0) {
                    324:         which("cpp", "/lib:/usr/ccs/lib:/usr/bin", cppname, BUFSIZ) ||
                    325:         which("cpp", getenv("PATH"), cppname, BUFSIZ);
                    326:     }
                    327: #endif
1.1       noro      328: }
                    329:
                    330: FILE *in_fp;
                    331:
1.24      noro      332: void process_args(int ac,char **av)
1.1       noro      333: {
                    334:        do_asirrc = 1;
1.33      noro      335: #if !defined(MPI)
1.1       noro      336:        do_message = 1;
                    337: #endif
1.38      ohara     338:        do_quiet = 0;
1.1       noro      339:        while ( ac > 0 ) {
                    340:                if ( !strcmp(*av,"-heap") && (ac >= 2) ) {
                    341:                        void GC_expand_hp(int);
                    342:
                    343:                        GC_expand_hp(atoi(*(av+1))); av += 2; ac -= 2;
                    344:                } else if ( !strcmp(*av,"-adj") && (ac >= 2) ) {
                    345:                        char *slash;
                    346:
                    347:                        slash = strrchr(*(av+1),'/');
                    348:                        if ( slash ) {
                    349:                                *slash = 0;
                    350:                                GC_free_space_numerator = atoi(slash+1);
                    351:                        }
                    352:                        GC_free_space_divisor = atoi(*(av+1));
                    353:                        av += 2; ac -= 2;
                    354:                } else if ( !strcmp(*av,"-cpp") && (ac >= 2) ) {
                    355:                        strcpy(cppname,*(av+1)); av += 2; ac -= 2;
                    356:                } else if ( !strcmp(*av,"-f") && (ac >= 2) ) {
1.38      ohara     357:                        do_quiet = 1;
1.1       noro      358:                        in_fp = fopen(*(av+1),"r");
                    359:                        if ( !in_fp ) {
1.62      noro      360:                                fprintf(stderr,"%s does not exist!\n",*(av+1));
1.1       noro      361:                                asir_terminate(1);
                    362:                        }
                    363:                        do_file = 1;
1.42      ohara     364:                        do_filename = *(av+1);
1.1       noro      365:                        av += 2; ac -= 2;
1.42      ohara     366:                } else if ( !strcmp(*av,"-E") ) {
                    367:                        asir_setenv = 1; av++; ac--;
1.38      ohara     368:                } else if ( !strcmp(*av,"-quiet") ) {
1.39      noro      369:                        do_quiet = 1; av++; ac--;
1.1       noro      370:                } else if ( !strcmp(*av,"-norc") ) {
                    371:                        do_asirrc = 0; av++; ac--;
                    372:                } else if ( !strcmp(*av,"-nomessage") ) {
                    373:                        do_message = 0; av++; ac--;
1.11      noro      374:                } else if ( !strcmp(*av,"-rootdir") && (ac >= 2) ) {
                    375:                        set_rootdir(*(av+1)); av += 2; ac -= 2;
1.1       noro      376:                } else if ( !strcmp(*av,"-maxheap") && (ac >= 2) ) {
                    377:                        void GC_set_max_heap_size(int);
                    378:
                    379:                        GC_set_max_heap_size(atoi(*(av+1))); av += 2; ac -= 2;
                    380: #if !defined(VISUAL)
                    381:                } else if ( !strcmp(*av,"-display") && (ac >= 2) ) {
                    382:                        strcpy(displayname,*(av+1)); av += 2; ac -= 2;
                    383: #endif
1.32      noro      384: #if FEP
1.13      saito     385:                } else if ( !strcmp(*av,"-fep") ) {
                    386:                        do_fep = 1; av++; ac--;
                    387: #endif
1.31      ohara     388: #if defined(PARI)
1.1       noro      389:                } else if ( !strcmp(*av,"-paristack") ) {
                    390:                        extern int paristack;
                    391:
                    392:                        paristack = atoi(*(av+1)); av += 2; ac -= 2;
                    393: #endif
                    394:                } else {
                    395:                        fprintf(stderr,"%s : unknown option.\n",*av);
                    396:                        asir_terminate(1);
                    397:                }
                    398:        }
1.32      noro      399: #if FEP
1.13      saito     400:        if ( do_fep ) {
                    401:                char *home;
                    402:                home = (char *)getenv("HOME");
                    403:                if (!home)
                    404:                        home = ".";
                    405:                sprintf (asir_history, "%s/.asir_history",home);
                    406:                read_history(asir_history);
                    407:                using_history();
                    408:        }
                    409: #endif
1.1       noro      410: }
                    411:
                    412: #include <signal.h>
                    413:
                    414: void sig_init() {
                    415: #if !defined(VISUAL)
                    416:        signal(SIGINT,int_handler);
                    417: #else
1.24      noro      418:        void register_ctrlc_handler();
                    419:
1.1       noro      420:        register_ctrlc_handler();
                    421: #endif
                    422:        signal(SIGSEGV,segv_handler);
                    423:
1.23      noro      424: #if defined(SIGFPE)
1.1       noro      425:        signal(SIGFPE,fpe_handler);
                    426: #endif
                    427:
1.23      noro      428: #if defined(SIGPIPE)
1.1       noro      429:        signal(SIGPIPE,pipe_handler);
                    430: #endif
                    431:
1.23      noro      432: #if defined(SIGILL)
1.1       noro      433:        signal(SIGILL,ill_handler);
                    434: #endif
                    435:
                    436: #if !defined(VISUAL)
                    437:        signal(SIGBUS,bus_handler);
                    438: #endif
                    439: }
                    440:
                    441: static void (*old_int)(int);
                    442:
                    443: void asir_save_handler() {
                    444:        old_int = signal(SIGINT,SIG_IGN);
                    445:        signal(SIGINT,old_int);
                    446: }
                    447:
                    448: void asir_set_handler() {
                    449:        signal(SIGINT,int_handler);
                    450: }
                    451:
                    452: void asir_reset_handler() {
                    453:        signal(SIGINT,old_int);
                    454: }
                    455:
1.62      noro      456: extern int I_am_server;
                    457:
1.24      noro      458: void resetenv(char *s)
1.1       noro      459: {
                    460:        extern FILE *outfile;
                    461:
1.53      noro      462:        fprintf(stderr,"%s\n",s);
1.1       noro      463:        while ( NEXT(asir_infile) )
                    464:                closecurrentinput();
                    465:        resetpvs();
                    466: #if !defined(VISUAL)
                    467:        if ( do_server_in_X11 )
                    468: #endif
                    469:                show_debug_window(0);
                    470: #if defined(VISUAL_LIB)
                    471:        w_noflush_stderr(0);
                    472: #endif
                    473:        asir_out = stdout;
1.31      ohara     474: #if defined(PARI)
1.1       noro      475:        pari_outfile = stdout;
                    476: #endif
                    477:        /* restore states */
                    478:        reset_engine();
                    479:        reset_io();
1.16      noro      480: #if !defined(VISUAL)
1.15      noro      481:        reset_timer();
1.16      noro      482: #endif
1.62      noro      483:        LONGJMP(main_env,1);
1.1       noro      484: }
                    485:
1.24      noro      486: void fatal(int n)
1.1       noro      487: {
                    488:        resetenv("return to toplevel");
                    489: }
                    490:
                    491: extern int ox_int_received, critical_when_signal;
                    492:
1.24      noro      493: void int_handler(int sig)
1.1       noro      494: {
                    495:        extern NODE PVSS;
1.53      noro      496:        NODE t;
1.48      noro      497:
1.1       noro      498:
                    499:        if ( do_file ) {
                    500:                ExitAsir();
                    501:        }
                    502:        if ( critical_when_signal ) {
                    503:                ox_int_received = 1;
                    504:                return;
                    505:        }
1.12      noro      506: #if defined(VISUAL)
1.19      noro      507:        suspend_timer();
1.1       noro      508: #endif
                    509:        signal(SIGINT,SIG_IGN);
1.3       noro      510: #if !defined(VISUAL)
                    511:     if ( do_server_in_X11 ) {
                    512:                debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
                    513:                restore_handler();
                    514:                return;
                    515:        }
1.1       noro      516: #endif
                    517: #if defined(linux)
                    518: #if 1
                    519:        while ( stdin->_IO_read_ptr < stdin->_IO_read_end )
                    520: #else
                    521:        while ( stdin->_gptr < stdin->_egptr )
                    522: #endif
                    523:                getchar();
                    524: #endif
                    525:        while ( 1 ) {
                    526:                char buf[BUFSIZ];
                    527:                char c;
                    528:
1.53      noro      529:                fprintf(stderr,"interrupt ?(q/t/c/d/u/w/?) "); fflush(stderr);
1.1       noro      530:                buf[0] = '\n';
                    531:                while ( buf[0] == '\n' )
                    532:                        fgets(buf,BUFSIZ,stdin);
                    533:                switch ( c = buf[0] ) {
                    534:                        case 'q':
                    535:                                while ( 1 ) {
1.53      noro      536:                                        fprintf(stderr,"Abort this session? (y or n) "); fflush(stderr);
1.1       noro      537:                                        fgets(buf,BUFSIZ,stdin);
                    538:                                        if ( !strncmp(buf,"y",1) ) {
1.53      noro      539:                                                fprintf(stderr,"Bye\n");
1.65      noro      540:                                                /* for terminating myself */
                    541:                                                asir_infile = 0;
1.48      noro      542:                                                asir_terminate(1);
1.1       noro      543:                                        } else if ( !strncmp(buf,"n",1) ) {
                    544:                                                restore_handler();
                    545:                                                return;
                    546:                                        }
                    547:                                }
                    548:                                break;
                    549:                        case 't':
                    550:                        case 'u':
                    551:                                while ( 1 ) {
1.53      noro      552:                                        fprintf(stderr,"Abort this computation? (y or n) "); fflush(stderr);
1.1       noro      553:                                        fgets(buf,BUFSIZ,stdin);
                    554:                                        if ( !strncmp(buf,"y",1) )
                    555:                                                break;
                    556:                                        else if ( !strncmp(buf,"n",1) ) {
                    557:                                                restore_handler();
                    558:                                                return;
                    559:                                        }
                    560:                                }
                    561:                                if ( debug_mode )
                    562:                                        debug_mode = 0;
                    563:                                restore_handler();
                    564:                                if ( c == 'u' ) {
1.53      noro      565:                                        if ( user_int_handler ) {
1.58      noro      566:                                                if ( !do_terse )
                    567:                                                        fprintf(stderr,
                    568:                                                                "Calling the registered exception callbacks...");
1.53      noro      569:                                                for ( t = user_int_handler; t; t = NEXT(t) )
                    570:                                                        bevalf((FUNC)BDY(t),0);
1.58      noro      571:                                                if ( !do_terse )
                    572:                                                        fprintf(stderr, "done.\n");
1.1       noro      573:                                        }
                    574:                                }
1.62      noro      575:                                resetenv("return to toplevel");
1.1       noro      576:                                break;
                    577:                        case 'd':
                    578: #if 0
                    579:                                nextbp = 1; nextbplevel = -1;
                    580: #endif
                    581:                                debug(PVSS?((VS)BDY(PVSS))->usrf->f.usrf->body:0);
                    582:                                restore_handler();
                    583:                                return;
                    584:                        case 'c':
                    585:                                restore_handler();
                    586:                                return; break;
                    587:                        case 'w':
1.48      noro      588:                                showpos();
                    589:                                break;
1.1       noro      590:                        case '?':
1.53      noro      591:                                fprintf(stderr, "q:quit t:toplevel c:continue d:debug u:call registered handler w:where\n");
1.1       noro      592:                                break;
                    593:                        default:
                    594:                                break;
                    595:                }
                    596:        }
                    597: }
                    598:
                    599: void restore_handler() {
1.12      noro      600: #if defined(VISUAL)
1.19      noro      601:        resume_timer();
1.1       noro      602: #endif
1.19      noro      603: #if defined(SIGINT)
1.1       noro      604:        signal(SIGINT,int_handler);
                    605: #endif
                    606: }
                    607:
1.24      noro      608: void segv_handler(int sig)
1.1       noro      609: {
1.19      noro      610: #if defined(SIGSEGV)
1.1       noro      611:        signal(SIGSEGV,segv_handler);
1.19      noro      612:        error("internal error (SEGV)");
1.1       noro      613: #endif
                    614: }
                    615:
1.24      noro      616: void ill_handler(int sig)
1.1       noro      617: {
1.19      noro      618: #if defined(SIGILL)
1.1       noro      619:        signal(SIGILL,ill_handler);
1.19      noro      620:        error("illegal instruction (ILL)");
1.1       noro      621: #endif
                    622: }
                    623:
1.24      noro      624: void alrm_handler(int sig)
1.1       noro      625: {
                    626:        fprintf(stderr,"interval timer expired (VTALRM)\n");
1.26      noro      627:        LONGJMP(timer_env,1);
1.1       noro      628: }
                    629:
1.24      noro      630: void bus_handler(int sig)
1.1       noro      631: {
                    632: #if defined(SIGBUS)
                    633:        signal(SIGBUS,bus_handler);
                    634:        error("internal error (BUS ERROR)");
                    635: #endif
                    636: }
                    637:
1.24      noro      638: void fpe_handler(int sig)
1.1       noro      639: {
1.19      noro      640: #if defined(SIGFPE)
1.1       noro      641:        signal(SIGFPE,fpe_handler);
1.19      noro      642:        error("internal error (FPE)");
1.1       noro      643: #endif
                    644: }
                    645:
1.24      noro      646: void pipe_handler(int sig)
1.1       noro      647: {
                    648: #if defined(SIGPIPE)
                    649:        signal(SIGPIPE,pipe_handler);
1.20      noro      650:        end_critical();
1.1       noro      651:        error("internal error (BROKEN PIPE)");
                    652: #endif
                    653: }
                    654:
                    655: void resize_buffer()
                    656: {
                    657: }
                    658:
                    659: void tty_init() {
                    660: }
                    661:
                    662: void tty_reset() {
                    663: }
                    664:
                    665: extern int evalstatline;
                    666:
1.24      noro      667: void set_lasterror(char *s)
1.1       noro      668: {
                    669:        strncpy(LastError,s,BUFSIZ);
                    670:        LastError[BUFSIZ-1] = 0;
                    671: }
                    672:
                    673: SNODE error_snode;
1.51      noro      674: int error_in_timer;
1.1       noro      675:
1.24      noro      676: void error(char *s)
1.1       noro      677: {
1.37      noro      678:        SNODE *snp=0;
1.1       noro      679:
1.16      noro      680: #if !defined(VISUAL)
1.51      noro      681:        if ( !error_in_timer && timer_is_set )
1.15      noro      682:                alrm_handler(SIGVTALRM);
1.16      noro      683: #endif
1.1       noro      684:        fprintf(stderr,"%s\n",s);
                    685:        set_lasterror(s);
                    686:        if ( CPVS != GPVS ) {
1.37      noro      687:                if ( CPVS && CPVS->usrf && CPVS->usrf->f.usrf )
1.7       noro      688:                        searchsn(&BDY(CPVS->usrf->f.usrf),evalstatline,&snp);
1.6       noro      689:                if ( snp )
                    690:                        error_snode = *snp;
                    691:                else
                    692:                        error_snode = 0;
1.1       noro      693:        } else
                    694:                error_snode = 0;
                    695:        if ( do_file ) {
                    696:                char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
                    697:
                    698:                sprintf(errbuf,"%s\n",s);
                    699:                showpos_to_string(errbuf+strlen(errbuf));
                    700:                set_lasterror(errbuf);
                    701:                ExitAsir();
                    702:        }
                    703:        if ( debug_mode )
1.26      noro      704:                LONGJMP(debug_env,1);
1.1       noro      705:        if ( CPVS != GPVS )
1.52      noro      706:                if ( !no_debug_on_error && (do_server_in_X11 || isatty(0)) )
1.1       noro      707:                        bp(error_snode);
1.62      noro      708:        if ( I_am_server )
                    709:                showpos_to_list(&LastStackTrace);
1.40      noro      710:        resetenv("return to toplevel");
                    711: }
                    712:
                    713: void toplevel(char *s)
                    714: {
                    715:        SNODE *snp=0;
                    716:
                    717: #if !defined(VISUAL)
                    718:        if ( timer_is_set )
                    719:                alrm_handler(SIGVTALRM);
                    720: #endif
                    721:        fprintf(stderr,"%s\n",s);
                    722:        if ( do_file ) {
                    723:                char errbuf[BUFSIZ*5]; /* sufficient to store stack information ? */
                    724:
                    725:                sprintf(errbuf,"%s\n",s);
                    726:                showpos_to_string(errbuf+strlen(errbuf));
                    727:                ExitAsir();
                    728:        }
1.1       noro      729:        resetenv("return to toplevel");
                    730: }
                    731:
                    732: #if !defined(VISUAL)
                    733: #include <sys/time.h>
                    734:
1.24      noro      735: void set_timer(int interval)
1.1       noro      736: {
                    737:        struct itimerval it;
                    738:
                    739:        it.it_interval.tv_sec = interval;
                    740:        it.it_interval.tv_usec = 0;
                    741:        it.it_value.tv_sec = interval;
                    742:        it.it_value.tv_usec = 0;
                    743:        setitimer(ITIMER_VIRTUAL,&it,0);
                    744:        signal(SIGVTALRM,alrm_handler);
1.15      noro      745:        timer_is_set = 1;
1.1       noro      746: }
                    747:
                    748: void reset_timer()
                    749: {
                    750:        struct itimerval it;
                    751:
                    752:        it.it_interval.tv_sec = 0;
                    753:        it.it_interval.tv_usec = 0;
                    754:        it.it_value.tv_sec = 0;
                    755:        it.it_value.tv_usec = 0;
                    756:        setitimer(ITIMER_VIRTUAL,&it,0);
                    757:        signal(SIGVTALRM,SIG_IGN);
1.15      noro      758:        timer_is_set = 0;
1.1       noro      759: }
                    760: #endif
                    761:
                    762: unsigned int get_asir_version();
1.14      noro      763: char *get_asir_distribution();
1.1       noro      764:
1.47      ohara     765: char *get_pariversion()
                    766: {
1.32      noro      767: #if PARI
                    768: #if 0
1.59      saito     769:        return PARIVERSION", Copyright (C) 2000-2005 The PARI Group.\n";
                    770: #else
                    771:        return "PARI 2.0.17, copyright 1989-1999, C. Batut, K. Belabas, D. Bernardi,\n   H. Cohen and M. Olivier.\n";
1.32      noro      772: #endif
                    773: #endif
1.47      ohara     774:        return "";
1.1       noro      775: }
1.14      noro      776:
1.47      ohara     777: char *get_intervalversion()
                    778: {
                    779: #if defined(INTERVAL)
                    780:        return " + Interval Arithmetic";
                    781: #else
                    782:        return "";
                    783: #endif
                    784: }
                    785:
                    786: void copyright()
                    787: {
1.68    ! fujiwara  788:        char *format = "This is Risa/Asir%s, Version %d (%s Distribution).\nCopyright (C) 1994-2000, all rights reserved, FUJITSU LABORATORIES LIMITED.\nCopyright 2000-2007, Risa/Asir committers, http://www.openxm.org/.\nGC 6.5 Copyright 1988-2005, H-J. Boehm, A. J. Demers, Xerox, SGI, HP.\n%s";
1.47      ohara     789:        printf(format, get_intervalversion(), get_asir_version(), get_asir_distribution(), get_pariversion());
                    790: }
1.5       noro      791:
1.47      ohara     792: char *scopyright()
                    793: {
                    794:        static char *notice;
                    795:        char *s1, *s2, *s3;
                    796:        int d, len;
1.68    ! fujiwara  797:        char *format = "This is Risa/Asir%s, Version %d (%s Distribution).\nCopyright (C) 1994-2000, all rights reserved, FUJITSU LABORATORIES LIMITED.\nCopyright 2000-2007, Risa/Asir committers, http://www.openxm.org/.\nGC 6.5 copyright 1988-2005, H-J. Boehm, A. J. Demers, Xerox, SGI, HP.\n%s";
1.47      ohara     798:        if (!notice) {
                    799:                s1 = get_intervalversion();
                    800:                s2 = get_asir_distribution();
                    801:                s3 = get_pariversion();
                    802:                d  = get_asir_version();
                    803:                len = (strlen(format)-8)+strlen(s1)+strlen(s2)+strlen(s3)+sizeof(int)*3;
                    804:                notice = MALLOC(len+1);
                    805:                sprintf(notice, format, s1, d, s2, s3);
                    806:        }
                    807:        return notice;
                    808: }

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