home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnuch40.zip / gnuchess-4.0.pl79 / src / ecocvt.c < prev    next >
C/C++ Source or Header  |  1998-09-28  |  2KB  |  66 lines

  1. /*
  2.  * ecocvt.c - ECO code for GNU Chess
  3.  *
  4.  * Copyright (c) 1985-1996 Stuart Cracraft, John Stanback,
  5.  *                         Daryl Baker, Conor McCarthy,
  6.  *                         Mike McGann, Chua Kong Sian
  7.  * Copyright (c) 1985-1996 Free Software Foundation
  8.  *
  9.  * This file is part of GNU CHESS.
  10.  *
  11.  * GNU Chess is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2, or (at your option)
  14.  * any later version.
  15.  *
  16.  * GNU Chess is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with GNU Chess; see the file COPYING.  If not, write to
  23.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25. #include <fcntl.h>
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28. #include "gnuchess.h"
  29. struct gdxdata
  30. {
  31.     unsigned long hashbd;
  32.     unsigned long hashkey;
  33.     unsigned int ecoptr;
  34.     utshort cntr;
  35. } DATA,DATA2;
  36.  
  37. struct stat buf;
  38. main(int argc, char *argv[])
  39. {
  40. int fd,ofd;
  41. int j=0;
  42. int i;
  43. int first;
  44. if(argc != 3){printf("Usage ecocvt infile outfile\n"); exit(1);}
  45. fd=open(argv[1],O_RDONLY);
  46. ofd=open(argv[2],O_CREAT | O_RDWR, 0644);
  47. stat(argv[1],&buf);
  48.  
  49. if(fd == 0) {printf("open error\n");exit(10);}
  50. if(ofd == 0) {printf("open error\n");exit(10);}
  51. first=1;
  52. for(i=0;i<buf.st_size; i+= sizeof(struct gdxdata)){
  53.     if(read(fd,&DATA,sizeof(struct gdxdata))<0){perror("ofd");exit(1);}
  54.     if(first){DATA2 = DATA; first=0; } else
  55.     {
  56.     if(DATA2.hashbd == DATA.hashbd && DATA2.hashkey == DATA.hashkey){j++;DATA.cntr = j;}
  57.     else {DATA2 = DATA; j=0;}
  58.     }
  59. if(DATA2.hashbd < DATA.hashbd)printf("erroe\n");
  60. if(    write(ofd,&DATA,sizeof(struct gdxdata)) <0){perror("write");exit(1);};
  61. }
  62. if(close(fd) < 0){perror("fd");exit(1);}
  63. if(close(ofd) < 0){perror("ofd");exit(1);}
  64. exit(0);
  65. }
  66.