Routino SVN Repository Browser

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

ViewVC logotype

Annotation of /trunk/src/profiles.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 472 - (hide annotations) (download) (as text)
Mon Aug 30 12:13:29 2010 UTC (14 years, 6 months ago) by amb
File MIME type: text/x-csrc
File size: 31298 byte(s)
Fix bug with writing out JSON profile information.

1 amb 83 /***************************************
2 amb 472 $Header: /home/amb/CVS/routino/src/profiles.c,v 1.45 2010-08-30 12:13:29 amb Exp $
3 amb 83
4 amb 363 Load the profiles from a file and the functions for handling them.
5 amb 151
6     Part of the Routino routing software.
7 amb 83 ******************/ /******************
8 amb 320 This file Copyright 2008-2010 Andrew M. Bishop
9 amb 83
10 amb 151 This program is free software: you can redistribute it and/or modify
11     it under the terms of the GNU Affero General Public License as published by
12     the Free Software Foundation, either version 3 of the License, or
13     (at your option) any later version.
14    
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     GNU Affero General Public License for more details.
19    
20     You should have received a copy of the GNU Affero General Public License
21     along with this program. If not, see <http://www.gnu.org/licenses/>.
22 amb 83 ***************************************/
23    
24    
25     #include <stdio.h>
26 amb 336 #include <string.h>
27 amb 341 #include <stdlib.h>
28 amb 83
29 amb 97 #include "types.h"
30 amb 83 #include "ways.h"
31 amb 449
32     #include "files.h"
33     #include "profiles.h"
34     #include "functions.h"
35 amb 341 #include "xmlparse.h"
36 amb 83
37    
38 amb 341 /*+ The profiles that have been loaded from file. +*/
39     static Profile **loaded_profiles=NULL;
40 amb 83
41 amb 341 /*+ The number of profiles that have been loaded from file. +*/
42     static int nloaded_profiles=0;
43 amb 83
44 amb 294
45 amb 341 /* The XML tag processing function prototypes */
46 amb 294
47 amb 373 //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding);
48     //static int RoutinoProfilesType_function(const char *_tag_,int _type_);
49     static int profileType_function(const char *_tag_,int _type_,const char *name,const char *transport);
50     //static int restrictionsType_function(const char *_tag_,int _type_);
51     static int lengthType_function(const char *_tag_,int _type_,const char *limit);
52     static int widthType_function(const char *_tag_,int _type_,const char *limit);
53     static int heightType_function(const char *_tag_,int _type_,const char *limit);
54     static int weightType_function(const char *_tag_,int _type_,const char *limit);
55     //static int propertiesType_function(const char *_tag_,int _type_);
56     static int onewayType_function(const char *_tag_,int _type_,const char *obey);
57     static int propertyType_function(const char *_tag_,int _type_,const char *type,const char *percent);
58     //static int preferencesType_function(const char *_tag_,int _type_);
59     static int preferenceType_function(const char *_tag_,int _type_,const char *highway,const char *percent);
60     //static int speedsType_function(const char *_tag_,int _type_);
61     static int speedType_function(const char *_tag_,int _type_,const char *highway,const char *kph);
62 amb 314
63    
64 amb 341 /* The XML tag definitions */
65 amb 83
66 amb 341 /*+ The speedType type tag. +*/
67 amb 367 static xmltag speedType_tag=
68 amb 341 {"speed",
69 amb 355 2, {"highway","kph"},
70 amb 367 speedType_function,
71 amb 341 {NULL}};
72 amb 83
73 amb 341 /*+ The speedsType type tag. +*/
74 amb 367 static xmltag speedsType_tag=
75 amb 341 {"speeds",
76 amb 355 0, {NULL},
77 amb 341 NULL,
78 amb 367 {&speedType_tag,NULL}};
79 amb 296
80 amb 341 /*+ The preferenceType type tag. +*/
81 amb 367 static xmltag preferenceType_tag=
82 amb 341 {"preference",
83 amb 355 2, {"highway","percent"},
84 amb 367 preferenceType_function,
85 amb 341 {NULL}};
86 amb 296
87 amb 341 /*+ The preferencesType type tag. +*/
88 amb 367 static xmltag preferencesType_tag=
89 amb 341 {"preferences",
90 amb 355 0, {NULL},
91 amb 341 NULL,
92 amb 367 {&preferenceType_tag,NULL}};
93 amb 83
94 amb 341 /*+ The propertyType type tag. +*/
95 amb 367 static xmltag propertyType_tag=
96 amb 341 {"property",
97 amb 355 2, {"type","percent"},
98 amb 367 propertyType_function,
99 amb 341 {NULL}};
100 amb 83
101 amb 341 /*+ The onewayType type tag. +*/
102 amb 367 static xmltag onewayType_tag=
103 amb 341 {"oneway",
104 amb 355 1, {"obey"},
105 amb 367 onewayType_function,
106 amb 341 {NULL}};
107 amb 83
108 amb 341 /*+ The propertiesType type tag. +*/
109 amb 367 static xmltag propertiesType_tag=
110 amb 341 {"properties",
111 amb 355 0, {NULL},
112 amb 341 NULL,
113 amb 367 {&propertyType_tag,NULL}};
114 amb 83
115 amb 341 /*+ The weightType type tag. +*/
116 amb 367 static xmltag weightType_tag=
117 amb 341 {"weight",
118 amb 355 1, {"limit"},
119 amb 367 weightType_function,
120 amb 341 {NULL}};
121 amb 83
122 amb 341 /*+ The heightType type tag. +*/
123 amb 367 static xmltag heightType_tag=
124 amb 341 {"height",
125 amb 355 1, {"limit"},
126 amb 367 heightType_function,
127 amb 341 {NULL}};
128 amb 83
129 amb 341 /*+ The widthType type tag. +*/
130 amb 367 static xmltag widthType_tag=
131 amb 341 {"width",
132 amb 355 1, {"limit"},
133 amb 367 widthType_function,
134 amb 341 {NULL}};
135 amb 83
136 amb 341 /*+ The lengthType type tag. +*/
137 amb 367 static xmltag lengthType_tag=
138 amb 341 {"length",
139 amb 355 1, {"limit"},
140 amb 367 lengthType_function,
141 amb 341 {NULL}};
142 amb 83
143 amb 341 /*+ The restrictionsType type tag. +*/
144 amb 367 static xmltag restrictionsType_tag=
145 amb 341 {"restrictions",
146 amb 355 0, {NULL},
147 amb 341 NULL,
148 amb 367 {&onewayType_tag,&weightType_tag,&heightType_tag,&widthType_tag,&lengthType_tag,NULL}};
149 amb 83
150 amb 341 /*+ The profileType type tag. +*/
151 amb 367 static xmltag profileType_tag=
152 amb 341 {"profile",
153 amb 355 2, {"name","transport"},
154 amb 367 profileType_function,
155     {&speedsType_tag,&preferencesType_tag,&propertiesType_tag,&restrictionsType_tag,NULL}};
156 amb 83
157 amb 341 /*+ The RoutinoProfilesType type tag. +*/
158 amb 367 static xmltag RoutinoProfilesType_tag=
159 amb 341 {"routino-profiles",
160 amb 355 0, {NULL},
161 amb 341 NULL,
162 amb 367 {&profileType_tag,NULL}};
163 amb 83
164 amb 367 /*+ The xmlDeclaration type tag. +*/
165     static xmltag xmlDeclaration_tag=
166 amb 348 {"xml",
167 amb 355 2, {"version","encoding"},
168 amb 341 NULL,
169     {NULL}};
170    
171    
172     /*+ The complete set of tags at the top level. +*/
173 amb 367 static xmltag *xml_toplevel_tags[]={&xmlDeclaration_tag,&RoutinoProfilesType_tag,NULL};
174 amb 341
175    
176     /* The XML tag processing functions */
177    
178    
179 amb 83 /*++++++++++++++++++++++++++++++++++++++
180 amb 344 The function that is called when the speedType XSD type is seen
181 amb 341
182 amb 367 int speedType_function Returns 0 if no error occured or something else otherwise.
183 amb 363
184 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
185    
186 amb 344 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
187    
188 amb 355 const char *highway The contents of the 'highway' attribute (or NULL if not defined).
189 amb 341
190 amb 355 const char *kph The contents of the 'kph' attribute (or NULL if not defined).
191 amb 341 ++++++++++++++++++++++++++++++++++++++*/
192    
193 amb 373 static int speedType_function(const char *_tag_,int _type_,const char *highway,const char *kph)
194 amb 341 {
195 amb 344 if(_type_&XMLPARSE_TAG_START)
196     {
197 amb 363 double speed;
198 amb 348 Highway highwaytype;
199 amb 341
200 amb 373 XMLPARSE_ASSERT_STRING(_tag_,highway);
201 amb 348
202     highwaytype=HighwayType(highway);
203    
204     if(highwaytype==Way_Count)
205 amb 373 XMLPARSE_INVALID(_tag_,highway);
206 amb 348
207 amb 373 XMLPARSE_ASSERT_FLOATING(_tag_,kph,speed);
208 amb 348
209 amb 363 loaded_profiles[nloaded_profiles-1]->speed[highwaytype]=kph_to_speed(speed);
210 amb 344 }
211 amb 363
212     return(0);
213 amb 341 }
214    
215    
216     /*++++++++++++++++++++++++++++++++++++++
217 amb 363 The function that is called when the speedsType XSD type is seen
218    
219 amb 367 int speedsType_function Returns 0 if no error occured or something else otherwise.
220 amb 363
221 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
222    
223 amb 363 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
224     ++++++++++++++++++++++++++++++++++++++*/
225    
226 amb 373 //static int speedsType_function(const char *_tag_,int _type_)
227 amb 363 //{
228     // return(0);
229     //}
230    
231    
232     /*++++++++++++++++++++++++++++++++++++++
233 amb 344 The function that is called when the preferenceType XSD type is seen
234 amb 341
235 amb 367 int preferenceType_function Returns 0 if no error occured or something else otherwise.
236 amb 363
237 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
238    
239 amb 344 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
240    
241 amb 355 const char *highway The contents of the 'highway' attribute (or NULL if not defined).
242 amb 341
243 amb 355 const char *percent The contents of the 'percent' attribute (or NULL if not defined).
244 amb 341 ++++++++++++++++++++++++++++++++++++++*/
245    
246 amb 373 static int preferenceType_function(const char *_tag_,int _type_,const char *highway,const char *percent)
247 amb 341 {
248 amb 344 if(_type_&XMLPARSE_TAG_START)
249     {
250 amb 348 Highway highwaytype;
251 amb 363 double p;
252 amb 341
253 amb 373 XMLPARSE_ASSERT_STRING(_tag_,highway);
254 amb 348
255     highwaytype=HighwayType(highway);
256    
257     if(highwaytype==Way_Count)
258 amb 373 XMLPARSE_INVALID(_tag_,highway);
259 amb 348
260 amb 373 XMLPARSE_ASSERT_FLOATING(_tag_,percent,p);
261 amb 348
262 amb 363 loaded_profiles[nloaded_profiles-1]->highway[highwaytype]=p;
263 amb 344 }
264 amb 363
265     return(0);
266 amb 341 }
267    
268    
269     /*++++++++++++++++++++++++++++++++++++++
270 amb 363 The function that is called when the preferencesType XSD type is seen
271    
272 amb 367 int preferencesType_function Returns 0 if no error occured or something else otherwise.
273 amb 363
274 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
275    
276 amb 363 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
277     ++++++++++++++++++++++++++++++++++++++*/
278    
279 amb 373 //static int preferencesType_function(const char *_tag_,int _type_)
280 amb 363 //{
281     // return(0);
282     //}
283    
284    
285     /*++++++++++++++++++++++++++++++++++++++
286 amb 344 The function that is called when the propertyType XSD type is seen
287 amb 341
288 amb 367 int propertyType_function Returns 0 if no error occured or something else otherwise.
289 amb 363
290 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
291    
292 amb 344 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
293    
294 amb 355 const char *type The contents of the 'type' attribute (or NULL if not defined).
295 amb 341
296 amb 355 const char *percent The contents of the 'percent' attribute (or NULL if not defined).
297 amb 341 ++++++++++++++++++++++++++++++++++++++*/
298    
299 amb 373 static int propertyType_function(const char *_tag_,int _type_,const char *type,const char *percent)
300 amb 341 {
301 amb 344 if(_type_&XMLPARSE_TAG_START)
302     {
303 amb 348 Property property;
304 amb 363 double p;
305 amb 341
306 amb 373 XMLPARSE_ASSERT_STRING(_tag_,type);
307 amb 348
308     property=PropertyType(type);
309    
310     if(property==Property_Count)
311 amb 373 XMLPARSE_INVALID(_tag_,type);
312 amb 348
313 amb 373 XMLPARSE_ASSERT_FLOATING(_tag_,percent,p);
314 amb 348
315 amb 363 loaded_profiles[nloaded_profiles-1]->props_yes[property]=p;
316 amb 344 }
317 amb 363
318     return(0);
319 amb 341 }
320    
321    
322     /*++++++++++++++++++++++++++++++++++++++
323 amb 344 The function that is called when the onewayType XSD type is seen
324 amb 341
325 amb 367 int onewayType_function Returns 0 if no error occured or something else otherwise.
326 amb 363
327 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
328    
329 amb 344 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
330    
331 amb 355 const char *obey The contents of the 'obey' attribute (or NULL if not defined).
332 amb 341 ++++++++++++++++++++++++++++++++++++++*/
333    
334 amb 373 static int onewayType_function(const char *_tag_,int _type_,const char *obey)
335 amb 341 {
336 amb 344 if(_type_&XMLPARSE_TAG_START)
337 amb 348 {
338 amb 363 int o;
339 amb 348
340 amb 373 XMLPARSE_ASSERT_INTEGER(_tag_,obey,o);
341 amb 348
342 amb 363 loaded_profiles[nloaded_profiles-1]->oneway=!!o;
343 amb 348 }
344 amb 363
345     return(0);
346 amb 341 }
347    
348    
349     /*++++++++++++++++++++++++++++++++++++++
350 amb 363 The function that is called when the propertiesType XSD type is seen
351    
352 amb 367 int propertiesType_function Returns 0 if no error occured or something else otherwise.
353 amb 363
354 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
355    
356 amb 363 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
357     ++++++++++++++++++++++++++++++++++++++*/
358    
359 amb 373 //static int propertiesType_function(const char *_tag_,int _type_)
360 amb 363 //{
361     // return(0);
362     //}
363    
364    
365     /*++++++++++++++++++++++++++++++++++++++
366 amb 344 The function that is called when the weightType XSD type is seen
367 amb 341
368 amb 367 int weightType_function Returns 0 if no error occured or something else otherwise.
369 amb 363
370 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
371    
372 amb 344 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
373    
374 amb 355 const char *limit The contents of the 'limit' attribute (or NULL if not defined).
375 amb 341 ++++++++++++++++++++++++++++++++++++++*/
376    
377 amb 373 static int weightType_function(const char *_tag_,int _type_,const char *limit)
378 amb 341 {
379 amb 344 if(_type_&XMLPARSE_TAG_START)
380 amb 348 {
381 amb 363 double l;
382 amb 348
383 amb 373 XMLPARSE_ASSERT_FLOATING(_tag_,limit,l);
384 amb 348
385 amb 363 loaded_profiles[nloaded_profiles-1]->weight=tonnes_to_weight(l);
386 amb 348 }
387 amb 363
388     return(0);
389 amb 341 }
390    
391    
392     /*++++++++++++++++++++++++++++++++++++++
393 amb 344 The function that is called when the heightType XSD type is seen
394 amb 341
395 amb 367 int heightType_function Returns 0 if no error occured or something else otherwise.
396 amb 363
397 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
398    
399 amb 344 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
400    
401 amb 355 const char *limit The contents of the 'limit' attribute (or NULL if not defined).
402 amb 341 ++++++++++++++++++++++++++++++++++++++*/
403    
404 amb 373 static int heightType_function(const char *_tag_,int _type_,const char *limit)
405 amb 341 {
406 amb 344 if(_type_&XMLPARSE_TAG_START)
407 amb 348 {
408 amb 363 double l;
409 amb 348
410 amb 373 XMLPARSE_ASSERT_FLOATING(_tag_,limit,l);
411 amb 348
412 amb 363 loaded_profiles[nloaded_profiles-1]->height=metres_to_height(l);
413 amb 348 }
414 amb 363
415     return(0);
416 amb 341 }
417    
418    
419     /*++++++++++++++++++++++++++++++++++++++
420 amb 344 The function that is called when the widthType XSD type is seen
421 amb 341
422 amb 367 int widthType_function Returns 0 if no error occured or something else otherwise.
423 amb 363
424 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
425    
426 amb 344 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
427    
428 amb 355 const char *limit The contents of the 'limit' attribute (or NULL if not defined).
429 amb 341 ++++++++++++++++++++++++++++++++++++++*/
430    
431 amb 373 static int widthType_function(const char *_tag_,int _type_,const char *limit)
432 amb 341 {
433 amb 344 if(_type_&XMLPARSE_TAG_START)
434 amb 348 {
435 amb 363 double l;
436 amb 348
437 amb 373 XMLPARSE_ASSERT_FLOATING(_tag_,limit,l);
438 amb 348
439 amb 363 loaded_profiles[nloaded_profiles-1]->width=metres_to_width(l);
440 amb 348 }
441 amb 363
442     return(0);
443 amb 341 }
444    
445    
446     /*++++++++++++++++++++++++++++++++++++++
447 amb 344 The function that is called when the lengthType XSD type is seen
448 amb 341
449 amb 367 int lengthType_function Returns 0 if no error occured or something else otherwise.
450 amb 363
451 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
452    
453 amb 344 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
454    
455 amb 355 const char *limit The contents of the 'limit' attribute (or NULL if not defined).
456 amb 341 ++++++++++++++++++++++++++++++++++++++*/
457    
458 amb 373 static int lengthType_function(const char *_tag_,int _type_,const char *limit)
459 amb 341 {
460 amb 344 if(_type_&XMLPARSE_TAG_START)
461 amb 348 {
462 amb 363 double l;
463 amb 348
464 amb 373 XMLPARSE_ASSERT_FLOATING(_tag_,limit,l);
465 amb 348
466 amb 363 loaded_profiles[nloaded_profiles-1]->length=metres_to_length(l);
467 amb 348 }
468 amb 363
469     return(0);
470 amb 341 }
471    
472    
473     /*++++++++++++++++++++++++++++++++++++++
474 amb 363 The function that is called when the restrictionsType XSD type is seen
475    
476 amb 367 int restrictionsType_function Returns 0 if no error occured or something else otherwise.
477 amb 363
478 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
479    
480 amb 363 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
481     ++++++++++++++++++++++++++++++++++++++*/
482    
483 amb 373 //static int restrictionsType_function(const char *_tag_,int _type_)
484 amb 363 //{
485     // return(0);
486     //}
487    
488    
489     /*++++++++++++++++++++++++++++++++++++++
490 amb 344 The function that is called when the profileType XSD type is seen
491 amb 341
492 amb 367 int profileType_function Returns 0 if no error occured or something else otherwise.
493 amb 363
494 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
495    
496 amb 344 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
497    
498 amb 355 const char *name The contents of the 'name' attribute (or NULL if not defined).
499 amb 341
500 amb 355 const char *transport The contents of the 'transport' attribute (or NULL if not defined).
501 amb 341 ++++++++++++++++++++++++++++++++++++++*/
502    
503 amb 373 static int profileType_function(const char *_tag_,int _type_,const char *name,const char *transport)
504 amb 341 {
505 amb 344 if(_type_&XMLPARSE_TAG_START)
506     {
507 amb 348 Transport transporttype;
508     int i;
509    
510 amb 373 XMLPARSE_ASSERT_STRING(_tag_,name);
511     XMLPARSE_ASSERT_STRING(_tag_,transport);
512 amb 348
513     for(i=0;i<nloaded_profiles;i++)
514     if(!strcmp(name,loaded_profiles[i]->name))
515 amb 373 XMLPARSE_MESSAGE(_tag_,"profile name must be unique");
516 amb 348
517     transporttype=TransportType(transport);
518    
519     if(transporttype==Transport_None)
520 amb 373 XMLPARSE_INVALID(_tag_,transport);
521 amb 348
522 amb 344 if((nloaded_profiles%16)==0)
523     loaded_profiles=(Profile**)realloc((void*)loaded_profiles,(nloaded_profiles+16)*sizeof(Profile*));
524 amb 341
525 amb 344 nloaded_profiles++;
526 amb 341
527 amb 344 loaded_profiles[nloaded_profiles-1]=(Profile*)calloc(1,sizeof(Profile));
528 amb 341
529 amb 344 loaded_profiles[nloaded_profiles-1]->name=strcpy(malloc(strlen(name)+1),name);
530 amb 348 loaded_profiles[nloaded_profiles-1]->transport=transporttype;
531 amb 344 }
532 amb 363
533     return(0);
534 amb 341 }
535    
536    
537     /*++++++++++++++++++++++++++++++++++++++
538 amb 363 The function that is called when the RoutinoProfilesType XSD type is seen
539    
540 amb 367 int RoutinoProfilesType_function Returns 0 if no error occured or something else otherwise.
541 amb 363
542 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
543    
544 amb 363 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
545     ++++++++++++++++++++++++++++++++++++++*/
546    
547 amb 373 //static int RoutinoProfilesType_function(const char *_tag_,int _type_)
548 amb 363 //{
549     // return(0);
550     //}
551    
552    
553     /*++++++++++++++++++++++++++++++++++++++
554 amb 367 The function that is called when the XML declaration is seen
555 amb 363
556 amb 367 int xmlDeclaration_function Returns 0 if no error occured or something else otherwise.
557 amb 363
558 amb 373 const char *_tag_ Set to the name of the element tag that triggered this function call.
559    
560 amb 363 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
561    
562     const char *version The contents of the 'version' attribute (or NULL if not defined).
563    
564     const char *encoding The contents of the 'encoding' attribute (or NULL if not defined).
565     ++++++++++++++++++++++++++++++++++++++*/
566    
567 amb 373 //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding)
568 amb 363 //{
569     // return(0);
570     //}
571    
572    
573     /*++++++++++++++++++++++++++++++++++++++
574 amb 341 The XML profile parser.
575    
576     int ParseXMLProfiles Returns 0 if OK or something else in case of an error.
577    
578     const char *filename The name of the file to read.
579     ++++++++++++++++++++++++++++++++++++++*/
580    
581     int ParseXMLProfiles(const char *filename)
582     {
583 amb 348 int retval;
584    
585     if(!ExistsFile(filename))
586     {
587     fprintf(stderr,"Error: Specified profiles file '%s' does not exist.\n",filename);
588     return(1);
589     }
590    
591 amb 341 FILE *file=fopen(filename,"r");
592    
593     if(!file)
594 amb 348 {
595     fprintf(stderr,"Error: Cannot open profiles file '%s' for reading.\n",filename);
596 amb 341 return(1);
597 amb 348 }
598 amb 341
599 amb 366 retval=ParseXML(file,xml_toplevel_tags,XMLPARSE_UNKNOWN_ATTR_ERRNONAME);
600 amb 348
601 amb 341 fclose(file);
602    
603 amb 363 if(retval)
604 amb 348 {
605     int i;
606    
607     for(i=0;i<nloaded_profiles;i++)
608     free(loaded_profiles[i]);
609     free(loaded_profiles);
610    
611     nloaded_profiles=0;
612    
613     return(1);
614     }
615    
616 amb 341 return(0);
617     }
618    
619    
620     /*++++++++++++++++++++++++++++++++++++++
621 amb 83 Get the profile for a type of transport.
622    
623     Profile *GetProfile Returns a pointer to the profile.
624    
625 amb 341 const char *name The name of the profile.
626 amb 83 ++++++++++++++++++++++++++++++++++++++*/
627    
628 amb 341 Profile *GetProfile(const char *name)
629 amb 83 {
630 amb 341 int i;
631    
632     for(i=0;i<nloaded_profiles;i++)
633     if(!strcmp(loaded_profiles[i]->name,name))
634     return(loaded_profiles[i]);
635    
636     return(NULL);
637 amb 83 }
638    
639    
640     /*++++++++++++++++++++++++++++++++++++++
641 amb 166 Update a profile with highway preference scaling factor.
642    
643 amb 410 int UpdateProfile Returns 1 in case of a problem.
644    
645 amb 166 Profile *profile The profile to be updated.
646 amb 410
647     Ways *ways The set of ways to use.
648 amb 166 ++++++++++++++++++++++++++++++++++++++*/
649    
650 amb 410 int UpdateProfile(Profile *profile,Ways *ways)
651 amb 166 {
652 amb 168 score_t hmax=0;
653 amb 166 int i;
654    
655 amb 410 /* Fix up the allowed transport types. */
656    
657 amb 341 profile->allow=ALLOWED(profile->transport);
658    
659 amb 460 if(!(profile->allow & ways->file.allow))
660 amb 410 return(1);
661    
662 amb 173 /* Normalise the highway preferences into the range 0 -> 1 */
663    
664 amb 300 for(i=1;i<Way_Count;i++)
665 amb 298 {
666     if(profile->highway[i]<0)
667     profile->highway[i]=0;
668    
669 amb 166 if(profile->highway[i]>hmax)
670     hmax=profile->highway[i];
671 amb 298 }
672 amb 166
673 amb 410 if(hmax==0)
674     return(1);
675    
676 amb 300 for(i=1;i<Way_Count;i++)
677 amb 298 profile->highway[i]/=hmax;
678 amb 173
679 amb 410 /* Normalise the property preferences into the range 0 -> 2 */
680 amb 298
681     for(i=1;i<Property_Count;i++)
682     {
683     if(profile->props_yes[i]<0)
684     profile->props_yes[i]=0;
685    
686     if(profile->props_yes[i]>100)
687     profile->props_yes[i]=100;
688    
689 amb 410 profile->props_yes[i]/=50;
690     profile->props_no [i] =2-profile->props_yes[i];
691 amb 298 }
692    
693 amb 410 /* Find the fastest preferred speed */
694 amb 173
695     profile->max_speed=0;
696    
697 amb 300 for(i=1;i<Way_Count;i++)
698 amb 173 if(profile->speed[i]>profile->max_speed)
699     profile->max_speed=profile->speed[i];
700    
701 amb 410 if(profile->max_speed==0)
702     return(1);
703    
704     /* Find the most preferred property combination */
705    
706 amb 298 profile->max_pref=1; /* since highway prefs were normalised to 1 */
707 amb 173
708 amb 298 for(i=1;i<Property_Count;i++)
709 amb 460 if(ways->file.props & PROPERTIES(i))
710 amb 410 {
711     if(profile->props_yes[i]>profile->props_no[i])
712     profile->max_pref*=profile->props_yes[i];
713     else
714     profile->max_pref*=profile->props_no[i];
715     }
716    
717     return(0);
718 amb 166 }
719    
720    
721     /*++++++++++++++++++++++++++++++++++++++
722 amb 83 Print out a profile.
723    
724     const Profile *profile The profile to print.
725     ++++++++++++++++++++++++++++++++++++++*/
726    
727     void PrintProfile(const Profile *profile)
728     {
729 amb 214 unsigned int i;
730 amb 83
731     printf("Profile\n=======\n");
732    
733     printf("\n");
734    
735     printf("Transport: %s\n",TransportName(profile->transport));
736    
737     printf("\n");
738    
739 amb 300 for(i=1;i<Way_Count;i++)
740 amb 166 printf("Highway %-12s: %3d%%\n",HighwayName(i),(int)profile->highway[i]);
741 amb 83
742     printf("\n");
743    
744 amb 300 for(i=1;i<Way_Count;i++)
745 amb 166 if(profile->highway[i])
746 amb 85 printf("Speed on %-12s: %3d km/h / %2.0f mph\n",HighwayName(i),profile->speed[i],(double)profile->speed[i]/1.6);
747 amb 83
748     printf("\n");
749    
750 amb 298 for(i=1;i<Property_Count;i++)
751     printf("Highway property %-12s: %3d%%\n",PropertyName(i),(int)profile->props_yes[i]);
752    
753     printf("\n");
754    
755 amb 138 printf("Obey one-way : %s\n",profile->oneway?"yes":"no");
756     printf("Minimum weight: %.1f tonnes\n",weight_to_tonnes(profile->weight));
757     printf("Minimum height: %.1f metres\n",height_to_metres(profile->height));
758     printf("Minimum width : %.1f metres\n",width_to_metres(profile->width));
759     printf("Minimum length: %.1f metres\n",length_to_metres(profile->length));
760 amb 83 }
761 amb 129
762    
763     /*++++++++++++++++++++++++++++++++++++++
764 amb 336 Print out the profiles as XML for use as program input.
765     ++++++++++++++++++++++++++++++++++++++*/
766    
767     void PrintProfilesXML(void)
768     {
769     unsigned int i,j;
770     char *padding=" ";
771    
772     printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
773     printf("\n");
774    
775     printf("<routino-profiles xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"routino-profiles.xsd\">\n");
776     printf("\n");
777    
778 amb 341 for(j=0;j<nloaded_profiles;j++)
779 amb 336 {
780 amb 341 printf(" <profile name=\"%s\" transport=\"%s\">\n",loaded_profiles[j]->name,TransportName(loaded_profiles[j]->transport));
781 amb 336
782     printf(" <speeds>\n");
783     for(i=1;i<Way_Count;i++)
784 amb 341 printf(" <speed highway=\"%s\"%s kph=\"%d\" />\n",HighwayName(i),padding+3+strlen(HighwayName(i)),loaded_profiles[j]->speed[i]);
785 amb 336 printf(" </speeds>\n");
786    
787     printf(" <preferences>\n");
788     for(i=1;i<Way_Count;i++)
789 amb 341 printf(" <preference highway=\"%s\"%s percent=\"%.0f\" />\n",HighwayName(i),padding+3+strlen(HighwayName(i)),loaded_profiles[j]->highway[i]);
790 amb 336 printf(" </preferences>\n");
791    
792     printf(" <properties>\n");
793     for(i=1;i<Property_Count;i++)
794 amb 341 printf(" <property type=\"%s\"%s percent=\"%.0f\" />\n",PropertyName(i),padding+6+strlen(PropertyName(i)),loaded_profiles[j]->props_yes[i]);
795 amb 336 printf(" </properties>\n");
796    
797     printf(" <restrictions>\n");
798 amb 341 printf(" <oneway obey=\"%d\" /> \n",loaded_profiles[j]->oneway);
799     printf(" <weight limit=\"%.1f\" />\n",weight_to_tonnes(loaded_profiles[j]->weight));
800     printf(" <height limit=\"%.1f\" />\n",height_to_metres(loaded_profiles[j]->height));
801     printf(" <width limit=\"%.1f\" />\n",width_to_metres(loaded_profiles[j]->width));
802     printf(" <length limit=\"%.1f\" />\n",length_to_metres(loaded_profiles[j]->length));
803 amb 336 printf(" </restrictions>\n");
804    
805     printf(" </profile>\n");
806     printf("\n");
807     }
808    
809     printf("</routino-profiles>\n");
810     }
811    
812    
813     /*++++++++++++++++++++++++++++++++++++++
814 amb 343 Print out the profiles as JavaScript Object Notation for use in a web form.
815 amb 129 ++++++++++++++++++++++++++++++++++++++*/
816    
817 amb 343 void PrintProfilesJSON(void)
818 amb 129 {
819 amb 214 unsigned int i,j;
820 amb 129
821 amb 343 printf("var routino={ // contains all default Routino options (generated using \"--help-profile-json\").\n");
822 amb 336 printf("\n");
823 amb 320
824     printf(" // Default transport type\n");
825     printf(" transport: 'motorcar',\n");
826     printf("\n");
827    
828     printf(" // Transport types\n");
829     printf(" transports: {");
830 amb 341 for(j=0;j<nloaded_profiles;j++)
831 amb 472 printf("%s%s: %d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),j+1);
832 amb 320 printf("},\n");
833 amb 129 printf("\n");
834    
835 amb 320 printf(" // Highway types\n");
836     printf(" highways: {");
837 amb 300 for(i=1;i<Way_Count;i++)
838 amb 292 printf("%s%s: %d",i==1?"":", ",HighwayName(i),i);
839 amb 320 printf("},\n");
840 amb 129 printf("\n");
841    
842 amb 320 printf(" // Property types\n");
843     printf(" properties: {");
844 amb 298 for(i=1;i<Property_Count;i++)
845     printf("%s%s: %d",i==1?"":", ",PropertyName(i),i);
846 amb 320 printf("},\n");
847 amb 298 printf("\n");
848    
849 amb 320 printf(" // Restriction types\n");
850     printf(" restrictions: {oneway: 1, weight: 2, height: 3, width: 4, length: 5},\n");
851 amb 138 printf("\n");
852    
853 amb 320 printf(" // Allowed highways\n");
854     printf(" profile_highway: {\n");
855 amb 300 for(i=1;i<Way_Count;i++)
856 amb 129 {
857 amb 320 printf(" %12s: {",HighwayName(i));
858 amb 341 for(j=0;j<nloaded_profiles;j++)
859 amb 472 printf("%s%s: %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->highway[i]);
860 amb 300 printf("}%s\n",i==(Way_Count-1)?"":",");
861 amb 129 }
862 amb 320 printf(" },\n");
863 amb 129 printf("\n");
864    
865 amb 320 printf(" // Speed limits\n");
866     printf(" profile_speed: {\n");
867 amb 300 for(i=1;i<Way_Count;i++)
868 amb 129 {
869 amb 320 printf(" %12s: {",HighwayName(i));
870 amb 341 for(j=0;j<nloaded_profiles;j++)
871 amb 472 printf("%s%s: %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->speed[i]);
872 amb 300 printf("}%s\n",i==(Way_Count-1)?"":",");
873 amb 129 }
874 amb 320 printf(" },\n");
875 amb 129 printf("\n");
876    
877 amb 320 printf(" // Highway properties\n");
878     printf(" profile_property: {\n");
879 amb 298 for(i=1;i<Property_Count;i++)
880     {
881 amb 320 printf(" %12s: {",PropertyName(i));
882 amb 341 for(j=0;j<nloaded_profiles;j++)
883 amb 472 printf("%s%s: %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->props_yes[i]);
884 amb 298 printf("}%s\n",i==(Property_Count-1)?"":",");
885     }
886 amb 320 printf(" },\n");
887 amb 298 printf("\n");
888    
889 amb 320 printf(" // Restrictions\n");
890     printf(" profile_restrictions: {\n");
891     printf(" %12s: {","oneway");
892 amb 341 for(j=0;j<nloaded_profiles;j++)
893 amb 472 printf("%s%s: %4d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->oneway);
894 amb 138 printf("},\n");
895 amb 320 printf(" %12s: {","weight");
896 amb 341 for(j=0;j<nloaded_profiles;j++)
897 amb 472 printf("%s%s: %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),weight_to_tonnes(loaded_profiles[j]->weight));
898 amb 138 printf("},\n");
899 amb 320 printf(" %12s: {","height");
900 amb 341 for(j=0;j<nloaded_profiles;j++)
901 amb 472 printf("%s%s: %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),height_to_metres(loaded_profiles[j]->height));
902 amb 138 printf("},\n");
903 amb 320 printf(" %12s: {","width");
904 amb 341 for(j=0;j<nloaded_profiles;j++)
905 amb 472 printf("%s%s: %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),width_to_metres(loaded_profiles[j]->width));
906 amb 138 printf("},\n");
907 amb 320 printf(" %12s: {","length");
908 amb 341 for(j=0;j<nloaded_profiles;j++)
909 amb 472 printf("%s%s: %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),length_to_metres(loaded_profiles[j]->length));
910 amb 138 printf("}\n");
911 amb 320 printf(" }\n");
912 amb 129 printf("\n");
913 amb 320
914     printf("}; // end of routino variable\n");
915 amb 129 }
916 amb 145
917    
918     /*++++++++++++++++++++++++++++++++++++++
919     Print out the profiles as Perl for use in a web CGI.
920     ++++++++++++++++++++++++++++++++++++++*/
921    
922     void PrintProfilesPerl(void)
923     {
924 amb 214 unsigned int i,j;
925 amb 145
926 amb 343 printf("$routino={ # contains all default Routino options (generated using \"--help-profile-perl\").\n");
927 amb 336 printf("\n");
928 amb 320
929     printf(" # Default transport type\n");
930     printf(" transport => 'motorcar',\n");
931     printf("\n");
932    
933     printf(" # Transport types\n");
934     printf(" transports => {");
935 amb 341 for(j=0;j<nloaded_profiles;j++)
936     printf("%s%s => %d",j==1?"":", ",TransportName(loaded_profiles[j]->transport),j);
937 amb 320 printf("},\n");
938 amb 145 printf("\n");
939    
940 amb 320 printf(" # Highway types\n");
941     printf(" highways => {");
942 amb 300 for(i=1;i<Way_Count;i++)
943 amb 320 printf("%s%s => %d",i==1?"":", ",HighwayName(i),i);
944     printf("},\n");
945 amb 145 printf("\n");
946    
947 amb 320 printf(" # Property types\n");
948     printf(" properties => {");
949 amb 298 for(i=1;i<Property_Count;i++)
950 amb 320 printf("%s%s => %d",i==1?"":", ",PropertyName(i),i);
951     printf("},\n");
952 amb 298 printf("\n");
953    
954 amb 320 printf(" # Restriction types\n");
955     printf(" restrictions => {oneway => 1, weight => 2, height => 3, width => 4, length => 5},\n");
956 amb 145 printf("\n");
957    
958 amb 320 printf(" # Allowed highways\n");
959     printf(" profile_highway => {\n");
960 amb 300 for(i=1;i<Way_Count;i++)
961 amb 145 {
962 amb 148 printf(" %12s => {",HighwayName(i));
963 amb 341 for(j=0;j<nloaded_profiles;j++)
964     printf("%s %s => %3d",j==1?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->highway[i]);
965 amb 300 printf("}%s\n",i==(Way_Count-1)?"":",");
966 amb 145 }
967 amb 320 printf(" },\n");
968 amb 145 printf("\n");
969    
970 amb 320 printf(" # Speed limits\n");
971     printf(" profile_speed => {\n");
972 amb 300 for(i=1;i<Way_Count;i++)
973 amb 145 {
974 amb 148 printf(" %12s => {",HighwayName(i));
975 amb 341 for(j=0;j<nloaded_profiles;j++)
976     printf("%s %s => %3d",j==1?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->speed[i]);
977 amb 300 printf("}%s\n",i==(Way_Count-1)?"":",");
978 amb 145 }
979 amb 320 printf(" },\n");
980 amb 145 printf("\n");
981    
982 amb 320 printf(" # Highway properties\n");
983     printf(" profile_property => {\n");
984 amb 298 for(i=1;i<Property_Count;i++)
985     {
986     printf(" %12s => {",PropertyName(i));
987 amb 341 for(j=0;j<nloaded_profiles;j++)
988     printf("%s %s => %3d",j==1?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->props_yes[i]);
989 amb 298 printf("}%s\n",i==(Property_Count-1)?"":",");
990     }
991 amb 320 printf(" },\n");
992 amb 298 printf("\n");
993    
994 amb 320 printf(" # Restrictions\n");
995     printf(" profile_restrictions => {\n");
996     printf(" %12s => {","oneway");
997 amb 341 for(j=0;j<nloaded_profiles;j++)
998     printf("%s %s => %4d",j==1?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->oneway);
999 amb 145 printf("},\n");
1000 amb 320 printf(" %12s => {","weight");
1001 amb 341 for(j=0;j<nloaded_profiles;j++)
1002     printf("%s %s => %4.1f",j==1?"":", ",TransportName(loaded_profiles[j]->transport),weight_to_tonnes(loaded_profiles[j]->weight));
1003 amb 145 printf("},\n");
1004 amb 320 printf(" %12s => {","height");
1005 amb 341 for(j=0;j<nloaded_profiles;j++)
1006     printf("%s %s => %4.1f",j==1?"":", ",TransportName(loaded_profiles[j]->transport),height_to_metres(loaded_profiles[j]->height));
1007 amb 145 printf("},\n");
1008 amb 320 printf(" %12s => {","width");
1009 amb 341 for(j=0;j<nloaded_profiles;j++)
1010     printf("%s %s => %4.1f",j==1?"":", ",TransportName(loaded_profiles[j]->transport),width_to_metres(loaded_profiles[j]->width));
1011 amb 145 printf("},\n");
1012 amb 320 printf(" %12s => {","length");
1013 amb 341 for(j=0;j<nloaded_profiles;j++)
1014     printf("%s %s => %4.1f",j==1?"":", ",TransportName(loaded_profiles[j]->transport),length_to_metres(loaded_profiles[j]->length));
1015 amb 145 printf("}\n");
1016 amb 320 printf(" },\n");
1017 amb 145 printf("\n");
1018 amb 320
1019     printf("}; # end of routino variable\n");
1020 amb 145 }

Properties

Name Value
cvs:description Definition of built-in profiles and other functions.