version 1.1, 1999/12/03 07:39:11 |
version 1.4, 2000/01/19 09:31:00 |
|
|
/* $OpenXM: OpenXM/src/asir99/io/ox_asir.c,v 1.5 1999/11/18 02:24:02 noro Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/io/ox_asir.c,v 1.3 2000/01/18 05:55:07 noro Exp $ */ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
#include "ox.h" |
#include "ox.h" |
Line 47 void ox_mpi_master_init() { |
|
Line 47 void ox_mpi_master_init() { |
|
for ( i = 1; i < mpi_nprocs; i++ ) { |
for ( i = 1; i < mpi_nprocs; i++ ) { |
/* client mode */ |
/* client mode */ |
idx = get_iofp(i,0,0); |
idx = get_iofp(i,0,0); |
ret = register_server(idx,idx); |
ret = register_server(0,idx,idx); |
} |
} |
} |
} |
|
|
Line 549 static void ox_asir_init(int argc,char **argv) |
|
Line 549 static void ox_asir_init(int argc,char **argv) |
|
char *getenv(); |
char *getenv(); |
static ox_asir_initialized = 0; |
static ox_asir_initialized = 0; |
FILE *ifp; |
FILE *ifp; |
|
char *homedir; |
|
char *ptr; |
|
|
#if !defined(VISUAL) && !MPI |
#if !defined(VISUAL) && !MPI |
do_server_in_X11 = 1; /* XXX */ |
do_server_in_X11 = 1; /* XXX */ |
Line 587 static void ox_asir_init(int argc,char **argv) |
|
Line 589 static void ox_asir_init(int argc,char **argv) |
|
#if defined(UINIT) |
#if defined(UINIT) |
reg_sysf(); |
reg_sysf(); |
#endif |
#endif |
|
/* if ASIR_CONFIG is set, execute it; else execute .asirrc */ |
|
if ( ptr = getenv("ASIR_CONFIG") ) |
|
strcpy(ifname,ptr); |
|
else { |
#if defined(THINK_C) |
#if defined(THINK_C) |
sprintf(ifname,"asirrc"); |
sprintf(ifname,"asirrc"); |
#else |
#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 |
#endif |
|
} |
if ( do_asirrc && (ifp = fopen(ifname,"r")) ) { |
if ( do_asirrc && (ifp = fopen(ifname,"r")) ) { |
input_init(ifp,ifname); |
input_init(ifp,ifname); |
if ( !setjmp(env) ) { |
if ( !setjmp(env) ) { |
Line 637 static void ox_io_init() { |
|
Line 651 static void ox_io_init() { |
|
write_char(iofp[0].out,&c); ox_flush_stream_force(0); |
write_char(iofp[0].out,&c); ox_flush_stream_force(0); |
read_char(iofp[0].in,&rc); |
read_char(iofp[0].in,&rc); |
iofp[0].conv = c == rc ? 0 : 1; |
iofp[0].conv = c == rc ? 0 : 1; |
|
} |
|
|
|
/* |
|
* Library mode functions |
|
*/ |
|
|
|
/* |
|
* Converts a binary encoded CMO into a risa object |
|
* and pushes it onto the stack. |
|
*/ |
|
|
|
void asir_ox_push_cmo(void *cmo) |
|
{ |
|
Obj obj; |
|
|
|
ox_copy_init(cmo); |
|
ox_buf_to_obj_as_cmo(&obj); |
|
asir_push_one(obj); |
|
} |
|
|
|
/* |
|
* Pop an object from the stack and converts it |
|
* int a binary encoded CMO. |
|
*/ |
|
|
|
int asir_ox_pop_cmo(void *cmo, int limit) |
|
{ |
|
Obj obj; |
|
int len; |
|
|
|
obj = asir_pop_one(); |
|
len = count_as_cmo(obj); |
|
if ( len <= limit ) { |
|
ox_copy_init(cmo); |
|
ox_obj_to_buf_as_cmo(obj); |
|
return len; |
|
} else |
|
return -1; |
|
} |
|
|
|
/* |
|
* Executes an SM command. |
|
*/ |
|
|
|
void asir_ox_push_cmd(unsigned int cmd) |
|
{ |
|
asir_do_cmd(cmd,0); |
|
} |
|
|
|
/* |
|
* Executes a string written in Asir. |
|
*/ |
|
|
|
void asir_ox_execute_string(char *s) |
|
{ |
|
STRING str; |
|
|
|
MKSTR(str,s); |
|
asir_push_one((Obj)str); |
|
asir_executeString(); |
|
} |
|
|
|
/* |
|
* Returns the size as a CMO of the object |
|
* at the top of the stack. |
|
*/ |
|
|
|
int asir_ox_peek_cmo_size() |
|
{ |
|
Obj obj; |
|
int len; |
|
|
|
obj = asir_pop_one(); |
|
len = count_as_cmo(obj); |
|
asir_push_one(obj); |
|
return len; |
|
} |
|
|
|
/* |
|
* Initialization. |
|
* byteorder = 1 : little endian |
|
* 0 : big endian |
|
*/ |
|
|
|
void asir_ox_io_init(); |
|
|
|
void asir_ox_init(int byteorder) |
|
{ |
|
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; |
|
char *getenv(); |
|
static ox_asir_initialized = 0; |
|
FILE *ifp; |
|
|
|
#if !defined(VISUAL) && !MPI |
|
do_server_in_X11 = 1; /* XXX */ |
|
#endif |
|
asir_save_handler(); |
|
#if PARI |
|
risa_pari_init(); |
|
#endif |
|
srandom((int)get_current_time()); |
|
|
|
#if defined(THINK_C) |
|
param_init(); |
|
#endif |
|
StackBottom = &tmp + 1; /* XXX */ |
|
rtime_init(); |
|
env_init(); |
|
endian_init(); |
|
#if !defined(VISUAL) && !defined(THINK_C) |
|
/* check_key(); */ |
|
#endif |
|
GC_init(); |
|
/* process_args(argc,argv); */ |
|
output_init(); |
|
arf_init(); |
|
nglob_init(); |
|
glob_init(); |
|
sig_init(); |
|
tty_init(); |
|
debug_init(); |
|
pf_init(); |
|
sysf_init(); |
|
parif_init(); |
|
#if defined(VISUAL) |
|
init_socket(); |
|
#endif |
|
#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) ) { |
|
read_exec_file = 1; |
|
read_eval_loop(); |
|
read_exec_file = 0; |
|
} |
|
fclose(ifp); |
|
} |
|
input_init(0,"string"); |
|
asir_ox_io_init(byteorder); |
|
create_my_mathcap("ox_asir"); |
|
} |
|
|
|
void asir_ox_io_init(byteorder) |
|
int byteorder; |
|
{ |
|
unsigned char c; |
|
extern int little_endian; |
|
extern int lib_ox_initialized; |
|
|
|
endian_init(); |
|
asir_OperandStackSize = BUFSIZ; |
|
asir_OperandStack = (Obj *)CALLOC(asir_OperandStackSize,sizeof(Obj)); |
|
asir_OperandStackPtr = -1; |
|
if ( little_endian ) |
|
c = 1; |
|
else |
|
c = 0; |
|
iofp[0].conv = c == byteorder ? 0 : 1; |
|
lib_ox_initialized = 1; |
|
do_message = 0; |
} |
} |