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

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

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