=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/builtin/file.c,v retrieving revision 1.15 retrieving revision 1.20 diff -u -p -r1.15 -r1.20 --- OpenXM_contrib2/asir2000/builtin/file.c 2001/10/09 01:36:05 1.15 +++ OpenXM_contrib2/asir2000/builtin/file.c 2004/04/26 05:28:40 1.20 @@ -45,14 +45,16 @@ * 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.14 2001/08/20 09:03:24 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/builtin/file.c,v 1.19 2003/11/12 07:48:50 noro 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 @@ -75,7 +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 Pload_exec(); +void Pexec(); extern int des_encryption; extern char *asir_libdir; @@ -90,7 +92,7 @@ struct ftab file_tab[] = { {"remove_file",Premove_file,1}, {"access",Paccess,1}, {"load",Pload,-1}, - {"load_exec",Pload_exec,1}, + {"exec",Pexec,1}, {"which",Pwhich,1}, {"loadfiles",Ploadfiles,1}, {"output",Poutput,-1}, @@ -129,11 +131,19 @@ void Popen_file(NODE arg,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); @@ -225,20 +235,30 @@ void Pget_byte(NODE arg,Q *rp) error("get_byte : invalid argument"); } -void Pput_byte(NODE arg,Q *rp) +void Pput_byte(NODE arg,Obj *rp) { - int i,c; + int i,j,c; FILE *fp; + Obj obj; + TB tb; 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 + if ( !(fp = file_ptrs[i]) ) error("put_byte : invalid argument"); + + obj = (Obj)ARG1(arg); + if ( !obj || OID(obj) == O_N ) { + c = QTOS((Q)obj); + putc(c,fp); + } else if ( OID(obj) == O_STR ) + fputs(BDY((STRING)obj),fp); + else if ( OID(obj) == O_TB ) { + tb = (TB)obj; + for ( j = 0; j < tb->next; j++ ) + fputs(tb->body[j],fp); + } + *rp = obj; } void Pload(NODE arg,Q *rp) @@ -270,7 +290,7 @@ void Pload(NODE arg,Q *rp) STOQ(ret,*rp); } -void Pload_exec(NODE arg,Q *rp) +void Pexec(NODE arg,Q *rp) { int ret; char *name0,*name; @@ -280,7 +300,7 @@ void Pload_exec(NODE arg,Q *rp) if ( !name ) ret = -1; else { - load_and_execfile(name); + execasirfile(name); ret = 0; } STOQ(ret,*rp); @@ -321,7 +341,7 @@ void Ploadfiles(NODE arg,Q *rp) void Poutput(NODE arg,Q *rp) { -#if PARI +#if defined(PARI) extern FILE *outfile; #endif FILE *fp; @@ -339,7 +359,7 @@ void Poutput(NODE arg,Q *rp) error("output : invalid filename"); break; } -#if PARI +#if defined(PARI) pari_outfile = #endif asir_out = fp;