Ready for reading by JAVA.
[timetab.git] / tt-extract.c
blobe399e014da9ad19d5848084df043e4700ac18145
1 /*
2 * IDOS Timetable 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_strings(uint32_t offset)
23 fseek(in,offset,SEEK_SET);
24 int32_t count;
26 fread(&count,1,sizeof(count),in);
27 printf("Will read %d strings\n",count);
29 int32_t * indexes;
30 indexes = malloc(sizeof(int32_t)*(count+1));
33 for (int i=0;i<=count;i++){
34 fread(indexes+i,1,sizeof(int32_t),in);
36 fseek(in,4,SEEK_CUR);
38 char buf[4096];
39 for (int i=0;i<count;i++){
40 fread(buf,indexes[i+1]-indexes[i],1,in);
41 for (int j=0; j<indexes[i+1]-indexes[i];j++)
42 printf("%c",buf[j]);
43 printf("\n");
48 int main(int argc, char * argv[])
50 in = fopen(argv[1], "r");
51 int32_t x;
52 int32_t y;
53 FILE * out;
54 int32_t len;
55 int32_t count;
56 int32_t next;
57 int32_t chunks;
58 int32_t blocks;
59 uint8_t * int_count;
60 char key;
61 int nulls;
62 uint8_t repeat;
63 uint8_t tried;
64 int chunk_id;
65 chunk_id=0;
67 next=0x6B;
68 repeat=true;
69 tried=false;
71 /* fclose(fopen("data/strings.dat","w"));
72 fclose(fopen("data/stations.dat","w"));*/
74 while (repeat)
76 fseek(in,next,SEEK_SET);
77 // printf("Chunk %d\n",chunk_id);
78 // printf("Reading header\n");
79 nulls=0;
80 do {
81 fread(&len,1,sizeof(len),in);
82 nulls++;
83 } while (len==0);
84 fread(&blocks,1,sizeof(blocks),in);
85 //int_count = malloc(blocks);
86 printf("Chunk: %d, Len: %d, blocks: %d, nulls:%d\n",chunk_id,len,blocks,nulls);
87 if (!(len%blocks==0)){
88 printf("Skipping, individable\n");
90 fseek(in,next+0x15,SEEK_SET);
91 fread(&len,1,sizeof(len),in);
92 fread(&blocks,1,sizeof(blocks),in);
93 if (len%blocks==0){
94 printf("Hacked\n");
95 next+=0x15;
96 continue;
101 else{
102 next= ftell(in)+len;
103 tried=false;
104 for (int i=0;i<len;i++)
106 uint8_t byte;
107 fread(&byte,1,1,in);
111 int rec_len;
112 rec_len=len/blocks;
113 int32_t buf[rec_len];
114 for (int i=blocks;i>0;i--){
115 fread(buf,1,rec_len,in);
116 for (int j=0;j<rec_len;j++)
117 printf("%x ",buf[j]);
118 printf("\n");
122 if ((next==0x1F3)||(next==0x3975b3))
123 next+=0x14;
124 if (next==0x4bad7)
125 next+=0x2D;
126 if ((next==0x71806)||(next==0x7a374)||(next==0x7a46e)||(next==0x7d046)||(next==0xbf32e)||(next==0xe4efc))
127 next+=0x15;
128 if (next==0xbf8d9)
129 next+=0x11;
130 if (next==0xd9faa)
131 next+=0x09;
132 if ((next==0xe4fd2)||(next==0x1ca76a)||(next==0x20c02e)||(next==0x39c94f))
133 next+=0x20;
134 if (next==0x2e1ca5)
135 next+=0x10;
136 if (next==0x434c0c)
137 next+=0x23;
138 if (next==0x4c1ff3)
139 next+=0x1C;
140 if (next==0x4e182f)
141 next+=0x18;
142 if (next==0x4ebacf)
143 break;
145 // HACK, UNREADED
146 if (next==0x399126)
147 next=0x39A370;
149 // if ((next==0x55193)||(next==0x613ce)||(next==0x61a5c)||(next==0x63129))
150 // next+=0x15;
151 /* if (next==0x28925)
152 next+=0x4;*/
154 printf("At: %x, next: %x\n",ftell(in),next);
155 if (chunk_id>630) scanf("%c",&key);
156 chunk_id++;
158 /* print_strings(next);
159 next=0xFB;
160 print_strings(next);
161 next=0x20B;
162 print_strings(next);
163 printf("At: %x\n",ftell(in));
165 //Banky
166 next=0x4E71C;
167 print_strings(next);
168 printf("At: %x\n",ftell(in));
170 //Bankomaty
171 next=0x59824;
172 print_strings(next);
173 printf("At: %x\n",ftell(in));
175 //Bezbariérové stanice
176 next=0x6184C;
177 print_strings(next);
178 printf("At: %x\n",ftell(in));
180 // Divadla
181 next=0x622CA;
182 print_strings(next);
183 printf("At: %x\n",ftell(in));
185 //Hotely
186 next=0x676AA;
187 print_strings(next);
188 printf("At: %x\n",ftell(in));
190 //Hotely
191 next=0x676AA;
192 print_strings(next);
193 printf("At: %x\n",ftell(in));*/