=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/io/ox_asir.c,v retrieving revision 1.22 retrieving revision 1.37 diff -u -p -r1.22 -r1.37 --- OpenXM_contrib2/asir2000/io/ox_asir.c 2000/11/14 08:38:39 1.22 +++ OpenXM_contrib2/asir2000/io/ox_asir.c 2001/12/28 09:50:36 1.37 @@ -44,7 +44,7 @@ * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. - * $OpenXM: OpenXM_contrib2/asir2000/io/ox_asir.c,v 1.21 2000/11/07 06:35:38 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/io/ox_asir.c,v 1.36 2001/12/27 07:51:17 noro Exp $ */ #include "ca.h" #include "parse.h" @@ -58,11 +58,12 @@ void ox_usr1_handler(); int asir_ox_init(); +/* environement is defined in libpari.a */ extern jmp_buf environnement; extern int do_message; extern int ox_flushing; -extern jmp_buf ox_env; +extern JMP_BUF ox_env; extern MATHCAP my_mathcap; extern int little_endian,ox_sock_id; @@ -134,10 +135,7 @@ void ox_main(int argc,char **argv) { int id; int cmd; Obj obj; - USINT ui; ERR err; - LIST list; - NODE n,n1; unsigned int serial; int ret; extern char LastError[]; @@ -145,7 +143,7 @@ void ox_main(int argc,char **argv) { ox_asir_init(argc,argv); if ( do_message ) fprintf(stderr,"I'm an ox_asir, Version %d.\n",ASIR_VERSION); - if ( setjmp(ox_env) ) { + if ( SETJMP(ox_env) ) { while ( NEXT(asir_infile) ) closecurrentinput(); ox_send_sync(0); @@ -174,7 +172,7 @@ void ox_main(int argc,char **argv) { break; if ( do_message ) fprintf(stderr," %s\n",name_of_cmd(cmd)); - if ( ret = setjmp(env) ) { + if ( ret = SETJMP(main_env) ) { if ( ret == 1 ) { create_error(&err,serial,LastError); asir_push_one((Obj)err); @@ -419,7 +417,7 @@ void asir_popString() val = asir_pop_one(); if ( !val ) - obuf = 0; + obuf = "0"; else { l = estimate_length(CO,val); buf = (char *)ALLOCA(l+1); @@ -491,6 +489,7 @@ int asir_executeString() char *cmd; #if PARI recover(0); + /* environement is defined in libpari.a */ if ( setjmp(environnement) ) { avma = top; recover(1); resetenv(""); @@ -522,11 +521,9 @@ static void asir_executeFunction(int serial) int argc; FUNC f; Obj result; - VL vl; NODE n,n1; STRING fname; char *path; - USINT ui; ERR err; Obj arg; static char buf[BUFSIZ]; @@ -641,17 +638,20 @@ Obj asir_peek_one() { void ox_asir_init(int argc,char **argv) { - int tmp; char ifname[BUFSIZ]; extern int GC_dont_gc; extern int read_exec_file; extern int do_asirrc; extern int do_server_in_X11; + extern char displayname[]; char *getenv(); static ox_asir_initialized = 0; FILE *ifp; char *homedir; char *ptr; +#if !defined(VISUAL) + int tmp; +#endif #if !defined(VISUAL) && !MPI do_server_in_X11 = 1; /* XXX */ @@ -662,17 +662,15 @@ void ox_asir_init(int argc,char **argv) #endif srandom((int)get_current_time()); -#if defined(THINK_C) - param_init(); -#endif rtime_init(); env_init(); endian_init(); -#if !defined(VISUAL) && !defined(THINK_C) -/* check_key(); */ -#endif GC_init(); process_args(--argc,++argv); +#if defined(__CYGWIN__) + if ( !displayname[0] ) + do_server_in_X11 = 0; /* XXX */ +#endif output_init(); arf_init(); nglob_init(); @@ -693,9 +691,6 @@ void ox_asir_init(int argc,char **argv) if ( ptr = getenv("ASIR_CONFIG") ) strcpy(ifname,ptr); else { -#if defined(THINK_C) - sprintf(ifname,"asirrc"); -#else homedir = getenv("HOME"); if ( !homedir ) { char rootname[BUFSIZ]; @@ -704,11 +699,10 @@ void ox_asir_init(int argc,char **argv) homedir = rootname; } sprintf(ifname,"%s/.asirrc",homedir); -#endif } if ( do_asirrc && (ifp = fopen(ifname,"r")) ) { input_init(ifp,ifname); - if ( !setjmp(env) ) { + if ( !SETJMP(main_env) ) { read_exec_file = 1; read_eval_loop(); read_exec_file = 0; @@ -716,9 +710,8 @@ void ox_asir_init(int argc,char **argv) fclose(ifp); } input_init(0,"string"); -#if !MPI +/* XXX Windows compatibility */ ox_io_init(); -#endif create_my_mathcap("ox_asir"); } @@ -726,6 +719,25 @@ void ox_io_init() { unsigned char c,rc; extern int I_am_server; + /* XXX : ssh forwards stdin to a remote host on PC Unix */ +#if defined(linux) +#include + int i; + + close(0); + for ( i = 5; i < NOFILE; i++ ) + close(i); +#elif defined(__FreeBSD__) +#include + int i; + struct rlimit rl; + + getrlimit(RLIMIT_NOFILE,&rl); + close(0); + for ( i = 5; i < rl.rlim_cur; i++ ) + close(i); +#endif + I_am_server = 1; endian_init(); #if defined(VISUAL) @@ -737,8 +749,10 @@ void ox_io_init() { iofp[0].in = fdopen(3,"r"); iofp[0].out = fdopen(4,"w"); +#if !defined(__CYGWIN__) setbuffer(iofp[0].in,(char *)malloc(LBUFSIZ),LBUFSIZ); setbuffer(iofp[0].out,(char *)malloc(LBUFSIZ),LBUFSIZ); +#endif signal(SIGUSR1,ox_usr1_handler); #endif asir_OperandStackSize = BUFSIZ; @@ -777,7 +791,7 @@ void asir_ox_push_cmo(void *cmo) /* * Pop an object from the stack and converts it - * int a binary encoded CMO. + * into a binary encoded CMO. */ int asir_ox_pop_cmo(void *cmo, int limit) @@ -801,6 +815,30 @@ int asir_ox_pop_cmo(void *cmo, int limit) return -1; } +int asir_ox_pop_string(void *string, int limit) +{ + Obj val; + int l; + + val = asir_pop_one(); + if ( !val ) { + if ( limit >= 2 ) { + sprintf(string,"0"); + l = strlen(string); + } else + l = -1; + } else { + l = estimate_length(CO,val); + if ( l+1 <= limit ) { + soutput_init(string); + sprintexpr(CO,val); + l = strlen(string); + } else + l = -1; + } + return l; +} + /* * Executes an SM command. */ @@ -811,7 +849,7 @@ void asir_ox_push_cmd(int cmd) ERR err; extern char LastError[]; - if ( ret = setjmp(env) ) { + if ( ret = SETJMP(main_env) ) { asir_reset_handler(); if ( ret == 1 ) { create_error(&err,0,LastError); /* XXX */ @@ -838,7 +876,7 @@ void asir_ox_execute_string(char *s) MKSTR(str,s); asir_push_one((Obj)str); - if ( ret = setjmp(env) ) { + if ( ret = SETJMP(main_env) ) { asir_reset_handler(); if ( ret == 1 ) { create_error(&err,0,LastError); /* XXX */ @@ -899,15 +937,9 @@ int asir_ox_init(int byteorder) #endif srandom((int)get_current_time()); -#if defined(THINK_C) - param_init(); -#endif rtime_init(); env_init(); endian_init(); -#if !defined(VISUAL) && !defined(THINK_C) -/* check_key(); */ -#endif GC_init(); /* process_args(argc,argv); */ output_init(); @@ -926,14 +958,10 @@ int asir_ox_init(int byteorder) #if defined(UINIT) reg_sysf(); #endif -#if defined(THINK_C) - sprintf(ifname,"asirrc"); -#else sprintf(ifname,"%s/.asirrc",getenv("HOME")); -#endif if ( do_asirrc && (ifp = fopen(ifname,"r")) ) { input_init(ifp,ifname); - if ( !setjmp(env) ) { + if ( !SETJMP(main_env) ) { read_exec_file = 1; read_eval_loop(); read_exec_file = 0;