Routino SVN Repository Browser

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

ViewVC logotype

Contents of /branches/libroutino/src/filedumperx.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1709 - (show annotations) (download) (as text)
Fri Jun 12 18:49:28 2015 UTC (9 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 8976 byte(s)
Correct an error in a comment.

1 /***************************************
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-2015 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 "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 char *nodes_filename,*ways_filename,*route_relations_filename,*turn_relations_filename;
56 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 /* Get the filenames. */
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 exit(EXIT_SUCCESS);
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 int fd;
131 NodeX nodex;
132
133 fd=ReOpenFileBuffered(filename);
134
135 while(!ReadFileBuffered(fd,&nodex,sizeof(NodeX)))
136 {
137 printf("Node %"Pnode_t"\n",nodex.id);
138 printf(" lat=%d lon=%d\n",nodex.latitude,nodex.longitude);
139 printf(" allow=%02x\n",nodex.allow);
140 printf(" flags=%02x\n",nodex.flags);
141 }
142
143 CloseFileBuffered(fd);
144 }
145
146
147 /*++++++++++++++++++++++++++++++++++++++
148 Print out all of the ways.
149
150 const char *filename The name of the file containing the data.
151 ++++++++++++++++++++++++++++++++++++++*/
152
153 static void print_ways(const char *filename)
154 {
155 FILESORT_VARINT waysize;
156 int fd;
157
158 fd=ReOpenFileBuffered(filename);
159
160 while(!ReadFileBuffered(fd,&waysize,FILESORT_VARSIZE))
161 {
162 WayX wayx;
163 node_t node;
164 char *name=NULL;
165 size_t malloced=0;
166 int first=1;
167
168 ReadFileBuffered(fd,&wayx,sizeof(WayX));
169
170 printf("Way %"Pway_t"\n",wayx.id);
171
172 while(!ReadFileBuffered(fd,&node,sizeof(node_t)) && node!=NO_NODE_ID)
173 {
174 if(first)
175 printf(" nodes=%"Pnode_t,node);
176 else
177 printf(",%"Pnode_t,node);
178
179 waysize-=sizeof(node_t);
180
181 first=0;
182 }
183
184 printf("\n");
185
186 waysize-=sizeof(node_t)+sizeof(WayX);
187
188 if(malloced<waysize)
189 {
190 malloced=waysize;
191 name=(char*)realloc((void*)name,malloced);
192 }
193
194 ReadFileBuffered(fd,name,waysize);
195
196 if(*name)
197 printf(" name=%s\n",name);
198 printf(" type=%02x\n",wayx.way.type);
199 printf(" allow=%02x\n",wayx.way.allow);
200 if(wayx.way.props)
201 printf(" props=%02x\n",wayx.way.props);
202 if(wayx.way.speed)
203 printf(" speed=%d\n",wayx.way.speed);
204 if(wayx.way.weight)
205 printf(" weight=%d\n",wayx.way.weight);
206 if(wayx.way.height)
207 printf(" height=%d\n",wayx.way.height);
208 if(wayx.way.width)
209 printf(" width=%d\n",wayx.way.width);
210 if(wayx.way.length)
211 printf(" length=%d\n",wayx.way.length);
212 }
213
214 CloseFileBuffered(fd);
215 }
216
217
218 /*++++++++++++++++++++++++++++++++++++++
219 Print out all of the route relations.
220
221 const char *filename The name of the file containing the data.
222 ++++++++++++++++++++++++++++++++++++++*/
223
224 static void print_route_relations(const char *filename)
225 {
226 FILESORT_VARINT relationsize;
227 int fd;
228
229 fd=ReOpenFileBuffered(filename);
230
231 while(!ReadFileBuffered(fd,&relationsize,FILESORT_VARSIZE))
232 {
233 RouteRelX relationx;
234 node_t nodeid;
235 way_t wayid;
236 relation_t relationid;
237
238 ReadFileBuffered(fd,&relationx,sizeof(RouteRelX));
239
240 printf("Relation %"Prelation_t"\n",relationx.id);
241 printf(" routes=%02x\n",relationx.routes);
242
243 while(!ReadFileBuffered(fd,&nodeid,sizeof(node_t)) && nodeid!=NO_NODE_ID)
244 printf(" node=%"Pnode_t"\n",nodeid);
245
246 while(!ReadFileBuffered(fd,&wayid,sizeof(way_t)) && wayid!=NO_WAY_ID);
247 printf(" way=%"Pway_t"\n",wayid);
248
249 while(!ReadFileBuffered(fd,&relationid,sizeof(relation_t)) && relationid!=NO_RELATION_ID);
250 printf(" relation=%"Prelation_t"\n",relationid);
251 }
252
253 CloseFileBuffered(fd);
254 }
255
256
257 /*++++++++++++++++++++++++++++++++++++++
258 Print out all of the turn relations.
259
260 const char *filename The name of the file containing the data.
261 ++++++++++++++++++++++++++++++++++++++*/
262
263 static void print_turn_relations(const char *filename)
264 {
265 int fd;
266 TurnRelX relationx;
267
268 fd=ReOpenFileBuffered(filename);
269
270 while(!ReadFileBuffered(fd,&relationx,sizeof(TurnRelX)))
271 {
272 printf("Relation %"Prelation_t"\n",relationx.id);
273 printf(" from=%"Pway_t"\n",relationx.from);
274 printf(" via=%"Pnode_t"\n",relationx.via);
275 printf(" to=%"Pway_t"\n",relationx.to);
276 printf(" type=%d\n",relationx.restriction);
277 if(relationx.except)
278 printf(" except=%02x\n",relationx.except);
279 }
280
281 CloseFileBuffered(fd);
282 }
283
284
285 /*++++++++++++++++++++++++++++++++++++++
286 Print out the usage information.
287
288 int detail The level of detail to use - 0 = low, 1 = high.
289
290 const char *argerr The argument that gave the error (if there is one).
291
292 const char *err Other error message (if there is one).
293 ++++++++++++++++++++++++++++++++++++++*/
294
295 static void print_usage(int detail,const char *argerr,const char *err)
296 {
297 fprintf(stderr,
298 "Usage: filedumperx [--help]\n"
299 " [--dir=<dirname>] [--prefix=<name>]\n"
300 " [--dump [--nodes]\n"
301 " [--ways]\n"
302 " [--route-relations]\n"
303 " [--turn-relations]]\n");
304
305 if(argerr)
306 fprintf(stderr,
307 "\n"
308 "Error with command line parameter: %s\n",argerr);
309
310 if(err)
311 fprintf(stderr,
312 "\n"
313 "Error: %s\n",err);
314
315 if(detail)
316 fprintf(stderr,
317 "\n"
318 "--help Prints this information.\n"
319 "\n"
320 "--dir=<dirname> The directory containing the routing database.\n"
321 "--prefix=<name> The filename prefix for the routing database.\n"
322 "\n"
323 "--dump Dump the intermediate files after parsing.\n"
324 " --nodes * all of the nodes.\n"
325 " --ways * all of the ways.\n"
326 " --route-relations * all of the route relations.\n"
327 " --turn-relations * all of the turn relations.\n");
328
329 exit(!detail);
330 }