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

Diff for /OpenXM_contrib2/asir2000/io/io.c between version 1.8 and 1.16

version 1.8, 2000/08/29 04:03:05 version 1.16, 2015/08/06 10:01:52
Line 44 
Line 44 
  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY   * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
  * 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/io/io.c,v 1.7 2000/08/25 08:06:19 noro Exp $   * $OpenXM: OpenXM_contrib2/asir2000/io/io.c,v 1.15 2015/08/04 06:20:45 noro Exp $
 */  */
 #include <stdio.h>  #include <stdio.h>
 #include "ca.h"  #include "ca.h"
 #if defined(VISUAL) || MPI  #include "parse.h"
   #if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__) || defined(MPI)
 #include "wsio.h"  #include "wsio.h"
 #endif  #endif
   
Line 56  extern int little_endian,lib_ox_need_conv;
Line 57  extern int little_endian,lib_ox_need_conv;
 extern int ox_do_copy, ox_do_count, ox_count_length, ox_file_io, ox_need_conv;  extern int ox_do_copy, ox_do_count, ox_count_length, ox_file_io, ox_need_conv;
 extern char *ox_copy_bptr;  extern char *ox_copy_bptr;
   
   /* XXX */
   void write_cmo(pointer,Obj);
   
 void reset_io()  void reset_io()
 {  {
         ox_file_io = 0;          ox_file_io = 0;
Line 72  void endian_init()
Line 76  void endian_init()
         ox_need_conv = 1;          ox_need_conv = 1;
 }  }
   
 int countobj(p)  int countobj(Obj p)
 Obj p;  
 {  {
         ox_count_length = 0;          ox_count_length = 0;
         ox_do_count = 1; saveobj(0,p); ox_do_count = 0;          ox_do_count = 1; saveobj(0,p); ox_do_count = 0;
         return ox_count_length;          return ox_count_length;
 }  }
   
 int count_as_cmo(p)  int count_as_cmo(Obj p)
 Obj p;  
 {  {
         ox_count_length = 0;          ox_count_length = 0;
         ox_do_count = 1; write_cmo(0,p); ox_do_count = 0;          ox_do_count = 1; write_cmo(0,p); ox_do_count = 0;
         return ox_count_length;          return ox_count_length;
 }  }
   
 int countvl(vl)  int countvl(VL vl)
 VL vl;  
 {  {
         ox_count_length = 0;          ox_count_length = 0;
         ox_do_count = 1; savevl(0,vl); ox_do_count = 0;          ox_do_count = 1; savevl(0,vl); ox_do_count = 0;
         return ox_count_length;          return ox_count_length;
 }  }
   
 void ox_copy_init(s)  void ox_copy_init(char *s)
 char *s;  
 {  {
         ox_copy_bptr = s;          ox_copy_bptr = s;
 }  }
   
 #if !defined(VISUAL)  #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
 /*  /*
  * library mode functions   * library mode functions
  * byte order is controlled by lib_ox_need_conv.   * byte order is controlled by lib_ox_need_conv.
  */   */
   
 void ox_obj_to_buf_as_cmo(p)  void ox_obj_to_buf_as_cmo(Obj p)
 Obj p;  
 {  {
         ox_need_conv = lib_ox_need_conv;          ox_need_conv = lib_ox_need_conv;
         ox_do_copy = 1; write_cmo(0,p); ox_do_copy = 0;          ox_do_copy = 1; write_cmo(0,p); ox_do_copy = 0;
 }  }
   
 void ox_buf_to_obj_as_cmo(p)  void ox_buf_to_obj_as_cmo(Obj *p)
 Obj *p;  
 {  {
         ox_need_conv = lib_ox_need_conv;          ox_need_conv = lib_ox_need_conv;
         ox_do_copy = 1; read_cmo(0,p); ox_do_copy = 0;          ox_do_copy = 1; read_cmo(0,p); ox_do_copy = 0;
 }  }
   
 void ox_vl_to_buf(vl)  void ox_vl_to_buf(VL vl)
 VL vl;  
 {  {
         ox_do_copy = 1; savevl(0,vl); ox_do_copy = 0;          ox_do_copy = 1; savevl(0,vl); ox_do_copy = 0;
 }  }
 #endif  #endif
   
 int gen_fread (ptr,size,nitems,stream)  int gen_fread (char *ptr,int size,int nitems,FILE *stream)
 char *ptr;  
 int size,nitems;  
 FILE *stream;  
 {  {
         int n;          int n;
   
Line 140  FILE *stream;
Line 134  FILE *stream;
                 n = size*nitems;                  n = size*nitems;
                 memcpy(ptr,ox_copy_bptr,n);                  memcpy(ptr,ox_copy_bptr,n);
                 ox_copy_bptr += n;                  ox_copy_bptr += n;
                   /* dummy return */
                   return 0;
         } else {          } else {
 #if defined(VISUAL)  #if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__)
                 if ( _fileno(stream) < 0 )                  if ( _fileno(stream) < 0 )
                         n = cread(ptr,size,nitems,(STREAM *)stream);                          n = cread(ptr,size,nitems,(STREAM *)stream);
                 else                  else
 #elif MPI  #elif defined(MPI)
                 if ( (char)fileno(stream) < 0 )                  if ( (char)fileno(stream) < 0 )
                         n = cread(ptr,size,nitems,(STREAM *)stream);                          n = cread(ptr,size,nitems,(STREAM *)stream);
                 else                  else
 #endif  #endif
                 n = fread(ptr,size,nitems,stream);                  n = fread(ptr,size,nitems,stream);
                 if ( !n )                  if ( !n ) {
                         ExitAsir();                          ExitAsir();
                 else                          /* NOTREACHED */
                           return 0;
                   } else
                         return n;                          return n;
         }          }
 }  }
   
 int gen_fwrite (ptr,size,nitems,stream)  int gen_fwrite (char *ptr,int size,int nitems,FILE *stream)
 char *ptr;  
 int size,nitems;  
 FILE *stream;  
 {  {
         int n;          int n;
   
         if ( ox_do_count )          if ( ox_do_count ) {
                 ox_count_length += size*nitems;                  ox_count_length += size*nitems;
         else if ( ox_do_copy ) {                  /* dummy return  */
                   return 0;
           } else if ( ox_do_copy ) {
                 n = size*nitems;                  n = size*nitems;
                 memcpy(ox_copy_bptr,ptr,n);                  memcpy(ox_copy_bptr,ptr,n);
                 ox_copy_bptr += n;                  ox_copy_bptr += n;
                   /* dummy return  */
                   return 0;
         } else          } else
 #if defined(VISUAL)  #if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__)
         if ( _fileno(stream) < 0 )          if ( _fileno(stream) < 0 )
                 return cwrite(ptr,size,nitems,(STREAM *)stream);                  return cwrite(ptr,size,nitems,(STREAM *)stream);
         else          else
 #elif MPI  #elif defined(MPI)
         if ( (char)fileno(stream) < 0 )          if ( (char)fileno(stream) < 0 )
                 return cwrite(ptr,size,nitems,(STREAM *)stream);                  return cwrite(ptr,size,nitems,(STREAM *)stream);
         else          else
Line 184  FILE *stream;
Line 183  FILE *stream;
                 return fwrite(ptr,size,nitems,stream);                  return fwrite(ptr,size,nitems,stream);
 }  }
   
 void write_char(f,p)  void write_char(FILE *f,unsigned char *p)
 FILE *f;  
 unsigned char *p;  
 {  {
         gen_fwrite(p,sizeof(unsigned char),1,f);          gen_fwrite(p,sizeof(unsigned char),1,f);
 }  }
   
 void write_short(f,p)  void write_short(FILE *f,unsigned short *p)
 FILE *f;  
 unsigned short *p;  
 {  {
         unsigned short t;          unsigned short t;
   
         if ( little_endian && (ox_file_io || ox_need_conv) ) {          if ( little_endian && (ox_file_io || ox_need_conv) ) {
                 t = htons(*p);                  t = htons(*p);
                 gen_fwrite(&t,sizeof(unsigned short),1,f);                  gen_fwrite((char *)&t,sizeof(unsigned short),1,f);
         } else          } else
                 gen_fwrite(p,sizeof(unsigned short),1,f);                  gen_fwrite((char *)p,sizeof(unsigned short),1,f);
 }  }
   
 void write_int(f,p)  void write_int(FILE *f,unsigned int *p)
 FILE *f;  
 unsigned int *p;  
 {  {
         unsigned int t;          unsigned int t;
   
         if ( little_endian && (ox_file_io || ox_need_conv) ) {          if ( little_endian && (ox_file_io || ox_need_conv) ) {
                 t = htonl(*p);                  t = htonl(*p);
                 gen_fwrite(&t,sizeof(unsigned int),1,f);                  gen_fwrite((char *)&t,sizeof(unsigned int),1,f);
         } else          } else
                 gen_fwrite(p,sizeof(unsigned int),1,f);                  gen_fwrite((char *)p,sizeof(unsigned int),1,f);
 }  }
   
 #if defined(VISUAL) && defined(DES_ENC)  void write_int64(FILE *f,UL *p)
   {
     unsigned int t;
   
           if ( little_endian && (ox_file_io || ox_need_conv) ) {
                   t = htonl(((unsigned int *)p)[1]);
                   gen_fwrite((char *)&t,sizeof(unsigned int),1,f);
                   t = htonl(((unsigned int *)p)[0]);
                   gen_fwrite((char *)&t,sizeof(unsigned int),1,f);
           } else
                   gen_fwrite((char *)p,sizeof(UL),1,f);
   }
   
   #if defined(DES_ENC)
 int des_encryption;  int des_encryption;
 static unsigned char asir_deskey[8] = {0xc7,0xe0,0xfc,0xb5,0xc3,0xad,0x8e,0x3a};  static unsigned char asir_deskey[8] = {0xc7,0xe0,0xfc,0xb5,0xc3,0xad,0x8e,0x3a};
 static unsigned char deskey_string[96];  static unsigned char deskey_string[96];
