=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/builtin/file.c,v retrieving revision 1.13 retrieving revision 1.19 diff -u -p -r1.13 -r1.19 --- OpenXM_contrib2/asir2000/builtin/file.c 2001/03/21 23:49:34 1.13 +++ OpenXM_contrib2/asir2000/builtin/file.c 2003/11/12 07:48:50 1.19 @@ -45,19 +45,23 @@ * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. * - * $OpenXM: OpenXM_contrib2/asir2000/builtin/file.c,v 1.12 2000/12/06 00:54:09 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/builtin/file.c,v 1.18 2003/11/01 23:58:43 takayama Exp $ */ #include "ca.h" #include "parse.h" +#include "ox.h" #include "base.h" +#if !defined(VISUAL) #include "unistd.h" -#if PARI +#endif +#if defined(PARI) #include "genpari.h" #endif #if defined(VISUAL) #include #include +#include /* #define ECGEN_KEYNAME "SoftWare\\Fujitsu\\WinECgen\\1.00.000" */ #define ECGEN_KEYNAME "SoftWare\\Fujitsu\\FSEcParamGen\\V1.0L10" #define ASIR_KEYNAME "SoftWare\\Fujitsu\\Asir\\1999.03.31" @@ -73,6 +77,7 @@ void Pbsave_compat(), Pbload_compat(); void Pbsave_cmo(), Pbload_cmo(); void Popen_file(), Pclose_file(), Pget_line(), Pget_byte(), Pput_byte(); void Ppurge_stdin(); +void Pexec(); extern int des_encryption; extern char *asir_libdir; @@ -87,6 +92,7 @@ struct ftab file_tab[] = { {"remove_file",Premove_file,1}, {"access",Paccess,1}, {"load",Pload,-1}, + {"exec",Pexec,1}, {"which",Pwhich,1}, {"loadfiles",Ploadfiles,1}, {"output",Poutput,-1}, @@ -107,16 +113,13 @@ struct ftab file_tab[] = { static FILE *file_ptrs[BUFSIZ]; -void Ppurge_stdin(rp) -Q *rp; +void Ppurge_stdin(Q *rp) { purge_stdin(stdin); *rp = 0; } -void Popen_file(arg,rp) -NODE arg; -Q *rp; +void Popen_file(NODE arg,Q *rp) { char *name; FILE *fp; @@ -128,11 +131,19 @@ Q *rp; if ( i == BUFSIZ ) error("open_file : too many open files"); name = BDY((STRING)ARG0(arg)); - if ( argc(arg) == 2 ) { + if (strcmp(name,"unix://stdin") == 0) { + fp = stdin; + }else if (strcmp(name,"unix://stdout") == 0) { + fp = stdout; + }else if (strcmp(name,"unix://stderr") == 0) { + fp = stderr; + }else{ + if ( argc(arg) == 2 ) { asir_assert(ARG1(arg),O_STR,"open_file"); fp = fopen(name,BDY((STRING)ARG1(arg))); - } else + } else fp = fopen(name,"r"); + } if ( !fp ) { sprintf(errbuf,"open_file : cannot open \"%s\"",name); error(errbuf); @@ -141,9 +152,7 @@ Q *rp; STOQ(i,*rp); } -void Pclose_file(arg,rp) -NODE arg; -Q *rp; +void Pclose_file(NODE arg,Q *rp) { int i; @@ -157,9 +166,7 @@ Q *rp; *rp = ONE; } -void Pget_line(arg,rp) -NODE arg; -STRING *rp; +void Pget_line(NODE arg,STRING *rp) { int i,j,c; FILE *fp; @@ -210,9 +217,7 @@ STRING *rp; error("get_line : invalid argument"); } -void Pget_byte(arg,rp) -NODE arg; -Q *rp; +void Pget_byte(NODE arg,Q *rp) { int i,c; FILE *fp; @@ -230,9 +235,7 @@ Q *rp; error("get_byte : invalid argument"); } -void Pput_byte(arg,rp) -NODE arg; -Q *rp; +void Pput_byte(NODE arg,Q *rp) { int i,c; FILE *fp; @@ -248,9 +251,7 @@ Q *rp; error("put_byte : invalid argument"); } -void Pload(arg,rp) -NODE arg; -Q *rp; +void Pload(NODE arg,Q *rp) { int ret = 0; char *name,*name0; @@ -279,10 +280,24 @@ Q *rp; STOQ(ret,*rp); } -void Pwhich(arg,rp) -NODE arg; -STRING *rp; +void Pexec(NODE arg,Q *rp) { + int ret; + char *name0,*name; + + name0 = BDY((STRING)ARG0(arg)); + searchasirpath(name0,&name); + if ( !name ) + ret = -1; + else { + execasirfile(name); + ret = 0; + } + STOQ(ret,*rp); +} + +void Pwhich(NODE arg,STRING *rp) +{ char *name; STRING str; @@ -300,9 +315,7 @@ STRING *rp; *rp = 0; } -void Ploadfiles(arg,rp) -NODE arg; -Q *rp; +void Ploadfiles(NODE arg,Q *rp) { int ret; @@ -316,11 +329,9 @@ Q *rp; STOQ(ret,*rp); } -void Poutput(arg,rp) -NODE arg; -Q *rp; +void Poutput(NODE arg,Q *rp) { -#if PARI +#if defined(PARI) extern FILE *outfile; #endif FILE *fp; @@ -338,7 +349,7 @@ Q *rp; error("output : invalid filename"); break; } -#if PARI +#if defined(PARI) pari_outfile = #endif asir_out = fp; @@ -347,9 +358,7 @@ Q *rp; extern int ox_file_io; -void Pbsave(arg,rp) -NODE arg; -Q *rp; +void Pbsave(NODE arg,Q *rp) { FILE *fp; VL vl,t; @@ -370,9 +379,7 @@ Q *rp; *rp = ONE; } -void Pbload(arg,rp) -NODE arg; -Obj *rp; +void Pbload(NODE arg,Obj *rp) { FILE *fp; @@ -387,12 +394,9 @@ Obj *rp; ox_file_io = 0; } -void Pbsave_cmo(arg,rp) -NODE arg; -Q *rp; +void Pbsave_cmo(NODE arg,Q *rp) { FILE *fp; - VL vl,t; asir_assert(ARG1(arg),O_STR,"bsave_cmo"); fp = fopen(BDY((STRING)ARG1(arg)),"wb"); @@ -405,9 +409,7 @@ Q *rp; *rp = ONE; } -void Pbload_cmo(arg,rp) -NODE arg; -Obj *rp; +void Pbload_cmo(NODE arg,Obj *rp) { FILE *fp; @@ -424,9 +426,7 @@ Obj *rp; static struct oSTRING rootdir; #if defined(VISUAL) -void get_rootdir(name,len) -char *name; -int len; +void get_rootdir(char *name,int len) { LONG ret; HKEY hOpenKey; @@ -462,8 +462,7 @@ int len; } } -void set_rootdir(name) -char *name; +void set_rootdir(char *name) { static char DirName[BUFSIZ]; @@ -476,15 +475,12 @@ char *name; } #else -void get_rootdir(name,len) -char *name; -int len; +void get_rootdir(char *name,int len) { strcpy(name,asir_libdir); } -void set_rootdir(name) -char *name; +void set_rootdir(char *name) { static char DirName[BUFSIZ]; @@ -496,11 +492,9 @@ char *name; #endif -void Pget_rootdir(rp) -STRING *rp; +void Pget_rootdir(STRING *rp) { static char DirName[BUFSIZ]; - int DirNameLen; if ( !rootdir.body ) { get_rootdir(DirName,sizeof(DirName)); @@ -511,9 +505,7 @@ STRING *rp; } #if defined(VISUAL) && defined(DES_ENC) -void Pbsave_enc(arg,rp) -NODE arg; -Obj *rp; +void Pbsave_enc(NODE arg,Obj *rp) { init_deskey(); des_encryption = 1; @@ -521,9 +513,7 @@ Obj *rp; des_encryption = 0; } -void Pbload_enc(arg,rp) -NODE arg; -Obj *rp; +void Pbload_enc(NODE arg,Obj *rp) { init_deskey(); des_encryption = 1; @@ -532,9 +522,7 @@ Obj *rp; } #endif -void Pbload27(arg,rp) -NODE arg; -Obj *rp; +void Pbload27(NODE arg,Obj *rp) { FILE *fp; Obj r; @@ -549,9 +537,7 @@ Obj *rp; bobjtoobj(BASE27,r,rp); } -void Pbsave_compat(arg,rp) -NODE arg; -Q *rp; +void Pbsave_compat(NODE arg,Q *rp) { FILE *fp; VL vl,t; @@ -572,9 +558,7 @@ Q *rp; *rp = ONE; } -void Pbload_compat(arg,rp) -NODE arg; -Obj *rp; +void Pbload_compat(NODE arg,Obj *rp) { FILE *fp; unsigned int hdr[2]; @@ -608,21 +592,14 @@ Obj *rp; fclose(fp); } -void Premove_file(arg,rp) -NODE arg; -Q *rp; +void Premove_file(NODE arg,Q *rp) { unlink((char *)BDY((STRING)ARG0(arg))); *rp = ONE; } -void Paccess(arg,rp) -NODE arg; -Q *rp; +void Paccess(NODE arg,Q *rp) { - char *name; - STRING str; - #if defined(VISUAL) if ( access(BDY((STRING)ARG0(arg)),04) >= 0 ) #else @@ -639,9 +616,7 @@ int process_id() return GetCurrentProcessId(); } -void call_exe(name,av) -char *name; -char **av; +void call_exe(char *name,char **av) { _spawnv(_P_WAIT,name,av); }