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

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

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