=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/io/ox_asir.c,v retrieving revision 1.3 retrieving revision 1.9 diff -u -p -r1.3 -r1.9 --- OpenXM_contrib2/asir2000/io/ox_asir.c 2000/01/18 05:55:07 1.3 +++ OpenXM_contrib2/asir2000/io/ox_asir.c 2000/03/10 06:42:23 1.9 @@ -1,11 +1,16 @@ -/* $OpenXM: OpenXM_contrib2/asir2000/io/ox_asir.c,v 1.2 1999/12/22 07:01:39 noro Exp $ */ +/* $OpenXM: OpenXM_contrib2/asir2000/io/ox_asir.c,v 1.8 2000/03/10 03:05:02 noro Exp $ */ #include "ca.h" #include "parse.h" +#include "signal.h" #include "ox.h" #include "version.h" +#if PARI +#include "genpari.h" +#endif void ox_usr1_handler(); + extern jmp_buf environnement; extern int do_message; @@ -456,11 +461,23 @@ static void asir_executeFunction(int serial) char *path; USINT ui; ERR err; + Obj arg; static char buf[BUFSIZ]; - func = ((STRING)asir_pop_one())->body; - argc = (int)(((USINT)asir_pop_one())->body); + arg = asir_pop_one(); + if ( !arg || OID(arg) != O_STR ) { + sprintf(buf,"executeFunction : invalid function name"); + goto error; + } else + func = ((STRING)arg)->body; + arg = asir_pop_one(); + if ( !arg || OID(arg) != O_USINT ) { + sprintf(buf,"executeFunction : invalid argc"); + goto error; + } else + argc = (int)(((USINT)arg)->body); + for ( n = 0; argc; argc-- ) { NEXTNODE(n,n1); BDY(n1) = (pointer)asir_pop_one(); @@ -491,13 +508,18 @@ static void asir_executeFunction(int serial) searchf(usrf,func,&f); if ( !f ) { sprintf(buf,"executeFunction : the function %s not found",func); - create_error(&err,serial,buf); - result = (Obj)err; + goto error; } else { result = (Obj)bevalf(f,n); } } asir_push_one(result); + return; + +error: + create_error(&err,serial,buf); + result = (Obj)err; + asir_push_one(result); } static void asir_end_flush() @@ -549,6 +571,8 @@ static void ox_asir_init(int argc,char **argv) char *getenv(); static ox_asir_initialized = 0; FILE *ifp; + char *homedir; + char *ptr; #if !defined(VISUAL) && !MPI do_server_in_X11 = 1; /* XXX */ @@ -587,11 +611,23 @@ static void ox_asir_init(int argc,char **argv) #if defined(UINIT) reg_sysf(); #endif +/* if ASIR_CONFIG is set, execute it; else execute .asirrc */ + if ( ptr = getenv("ASIR_CONFIG") ) + strcpy(ifname,ptr); + else { #if defined(THINK_C) - sprintf(ifname,"asirrc"); + sprintf(ifname,"asirrc"); #else - sprintf(ifname,"%s/.asirrc",getenv("HOME")); + homedir = getenv("HOME"); + if ( !homedir ) { + char rootname[BUFSIZ]; + + get_rootdir(rootname,sizeof(rootname)); + homedir = rootname; + } + sprintf(ifname,"%s/.asirrc",homedir); #endif + } if ( do_asirrc && (ifp = fopen(ifname,"r")) ) { input_init(ifp,ifname); if ( !setjmp(env) ) { @@ -683,7 +719,17 @@ int asir_ox_pop_cmo(void *cmo, int limit) void asir_ox_push_cmd(unsigned int cmd) { - asir_do_cmd(cmd,0); + int ret; + ERR err; + extern char LastError[]; + + if ( ret = setjmp(env) ) { + if ( ret == 1 ) { + create_error(&err,0,LastError); /* XXX */ + asir_push_one((Obj)err); + } + } else + asir_do_cmd(cmd,0); } /* @@ -693,10 +739,19 @@ void asir_ox_push_cmd(unsigned int cmd) void asir_ox_execute_string(char *s) { STRING str; + int ret; + ERR err; + extern char LastError[]; MKSTR(str,s); asir_push_one((Obj)str); - asir_executeString(); + if ( ret = setjmp(env) ) { + if ( ret == 1 ) { + create_error(&err,0,LastError); /* XXX */ + asir_push_one((Obj)err); + } + } else + asir_executeString(); } /* @@ -736,7 +791,7 @@ void asir_ox_init(int byteorder) FILE *ifp; #if !defined(VISUAL) && !MPI - do_server_in_X11 = 1; /* XXX */ + do_server_in_X11 = 0; /* XXX */ #endif asir_save_handler(); #if PARI