home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 44
/
Amiga_Dream_44.iso
/
RiscPc
/
jeux
/
ArcBoard004.arc
/
!GNUChessX
/
src
/
misc
/
ecocvt_c
< prev
next >
Wrap
Text File
|
1995-07-02
|
1KB
|
42 lines
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "gnuchess.h"
struct gdxdata
{
unsigned long hashbd;
unsigned long hashkey;
unsigned int ecoptr;
utshort cntr;
} DATA,DATA2;
struct stat buf;
main(int argc, char *argv[])
{
int fd,ofd;
int j=0;
int i;
int first;
if(argc != 3){printf("Usage ecocvt infile outfile\n"); exit(1);}
fd=open(argv[1],O_RDONLY);
ofd=open(argv[2],O_CREAT | O_RDWR, 0644);
stat(argv[1],&buf);
if(fd == 0) {printf("open error\n");exit(10);}
if(ofd == 0) {printf("open error\n");exit(10);}
first=1;
for(i=0;i<buf.st_size; i+= sizeof(struct gdxdata)){
if(read(fd,&DATA,sizeof(struct gdxdata))<0){perror("ofd");exit(1);}
if(first){DATA2 = DATA; first=0; } else
{
if(DATA2.hashbd == DATA.hashbd && DATA2.hashkey == DATA.hashkey){j++;DATA.cntr = j;}
else {DATA2 = DATA; j=0;}
}
if(DATA2.hashbd < DATA.hashbd)printf("erroe\n");
if( write(ofd,&DATA,sizeof(struct gdxdata)) <0){perror("write");exit(1);};
}
if(close(fd) < 0){perror("fd");exit(1);}
if(close(ofd) < 0){perror("ofd");exit(1);}
exit(0);
}