Line 233  void init_deskey()
Line 239  void init_deskey()
 }  }
 #endif  #endif
   
 void write_intarray(f,p,l)  void write_intarray(FILE *f,unsigned int *p,int l)
 FILE *f;  
 unsigned int *p;  
 int l;  
 {  {
         int i;          int i;
         unsigned int t;          unsigned int t;
 #if defined(VISUAL) && defined(DES_ENC)  #if defined(DES_ENC)
         int l2;          int l2;
         unsigned int plain[2],encrypted[2];          unsigned int plain[2],encrypted[2];
   
Line 252  int l;
Line 255  int l;
                         des_enc(plain,deskey_string,encrypted);                          des_enc(plain,deskey_string,encrypted);
                         encrypted[0] = htonl(encrypted[0]);                          encrypted[0] = htonl(encrypted[0]);
                         encrypted[1] = htonl(encrypted[1]);                          encrypted[1] = htonl(encrypted[1]);
                         gen_fwrite(encrypted,sizeof(unsigned int),2,f);                          gen_fwrite((char *)encrypted,sizeof(unsigned int),2,f);
                 }                  }
                 if ( (l2<<1) < l ) {                  if ( (l2<<1) < l ) {
                         plain[0] = *p;                          plain[0] = *p;
Line 260  int l;
Line 263  int l;
                         des_enc(plain,deskey_string,encrypted);                          des_enc(plain,deskey_string,encrypted);
                         encrypted[0] = htonl(encrypted[0]);                          encrypted[0] = htonl(encrypted[0]);
                         encrypted[1] = htonl(encrypted[1]);                          encrypted[1] = htonl(encrypted[1]);
                         gen_fwrite(encrypted,sizeof(unsigned int),2,f);                          gen_fwrite((char *)encrypted,sizeof(unsigned int),2,f);
                 }                  }
         } else          } else
 #endif  #endif
         if ( little_endian && (ox_file_io || ox_need_conv) )          if ( little_endian && (ox_file_io || ox_need_conv) )
                 for ( i = 0; i < l; i++, p++) {                  for ( i = 0; i < l; i++, p++) {
                         t = htonl(*p);                          t = htonl(*p);
                         gen_fwrite(&t,sizeof(unsigned int),1,f);                          gen_fwrite((char *)&t,sizeof(unsigned int),1,f);
                 }                  }
         else          else
                 gen_fwrite(p,sizeof(unsigned int),l,f);                  gen_fwrite((char *)p,sizeof(unsigned int),l,f);
 }  }
   
 #if defined(LONG_IS_64BIT)  #if SIZEOF_LONG == 8
 void write_longarray(f,p,l)  /* write l longword (1longword=8bytes) */
 FILE *f;  void write_longarray(FILE *f,unsigned long *p,int l)
 unsigned long *p;  
 int l;  
 {  {
         int i;          int i;
         unsigned long w;          unsigned long w;
Line 295  int l;
Line 296  int l;
 }  }
 #endif  #endif
   
 void write_double(f,p)  void write_double(FILE *f,double *p)
 FILE *f;  
 double *p;  
 {  {
         unsigned int t;          unsigned int t;
   
         if ( little_endian && (ox_file_io || ox_need_conv) ) {          if ( little_endian && (ox_file_io || ox_need_conv) ) {
                 t = htonl(((unsigned int *)p)[1]);                  t = htonl(((unsigned int *)p)[1]);
                 gen_fwrite(&t,sizeof(unsigned int),1,f);                  gen_fwrite((char *)&t,sizeof(unsigned int),1,f);
                 t = htonl(((unsigned int *)p)[0]);                  t = htonl(((unsigned int *)p)[0]);
                 gen_fwrite(&t,sizeof(unsigned int),1,f);                  gen_fwrite((char *)&t,sizeof(unsigned int),1,f);
         } else          } else
                 gen_fwrite(p,sizeof(double),1,f);                  gen_fwrite((char *)p,sizeof(double),1,f);
 }  }
   
 void write_string(f,p,l)  void write_string(FILE *f,unsigned char *p,int l)
 FILE *f;  
 unsigned char *p;  
 {  {
         gen_fwrite(p,sizeof(unsigned char),l,f);          gen_fwrite(p,sizeof(unsigned char),l,f);
 }  }
   
 void read_char(f,p)  void read_char(FILE *f,unsigned char *p)
 FILE *f;  
 unsigned char *p;  
 {  {
         gen_fread((char *)p,sizeof(unsigned char),1,f);          gen_fread((char *)p,sizeof(unsigned char),1,f);
 }  }
   
 void read_short(f,p)  void read_short(FILE *f,unsigned short *p)
 FILE *f;  
 unsigned short *p;  
 {  {
         gen_fread(p,sizeof(unsigned short),1,f);          gen_fread((char *)p,sizeof(unsigned short),1,f);
         if ( little_endian && (ox_file_io || ox_need_conv) )          if ( little_endian && (ox_file_io || ox_need_conv) )
                 *p = ntohs(*p);                  *p = ntohs(*p);
 }  }
   
 void read_int(f,p)  void read_int(FILE *f,unsigned int *p)
 FILE *f;  
 unsigned int *p;  
 {  {
         gen_fread(p,sizeof(unsigned int),1,f);          gen_fread((char *)p,sizeof(unsigned int),1,f);
         if ( little_endian && (ox_file_io || ox_need_conv) )          if ( little_endian && (ox_file_io || ox_need_conv) )
                 *p = ntohl(*p);                  *p = ntohl(*p);
 }  }
   
 void read_intarray(f,p,l)  void read_int64(FILE *f,UL *p)
 FILE *f;  
 unsigned int *p;  
 int l;  
 {  {
         int i;  
         unsigned int t;          unsigned int t;
 #if defined(VISUAL) && defined(DES_ENC)  
           if ( little_endian && (ox_file_io || ox_need_conv) ) {
                   gen_fread((char *)&t,sizeof(unsigned int),1,f);
                   ((unsigned int *)p)[1] = ntohl(t);
                   gen_fread((char *)&t,sizeof(unsigned int),1,f);
                   ((unsigned int *)p)[0] = ntohl(t);
           } else
                   gen_fread((char *)p,sizeof(UL),1,f);
   }
   
   void read_intarray(FILE *f,unsigned int *p,int l)
   {
           int i;
   #if defined(DES_ENC)
         int l2;          int l2;
         unsigned int plain[2],encrypted[2];          unsigned int plain[2],encrypted[2];
   
Line 373  int l;
Line 373  int l;
         } else          } else
 #endif  #endif
         {          {
                 gen_fread(p,sizeof(unsigned int),l,f);                  gen_fread((char *)p,sizeof(unsigned int),l,f);
                 if ( little_endian && (ox_file_io || ox_need_conv) )                  if ( little_endian && (ox_file_io || ox_need_conv) )
                         for ( i = 0; i < l; i++, p++ )                          for ( i = 0; i < l; i++, p++ )
                                 *p = ntohl(*p);                                  *p = ntohl(*p);
         }          }
 }  }
   
 #if defined(LONG_IS_64BIT)  #if SIZEOF_LONG == 8
 void read_longarray(f,p,l)  /* read l word (1word=4bytes) */
 FILE *f;  void read_longarray(FILE *f,unsigned long *p,int l)
 unsigned long *p;  
 int l;  
 {  {
         int i;          int i;
         unsigned int hi,lo;          unsigned int hi,lo;
Line 405  int l;
Line 403  int l;
 }  }
 #endif  #endif
   
 void read_string(f,p,l)  void read_string(FILE *f,unsigned char *p,int l)
 FILE *f;  
 unsigned char *p;  
 {  {
         gen_fread((char *)p,sizeof(unsigned char),l,f);          gen_fread((char *)p,sizeof(unsigned char),l,f);
 }  }
   
 void read_double(f,p)  void read_double(FILE *f,double *p)
 FILE *f;  
 double *p;  
 {  {
         unsigned int t;          unsigned int t;
   

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.16

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