Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Annotation of /branches/destination-access/src/filedumperx.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1168 - (hide annotations) (download) (as text)
Wed Nov 21 09:20:57 2012 UTC (12 years, 3 months ago) by amb
Original Path: trunk/src/filedumperx.c
File MIME type: text/x-csrc
File size: 10270 byte(s)
Revert r1164 - some super-segments are longer than 65535 metres even if no
individual segment is.

1 amb 1149 /***************************************
2     Memory file dumper for the intermediate files containing parsed data.
3    
4     Part of the Routino routing software.
5     ******************/ /******************
6     This file Copyright 2008-2012 Andrew M. Bishop
7    
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 "segmentsx.h"
31     #include "waysx.h"
32     #include "relationsx.h"
33    
34     #include "files.h"
35     #include "sorting.h"
36    
37    
38     /* Local functions */
39    
40     static void print_nodes(const char *filename);
41     static void print_segments(const char *filename);
42     static void print_ways(const char *filename);
43     static void print_route_relations(const char *filename);
44     static void print_turn_relations(const char *filename);
45    
46     static void print_usage(int detail,const char *argerr,const char *err);
47    
48    
49     /*++++++++++++++++++++++++++++++++++++++
50     The main program for the file dumper.
51     ++++++++++++++++++++++++++++++++++++++*/
52    
53     int main(int argc,char** argv)
54     {
55     int arg;
56     char *dirname=NULL,*prefix=NULL;
57     char *nodes_filename,*segments_filename,*ways_filename,*route_relations_filename,*turn_relations_filename;
58     int option_dump;
59    
60     /* Parse the command line arguments */
61    
62     for(arg=1;arg<argc;arg++)
63     {
64     if(!strcmp(argv[arg],"--help"))
65     print_usage(1,NULL,NULL);
66     else if(!strncmp(argv[arg],"--dir=",6))
67     dirname=&argv[arg][6];
68     else if(!strncmp(argv[arg],"--prefix=",9))
69     prefix=&argv[arg][9];
70     else if(!strcmp(argv[arg],"--dump"))
71     option_dump=1;
72     else if(!strcmp(argv[arg],"--nodes"))
73     ;
74     else if(!strcmp(argv[arg],"--segments"))
75     ;
76     else if(!strcmp(argv[arg],"--ways"))
77     ;
78     else if(!strcmp(argv[arg],"--route-relations"))
79     ;
80     else if(!strcmp(argv[arg],"--turn-relations"))
81     ;
82     else
83     print_usage(0,argv[arg],NULL);
84     }
85    
86     if((option_dump)!=1)
87     print_usage(0,NULL,"Must choose --dump.");
88    
89     /* Load in the data - Note: No error checking because Load*List() will call exit() in case of an error. */
90    
91     nodes_filename=FileName(dirname,prefix,"nodesx.parsed.mem");
92    
93     segments_filename=FileName(dirname,prefix,"segmentsx.parsed.mem");
94    
95     ways_filename=FileName(dirname,prefix,"waysx.parsed.mem");
96    
97     route_relations_filename=FileName(dirname,prefix,"relationsx.route.parsed.mem");
98    
99     turn_relations_filename=FileName(dirname,prefix,"relationsx.turn.parsed.mem");
100    
101     /* Print out internal data (in plain text format) */
102    
103     if(option_dump)
104     {
105     for(arg=1;arg<argc;arg++)
106     if(!strcmp(argv[arg],"--nodes"))
107     {
108     print_nodes(nodes_filename);
109     }
110     else if(!strcmp(argv[arg],"--segments"))
111     {
112     print_segments(segments_filename);
113     }
114     else if(!strcmp(argv[arg],"--ways"))
115     {
116     print_ways(ways_filename);
117     }
118     else if(!strcmp(argv[arg],"--route-relations"))
119     {
120     print_route_relations(route_relations_filename);
121     }
122     else if(!strcmp(argv[arg],"--turn-relations"))
123     {
124     print_turn_relations(turn_relations_filename);
125     }
126     }
127    
128     return(0);
129     }
130    
131    
132     /*++++++++++++++++++++++++++++++++++++++
133     Print out all of the nodes.
134    
135     const char *filename The name of the file containing the data.
136     ++++++++++++++++++++++++++++++++++++++*/
137    
138     static void print_nodes(const char *filename)
139     {
140     off_t size,position=0;
141     int fd;
142    
143     size=SizeFile(filename);
144    
145     fd=ReOpenFile(filename);
146    
147     while(position<size)
148     {
149     NodeX nodex;
150    
151     ReadFile(fd,&nodex,sizeof(NodeX));
152    
153     printf("Node %"Pnode_t"\n",nodex.id);
154     printf(" lat=%d lon=%d\n",nodex.latitude,nodex.longitude);
155     printf(" allow=%02x\n",nodex.allow);
156     printf(" flags=%02x\n",nodex.flags);
157    
158     position+=sizeof(NodeX);
159     }
160    
161     CloseFile(fd);
162     }
163    
164    
165     /*++++++++++++++++++++++++++++++++++++++
166     Print out all of the segments.
167    
168     const char *filename The name of the file containing the data.
169     ++++++++++++++++++++++++++++++++++++++*/
170    
171     static void print_segments(const char *filename)
172     {
173     off_t size,position=0;
174     int fd;
175    
176     size=SizeFile(filename);
177    
178     fd=ReOpenFile(filename);
179    
180     while(position<size)
181     {
182     SegmentX segmentx;
183    
184     ReadFile(fd,&segmentx,sizeof(SegmentX));
185    
186     printf("Segment\n");
187     printf(" node1=%"Pnode_t" node2=%"Pnode_t"\n",segmentx.node1,segmentx.node2);
188     printf(" way=%"Pway_t"\n",segmentx.way);
189 amb 1168 if(segmentx.distance&SEGMENT_AREA)
190 amb 1149 printf(" Part of area\n");
191 amb 1168 if(segmentx.distance&ONEWAY_1TO2)
192 amb 1149 printf(" One-way (forward)\n");
193 amb 1168 if(segmentx.distance&ONEWAY_2TO1)
194 amb 1149 printf(" One-way (reverse)\n");
195    
196     position+=sizeof(SegmentX);
197     }
198    
199     CloseFile(fd);
200     }
201    
202    
203     /*++++++++++++++++++++++++++++++++++++++
204     Print out all of the ways.
205    
206     const char *filename The name of the file containing the data.
207     ++++++++++++++++++++++++++++++++++++++*/
208    
209     static void print_ways(const char *filename)
210     {
211     off_t size,position=0;
212     int fd;
213    
214     size=SizeFile(filename);
215    
216     fd=ReOpenFile(filename);
217    
218     while(position<size)
219     {
220     FILESORT_VARINT waysize;
221     WayX wayx;
222     char *name=NULL;
223     int malloced=0;
224    
225     ReadFile(fd,&waysize,FILESORT_VARSIZE);
226    
227     ReadFile(fd,&wayx,sizeof(WayX));
228    
229 amb 1156 if(malloced<(waysize-sizeof(WayX)))
230 amb 1149 {
231 amb 1156 malloced=(waysize-sizeof(WayX));
232 amb 1149 name=(char*)realloc((void*)name,malloced);
233     }
234    
235 amb 1156 ReadFile(fd,name,(waysize-sizeof(WayX)));
236 amb 1149
237     printf("Way %"Pway_t"\n",wayx.id);
238     if(*name)
239     printf(" name=%s\n",name);
240     printf(" type=%02x\n",wayx.way.type);
241     printf(" allow=%02x\n",wayx.way.allow);
242     if(wayx.way.props)
243     printf(" props=%02x\n",wayx.way.props);
244     if(wayx.way.speed)
245     printf(" speed=%d\n",wayx.way.speed);
246     if(wayx.way.weight)
247     printf(" weight=%d\n",wayx.way.weight);
248     if(wayx.way.height)
249     printf(" height=%d\n",wayx.way.height);
250     if(wayx.way.width)
251     printf(" width=%d\n",wayx.way.width);
252     if(wayx.way.length)
253     printf(" length=%d\n",wayx.way.length);
254    
255     position+=waysize+FILESORT_VARSIZE;
256     }
257    
258     CloseFile(fd);
259     }
260    
261    
262     /*++++++++++++++++++++++++++++++++++++++
263     Print out all of the route relations.
264    
265     const char *filename The name of the file containing the data.
266     ++++++++++++++++++++++++++++++++++++++*/
267    
268     static void print_route_relations(const char *filename)
269     {
270     off_t size,position=0;
271     int fd;
272    
273     size=SizeFile(filename);
274    
275     fd=ReOpenFile(filename);
276    
277     while(position<size)
278     {
279     FILESORT_VARINT relationsize;
280     RouteRelX relationx;
281     way_t wayid;
282     relation_t relationid;
283    
284     ReadFile(fd,&relationsize,FILESORT_VARSIZE);
285    
286     ReadFile(fd,&relationx,sizeof(RouteRelX));
287    
288     printf("Relation %"Prelation_t"\n",relationx.id);
289     printf(" routes=%02x\n",relationx.routes);
290    
291     do
292     {
293     ReadFile(fd,&wayid,sizeof(way_t));
294    
295     printf(" way=%"Pway_t"\n",wayid);
296     }
297     while(wayid!=NO_WAY_ID);
298    
299     do
300     {
301     ReadFile(fd,&relationid,sizeof(relation_t));
302    
303     printf(" relation=%"Prelation_t"\n",relationid);
304     }
305     while(relationid!=NO_RELATION_ID);
306    
307     position+=relationsize+FILESORT_VARSIZE;
308     }
309    
310     CloseFile(fd);
311     }
312    
313    
314     /*++++++++++++++++++++++++++++++++++++++
315     Print out all of the turn relations.
316    
317     const char *filename The name of the file containing the data.
318     ++++++++++++++++++++++++++++++++++++++*/
319    
320     static void print_turn_relations(const char *filename)
321     {
322     off_t size,position=0;
323     int fd;
324    
325     size=SizeFile(filename);
326    
327     fd=ReOpenFile(filename);
328    
329     while(position<size)
330     {
331 amb 1163 TurnRelX relationx;
332 amb 1149
333 amb 1163 ReadFile(fd,&relationx,sizeof(TurnRelX));
334 amb 1149
335     printf("Relation %"Prelation_t"\n",relationx.id);
336     printf(" from=%"Pway_t"\n",relationx.from);
337     printf(" via=%"Pnode_t"\n",relationx.via);
338     printf(" to=%"Pway_t"\n",relationx.to);
339     printf(" type=%d\n",relationx.restriction);
340     if(relationx.except)
341     printf(" except=%02x\n",relationx.except);
342    
343 amb 1163 position+=sizeof(TurnRelX);
344 amb 1149 }
345    
346     CloseFile(fd);
347     }
348    
349    
350     /*++++++++++++++++++++++++++++++++++++++
351     Print out the usage information.
352    
353     int detail The level of detail to use - 0 = low, 1 = high.
354    
355     const char *argerr The argument that gave the error (if there is one).
356    
357     const char *err Other error message (if there is one).
358     ++++++++++++++++++++++++++++++++++++++*/
359    
360     static void print_usage(int detail,const char *argerr,const char *err)
361     {
362     fprintf(stderr,
363     "Usage: filedumper [--help]\n"
364     " [--dir=<dirname>] [--prefix=<name>]\n"
365     " [--dump [--nodes]\n"
366     " [--segments]\n"
367     " [--ways]\n"
368     " [--route-relations]\n"
369     " [--turn-relations]]\n");
370    
371     if(argerr)
372     fprintf(stderr,
373     "\n"
374     "Error with command line parameter: %s\n",argerr);
375    
376     if(err)
377     fprintf(stderr,
378     "\n"
379     "Error: %s\n",err);
380    
381     if(detail)
382     fprintf(stderr,
383     "\n"
384     "--help Prints this information.\n"
385     "\n"
386     "--dir=<dirname> The directory containing the routing database.\n"
387     "--prefix=<name> The filename prefix for the routing database.\n"
388     "\n"
389     "--dump Dump the intermediate files after parsing.\n"
390     " --nodes * all of the nodes.\n"
391     " --segments * all of the segments.\n"
392     " --ways * all of the ways.\n"
393     " --route-relations * all of the route relations.\n"
394     " --turn-relations * all of the turn relations.\n");
395    
396     exit(!detail);
397     }