[BACK]Return to file.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / builtin

Diff for /OpenXM_contrib2/asir2000/builtin/file.c between version 1.15 and 1.23

version 1.15, 2001/10/09 01:36:05 version 1.23, 2006/09/13 02:26:13
Line 45 
Line 45 
  * 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/builtin/file.c,v 1.14 2001/08/20 09:03:24 noro Exp $   * $OpenXM: OpenXM_contrib2/asir2000/builtin/file.c,v 1.22 2006/02/08 02:11:19 noro Exp $
 */  */
 #include "ca.h"  #include "ca.h"
 #include "parse.h"  #include "parse.h"
 #include "ox.h"  #include "ox.h"
 #include "base.h"  #include "base.h"
   #if !defined(VISUAL)
 #include "unistd.h"  #include "unistd.h"
 #if PARI  #endif
   #if defined(PARI)
 #include "genpari.h"  #include "genpari.h"
 #endif  #endif
   
Line 75  void Pbsave_compat(), Pbload_compat();
Line 77  void Pbsave_compat(), Pbload_compat();
 void Pbsave_cmo(), Pbload_cmo();  void Pbsave_cmo(), Pbload_cmo();
 void Popen_file(), Pclose_file(), Pget_line(), Pget_byte(), Pput_byte();  void Popen_file(), Pclose_file(), Pget_line(), Pget_byte(), Pput_byte();
 void Ppurge_stdin();  void Ppurge_stdin();
 void Pload_exec();  void Pimport();
   
 extern int des_encryption;  extern int des_encryption;
 extern char *asir_libdir;  extern char *asir_libdir;
Line 90  struct ftab file_tab[] = {
Line 92  struct ftab file_tab[] = {
         {"remove_file",Premove_file,1},          {"remove_file",Premove_file,1},
         {"access",Paccess,1},          {"access",Paccess,1},
         {"load",Pload,-1},          {"load",Pload,-1},
         {"load_exec",Pload_exec,1},          {"import",Pimport,-1},
         {"which",Pwhich,1},          {"which",Pwhich,1},
         {"loadfiles",Ploadfiles,1},          {"loadfiles",Ploadfiles,1},
         {"output",Poutput,-1},          {"output",Poutput,-1},
Line 129  void Popen_file(NODE arg,Q *rp)
Line 131  void Popen_file(NODE arg,Q *rp)
         if ( i == BUFSIZ )          if ( i == BUFSIZ )
                 error("open_file : too many open files");                  error("open_file : too many open files");
         name = BDY((STRING)ARG0(arg));          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");                  asir_assert(ARG1(arg),O_STR,"open_file");
                 fp = fopen(name,BDY((STRING)ARG1(arg)));                  fp = fopen(name,BDY((STRING)ARG1(arg)));
         } else            } else
                 fp = fopen(name,"r");                  fp = fopen(name,"r");
       }
         if ( !fp ) {          if ( !fp ) {
                 sprintf(errbuf,"open_file : cannot open \"%s\"",name);                  sprintf(errbuf,"open_file : cannot open \"%s\"",name);
                 error(errbuf);                  error(errbuf);
Line 225  void Pget_byte(NODE arg,Q *rp)
Line 235  void Pget_byte(NODE arg,Q *rp)
                 error("get_byte : invalid argument");                  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;          FILE *fp;
           Obj obj;
           TB tb;
   
         asir_assert(ARG0(arg),O_N,"put_byte");          asir_assert(ARG0(arg),O_N,"put_byte");
         asir_assert(ARG1(arg),O_N,"put_byte");  
         i = QTOS((Q)ARG0(arg));          i = QTOS((Q)ARG0(arg));
         c = QTOS((Q)ARG1(arg));          if ( !(fp = file_ptrs[i]) )
         if ( fp = file_ptrs[i] ) {  
                 putc(c,fp);  
                 STOQ(c,*rp);  
         } else  
                 error("put_byte : invalid argument");                  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)  void Pload(NODE arg,Q *rp)
Line 247  void Pload(NODE arg,Q *rp)
Line 267  void Pload(NODE arg,Q *rp)
         char *name,*name0;          char *name,*name0;
         char errbuf[BUFSIZ];          char errbuf[BUFSIZ];
   
           if ( !arg ) error("load : invalid argument");
         if ( ARG0(arg) ) {          if ( ARG0(arg) ) {
                 switch (OID(ARG0(arg))) {                  switch (OID(ARG0(arg))) {
                         case O_STR:                          case O_STR:
Line 256  void Pload(NODE arg,Q *rp)
Line 277  void Pload(NODE arg,Q *rp)
                                         sprintf(errbuf,"load : \"%s\" not found in the search path",name0);                                          sprintf(errbuf,"load : \"%s\" not found in the search path",name0);
                                         error(errbuf);                                          error(errbuf);
                                 }                                  }
                                 ret = loadfile(name);                                  execasirfile(name);
                                 if ( !ret ) {  
                                         sprintf(errbuf,"load : \"%s\" could not be loaded",name);  
                                         error(errbuf);  
                                 }  
                                 break;                                  break;
                         default:                          default:
                                 error("load : invalid argument");                                  error("load : invalid argument");
Line 270  void Pload(NODE arg,Q *rp)
Line 287  void Pload(NODE arg,Q *rp)
         STOQ(ret,*rp);          STOQ(ret,*rp);
 }  }
   
 void Pload_exec(NODE arg,Q *rp)  NODE imported_files;
   
   void Pimport(NODE arg,Q *rp)
 {  {
         int ret;          char *name;
         char *name0,*name;          NODE t,p,opt;
   
         name0 = BDY((STRING)ARG0(arg));          name = BDY((STRING)ARG0(arg));
         searchasirpath(name0,&name);          for ( t = imported_files; t; t = NEXT(t) )
         if ( !name )                  if ( !strcmp((char *)BDY(t),name) ) break;
                 ret = -1;          if ( !t ) {
         else {                  Pload(arg,rp);
                 load_and_execfile(name);                  MKNODE(t,name,imported_files);
                 ret = 0;                  imported_files = t;
                   return;
           } else if ( current_option ) {
                   for ( opt = current_option; opt; opt = NEXT(opt) ) {
                           p = BDY((LIST)BDY(opt));
                           if ( !strcmp(BDY((STRING)BDY(p)),"reimport") && BDY(NEXT(p)) ) {
                                   Pload(arg,rp);
                                   return;
                           }
                   }
         }          }
         STOQ(ret,*rp);          *rp = 0;
 }  }
   
 void Pwhich(NODE arg,STRING *rp)  void Pwhich(NODE arg,STRING *rp)
Line 321  void Ploadfiles(NODE arg,Q *rp)
Line 349  void Ploadfiles(NODE arg,Q *rp)
   
 void Poutput(NODE arg,Q *rp)  void Poutput(NODE arg,Q *rp)
 {  {
 #if PARI  #if defined(PARI)
         extern FILE *outfile;          extern FILE *outfile;
 #endif  #endif
         FILE *fp;          FILE *fp;
Line 339  void Poutput(NODE arg,Q *rp)
Line 367  void Poutput(NODE arg,Q *rp)
                                 error("output : invalid filename");                                  error("output : invalid filename");
                         break;                          break;
         }          }
 #if PARI  #if defined(PARI)
         pari_outfile =          pari_outfile =
 #endif  #endif
         asir_out = fp;          asir_out = fp;

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.23

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>