version 1.27, 2001/09/20 23:11:42 |
version 1.43, 2003/03/07 06:39:57 |
|
|
* OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY |
* OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* $OpenXM: OpenXM_contrib2/asir2000/io/ox_asir.c,v 1.26 2001/09/20 10:44:18 noro Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/io/ox_asir.c,v 1.42 2003/03/07 03:12:28 noro Exp $ |
*/ |
*/ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
#include "signal.h" |
#include "signal.h" |
#include "ox.h" |
#include "ox.h" |
#include "version.h" |
#include "version.h" |
#if PARI |
#if defined(PARI) |
#include "genpari.h" |
#include "genpari.h" |
#endif |
#endif |
|
|
void ox_usr1_handler(); |
void ox_usr1_handler(); |
int asir_ox_init(); |
int asir_ox_init(); |
|
|
|
/* environement is defined in libpari.a */ |
extern jmp_buf environnement; |
extern jmp_buf environnement; |
|
|
extern int do_message; |
extern int do_message; |
extern int ox_flushing; |
extern int ox_flushing; |
extern jmp_buf ox_env; |
extern JMP_BUF ox_env; |
extern MATHCAP my_mathcap; |
extern MATHCAP my_mathcap; |
|
|
extern int little_endian,ox_sock_id; |
extern int little_endian,ox_sock_id; |
Line 77 Obj *asir_OperandStack; |
|
Line 78 Obj *asir_OperandStack; |
|
int asir_OperandStackPtr = -1; |
int asir_OperandStackPtr = -1; |
|
|
void ox_io_init(); |
void ox_io_init(); |
void ox_asir_init(int,char **); |
void ox_asir_init(int,char **,char *); |
Obj asir_pop_one(); |
Obj asir_pop_one(); |
Obj asir_peek_one(); |
Obj asir_peek_one(); |
void asir_push_one(Obj); |
void asir_push_one(Obj); |
Line 97 char *name_of_id(int); |
|
Line 98 char *name_of_id(int); |
|
static void asir_do_cmd(int,unsigned int); |
static void asir_do_cmd(int,unsigned int); |
static void asir_executeFunction(int); |
static void asir_executeFunction(int); |
|
|
#if MPI |
#if defined(MPI) |
/* XXX : currently MPI version supports only a homogeneous cluster. */ |
/* XXX : currently MPI version supports only a homogeneous cluster. */ |
|
|
extern int mpi_nprocs,mpi_myid; |
extern int mpi_nprocs,mpi_myid; |
Line 134 void ox_main(int argc,char **argv) { |
|
Line 135 void ox_main(int argc,char **argv) { |
|
int id; |
int id; |
int cmd; |
int cmd; |
Obj obj; |
Obj obj; |
USINT ui; |
|
ERR err; |
ERR err; |
LIST list; |
|
NODE n,n1; |
|
unsigned int serial; |
unsigned int serial; |
int ret; |
int ret; |
extern char LastError[]; |
extern char LastError[]; |
|
|
ox_asir_init(argc,argv); |
ox_asir_init(argc,argv,"ox_asir"); |
if ( do_message ) |
if ( do_message ) |
fprintf(stderr,"I'm an ox_asir, Version %d.\n",ASIR_VERSION); |
fprintf(stderr,"I'm an ox_asir, Version %d.\n",ASIR_VERSION); |
if ( setjmp(ox_env) ) { |
if ( SETJMP(ox_env) ) { |
while ( NEXT(asir_infile) ) |
while ( NEXT(asir_infile) ) |
closecurrentinput(); |
closecurrentinput(); |
ox_send_sync(0); |
ox_send_sync(0); |
Line 174 void ox_main(int argc,char **argv) { |
|
Line 172 void ox_main(int argc,char **argv) { |
|
break; |
break; |
if ( do_message ) |
if ( do_message ) |
fprintf(stderr," %s\n",name_of_cmd(cmd)); |
fprintf(stderr," %s\n",name_of_cmd(cmd)); |
if ( ret = setjmp(main_env) ) { |
if ( ret = SETJMP(main_env) ) { |
if ( ret == 1 ) { |
if ( ret == 1 ) { |
create_error(&err,serial,LastError); |
create_error(&err,serial,LastError); |
asir_push_one((Obj)err); |
asir_push_one((Obj)err); |
Line 489 int asir_executeString() |
|
Line 487 int asir_executeString() |
|
SNODE snode; |
SNODE snode; |
pointer val; |
pointer val; |
char *cmd; |
char *cmd; |
#if PARI |
#if defined(PARI) |
recover(0); |
recover(0); |
|
/* environement is defined in libpari.a */ |
if ( setjmp(environnement) ) { |
if ( setjmp(environnement) ) { |
avma = top; recover(1); |
avma = top; recover(1); |
resetenv(""); |
resetenv(""); |
Line 522 static void asir_executeFunction(int serial) |
|
Line 521 static void asir_executeFunction(int serial) |
|
int argc; |
int argc; |
FUNC f; |
FUNC f; |
Obj result; |
Obj result; |
VL vl; |
|
NODE n,n1; |
NODE n,n1; |
STRING fname; |
STRING fname; |
char *path; |
char *path; |
USINT ui; |
|
ERR err; |
ERR err; |
Obj arg; |
Obj arg; |
static char buf[BUFSIZ]; |
static char buf[BUFSIZ]; |
Line 639 Obj asir_peek_one() { |
|
Line 636 Obj asir_peek_one() { |
|
} |
} |
} |
} |
|
|
void ox_asir_init(int argc,char **argv) |
void ox_asir_init(int argc,char **argv,char *servername) |
{ |
{ |
int tmp; |
|
char ifname[BUFSIZ]; |
char ifname[BUFSIZ]; |
extern int GC_dont_gc; |
extern int GC_dont_gc; |
extern int read_exec_file; |
extern int read_exec_file; |
extern int do_asirrc; |
extern int do_asirrc; |
extern int do_server_in_X11; |
extern int do_server_in_X11; |
|
extern char displayname[]; |
char *getenv(); |
char *getenv(); |
static ox_asir_initialized = 0; |
static ox_asir_initialized = 0; |
FILE *ifp; |
FILE *ifp; |
char *homedir; |
char *homedir; |
char *ptr; |
char *ptr; |
|
#if !defined(VISUAL) |
|
int tmp; |
|
#endif |
|
|
#if !defined(VISUAL) && !MPI |
#if !defined(VISUAL) && !defined(MPI) |
do_server_in_X11 = 1; /* XXX */ |
do_server_in_X11 = 1; /* XXX */ |
#endif |
#endif |
asir_save_handler(); |
asir_save_handler(); |
#if PARI |
#if defined(PARI) |
risa_pari_init(); |
risa_pari_init(); |
#endif |
#endif |
srandom((int)get_current_time()); |
srandom((int)get_current_time()); |
Line 667 void ox_asir_init(int argc,char **argv) |
|
Line 667 void ox_asir_init(int argc,char **argv) |
|
endian_init(); |
endian_init(); |
GC_init(); |
GC_init(); |
process_args(--argc,++argv); |
process_args(--argc,++argv); |
|
#if defined(__CYGWIN__) |
|
if ( !displayname[0] ) |
|
do_server_in_X11 = 0; /* XXX */ |
|
#endif |
output_init(); |
output_init(); |
arf_init(); |
arf_init(); |
nglob_init(); |
nglob_init(); |
Line 698 void ox_asir_init(int argc,char **argv) |
|
Line 702 void ox_asir_init(int argc,char **argv) |
|
} |
} |
if ( do_asirrc && (ifp = fopen(ifname,"r")) ) { |
if ( do_asirrc && (ifp = fopen(ifname,"r")) ) { |
input_init(ifp,ifname); |
input_init(ifp,ifname); |
if ( !setjmp(main_env) ) { |
if ( !SETJMP(main_env) ) { |
read_exec_file = 1; |
read_exec_file = 1; |
read_eval_loop(); |
read_eval_loop(); |
read_exec_file = 0; |
read_exec_file = 0; |
Line 706 void ox_asir_init(int argc,char **argv) |
|
Line 710 void ox_asir_init(int argc,char **argv) |
|
fclose(ifp); |
fclose(ifp); |
} |
} |
input_init(0,"string"); |
input_init(0,"string"); |
#if !MPI |
/* XXX Windows compatibility */ |
ox_io_init(); |
ox_io_init(); |
#endif |
create_my_mathcap(servername); |
create_my_mathcap("ox_asir"); |
|
} |
} |
|
|
void ox_io_init() { |
void ox_io_init() { |
unsigned char c,rc; |
unsigned char c,rc; |
extern int I_am_server; |
extern int I_am_server; |
int i; |
|
|
|
/* XXX : ssh forwards stdin to a remote host */ |
/* XXX : ssh forwards stdin to a remote host on PC Unix */ |
#if defined(linux) || defined(__NeXT__) || defined(ultrix) |
#if defined(linux) |
#include <sys/param.h> |
#include <sys/param.h> |
close(0); |
int i; |
for ( i = 5; i < NOFILE; i++ ) |
|
close(i); |
close(0); |
#else |
for ( i = 5; i < NOFILE; i++ ) |
|
close(i); |
|
#elif defined(__FreeBSD__) |
#include <sys/resource.h> |
#include <sys/resource.h> |
struct rlimit rl; |
int i; |
|
struct rlimit rl; |
|
|
getrlimit(RLIMIT_NOFILE,&rl); |
getrlimit(RLIMIT_NOFILE,&rl); |
close(0); |
close(0); |
for ( i = 5; i < rl.rlim_cur; i++ ) |
for ( i = 5; i < rl.rlim_cur; i++ ) |
close(i); |
close(i); |
#endif |
#endif |
|
|
I_am_server = 1; |
I_am_server = 1; |
Line 744 void ox_io_init() { |
|
Line 749 void ox_io_init() { |
|
iofp[0].in = fdopen(3,"r"); |
iofp[0].in = fdopen(3,"r"); |
iofp[0].out = fdopen(4,"w"); |
iofp[0].out = fdopen(4,"w"); |
|
|
|
#if !defined(__CYGWIN__) |
setbuffer(iofp[0].in,(char *)malloc(LBUFSIZ),LBUFSIZ); |
setbuffer(iofp[0].in,(char *)malloc(LBUFSIZ),LBUFSIZ); |
setbuffer(iofp[0].out,(char *)malloc(LBUFSIZ),LBUFSIZ); |
setbuffer(iofp[0].out,(char *)malloc(LBUFSIZ),LBUFSIZ); |
|
#endif |
signal(SIGUSR1,ox_usr1_handler); |
signal(SIGUSR1,ox_usr1_handler); |
#endif |
#endif |
asir_OperandStackSize = BUFSIZ; |
asir_OperandStackSize = BUFSIZ; |
Line 784 void asir_ox_push_cmo(void *cmo) |
|
Line 791 void asir_ox_push_cmo(void *cmo) |
|
|
|
/* |
/* |
* Pop an object from the stack and converts it |
* 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) |
int asir_ox_pop_cmo(void *cmo, int limit) |
Line 808 int asir_ox_pop_cmo(void *cmo, int limit) |
|
Line 815 int asir_ox_pop_cmo(void *cmo, int limit) |
|
return -1; |
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. |
* Executes an SM command. |
*/ |
*/ |
Line 818 void asir_ox_push_cmd(int cmd) |
|
Line 849 void asir_ox_push_cmd(int cmd) |
|
ERR err; |
ERR err; |
extern char LastError[]; |
extern char LastError[]; |
|
|
if ( ret = setjmp(main_env) ) { |
if ( ret = SETJMP(main_env) ) { |
asir_reset_handler(); |
asir_reset_handler(); |
if ( ret == 1 ) { |
if ( ret == 1 ) { |
create_error(&err,0,LastError); /* XXX */ |
create_error(&err,0,LastError); /* XXX */ |
Line 845 void asir_ox_execute_string(char *s) |
|
Line 876 void asir_ox_execute_string(char *s) |
|
|
|
MKSTR(str,s); |
MKSTR(str,s); |
asir_push_one((Obj)str); |
asir_push_one((Obj)str); |
if ( ret = setjmp(main_env) ) { |
if ( ret = SETJMP(main_env) ) { |
asir_reset_handler(); |
asir_reset_handler(); |
if ( ret == 1 ) { |
if ( ret == 1 ) { |
create_error(&err,0,LastError); /* XXX */ |
create_error(&err,0,LastError); /* XXX */ |
Line 869 int asir_ox_peek_cmo_size() |
|
Line 900 int asir_ox_peek_cmo_size() |
|
Obj obj; |
Obj obj; |
int len; |
int len; |
|
|
obj = asir_pop_one(); |
obj = asir_peek_one(); |
asir_push_one(obj); |
|
if ( !valid_as_cmo(obj) ) { |
if ( !valid_as_cmo(obj) ) { |
fprintf(stderr,"The object at the stack top is invalid as a CMO.\n"); |
fprintf(stderr,"The object at the stack top is invalid as a CMO.\n"); |
return 0; |
return 0; |
Line 879 int asir_ox_peek_cmo_size() |
|
Line 909 int asir_ox_peek_cmo_size() |
|
return len; |
return len; |
} |
} |
|
|
|
int asir_ox_peek_cmo_string_length() |
|
{ |
|
Obj obj; |
|
int len; |
|
|
|
obj = asir_peek_one(); |
|
if ( !valid_as_cmo(obj) ) { |
|
fprintf(stderr,"The object at the stack top is invalid as a CMO.\n"); |
|
return 0; |
|
} |
|
len = estimate_length(CO,obj); |
|
return len+1; |
|
} |
|
|
/* |
/* |
* Initialization. |
* Initialization. |
* byteorder=0 => native |
* byteorder=0 => native |
Line 897 int asir_ox_init(int byteorder) |
|
Line 941 int asir_ox_init(int byteorder) |
|
static ox_asir_initialized = 0; |
static ox_asir_initialized = 0; |
FILE *ifp; |
FILE *ifp; |
|
|
#if !defined(VISUAL) && !MPI |
#if !defined(VISUAL) && !defined(MPI) |
do_server_in_X11 = 0; /* XXX */ |
do_server_in_X11 = 0; /* XXX */ |
#endif |
#endif |
asir_save_handler(); |
asir_save_handler(); |
#if PARI |
#if defined(PARI) |
risa_pari_init(); |
risa_pari_init(); |
#endif |
#endif |
srandom((int)get_current_time()); |
srandom((int)get_current_time()); |
Line 930 int asir_ox_init(int byteorder) |
|
Line 974 int asir_ox_init(int byteorder) |
|
sprintf(ifname,"%s/.asirrc",getenv("HOME")); |
sprintf(ifname,"%s/.asirrc",getenv("HOME")); |
if ( do_asirrc && (ifp = fopen(ifname,"r")) ) { |
if ( do_asirrc && (ifp = fopen(ifname,"r")) ) { |
input_init(ifp,ifname); |
input_init(ifp,ifname); |
if ( !setjmp(main_env) ) { |
if ( !SETJMP(main_env) ) { |
read_exec_file = 1; |
read_exec_file = 1; |
read_eval_loop(); |
read_eval_loop(); |
read_exec_file = 0; |
read_exec_file = 0; |