Ready for reading by JAVA.
[timetab.git] / tt-stations.c
blob0c1d57b157630252476077efd651b8ea0f383e81
1 /*
2 * IDOS Stations Extractor
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.
8 */
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <inttypes.h>
13 #include <sys/stat.h>
14 #include <errno.h>
15 #include <stdbool.h>
19 FILE * in;
21 void print_stations(uint32_t offset)
23 fseek(in,offset,SEEK_SET);
24 int32_t len;
25 int32_t count;
26 int32_t mincount;
28 fread(&len,1,sizeof(len),in);
29 fread(&count,1,sizeof(count),in);
30 offset=ftell(in)+len;
31 mincount=count;
32 printf("Will read %d stations\n",count);
34 int32_t * indexes;
35 indexes = malloc(sizeof(int32_t)*(count+1));
38 for (int i=0;i<count;i++){
39 fread(indexes+i,1,sizeof(int32_t),in);
41 indexes[count]=indexes[count-1];
43 int32_t foo;
44 fread(&len,1,sizeof(len),in);
45 fread(&foo,1,sizeof(count),in);
46 offset=ftell(in)+len;
48 char ** buf;
49 buf = malloc(sizeof(char *)*count);
51 int32_t str_len;
52 for (int i=0;i<count;i++){
53 str_len = indexes[i+1]-indexes[i];
54 buf[i] = malloc(str_len);
55 fread(buf[i],str_len,1,in);
58 fread(&len,1,sizeof(len),in);
59 fread(&count,1,sizeof(count),in);
60 offset=ftell(in)+len;
61 mincount = (count<mincount)?count:mincount;
63 int32_t * map;
64 map = malloc(sizeof(int32_t)*count);
65 for (int i=0;i<count;i++)
67 fread(map+i,1,sizeof(int32_t),in);
70 fread(&len,1,sizeof(len),in);
71 fread(&count,1,sizeof(count),in);
72 offset=ftell(in)+len;
73 mincount = (count<mincount)?count:mincount;
75 int16_t * id;
76 id = malloc(sizeof(int16_t)*count);
77 for (int i=0;i<count;i++)
79 fread(id+i,1,sizeof(int16_t),in);
82 fread(&len,1,sizeof(len),in);
83 fread(&count,1,sizeof(count),in);
84 offset=ftell(in)+len;
85 fseek(in,offset,SEEK_SET); //skip first letter of station
87 fread(&len,1,sizeof(len),in);
88 fread(&count,1,sizeof(count),in);
89 offset=ftell(in)+len;
90 fseek(in,offset,SEEK_SET); //skip second letter of station
92 fseek(in,4,SEEK_CUR); //null skip
94 fread(&len,1,sizeof(len),in);
95 fread(&count,1,sizeof(count),in);
96 mincount = (count<mincount)?count:mincount;
98 int16_t * unk1;
99 unk1 = malloc(sizeof(int16_t)*count);
100 for (int i=0;i<count;i++)
102 fread(unk1+i,1,sizeof(int16_t),in);
105 fseek(in,12,SEEK_CUR); //null skip
107 fread(&len,1,sizeof(len),in);
108 fread(&count,1,sizeof(count),in);
109 mincount = (count<mincount)?count:mincount;
110 printf("Count: %d\n",count);
112 int16_t * unk2;
113 unk2 = malloc(sizeof(int16_t)*count);
114 for (int i=0;i<count;i++)
116 fread(unk2+i,1,sizeof(int16_t),in);
120 FILE * out;
121 out = fopen("tt-data/stations.dat","w");
122 for (int i=0;i<mincount;i++)
124 len = indexes[i+1]-indexes[i];
125 fprintf(out,"%d ",len);
126 for (int j=0; j<len;j++)
127 fprintf(out,"%c",buf[i][j]);
128 fprintf(out," %d %d %d %d\n",map[i],id[i],unk1[i],unk2[i]);
130 fclose(out);
136 int main(int argc, char * argv[])
138 in = fopen(argv[1], "r");
139 int32_t next;
141 next=0x207;
143 print_stations(next);
144 exit(0);