Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/filedumperx.c
Parent Directory
|
Revision Log
Revision 1405 -
(hide annotations)
(download)
(as text)
Thu Jun 20 18:36:47 2013 UTC (11 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 9212 byte(s)
Thu Jun 20 18:36:47 2013 UTC (11 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 9212 byte(s)
Use the new functions for buffering while reading when looping through files that use the FILESORT_VARINT method of storing data.
1 | amb | 1149 | /*************************************** |
2 | Memory file dumper for the intermediate files containing parsed data. | ||
3 | |||
4 | Part of the Routino routing software. | ||
5 | ******************/ /****************** | ||
6 | amb | 1299 | This file Copyright 2008-2013 Andrew M. Bishop |
7 | amb | 1149 | |
8 | This program is free software: you can redistribute it and/or modify | ||
9 | it under the terms of the GNU Affero General Public License as published by | ||
10 | the Free Software Foundation, either version 3 of the License, or | ||
11 | (at your option) any later version. | ||
12 | |||
13 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU Affero General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Affero General Public License | ||
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | ***************************************/ | ||
21 | |||
22 | |||
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <string.h> | ||
26 | #include <sys/stat.h> | ||
27 | |||
28 | #include "typesx.h" | ||
29 | #include "nodesx.h" | ||
30 | #include "waysx.h" | ||
31 | #include "relationsx.h" | ||
32 | |||
33 | #include "files.h" | ||
34 | #include "sorting.h" | ||
35 | |||
36 | |||
37 | /* Local functions */ | ||
38 | |||
39 | static void print_nodes(const char *filename); | ||
40 | static void print_ways(const char *filename); | ||
41 | static void print_route_relations(const char *filename); | ||
42 | static void print_turn_relations(const char *filename); | ||
43 | |||
44 | static void print_usage(int detail,const char *argerr,const char *err); | ||
45 | |||
46 | |||
47 | /*++++++++++++++++++++++++++++++++++++++ | ||
48 | The main program for the file dumper. | ||
49 | ++++++++++++++++++++++++++++++++++++++*/ | ||
50 | |||
51 | int main(int argc,char** argv) | ||
52 | { | ||
53 | int arg; | ||
54 | char *dirname=NULL,*prefix=NULL; | ||
55 | amb | 1340 | char *nodes_filename,*ways_filename,*route_relations_filename,*turn_relations_filename; |
56 | amb | 1149 | int option_dump; |
57 | |||
58 | /* Parse the command line arguments */ | ||
59 | |||
60 | for(arg=1;arg<argc;arg++) | ||
61 | { | ||
62 | if(!strcmp(argv[arg],"--help")) | ||
63 | print_usage(1,NULL,NULL); | ||
64 | else if(!strncmp(argv[arg],"--dir=",6)) | ||
65 | dirname=&argv[arg][6]; | ||
66 | else if(!strncmp(argv[arg],"--prefix=",9)) | ||
67 | prefix=&argv[arg][9]; | ||
68 | else if(!strcmp(argv[arg],"--dump")) | ||
69 | option_dump=1; | ||
70 | else if(!strcmp(argv[arg],"--nodes")) | ||
71 | ; | ||
72 | else if(!strcmp(argv[arg],"--ways")) | ||
73 | ; | ||
74 | else if(!strcmp(argv[arg],"--route-relations")) | ||
75 | ; | ||
76 | else if(!strcmp(argv[arg],"--turn-relations")) | ||
77 | ; | ||
78 | else | ||
79 | print_usage(0,argv[arg],NULL); | ||
80 | } | ||
81 | |||
82 | if((option_dump)!=1) | ||
83 | print_usage(0,NULL,"Must choose --dump."); | ||
84 | |||
85 | /* Load in the data - Note: No error checking because Load*List() will call exit() in case of an error. */ | ||
86 | |||
87 | nodes_filename=FileName(dirname,prefix,"nodesx.parsed.mem"); | ||
88 | |||
89 | ways_filename=FileName(dirname,prefix,"waysx.parsed.mem"); | ||
90 | |||
91 | route_relations_filename=FileName(dirname,prefix,"relationsx.route.parsed.mem"); | ||
92 | |||
93 | turn_relations_filename=FileName(dirname,prefix,"relationsx.turn.parsed.mem"); | ||
94 | |||
95 | /* Print out internal data (in plain text format) */ | ||
96 | |||
97 | if(option_dump) | ||
98 | { | ||
99 | for(arg=1;arg<argc;arg++) | ||
100 | if(!strcmp(argv[arg],"--nodes")) | ||
101 | { | ||
102 | print_nodes(nodes_filename); | ||
103 | } | ||
104 | else if(!strcmp(argv[arg],"--ways")) | ||
105 | { | ||
106 | print_ways(ways_filename); | ||
107 | } | ||
108 | else if(!strcmp(argv[arg],"--route-relations")) | ||
109 | { | ||
110 | print_route_relations(route_relations_filename); | ||
111 | } | ||
112 | else if(!strcmp(argv[arg],"--turn-relations")) | ||
113 | { | ||
114 | print_turn_relations(turn_relations_filename); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | return(0); | ||
119 | } | ||
120 | |||
121 | |||
122 | /*++++++++++++++++++++++++++++++++++++++ | ||
123 | Print out all of the nodes. | ||
124 | |||
125 | const char *filename The name of the file containing the data. | ||
126 | ++++++++++++++++++++++++++++++++++++++*/ | ||
127 | |||
128 | static void print_nodes(const char *filename) | ||
129 | { | ||
130 | off_t size,position=0; | ||
131 | int fd; | ||
132 | |||
133 | size=SizeFile(filename); | ||
134 | |||
135 | fd=ReOpenFile(filename); | ||
136 | |||
137 | while(position<size) | ||
138 | { | ||
139 | NodeX nodex; | ||
140 | |||
141 | ReadFile(fd,&nodex,sizeof(NodeX)); | ||
142 | |||
143 | printf("Node %"Pnode_t"\n",nodex.id); | ||
144 | printf(" lat=%d lon=%d\n",nodex.latitude,nodex.longitude); | ||
145 | printf(" allow=%02x\n",nodex.allow); | ||
146 | printf(" flags=%02x\n",nodex.flags); | ||
147 | |||
148 | position+=sizeof(NodeX); | ||
149 | } | ||
150 | |||
151 | CloseFile(fd); | ||
152 | } | ||
153 | |||
154 | |||
155 | /*++++++++++++++++++++++++++++++++++++++ | ||
156 | Print out all of the ways. | ||
157 | |||
158 | const char *filename The name of the file containing the data. | ||
159 | ++++++++++++++++++++++++++++++++++++++*/ | ||
160 | |||
161 | static void print_ways(const char *filename) | ||
162 | { | ||
163 | amb | 1405 | FILESORT_VARINT waysize; |
164 | amb | 1149 | int fd; |
165 | |||
166 | amb | 1405 | fd=ReOpenFileBuffered(filename); |
167 | amb | 1149 | |
168 | amb | 1405 | while(!ReadFileBuffered(fd,&waysize,FILESORT_VARSIZE)) |
169 | amb | 1149 | { |
170 | WayX wayx; | ||
171 | amb | 1338 | node_t node; |
172 | amb | 1149 | char *name=NULL; |
173 | amb | 1299 | size_t malloced=0; |
174 | amb | 1338 | int first=1; |
175 | amb | 1149 | |
176 | amb | 1405 | ReadFileBuffered(fd,&wayx,sizeof(WayX)); |
177 | amb | 1149 | |
178 | amb | 1338 | printf("Way %"Pway_t"\n",wayx.id); |
179 | |||
180 | amb | 1405 | while(!ReadFileBuffered(fd,&node,sizeof(node_t)) && node!=NO_NODE_ID) |
181 | amb | 1149 | { |
182 | amb | 1338 | if(first) |
183 | printf(" nodes=%"Pnode_t,node); | ||
184 | else | ||
185 | printf(",%"Pnode_t,node); | ||
186 | |||
187 | waysize-=sizeof(node_t); | ||
188 | |||
189 | first=0; | ||
190 | } | ||
191 | |||
192 | printf("\n"); | ||
193 | |||
194 | waysize-=sizeof(node_t)+sizeof(WayX); | ||
195 | |||
196 | if(malloced<waysize) | ||
197 | { | ||
198 | malloced=waysize; | ||
199 | amb | 1149 | name=(char*)realloc((void*)name,malloced); |
200 | } | ||
201 | |||
202 | amb | 1405 | ReadFileBuffered(fd,name,waysize); |
203 | amb | 1149 | |
204 | if(*name) | ||
205 | printf(" name=%s\n",name); | ||
206 | printf(" type=%02x\n",wayx.way.type); | ||
207 | printf(" allow=%02x\n",wayx.way.allow); | ||
208 | if(wayx.way.props) | ||
209 | printf(" props=%02x\n",wayx.way.props); | ||
210 | if(wayx.way.speed) | ||
211 | printf(" speed=%d\n",wayx.way.speed); | ||
212 | if(wayx.way.weight) | ||
213 | printf(" weight=%d\n",wayx.way.weight); | ||
214 | if(wayx.way.height) | ||
215 | printf(" height=%d\n",wayx.way.height); | ||
216 | if(wayx.way.width) | ||
217 | printf(" width=%d\n",wayx.way.width); | ||
218 | if(wayx.way.length) | ||
219 | printf(" length=%d\n",wayx.way.length); | ||
220 | } | ||
221 | |||
222 | amb | 1405 | CloseFileBuffered(fd); |
223 | amb | 1149 | } |
224 | |||
225 | |||
226 | /*++++++++++++++++++++++++++++++++++++++ | ||
227 | Print out all of the route relations. | ||
228 | |||
229 | const char *filename The name of the file containing the data. | ||
230 | ++++++++++++++++++++++++++++++++++++++*/ | ||
231 | |||
232 | static void print_route_relations(const char *filename) | ||
233 | { | ||
234 | amb | 1405 | FILESORT_VARINT relationsize; |
235 | amb | 1149 | int fd; |
236 | |||
237 | amb | 1405 | fd=ReOpenFileBuffered(filename); |
238 | amb | 1149 | |
239 | amb | 1405 | while(!ReadFileBuffered(fd,&relationsize,FILESORT_VARSIZE)) |
240 | amb | 1149 | { |
241 | RouteRelX relationx; | ||
242 | amb | 1405 | node_t nodeid; |
243 | amb | 1149 | way_t wayid; |
244 | relation_t relationid; | ||
245 | |||
246 | amb | 1405 | ReadFileBuffered(fd,&relationx,sizeof(RouteRelX)); |
247 | amb | 1149 | |
248 | printf("Relation %"Prelation_t"\n",relationx.id); | ||
249 | printf(" routes=%02x\n",relationx.routes); | ||
250 | |||
251 | amb | 1405 | while(!ReadFileBuffered(fd,&nodeid,sizeof(node_t)) && nodeid!=NO_NODE_ID) |
252 | printf(" node=%"Pnode_t"\n",nodeid); | ||
253 | amb | 1149 | |
254 | amb | 1405 | while(!ReadFileBuffered(fd,&wayid,sizeof(way_t)) && wayid!=NO_WAY_ID); |
255 | amb | 1149 | printf(" way=%"Pway_t"\n",wayid); |
256 | |||
257 | amb | 1405 | while(!ReadFileBuffered(fd,&relationid,sizeof(relation_t)) && relationid!=NO_RELATION_ID); |
258 | amb | 1149 | printf(" relation=%"Prelation_t"\n",relationid); |
259 | } | ||
260 | |||
261 | amb | 1405 | CloseFileBuffered(fd); |
262 | amb | 1149 | } |
263 | |||
264 | |||
265 | /*++++++++++++++++++++++++++++++++++++++ | ||
266 | Print out all of the turn relations. | ||
267 | |||
268 | const char *filename The name of the file containing the data. | ||
269 | ++++++++++++++++++++++++++++++++++++++*/ | ||
270 | |||
271 | static void print_turn_relations(const char *filename) | ||
272 | { | ||
273 | off_t size,position=0; | ||
274 | int fd; | ||
275 | |||
276 | size=SizeFile(filename); | ||
277 | |||
278 | fd=ReOpenFile(filename); | ||
279 | |||
280 | while(position<size) | ||
281 | { | ||
282 | amb | 1163 | TurnRelX relationx; |
283 | amb | 1149 | |
284 | amb | 1163 | ReadFile(fd,&relationx,sizeof(TurnRelX)); |
285 | amb | 1149 | |
286 | printf("Relation %"Prelation_t"\n",relationx.id); | ||
287 | printf(" from=%"Pway_t"\n",relationx.from); | ||
288 | printf(" via=%"Pnode_t"\n",relationx.via); | ||
289 | printf(" to=%"Pway_t"\n",relationx.to); | ||
290 | printf(" type=%d\n",relationx.restriction); | ||
291 | if(relationx.except) | ||
292 | printf(" except=%02x\n",relationx.except); | ||
293 | |||
294 | amb | 1163 | position+=sizeof(TurnRelX); |
295 | amb | 1149 | } |
296 | |||
297 | CloseFile(fd); | ||
298 | } | ||
299 | |||
300 | |||
301 | /*++++++++++++++++++++++++++++++++++++++ | ||
302 | Print out the usage information. | ||
303 | |||
304 | int detail The level of detail to use - 0 = low, 1 = high. | ||
305 | |||
306 | const char *argerr The argument that gave the error (if there is one). | ||
307 | |||
308 | const char *err Other error message (if there is one). | ||
309 | ++++++++++++++++++++++++++++++++++++++*/ | ||
310 | |||
311 | static void print_usage(int detail,const char *argerr,const char *err) | ||
312 | { | ||
313 | fprintf(stderr, | ||
314 | amb | 1340 | "Usage: filedumperx [--help]\n" |
315 | " [--dir=<dirname>] [--prefix=<name>]\n" | ||
316 | " [--dump [--nodes]\n" | ||
317 | " [--ways]\n" | ||
318 | " [--route-relations]\n" | ||
319 | " [--turn-relations]]\n"); | ||
320 | amb | 1149 | |
321 | if(argerr) | ||
322 | fprintf(stderr, | ||
323 | "\n" | ||
324 | "Error with command line parameter: %s\n",argerr); | ||
325 | |||
326 | if(err) | ||
327 | fprintf(stderr, | ||
328 | "\n" | ||
329 | "Error: %s\n",err); | ||
330 | |||
331 | if(detail) | ||
332 | fprintf(stderr, | ||
333 | "\n" | ||
334 | "--help Prints this information.\n" | ||
335 | "\n" | ||
336 | "--dir=<dirname> The directory containing the routing database.\n" | ||
337 | "--prefix=<name> The filename prefix for the routing database.\n" | ||
338 | "\n" | ||
339 | "--dump Dump the intermediate files after parsing.\n" | ||
340 | " --nodes * all of the nodes.\n" | ||
341 | " --ways * all of the ways.\n" | ||
342 | " --route-relations * all of the route relations.\n" | ||
343 | " --turn-relations * all of the turn relations.\n"); | ||
344 | |||
345 | exit(!detail); | ||
346 | } |