home *** CD-ROM | disk | FTP | other *** search
/ Dream 44 / Amiga_Dream_44.iso / RiscPc / jeux / ArcBoard004.arc / !GNUChessX / src / misc / ecocvt_c < prev    next >
Text File  |  1995-07-02  |  1KB  |  42 lines

  1. #include <fcntl.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include "gnuchess.h"
  5. struct gdxdata
  6. {
  7.     unsigned long hashbd;
  8.     unsigned long hashkey;
  9.     unsigned int ecoptr;
  10.     utshort cntr;
  11. } DATA,DATA2;
  12.  
  13. struct stat buf;
  14. main(int argc, char *argv[])
  15. {
  16. int fd,ofd;
  17. int j=0;
  18. int i;
  19. int first;
  20. if(argc != 3){printf("Usage ecocvt infile outfile\n"); exit(1);}
  21. fd=open(argv[1],O_RDONLY);
  22. ofd=open(argv[2],O_CREAT | O_RDWR, 0644);
  23. stat(argv[1],&buf);
  24.  
  25. if(fd == 0) {printf("open error\n");exit(10);}
  26. if(ofd == 0) {printf("open error\n");exit(10);}
  27. first=1;
  28. for(i=0;i<buf.st_size; i+= sizeof(struct gdxdata)){
  29.     if(read(fd,&DATA,sizeof(struct gdxdata))<0){perror("ofd");exit(1);}
  30.     if(first){DATA2 = DATA; first=0; } else
  31.     {
  32.     if(DATA2.hashbd == DATA.hashbd && DATA2.hashkey == DATA.hashkey){j++;DATA.cntr = j;}
  33.     else {DATA2 = DATA; j=0;}
  34.     }
  35. if(DATA2.hashbd < DATA.hashbd)printf("erroe\n");
  36. if(    write(ofd,&DATA,sizeof(struct gdxdata)) <0){perror("write");exit(1);};
  37. }
  38. if(close(fd) < 0){perror("fd");exit(1);}
  39. if(close(ofd) < 0){perror("ofd");exit(1);}
  40. exit(0);
  41. }
  42.