4 * (c) 2013 Tomas Pokorny <jethro@kam.mff.cuni.cz>
6 * This software can be freely distributed and used according
7 * to the terms of the GNU General Public License.
21 int main(int argc
, char * argv
[])
23 in
= fopen(argv
[1], "r");
37 fclose(fopen("map/chunks.dat","w"));
38 fclose(fopen("map/stations.dat","w"));
40 fseek(in
,next
,SEEK_SET
);
41 printf("Reading header\n");
42 fread(&len
,1,sizeof(len
),in
);
43 fread(&blocks
,1,sizeof(blocks
),in
);
44 int_count
= malloc(blocks
);
45 for (int i
=0;i
<blocks
;i
++)
47 printf("Len: %d, blocks: %d\n",len
,blocks
);
50 printf("Skipping, header had changed.\n");
56 for (int i
=blocks
;i
>0;i
--){
57 fread(buf
,1,rec_len
,in
);
58 for (int j
=0;j
<rec_len
;j
++)
65 int_count
[5]=int_count
[6]=int_count
[7]=3;
68 for (int blkid
=0;blkid
<blocks
;blkid
++)
70 fseek(in
,next
,SEEK_SET
);
75 fread(&chunks
,1,sizeof(chunks
),in
);
81 printf("Read %d null ints, will read %d chunks\n",nulls
,chunks
);
82 if (int_count
[blkid
]==3)
85 fseek(in
,next
,SEEK_SET
);
86 printf("Reading stations\n");
87 fread(&len
,1,sizeof(len
),in
);
88 fread(&count
,1,sizeof(count
),in
);
91 printf("Base: %x Next: %x, count: %d\n",(uint32_t)ftell(in
),len
,count
);
94 out
= fopen("map/stations.dat","a");
95 for (int i
=count
;i
>0;i
--)
97 fread(&x
,1,sizeof(x
),in
);
98 fread(&y
,1,sizeof(y
),in
);
99 fread(&idx
,1,sizeof(idx
),in
);
100 fprintf(out
,"%d %d %d\n",x
,y
,idx
);
106 printf("Reading %d chunks\n",chunks
);
107 for (int j
=chunks
;j
>0;j
--)
109 fseek(in
,next
,SEEK_SET
);
110 fread(&len
,1,sizeof(len
),in
);
111 fread(&count
,1,sizeof(count
),in
);
114 printf("Base: %x Next: %x, count: %d\n",(uint32_t)ftell(in
),len
,count
);
116 out
= fopen("map/chunks.dat","a");
117 for (int i
=count
;i
>0;i
--)
119 fread(&x
,1,sizeof(x
),in
);
120 fread(&y
,1,sizeof(y
),in
);
121 fprintf(out
,"%d %d\n",x
,y
);
131 printf("At: %x continue?",(uint32_t)ftell(in
));
134 fseek(in
,next
,SEEK_SET
);
135 printf("Reading header\n");
137 fread(&len
,1,sizeof(len
),in
);
142 printf("Read %d null ints, will read header of length %x \n",nulls
,len
);
144 fread(&blocks
,1,sizeof(blocks
),in
);
145 int_count
= malloc(blocks
);
146 for (int i
=0;i
<blocks
;i
++)
148 printf("Len: %d, blocks: %d\n",len
,blocks
);
149 next
= ftell(in
)+len
;
150 if (!(len
%blocks
==0))
151 printf("Skipping, header had changed.\n");
156 int32_t buf
[rec_len
];
157 for (int i
=blocks
;i
>0;i
--){
158 fread(buf
,1,rec_len
,in
);
159 for (int j
=0;j
<rec_len
;j
++)
160 printf("%x ",buf
[j
]);
169 for (int blkid
=0;blkid
<blocks
;blkid
++)
171 fseek(in
,next
,SEEK_SET
);
176 fread(&chunks
,1,sizeof(chunks
),in
);
182 printf("Read %d null ints, will read %d chunks\n",nulls
,chunks
);
183 if (int_count
[blkid
]==3)
186 fseek(in
,next
,SEEK_SET
);
187 printf("Reading stations\n");
188 fread(&len
,1,sizeof(len
),in
);
189 fread(&count
,1,sizeof(count
),in
);
192 printf("Base: %x Next: %x, count: %d\n",(uint32_t)ftell(in
),len
,count
);
195 out
= fopen("map/stations.dat","a");
196 for (int i
=count
;i
>0;i
--)
198 fread(&x
,1,sizeof(x
),in
);
199 fread(&y
,1,sizeof(y
),in
);
200 fread(&idx
,1,sizeof(idx
),in
);
201 fprintf(out
,"%d %d %d\n",x
,y
,idx
);
207 printf("Reading %d chunks\n",chunks
);
208 for (int j
=chunks
;j
>0;j
--)
210 fseek(in
,next
,SEEK_SET
);
211 fread(&len
,1,sizeof(len
),in
);
212 fread(&count
,1,sizeof(count
),in
);
215 printf("Base: %x Next: %x, count: %d\n",(uint32_t)ftell(in
),len
,count
);
217 out
= fopen("map/chunks.dat","a");
218 for (int i
=count
;i
>0;i
--)
220 fread(&x
,1,sizeof(x
),in
);
221 fread(&y
,1,sizeof(y
),in
);
222 fprintf(out
,"%d %d\n",x
,y
);
234 printf("At: %x continue?",(uint32_t)ftell(in
));