=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/builtin/file.c,v retrieving revision 1.11 retrieving revision 1.14 diff -u -p -r1.11 -r1.14 --- OpenXM_contrib2/asir2000/builtin/file.c 2000/12/05 01:24:50 1.11 +++ OpenXM_contrib2/asir2000/builtin/file.c 2001/08/20 09:03:24 1.14 @@ -45,7 +45,7 @@ * 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.10 2000/11/13 01:48:12 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/builtin/file.c,v 1.13 2001/03/21 23:49:34 noro Exp $ */ #include "ca.h" #include "parse.h" @@ -71,21 +71,24 @@ void Pload(), Pwhich(), Ploadfiles(), Poutput(); void Pbsave(), Pbload(), Pbload27(); void Pbsave_compat(), Pbload_compat(); void Pbsave_cmo(), Pbload_cmo(); -void Popen_file(), Pclose_file(), Pget_line(), Pget_byte(); +void Popen_file(), Pclose_file(), Pget_line(), Pget_byte(), Pput_byte(); void Ppurge_stdin(); +void Pload_exec(); extern int des_encryption; extern char *asir_libdir; struct ftab file_tab[] = { {"purge_stdin",Ppurge_stdin,0}, - {"open_file",Popen_file,1}, + {"open_file",Popen_file,-2}, {"close_file",Pclose_file,1}, {"get_byte",Pget_byte,1}, + {"put_byte",Pput_byte,2}, {"get_line",Pget_line,-1}, {"remove_file",Premove_file,1}, {"access",Paccess,1}, {"load",Pload,-1}, + {"load_exec",Pload_exec,1}, {"which",Pwhich,1}, {"loadfiles",Ploadfiles,1}, {"output",Poutput,-1}, @@ -127,9 +130,13 @@ Q *rp; if ( i == BUFSIZ ) error("open_file : too many open files"); name = BDY((STRING)ARG0(arg)); - fp = fopen(name,"r"); + if ( argc(arg) == 2 ) { + asir_assert(ARG1(arg),O_STR,"open_file"); + fp = fopen(name,BDY((STRING)ARG1(arg))); + } else + fp = fopen(name,"r"); if ( !fp ) { - sprintf(errbuf,"open_file : \"%s\" not found",name); + sprintf(errbuf,"open_file : cannot open \"%s\"",name); error(errbuf); } file_ptrs[i] = fp; @@ -225,6 +232,24 @@ Q *rp; error("get_byte : invalid argument"); } +void Pput_byte(arg,rp) +NODE arg; +Q *rp; +{ + int i,c; + FILE *fp; + + asir_assert(ARG0(arg),O_N,"put_byte"); + asir_assert(ARG1(arg),O_N,"put_byte"); + i = QTOS((Q)ARG0(arg)); + c = QTOS((Q)ARG1(arg)); + if ( fp = file_ptrs[i] ) { + putc(c,fp); + STOQ(c,*rp); + } else + error("put_byte : invalid argument"); +} + void Pload(arg,rp) NODE arg; Q *rp; @@ -256,6 +281,22 @@ Q *rp; STOQ(ret,*rp); } +void Pload_exec(arg,rp) +NODE arg; +Q *rp; +{ + int ret = 0; + char *name0,*name; + + name0 = BDY((STRING)ARG0(arg)); + searchasirpath(name0,&name); + if ( !name ) + ret = -1; + else + ret = load_and_execfile(name); + STOQ(ret,*rp); +} + void Pwhich(arg,rp) NODE arg; STRING *rp; @@ -409,9 +450,17 @@ int len; HKEY hOpenKey; DWORD Type; char *slash; - + if ( rootdir.body ) { strcpy(name,rootdir.body); + return; + } + + if ( access("UseCurrentDir",0) >= 0 ) { + GetCurrentDirectory(BUFSIZ,name); + slash = strrchr(name,'\\'); + if ( slash ) + *slash = 0; return; } name[0] = 0;