annotate scn2k/gandump.cc @ 29:d229cce98f50

* no more (or, at least, less) duplicate code between scn2kdump and the rest
author thib
date Fri, 06 Mar 2009 20:02:26 +0000
parents 223b71206888
children 6d1a5b7f0838
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 #include<stdio.h>
223b71206888 Initial import
thib
parents:
diff changeset
2 #include<string.h>
223b71206888 Initial import
thib
parents:
diff changeset
3
223b71206888 Initial import
thib
parents:
diff changeset
4 char* ganname[6] = {"ptn", "x", "y", "time", "alpha", "?"};
223b71206888 Initial import
thib
parents:
diff changeset
5 int main(int argc, char** argv) {
223b71206888 Initial import
thib
parents:
diff changeset
6 if (argc != 2) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
7 FILE* f = fopen(argv[1],"rb");
223b71206888 Initial import
thib
parents:
diff changeset
8 if (f==0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
9 fseek(f,0,2); int sz=ftell(f); fseek(f,0,0);
223b71206888 Initial import
thib
parents:
diff changeset
10 char* buf = new char[sz];
223b71206888 Initial import
thib
parents:
diff changeset
11 char* bufo = buf;
223b71206888 Initial import
thib
parents:
diff changeset
12 fread(buf,1,sz,f);
223b71206888 Initial import
thib
parents:
diff changeset
13 fclose(f);
223b71206888 Initial import
thib
parents:
diff changeset
14
223b71206888 Initial import
thib
parents:
diff changeset
15 int i;
223b71206888 Initial import
thib
parents:
diff changeset
16 for (i=0; i<16; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
17 printf("%02x ",int(buf[i])&0xff);
223b71206888 Initial import
thib
parents:
diff changeset
18 }
223b71206888 Initial import
thib
parents:
diff changeset
19 printf("\n");
223b71206888 Initial import
thib
parents:
diff changeset
20 buf+=16;
223b71206888 Initial import
thib
parents:
diff changeset
21 printf("file '%s'\n",buf);
223b71206888 Initial import
thib
parents:
diff changeset
22 buf += strlen(buf)+1;
223b71206888 Initial import
thib
parents:
diff changeset
23 printf("N1 = %3d\n", *(int*)buf); buf+=4;
223b71206888 Initial import
thib
parents:
diff changeset
24 int ptns = *(int*)buf; buf += 4;
223b71206888 Initial import
thib
parents:
diff changeset
25 for (i=0; i<ptns; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
26 int j;
223b71206888 Initial import
thib
parents:
diff changeset
27 printf("\tN2 = %3d\n",*(int*)buf); buf += 4;
223b71206888 Initial import
thib
parents:
diff changeset
28 int n = *(int*)buf; buf += 4;
223b71206888 Initial import
thib
parents:
diff changeset
29 for (j=0; j<n; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
30 printf("\t%3d: ",j);
223b71206888 Initial import
thib
parents:
diff changeset
31 int k; int d1,d2;
223b71206888 Initial import
thib
parents:
diff changeset
32 for (k=0; k<6; k++) {
223b71206888 Initial import
thib
parents:
diff changeset
33 d1 = *(int*)(buf+k*8);
223b71206888 Initial import
thib
parents:
diff changeset
34 d2 = *(int*)(buf+k*8+4);
223b71206888 Initial import
thib
parents:
diff changeset
35 if (d1 != 30100+k) printf("err: d1 %d\n",d1);
223b71206888 Initial import
thib
parents:
diff changeset
36 printf("%s: %5d, ",ganname[k],d2);
223b71206888 Initial import
thib
parents:
diff changeset
37 }
223b71206888 Initial import
thib
parents:
diff changeset
38 printf("\n");
223b71206888 Initial import
thib
parents:
diff changeset
39 buf += 6*8;
223b71206888 Initial import
thib
parents:
diff changeset
40 int d = *(int*)buf; buf += 4;
223b71206888 Initial import
thib
parents:
diff changeset
41 if (d != 999999) printf("err: dd %d\n",d);
223b71206888 Initial import
thib
parents:
diff changeset
42 }
223b71206888 Initial import
thib
parents:
diff changeset
43 }
223b71206888 Initial import
thib
parents:
diff changeset
44 if (buf != bufo+sz) { printf("orig sz %d read %d\n",sz,buf-bufo);}
223b71206888 Initial import
thib
parents:
diff changeset
45 }