Routino SVN Repository Browser

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

ViewVC logotype

Contents of /trunk/src/translations.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1980 - (show annotations) (download) (as text)
Sun Apr 7 15:55:17 2019 UTC (5 years, 11 months ago) by amb
File MIME type: text/x-csrc
File size: 57170 byte(s)
Free some memory to avoid leaks - found by running with gcc's runtime
sanitizer enabled (make SANITIZE=1 test).

1 /***************************************
2 Load the translations from a file and the functions for handling them.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2010-2016, 2019 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 <string.h>
25 #include <stdlib.h>
26
27 #include "files.h"
28 #include "translations.h"
29 #include "xmlparse.h"
30
31
32 /* Default English translations - Must not require any UTF-8 encoding */
33
34 static Translation default_translation=
35 {
36 .lang = "--",
37 .language = "English (built-in)",
38
39 .raw_copyright_creator = {"Creator","Routino - http://www.routino.org/"},
40 .raw_copyright_source = {NULL,NULL},
41 .raw_copyright_license = {NULL,NULL},
42
43 .xml_copyright_creator = {"Creator","Routino - http://www.routino.org/"},
44 .xml_copyright_source = {NULL,NULL},
45 .xml_copyright_license = {NULL,NULL},
46
47 .xml_heading = {"South","South-West","West","North-West","North","North-East","East","South-East","South"},
48 .xml_turn = {"Very sharp left","Sharp left","Left","Slight left","Straight on","Slight right","Right","Sharp right","Very sharp right"},
49 .xml_ordinal = {"First","Second","Third","Fourth","Fifth","Sixth","Seventh","Eighth","Ninth","Tenth"},
50
51 .notxml_heading = {"South","South-West","West","North-West","North","North-East","East","South-East","South"},
52 .notxml_turn = {"Very sharp left","Sharp left","Left","Slight left","Straight on","Slight right","Right","Sharp right","Very sharp right"},
53 .notxml_ordinal = {"First","Second","Third","Fourth","Fifth","Sixth","Seventh","Eighth","Ninth","Tenth"},
54
55 .raw_highway = {"","motorway","trunk road","primary road","secondary road","tertiary road","unclassified road","residential road","service road","track","cycleway","path","steps","ferry"},
56
57 .xml_route_shortest = "Shortest",
58 .xml_route_quickest = "Quickest",
59
60 .html_waypoint = "Waypoint",
61 .html_junction = "Junction",
62 .html_roundabout = "Roundabout",
63
64 .html_title = "%s Route",
65 .html_start = "<tr class='n'><td>Start at %s, head <span class='b'>%s</span>\n", /* span tags added when reading XML translations file */
66 .html_node = "<tr class='n'><td>At %s, go <span class='t'>%s</span> heading <span class='b'>%s</span>\n", /* span tags added when reading XML translations file */
67 .html_rbnode = "<tr class='n'><td>Leave %s, take the <span class='b'>%s</span> exit heading <span class='b'>%s</span>\n", /* span tags added when reading XML translations file */
68 .html_segment = "<tr class='s'><td>Follow <span class='h'>%s</span> for <span class='d'>%.3f km, %.1f min</span>", /* span tags added when reading XML translations file */
69 .html_stop = "<tr class='n'><td>Stop at %s\n",
70 .html_total = "<tr class='t'><td><span class='j'>Total %.1f km, %.0f minutes</span>\n",/* span tags added when reading XML translations file */
71 .html_subtotal= "<span class='j'>%.1f km, %.0f minutes</span>\n",/* span tag added when reading XML translations file */
72
73 .nothtml_waypoint = "Waypoint",
74 .nothtml_junction = "Junction",
75 .nothtml_roundabout = "Roundabout",
76
77 .nothtml_title = "%s Route",
78 .nothtml_start = "Start at %s, head %s",
79 .nothtml_node = "At %s, go %s heading %s",
80 .nothtml_rbnode = "Leave %s, take the %s exit heading %s",
81 .nothtml_segment = "Follow %s for %.3f km, %.1f min",
82 .nothtml_stop = "Stop at %s",
83 .nothtml_total = "Total %.1f km, %.0f minutes",
84 .nothtml_subtotal= "%.1f km, %.0f minutes",
85
86 .gpx_desc = "%s route between 'start' and 'finish' waypoints",
87 .gpx_name = "%s route",
88 .gpx_step = "%s on '%s' for %.3f km, %.1f min",
89 .gpx_final = "Total Journey %.1f km, %.0f minutes",
90
91 .gpx_waypt = "WAYPT",
92 .gpx_trip = "TRIP",
93 };
94
95
96 /* Local variables (re-intialised by FreeXMLTranslations() function) */
97
98 /*+ The translations that have been loaded from file. +*/
99 static Translation **loaded_translations=NULL;
100
101 /*+ The number of translations that have been loaded from file. +*/
102 static int nloaded_translations=0;
103
104
105 /* Local variables (re-initialised for each file) */
106
107 /*+ Store all of the translations. +*/
108 static int store_all;
109
110 /*+ The translation language that is to be stored. +*/
111 static const char *store_lang;
112
113 /*+ This current language is to be stored. +*/
114 static int store;
115
116 /*+ The chosen language has been stored. +*/
117 static int stored;
118
119
120 /* The XML tag processing function prototypes */
121
122 //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding);
123 //static int RoutinoTranslationsType_function(const char *_tag_,int _type_);
124 static int LanguageType_function(const char *_tag_,int _type_,const char *lang,const char *language);
125 //static int CopyrightType_function(const char *_tag_,int _type_);
126 static int TurnType_function(const char *_tag_,int _type_,const char *direction,const char *string);
127 static int HeadingType_function(const char *_tag_,int _type_,const char *direction,const char *string);
128 static int OrdinalType_function(const char *_tag_,int _type_,const char *number,const char *string);
129 static int HighwayType_function(const char *_tag_,int _type_,const char *type,const char *string);
130 static int RouteType_function(const char *_tag_,int _type_,const char *type,const char *string);
131 //static int HTMLType_function(const char *_tag_,int _type_);
132 //static int GPXType_function(const char *_tag_,int _type_);
133 static int CopyrightCreatorType_function(const char *_tag_,int _type_,const char *string,const char *text);
134 static int CopyrightSourceType_function(const char *_tag_,int _type_,const char *string,const char *text);
135 static int CopyrightLicenseType_function(const char *_tag_,int _type_,const char *string,const char *text);
136 static int HTMLWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string);
137 static int HTMLTitleType_function(const char *_tag_,int _type_,const char *text);
138 static int HTMLStartType_function(const char *_tag_,int _type_,const char *text);
139 static int HTMLNodeType_function(const char *_tag_,int _type_,const char *text);
140 static int HTMLRBNodeType_function(const char *_tag_,int _type_,const char *text);
141 static int HTMLSegmentType_function(const char *_tag_,int _type_,const char *text);
142 static int HTMLStopType_function(const char *_tag_,int _type_,const char *text);
143 static int HTMLTotalType_function(const char *_tag_,int _type_,const char *text);
144 static int HTMLSubtotalType_function(const char *_tag_,int _type_,const char *text);
145 static int GPXWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string);
146 static int GPXDescType_function(const char *_tag_,int _type_,const char *text);
147 static int GPXNameType_function(const char *_tag_,int _type_,const char *text);
148 static int GPXStepType_function(const char *_tag_,int _type_,const char *text);
149 static int GPXFinalType_function(const char *_tag_,int _type_,const char *text);
150
151
152 /* The XML tag definitions (forward declarations) */
153
154 static const xmltag xmlDeclaration_tag;
155 static const xmltag RoutinoTranslationsType_tag;
156 static const xmltag LanguageType_tag;
157 static const xmltag CopyrightType_tag;
158 static const xmltag TurnType_tag;
159 static const xmltag HeadingType_tag;
160 static const xmltag OrdinalType_tag;
161 static const xmltag HighwayType_tag;
162 static const xmltag RouteType_tag;
163 static const xmltag HTMLType_tag;
164 static const xmltag GPXType_tag;
165 static const xmltag CopyrightCreatorType_tag;
166 static const xmltag CopyrightSourceType_tag;
167 static const xmltag CopyrightLicenseType_tag;
168 static const xmltag HTMLWaypointType_tag;
169 static const xmltag HTMLTitleType_tag;
170 static const xmltag HTMLStartType_tag;
171 static const xmltag HTMLNodeType_tag;
172 static const xmltag HTMLRBNodeType_tag;
173 static const xmltag HTMLSegmentType_tag;
174 static const xmltag HTMLStopType_tag;
175 static const xmltag HTMLTotalType_tag;
176 static const xmltag HTMLSubtotalType_tag;
177 static const xmltag GPXWaypointType_tag;
178 static const xmltag GPXDescType_tag;
179 static const xmltag GPXNameType_tag;
180 static const xmltag GPXStepType_tag;
181 static const xmltag GPXFinalType_tag;
182
183
184 /* The XML tag definition values */
185
186 /*+ The complete set of tags at the top level. +*/
187 static const xmltag * const xml_toplevel_tags[]={&xmlDeclaration_tag,&RoutinoTranslationsType_tag,NULL};
188
189 /*+ The xmlDeclaration type tag. +*/
190 static const xmltag xmlDeclaration_tag=
191 {"xml",
192 2, {"version","encoding"},
193 NULL,
194 {NULL}};
195
196 /*+ The RoutinoTranslationsType type tag. +*/
197 static const xmltag RoutinoTranslationsType_tag=
198 {"routino-translations",
199 0, {NULL},
200 NULL,
201 {&LanguageType_tag,NULL}};
202
203 /*+ The LanguageType type tag. +*/
204 static const xmltag LanguageType_tag=
205 {"language",
206 2, {"lang","language"},
207 LanguageType_function,
208 {&CopyrightType_tag,&TurnType_tag,&HeadingType_tag,&OrdinalType_tag,&HighwayType_tag,&RouteType_tag,&HTMLType_tag,&GPXType_tag,NULL}};
209
210 /*+ The CopyrightType type tag. +*/
211 static const xmltag CopyrightType_tag=
212 {"copyright",
213 0, {NULL},
214 NULL,
215 {&CopyrightCreatorType_tag,&CopyrightSourceType_tag,&CopyrightLicenseType_tag,NULL}};
216
217 /*+ The TurnType type tag. +*/
218 static const xmltag TurnType_tag=
219 {"turn",
220 2, {"direction","string"},
221 TurnType_function,
222 {NULL}};
223
224 /*+ The HeadingType type tag. +*/
225 static const xmltag HeadingType_tag=
226 {"heading",
227 2, {"direction","string"},
228 HeadingType_function,
229 {NULL}};
230
231 /*+ The OrdinalType type tag. +*/
232 static const xmltag OrdinalType_tag=
233 {"ordinal",
234 2, {"number","string"},
235 OrdinalType_function,
236 {NULL}};
237
238 /*+ The HighwayType type tag. +*/
239 static const xmltag HighwayType_tag=
240 {"highway",
241 2, {"type","string"},
242 HighwayType_function,
243 {NULL}};
244
245 /*+ The RouteType type tag. +*/
246 static const xmltag RouteType_tag=
247 {"route",
248 2, {"type","string"},
249 RouteType_function,
250 {NULL}};
251
252 /*+ The HTMLType type tag. +*/
253 static const xmltag HTMLType_tag=
254 {"output-html",
255 0, {NULL},
256 NULL,
257 {&HTMLWaypointType_tag,&HTMLTitleType_tag,&HTMLStartType_tag,&HTMLNodeType_tag,&HTMLRBNodeType_tag,&HTMLSegmentType_tag,&HTMLStopType_tag,&HTMLTotalType_tag,&HTMLSubtotalType_tag,NULL}};
258
259 /*+ The GPXType type tag. +*/
260 static const xmltag GPXType_tag=
261 {"output-gpx",
262 0, {NULL},
263 NULL,
264 {&GPXWaypointType_tag,&GPXDescType_tag,&GPXNameType_tag,&GPXStepType_tag,&GPXFinalType_tag,NULL}};
265
266 /*+ The CopyrightCreatorType type tag. +*/
267 static const xmltag CopyrightCreatorType_tag=
268 {"creator",
269 2, {"string","text"},
270 CopyrightCreatorType_function,
271 {NULL}};
272
273 /*+ The CopyrightSourceType type tag. +*/
274 static const xmltag CopyrightSourceType_tag=
275 {"source",
276 2, {"string","text"},
277 CopyrightSourceType_function,
278 {NULL}};
279
280 /*+ The CopyrightLicenseType type tag. +*/
281 static const xmltag CopyrightLicenseType_tag=
282 {"license",
283 2, {"string","text"},
284 CopyrightLicenseType_function,
285 {NULL}};
286
287 /*+ The HTMLWaypointType type tag. +*/
288 static const xmltag HTMLWaypointType_tag=
289 {"waypoint",
290 2, {"type","string"},
291 HTMLWaypointType_function,
292 {NULL}};
293
294 /*+ The HTMLTitleType type tag. +*/
295 static const xmltag HTMLTitleType_tag=
296 {"title",
297 1, {"text"},
298 HTMLTitleType_function,
299 {NULL}};
300
301 /*+ The HTMLStartType type tag. +*/
302 static const xmltag HTMLStartType_tag=
303 {"start",
304 1, {"text"},
305 HTMLStartType_function,
306 {NULL}};
307
308 /*+ The HTMLNodeType type tag. +*/
309 static const xmltag HTMLNodeType_tag=
310 {"node",
311 1, {"text"},
312 HTMLNodeType_function,
313 {NULL}};
314
315 /*+ The HTMLRBNodeType type tag. +*/
316 static const xmltag HTMLRBNodeType_tag=
317 {"rbnode",
318 1, {"text"},
319 HTMLRBNodeType_function,
320 {NULL}};
321
322 /*+ The HTMLSegmentType type tag. +*/
323 static const xmltag HTMLSegmentType_tag=
324 {"segment",
325 1, {"text"},
326 HTMLSegmentType_function,
327 {NULL}};
328
329 /*+ The HTMLStopType type tag. +*/
330 static const xmltag HTMLStopType_tag=
331 {"stop",
332 1, {"text"},
333 HTMLStopType_function,
334 {NULL}};
335
336 /*+ The HTMLTotalType type tag. +*/
337 static const xmltag HTMLTotalType_tag=
338 {"total",
339 1, {"text"},
340 HTMLTotalType_function,
341 {NULL}};
342
343 /*+ The HTMLSubtotalType type tag. +*/
344 static const xmltag HTMLSubtotalType_tag=
345 {"subtotal",
346 1, {"text"},
347 HTMLSubtotalType_function,
348 {NULL}};
349
350 /*+ The GPXWaypointType type tag. +*/
351 static const xmltag GPXWaypointType_tag=
352 {"waypoint",
353 2, {"type","string"},
354 GPXWaypointType_function,
355 {NULL}};
356
357 /*+ The GPXDescType type tag. +*/
358 static const xmltag GPXDescType_tag=
359 {"desc",
360 1, {"text"},
361 GPXDescType_function,
362 {NULL}};
363
364 /*+ The GPXNameType type tag. +*/
365 static const xmltag GPXNameType_tag=
366 {"name",
367 1, {"text"},
368 GPXNameType_function,
369 {NULL}};
370
371 /*+ The GPXStepType type tag. +*/
372 static const xmltag GPXStepType_tag=
373 {"step",
374 1, {"text"},
375 GPXStepType_function,
376 {NULL}};
377
378 /*+ The GPXFinalType type tag. +*/
379 static const xmltag GPXFinalType_tag=
380 {"final",
381 1, {"text"},
382 GPXFinalType_function,
383 {NULL}};
384
385
386 /* The XML tag processing functions */
387
388
389 /*++++++++++++++++++++++++++++++++++++++
390 The function that is called when the XML declaration is seen
391
392 int xmlDeclaration_function Returns 0 if no error occured or something else otherwise.
393
394 const char *_tag_ Set to the name of the element tag that triggered this function call.
395
396 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
397
398 const char *version The contents of the 'version' attribute (or NULL if not defined).
399
400 const char *encoding The contents of the 'encoding' attribute (or NULL if not defined).
401 ++++++++++++++++++++++++++++++++++++++*/
402
403 //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding)
404 //{
405 // return(0);
406 //}
407
408
409 /*++++++++++++++++++++++++++++++++++++++
410 The function that is called when the RoutinoTranslationsType XSD type is seen
411
412 int RoutinoTranslationsType_function Returns 0 if no error occured or something else otherwise.
413
414 const char *_tag_ Set to the name of the element tag that triggered this function call.
415
416 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
417 ++++++++++++++++++++++++++++++++++++++*/
418
419 //static int RoutinoTranslationsType_function(const char *_tag_,int _type_)
420 //{
421 // return(0);
422 //}
423
424
425 /*++++++++++++++++++++++++++++++++++++++
426 The function that is called when the LanguageType XSD type is seen
427
428 int LanguageType_function Returns 0 if no error occured or something else otherwise.
429
430 const char *_tag_ Set to the name of the element tag that triggered this function call.
431
432 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
433
434 const char *lang The contents of the 'lang' attribute (or NULL if not defined).
435
436 const char *language The contents of the 'language' attribute (or NULL if not defined).
437 ++++++++++++++++++++++++++++++++++++++*/
438
439 static int LanguageType_function(const char *_tag_,int _type_,const char *lang,const char *language)
440 {
441 if(_type_&XMLPARSE_TAG_START)
442 {
443 XMLPARSE_ASSERT_STRING(_tag_,lang);
444 XMLPARSE_ASSERT_STRING(_tag_,language);
445
446 if(store_all)
447 store=1;
448 else if(!store_lang && !stored)
449 store=1;
450 else if(store_lang && !strcmp(store_lang,lang))
451 store=1;
452 else
453 store=0;
454
455 if(store)
456 {
457 int i;
458
459 for(i=0;i<nloaded_translations;i++)
460 if(!strcmp(lang,loaded_translations[i]->lang))
461 XMLPARSE_MESSAGE(_tag_,"translation name must be unique");
462
463 if((nloaded_translations%16)==0)
464 loaded_translations=(Translation**)realloc((void*)loaded_translations,(nloaded_translations+16)*sizeof(Translation*));
465
466 nloaded_translations++;
467
468 loaded_translations[nloaded_translations-1]=(Translation*)calloc(1,sizeof(Translation));
469
470 *loaded_translations[nloaded_translations-1]=default_translation;
471
472 loaded_translations[nloaded_translations-1]->lang =strcpy(malloc(strlen(lang )+1),lang );
473 loaded_translations[nloaded_translations-1]->language=strcpy(malloc(strlen(language)+1),language);
474 }
475 }
476
477 if(_type_&XMLPARSE_TAG_END && store)
478 {
479 store=0;
480 stored=1;
481 }
482
483 return(0);
484 }
485
486
487 /*++++++++++++++++++++++++++++++++++++++
488 The function that is called when the CopyrightType XSD type is seen
489
490 int CopyrightType_function Returns 0 if no error occured or something else otherwise.
491
492 const char *_tag_ Set to the name of the element tag that triggered this function call.
493
494 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
495 ++++++++++++++++++++++++++++++++++++++*/
496
497 //static int CopyrightType_function(const char *_tag_,int _type_)
498 //{
499 // return(0);
500 //}
501
502
503 /*++++++++++++++++++++++++++++++++++++++
504 The function that is called when the TurnType XSD type is seen
505
506 int TurnType_function Returns 0 if no error occured or something else otherwise.
507
508 const char *_tag_ Set to the name of the element tag that triggered this function call.
509
510 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
511
512 const char *direction The contents of the 'direction' attribute (or NULL if not defined).
513
514 const char *string The contents of the 'string' attribute (or NULL if not defined).
515 ++++++++++++++++++++++++++++++++++++++*/
516
517 static int TurnType_function(const char *_tag_,int _type_,const char *direction,const char *string)
518 {
519 if(_type_&XMLPARSE_TAG_START && store)
520 {
521 char *xmlstring;
522 int d;
523
524 XMLPARSE_ASSERT_INTEGER(_tag_,direction); d=atoi(direction);
525 XMLPARSE_ASSERT_STRING(_tag_,string);
526
527 d+=4;
528
529 if(d<0 || d>8)
530 XMLPARSE_INVALID(_tag_,direction);
531
532 loaded_translations[nloaded_translations-1]->notxml_turn[d]=strcpy(malloc(strlen(string)+1),string);
533
534 xmlstring=ParseXML_Encode_Safe_XML(string);
535 loaded_translations[nloaded_translations-1]->xml_turn[d]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
536 }
537
538 return(0);
539 }
540
541
542 /*++++++++++++++++++++++++++++++++++++++
543 The function that is called when the HeadingType XSD type is seen
544
545 int HeadingType_function Returns 0 if no error occured or something else otherwise.
546
547 const char *_tag_ Set to the name of the element tag that triggered this function call.
548
549 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
550
551 const char *direction The contents of the 'direction' attribute (or NULL if not defined).
552
553 const char *string The contents of the 'string' attribute (or NULL if not defined).
554 ++++++++++++++++++++++++++++++++++++++*/
555
556 static int HeadingType_function(const char *_tag_,int _type_,const char *direction,const char *string)
557 {
558 if(_type_&XMLPARSE_TAG_START && store)
559 {
560 char *xmlstring;
561 int d;
562
563 XMLPARSE_ASSERT_INTEGER(_tag_,direction); d=atoi(direction);
564 XMLPARSE_ASSERT_STRING(_tag_,string);
565
566 d+=4;
567
568 if(d<0 || d>8)
569 XMLPARSE_INVALID(_tag_,direction);
570
571 loaded_translations[nloaded_translations-1]->notxml_heading[d]=strcpy(malloc(strlen(string)+1),string);
572
573 xmlstring=ParseXML_Encode_Safe_XML(string);
574 loaded_translations[nloaded_translations-1]->xml_heading[d]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
575 }
576
577 return(0);
578 }
579
580
581 /*++++++++++++++++++++++++++++++++++++++
582 The function that is called when the OrdinalType XSD type is seen
583
584 int OrdinalType_function Returns 0 if no error occured or something else otherwise.
585
586 const char *_tag_ Set to the name of the element tag that triggered this function call.
587
588 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
589
590 const char *number The contents of the 'number' attribute (or NULL if not defined).
591
592 const char *string The contents of the 'string' attribute (or NULL if not defined).
593 ++++++++++++++++++++++++++++++++++++++*/
594
595 static int OrdinalType_function(const char *_tag_,int _type_,const char *number,const char *string)
596 {
597 if(_type_&XMLPARSE_TAG_START && store)
598 {
599 char *xmlstring;
600 int n;
601
602 XMLPARSE_ASSERT_INTEGER(_tag_,number); n=atoi(number);
603 XMLPARSE_ASSERT_STRING(_tag_,string);
604
605 if(n<1 || n>10)
606 XMLPARSE_INVALID(_tag_,number);
607
608 loaded_translations[nloaded_translations-1]->notxml_ordinal[n-1]=strcpy(malloc(strlen(string)+1),string);
609
610 xmlstring=ParseXML_Encode_Safe_XML(string);
611 loaded_translations[nloaded_translations-1]->xml_ordinal[n-1]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
612 }
613
614 return(0);
615 }
616
617
618 /*++++++++++++++++++++++++++++++++++++++
619 The function that is called when the HighwayType XSD type is seen
620
621 int HighwayType_function Returns 0 if no error occured or something else otherwise.
622
623 const char *_tag_ Set to the name of the element tag that triggered this function call.
624
625 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
626
627 const char *type The contents of the 'type' attribute (or NULL if not defined).
628
629 const char *string The contents of the 'string' attribute (or NULL if not defined).
630 ++++++++++++++++++++++++++++++++++++++*/
631
632 static int HighwayType_function(const char *_tag_,int _type_,const char *type,const char *string)
633 {
634 if(_type_&XMLPARSE_TAG_START && store)
635 {
636 Highway highway;
637
638 XMLPARSE_ASSERT_STRING(_tag_,type);
639 XMLPARSE_ASSERT_STRING(_tag_,string);
640
641 highway=HighwayType(type);
642
643 if(highway==Highway_None)
644 XMLPARSE_INVALID(_tag_,type);
645
646 loaded_translations[nloaded_translations-1]->raw_highway[highway]=strcpy(malloc(strlen(string)+1),string);
647 }
648
649 return(0);
650 }
651
652
653 /*++++++++++++++++++++++++++++++++++++++
654 The function that is called when the RouteType XSD type is seen
655
656 int RouteType_function Returns 0 if no error occured or something else otherwise.
657
658 const char *_tag_ Set to the name of the element tag that triggered this function call.
659
660 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
661
662 const char *type The contents of the 'type' attribute (or NULL if not defined).
663
664 const char *string The contents of the 'string' attribute (or NULL if not defined).
665 ++++++++++++++++++++++++++++++++++++++*/
666
667 static int RouteType_function(const char *_tag_,int _type_,const char *type,const char *string)
668 {
669 if(_type_&XMLPARSE_TAG_START && store)
670 {
671 char *xmlstring;
672
673 XMLPARSE_ASSERT_STRING(_tag_,type);
674 XMLPARSE_ASSERT_STRING(_tag_,string);
675
676 xmlstring=ParseXML_Encode_Safe_XML(string);
677
678 if(!strcmp(type,"shortest"))
679 loaded_translations[nloaded_translations-1]->xml_route_shortest=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
680 else if(!strcmp(type,"quickest"))
681 loaded_translations[nloaded_translations-1]->xml_route_quickest=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
682 else
683 XMLPARSE_INVALID(_tag_,type);
684 }
685
686 return(0);
687 }
688
689
690 /*++++++++++++++++++++++++++++++++++++++
691 The function that is called when the HTMLType XSD type is seen
692
693 int HTMLType_function Returns 0 if no error occured or something else otherwise.
694
695 const char *_tag_ Set to the name of the element tag that triggered this function call.
696
697 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
698 ++++++++++++++++++++++++++++++++++++++*/
699
700 //static int HTMLType_function(const char *_tag_,int _type_)
701 //{
702 // return(0);
703 //}
704
705
706 /*++++++++++++++++++++++++++++++++++++++
707 The function that is called when the GPXType XSD type is seen
708
709 int GPXType_function Returns 0 if no error occured or something else otherwise.
710
711 const char *_tag_ Set to the name of the element tag that triggered this function call.
712
713 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
714 ++++++++++++++++++++++++++++++++++++++*/
715
716 //static int GPXType_function(const char *_tag_,int _type_)
717 //{
718 // return(0);
719 //}
720
721
722 /*++++++++++++++++++++++++++++++++++++++
723 The function that is called when the CopyrightCreatorType XSD type is seen
724
725 int CopyrightCreatorType_function Returns 0 if no error occured or something else otherwise.
726
727 const char *_tag_ Set to the name of the element tag that triggered this function call.
728
729 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
730
731 const char *string The contents of the 'string' attribute (or NULL if not defined).
732
733 const char *text The contents of the 'text' attribute (or NULL if not defined).
734 ++++++++++++++++++++++++++++++++++++++*/
735
736 static int CopyrightCreatorType_function(const char *_tag_,int _type_,const char *string,const char *text)
737 {
738 if(_type_&XMLPARSE_TAG_START && store)
739 {
740 char *xmlstring,*xmltext;
741
742 XMLPARSE_ASSERT_STRING(_tag_,string);
743 XMLPARSE_ASSERT_STRING(_tag_,text);
744
745 loaded_translations[nloaded_translations-1]->raw_copyright_creator[0]=strcpy(malloc(strlen(string)+1),string);
746 loaded_translations[nloaded_translations-1]->raw_copyright_creator[1]=strcpy(malloc(strlen(text)+1) ,text);
747
748 xmlstring=ParseXML_Encode_Safe_XML(string);
749 loaded_translations[nloaded_translations-1]->xml_copyright_creator[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
750
751 xmltext=ParseXML_Encode_Safe_XML(text);
752 loaded_translations[nloaded_translations-1]->xml_copyright_creator[1]=strcpy(malloc(strlen(xmltext)+1),xmltext);
753 }
754
755 return(0);
756 }
757
758
759 /*++++++++++++++++++++++++++++++++++++++
760 The function that is called when the CopyrightSourceType XSD type is seen
761
762 int CopyrightSourceType_function Returns 0 if no error occured or something else otherwise.
763
764 const char *_tag_ Set to the name of the element tag that triggered this function call.
765
766 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
767
768 const char *string The contents of the 'string' attribute (or NULL if not defined).
769
770 const char *text The contents of the 'text' attribute (or NULL if not defined).
771 ++++++++++++++++++++++++++++++++++++++*/
772
773 static int CopyrightSourceType_function(const char *_tag_,int _type_,const char *string,const char *text)
774 {
775 if(_type_&XMLPARSE_TAG_START && store)
776 {
777 char *xmlstring,*xmltext;
778
779 XMLPARSE_ASSERT_STRING(_tag_,string);
780 XMLPARSE_ASSERT_STRING(_tag_,text);
781
782 loaded_translations[nloaded_translations-1]->raw_copyright_source[0]=strcpy(malloc(strlen(string)+1),string);
783 loaded_translations[nloaded_translations-1]->raw_copyright_source[1]=strcpy(malloc(strlen(text)+1) ,text);
784
785 xmlstring=ParseXML_Encode_Safe_XML(string);
786 loaded_translations[nloaded_translations-1]->xml_copyright_source[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
787
788 xmltext=ParseXML_Encode_Safe_XML(text);
789 loaded_translations[nloaded_translations-1]->xml_copyright_source[1]=strcpy(malloc(strlen(xmltext)+1),xmltext);
790 }
791
792 return(0);
793 }
794
795
796 /*++++++++++++++++++++++++++++++++++++++
797 The function that is called when the CopyrightLicenseType XSD type is seen
798
799 int CopyrightLicenseType_function Returns 0 if no error occured or something else otherwise.
800
801 const char *_tag_ Set to the name of the element tag that triggered this function call.
802
803 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
804
805 const char *string The contents of the 'string' attribute (or NULL if not defined).
806
807 const char *text The contents of the 'text' attribute (or NULL if not defined).
808 ++++++++++++++++++++++++++++++++++++++*/
809
810 static int CopyrightLicenseType_function(const char *_tag_,int _type_,const char *string,const char *text)
811 {
812 if(_type_&XMLPARSE_TAG_START && store)
813 {
814 char *xmlstring,*xmltext;
815
816 XMLPARSE_ASSERT_STRING(_tag_,string);
817 XMLPARSE_ASSERT_STRING(_tag_,text);
818
819 loaded_translations[nloaded_translations-1]->raw_copyright_license[0]=strcpy(malloc(strlen(string)+1),string);
820 loaded_translations[nloaded_translations-1]->raw_copyright_license[1]=strcpy(malloc(strlen(text)+1) ,text);
821
822 xmlstring=ParseXML_Encode_Safe_XML(string);
823 loaded_translations[nloaded_translations-1]->xml_copyright_license[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
824
825 xmltext=ParseXML_Encode_Safe_XML(text);
826 loaded_translations[nloaded_translations-1]->xml_copyright_license[1]=strcpy(malloc(strlen(xmltext)+1),xmltext);
827 }
828
829 return(0);
830 }
831
832
833 /*++++++++++++++++++++++++++++++++++++++
834 The function that is called when the HTMLWaypointType XSD type is seen
835
836 int HTMLWaypointType_function Returns 0 if no error occured or something else otherwise.
837
838 const char *_tag_ Set to the name of the element tag that triggered this function call.
839
840 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
841
842 const char *type The contents of the 'type' attribute (or NULL if not defined).
843
844 const char *string The contents of the 'string' attribute (or NULL if not defined).
845 ++++++++++++++++++++++++++++++++++++++*/
846
847 static int HTMLWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string)
848 {
849 if(_type_&XMLPARSE_TAG_START && store)
850 {
851 char *xmlstring;
852
853 XMLPARSE_ASSERT_STRING(_tag_,type);
854 XMLPARSE_ASSERT_STRING(_tag_,string);
855
856 xmlstring=ParseXML_Encode_Safe_XML(string);
857
858 if(!strcmp(type,"waypoint"))
859 {
860 loaded_translations[nloaded_translations-1]->nothtml_waypoint=strcpy(malloc(strlen(string)+1),string);
861
862 loaded_translations[nloaded_translations-1]->html_waypoint=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
863 }
864 else if(!strcmp(type,"junction"))
865 {
866 loaded_translations[nloaded_translations-1]->nothtml_junction=strcpy(malloc(strlen(string)+1),string);
867
868 loaded_translations[nloaded_translations-1]->html_junction=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
869 }
870 else if(!strcmp(type,"roundabout"))
871 {
872 loaded_translations[nloaded_translations-1]->nothtml_roundabout=strcpy(malloc(strlen(string)+1),string);
873
874 loaded_translations[nloaded_translations-1]->html_roundabout=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
875 }
876 else
877 XMLPARSE_INVALID(_tag_,type);
878 }
879
880 return(0);
881 }
882
883
884 /*++++++++++++++++++++++++++++++++++++++
885 The function that is called when the HTMLTitleType XSD type is seen
886
887 int HTMLTitleType_function Returns 0 if no error occured or something else otherwise.
888
889 const char *_tag_ Set to the name of the element tag that triggered this function call.
890
891 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
892
893 const char *text The contents of the 'text' attribute (or NULL if not defined).
894 ++++++++++++++++++++++++++++++++++++++*/
895
896 static int HTMLTitleType_function(const char *_tag_,int _type_,const char *text)
897 {
898 if(_type_&XMLPARSE_TAG_START && store)
899 {
900 char *xmltext;
901
902 XMLPARSE_ASSERT_STRING(_tag_,text);
903
904 xmltext=ParseXML_Encode_Safe_XML(text);
905
906 loaded_translations[nloaded_translations-1]->nothtml_title=strcpy(malloc(strlen(text)+1),text);
907
908 loaded_translations[nloaded_translations-1]->html_title=strcpy(malloc(strlen(xmltext)+1),xmltext);
909 }
910
911 return(0);
912 }
913
914
915 /*++++++++++++++++++++++++++++++++++++++
916 The function that is called when the HTMLStartType XSD type is seen
917
918 int HTMLStartType_function Returns 0 if no error occured or something else otherwise.
919
920 const char *_tag_ Set to the name of the element tag that triggered this function call.
921
922 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
923
924 const char *text The contents of the 'text' attribute (or NULL if not defined).
925 ++++++++++++++++++++++++++++++++++++++*/
926
927 static int HTMLStartType_function(const char *_tag_,int _type_,const char *text)
928 {
929 if(_type_&XMLPARSE_TAG_START && store)
930 {
931 char *xmltext;
932 const char *p;
933 char *q;
934
935 XMLPARSE_ASSERT_STRING(_tag_,text);
936
937 xmltext=ParseXML_Encode_Safe_XML(text);
938
939 loaded_translations[nloaded_translations-1]->nothtml_start=strcpy(malloc(strlen(text)+1),text);
940
941 loaded_translations[nloaded_translations-1]->html_start=malloc(sizeof("<tr class='n'><td>")+strlen(xmltext)+sizeof("<span class='b'>")+sizeof("</span>")+1+1);
942
943 p=xmltext;
944 q=loaded_translations[nloaded_translations-1]->html_start;
945
946 strcpy(q,"<tr class='n'><td>"); q+=sizeof("<tr class='n'><td>")-1;
947
948 while(*p!='%')
949 *q++=*p++;
950
951 *q++=*p++;
952
953 while(*p!='%')
954 *q++=*p++;
955
956 p+=2;
957 strcpy(q,"<span class='b'>%s</span>"); q+=sizeof("<span class='b'>%s</span>")-1;
958
959 strcpy(q,p);
960 strcat(q,"\n");
961 }
962
963 return(0);
964 }
965
966
967 /*++++++++++++++++++++++++++++++++++++++
968 The function that is called when the HTMLNodeType XSD type is seen
969
970 int HTMLNodeType_function Returns 0 if no error occured or something else otherwise.
971
972 const char *_tag_ Set to the name of the element tag that triggered this function call.
973
974 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
975
976 const char *text The contents of the 'text' attribute (or NULL if not defined).
977 ++++++++++++++++++++++++++++++++++++++*/
978
979 static int HTMLNodeType_function(const char *_tag_,int _type_,const char *text)
980 {
981 if(_type_&XMLPARSE_TAG_START && store)
982 {
983 char *xmltext;
984 const char *p;
985 char *q;
986
987 XMLPARSE_ASSERT_STRING(_tag_,text);
988
989 xmltext=ParseXML_Encode_Safe_XML(text);
990
991 loaded_translations[nloaded_translations-1]->nothtml_node=strcpy(malloc(strlen(text)+1),text);
992
993 loaded_translations[nloaded_translations-1]->html_node=malloc(sizeof("<tr class='n'><td>")+strlen(xmltext)+2*sizeof("<span class='b'>")+2*sizeof("</span>")+1+1);
994
995 p=xmltext;
996 q=loaded_translations[nloaded_translations-1]->html_node;
997
998 strcpy(q,"<tr class='n'><td>"); q+=sizeof("<tr class='n'><td>")-1;
999
1000 while(*p!='%')
1001 *q++=*p++;
1002
1003 *q++=*p++;
1004
1005 while(*p!='%')
1006 *q++=*p++;
1007
1008 p+=2;
1009 strcpy(q,"<span class='t'>%s</span>"); q+=sizeof("<span class='t'>%s</span>")-1;
1010
1011 while(*p!='%')
1012 *q++=*p++;
1013
1014 p+=2;
1015 strcpy(q,"<span class='b'>%s</span>"); q+=sizeof("<span class='b'>%s</span>")-1;
1016
1017 strcpy(q,p);
1018 strcat(q,"\n");
1019 }
1020
1021 return(0);
1022 }
1023
1024
1025 /*++++++++++++++++++++++++++++++++++++++
1026 The function that is called when the HTMLRBNodeType XSD type is seen
1027
1028 int HTMLRBNodeType_function Returns 0 if no error occured or something else otherwise.
1029
1030 const char *_tag_ Set to the name of the element tag that triggered this function call.
1031
1032 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1033
1034 const char *text The contents of the 'text' attribute (or NULL if not defined).
1035 ++++++++++++++++++++++++++++++++++++++*/
1036
1037 static int HTMLRBNodeType_function(const char *_tag_,int _type_,const char *text)
1038 {
1039 if(_type_&XMLPARSE_TAG_START && store)
1040 {
1041 char *xmltext;
1042 const char *p;
1043 char *q;
1044
1045 XMLPARSE_ASSERT_STRING(_tag_,text);
1046
1047 xmltext=ParseXML_Encode_Safe_XML(text);
1048
1049 loaded_translations[nloaded_translations-1]->nothtml_rbnode=strcpy(malloc(strlen(text)+1),text);
1050
1051 loaded_translations[nloaded_translations-1]->html_rbnode=malloc(sizeof("<tr class='n'><td>")+strlen(xmltext)+2*sizeof("<span class='b'>")+2*sizeof("</span>")+1+1);
1052
1053 p=xmltext;
1054 q=loaded_translations[nloaded_translations-1]->html_rbnode;
1055
1056 strcpy(q,"<tr class='n'><td>"); q+=sizeof("<tr class='n'><td>")-1;
1057
1058 while(*p!='%')
1059 *q++=*p++;
1060
1061 *q++=*p++;
1062
1063 while(*p!='%')
1064 *q++=*p++;
1065
1066 p+=2;
1067 strcpy(q,"<span class='t'>%s</span>"); q+=sizeof("<span class='t'>%s</span>")-1;
1068
1069 while(*p!='%')
1070 *q++=*p++;
1071
1072 p+=2;
1073 strcpy(q,"<span class='b'>%s</span>"); q+=sizeof("<span class='b'>%s</span>")-1;
1074
1075 strcpy(q,p);
1076 strcat(q,"\n");
1077 }
1078
1079 return(0);
1080 }
1081
1082
1083 /*++++++++++++++++++++++++++++++++++++++
1084 The function that is called when the HTMLSegmentType XSD type is seen
1085
1086 int HTMLSegmentType_function Returns 0 if no error occured or something else otherwise.
1087
1088 const char *_tag_ Set to the name of the element tag that triggered this function call.
1089
1090 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1091
1092 const char *text The contents of the 'text' attribute (or NULL if not defined).
1093 ++++++++++++++++++++++++++++++++++++++*/
1094
1095 static int HTMLSegmentType_function(const char *_tag_,int _type_,const char *text)
1096 {
1097 if(_type_&XMLPARSE_TAG_START && store)
1098 {
1099 char *xmltext;
1100 const char *p;
1101 char *q;
1102
1103 XMLPARSE_ASSERT_STRING(_tag_,text);
1104
1105 xmltext=ParseXML_Encode_Safe_XML(text);
1106
1107 loaded_translations[nloaded_translations-1]->nothtml_segment=strcpy(malloc(strlen(text)+1),text);
1108
1109 loaded_translations[nloaded_translations-1]->html_segment=malloc(sizeof("<tr class='s'><td>")+strlen(xmltext)+2*sizeof("<span class='b'>")+2*sizeof("</span>")+1);
1110
1111 p=xmltext;
1112 q=loaded_translations[nloaded_translations-1]->html_segment;
1113
1114 strcpy(q,"<tr class='s'><td>"); q+=sizeof("<tr class='s'><td>")-1;
1115
1116 while(*p!='%')
1117 *q++=*p++;
1118
1119 p+=2;
1120 strcpy(q,"<span class='h'>%s</span>"); q+=sizeof("<span class='h'>%s</span>")-1;
1121
1122 while(*p!='%')
1123 *q++=*p++;
1124
1125 strcpy(q,"<span class='d'>"); q+=sizeof("<span class='d'>")-1;
1126
1127 strcpy(q,p);
1128 strcat(q,"</span>");
1129 }
1130
1131 return(0);
1132 }
1133
1134
1135 /*++++++++++++++++++++++++++++++++++++++
1136 The function that is called when the HTMLStopType XSD type is seen
1137
1138 int HTMLStopType_function Returns 0 if no error occured or something else otherwise.
1139
1140 const char *_tag_ Set to the name of the element tag that triggered this function call.
1141
1142 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1143
1144 const char *text The contents of the 'text' attribute (or NULL if not defined).
1145 ++++++++++++++++++++++++++++++++++++++*/
1146
1147 static int HTMLStopType_function(const char *_tag_,int _type_,const char *text)
1148 {
1149 if(_type_&XMLPARSE_TAG_START && store)
1150 {
1151 char *xmltext;
1152
1153 XMLPARSE_ASSERT_STRING(_tag_,text);
1154
1155 xmltext=ParseXML_Encode_Safe_XML(text);
1156
1157 loaded_translations[nloaded_translations-1]->nothtml_stop=strcpy(malloc(strlen(text)+1),text);
1158
1159 loaded_translations[nloaded_translations-1]->html_stop=malloc(sizeof("<tr class='n'><td>")+strlen(xmltext)+1+1);
1160
1161 strcpy(loaded_translations[nloaded_translations-1]->html_stop,"<tr class='n'><td>");
1162 strcat(loaded_translations[nloaded_translations-1]->html_stop,xmltext);
1163 strcat(loaded_translations[nloaded_translations-1]->html_stop,"\n");
1164 }
1165
1166 return(0);
1167 }
1168
1169
1170 /*++++++++++++++++++++++++++++++++++++++
1171 The function that is called when the HTMLTotalType XSD type is seen
1172
1173 int HTMLTotalType_function Returns 0 if no error occured or something else otherwise.
1174
1175 const char *_tag_ Set to the name of the element tag that triggered this function call.
1176
1177 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1178
1179 const char *text The contents of the 'text' attribute (or NULL if not defined).
1180 ++++++++++++++++++++++++++++++++++++++*/
1181
1182 static int HTMLTotalType_function(const char *_tag_,int _type_,const char *text)
1183 {
1184 if(_type_&XMLPARSE_TAG_START && store)
1185 {
1186 char *xmltext;
1187
1188 XMLPARSE_ASSERT_STRING(_tag_,text);
1189
1190 xmltext=ParseXML_Encode_Safe_XML(text);
1191
1192 loaded_translations[nloaded_translations-1]->nothtml_total=strcpy(malloc(strlen(text)+1),text);
1193
1194 loaded_translations[nloaded_translations-1]->html_total=malloc(sizeof("<tr class='t'><td>")+strlen(xmltext)+sizeof("<span class='j'>")+sizeof("</span>")+1+1);
1195
1196 strcpy(loaded_translations[nloaded_translations-1]->html_total,"<tr class='t'><td>");
1197 strcat(loaded_translations[nloaded_translations-1]->html_total,"<span class='j'>");
1198 strcat(loaded_translations[nloaded_translations-1]->html_total,xmltext);
1199 strcat(loaded_translations[nloaded_translations-1]->html_total,"</span>");
1200 strcat(loaded_translations[nloaded_translations-1]->html_total,"\n");
1201 }
1202
1203 return(0);
1204 }
1205
1206
1207 /*++++++++++++++++++++++++++++++++++++++
1208 The function that is called when the HTMLSubtotalType XSD type is seen
1209
1210 int HTMLSubtotalType_function Returns 0 if no error occured or something else otherwise.
1211
1212 const char *_tag_ Set to the name of the element tag that triggered this function call.
1213
1214 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1215
1216 const char *text The contents of the 'text' attribute (or NULL if not defined).
1217 ++++++++++++++++++++++++++++++++++++++*/
1218
1219 static int HTMLSubtotalType_function(const char *_tag_,int _type_,const char *text)
1220 {
1221 if(_type_&XMLPARSE_TAG_START && store)
1222 {
1223 char *xmltext;
1224
1225 XMLPARSE_ASSERT_STRING(_tag_,text);
1226
1227 xmltext=ParseXML_Encode_Safe_XML(text);
1228
1229 loaded_translations[nloaded_translations-1]->nothtml_subtotal=strcpy(malloc(strlen(text)+1),text);
1230
1231 loaded_translations[nloaded_translations-1]->html_subtotal=malloc(sizeof(" [<span class='j'>")+strlen(xmltext)+sizeof("</span>]")+1+1);
1232
1233 strcpy(loaded_translations[nloaded_translations-1]->html_subtotal," [<span class='j'>");
1234 strcat(loaded_translations[nloaded_translations-1]->html_subtotal,xmltext);
1235 strcat(loaded_translations[nloaded_translations-1]->html_subtotal,"</span>]");
1236 strcat(loaded_translations[nloaded_translations-1]->html_subtotal,"\n");
1237 }
1238
1239 return(0);
1240 }
1241
1242
1243 /*++++++++++++++++++++++++++++++++++++++
1244 The function that is called when the GPXWaypointType XSD type is seen
1245
1246 int GPXWaypointType_function Returns 0 if no error occured or something else otherwise.
1247
1248 const char *_tag_ Set to the name of the element tag that triggered this function call.
1249
1250 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1251
1252 const char *type The contents of the 'type' attribute (or NULL if not defined).
1253
1254 const char *string The contents of the 'string' attribute (or NULL if not defined).
1255 ++++++++++++++++++++++++++++++++++++++*/
1256
1257 static int GPXWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string)
1258 {
1259 if(_type_&XMLPARSE_TAG_START && store)
1260 {
1261 char *xmlstring;
1262
1263 XMLPARSE_ASSERT_STRING(_tag_,type);
1264 XMLPARSE_ASSERT_STRING(_tag_,string);
1265
1266 xmlstring=ParseXML_Encode_Safe_XML(string);
1267
1268 if(!strcmp(type,"waypt"))
1269 loaded_translations[nloaded_translations-1]->gpx_waypt=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
1270 else if(!strcmp(type,"trip"))
1271 loaded_translations[nloaded_translations-1]->gpx_trip=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
1272 else
1273 XMLPARSE_INVALID(_tag_,type);
1274 }
1275
1276 return(0);
1277 }
1278
1279
1280 /*++++++++++++++++++++++++++++++++++++++
1281 The function that is called when the GPXDescType XSD type is seen
1282
1283 int GPXDescType_function Returns 0 if no error occured or something else otherwise.
1284
1285 const char *_tag_ Set to the name of the element tag that triggered this function call.
1286
1287 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1288
1289 const char *text The contents of the 'text' attribute (or NULL if not defined).
1290 ++++++++++++++++++++++++++++++++++++++*/
1291
1292 static int GPXDescType_function(const char *_tag_,int _type_,const char *text)
1293 {
1294 if(_type_&XMLPARSE_TAG_START && store)
1295 {
1296 char *xmltext;
1297
1298 XMLPARSE_ASSERT_STRING(_tag_,text);
1299
1300 xmltext=ParseXML_Encode_Safe_XML(text);
1301 loaded_translations[nloaded_translations-1]->gpx_desc=strcpy(malloc(strlen(xmltext)+1),xmltext);
1302 }
1303
1304 return(0);
1305 }
1306
1307
1308 /*++++++++++++++++++++++++++++++++++++++
1309 The function that is called when the GPXNameType XSD type is seen
1310
1311 int GPXNameType_function Returns 0 if no error occured or something else otherwise.
1312
1313 const char *_tag_ Set to the name of the element tag that triggered this function call.
1314
1315 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1316
1317 const char *text The contents of the 'text' attribute (or NULL if not defined).
1318 ++++++++++++++++++++++++++++++++++++++*/
1319
1320 static int GPXNameType_function(const char *_tag_,int _type_,const char *text)
1321 {
1322 if(_type_&XMLPARSE_TAG_START && store)
1323 {
1324 char *xmltext;
1325
1326 XMLPARSE_ASSERT_STRING(_tag_,text);
1327
1328 xmltext=ParseXML_Encode_Safe_XML(text);
1329 loaded_translations[nloaded_translations-1]->gpx_name=strcpy(malloc(strlen(xmltext)+1),xmltext);
1330 }
1331
1332 return(0);
1333 }
1334
1335
1336 /*++++++++++++++++++++++++++++++++++++++
1337 The function that is called when the GPXStepType XSD type is seen
1338
1339 int GPXStepType_function Returns 0 if no error occured or something else otherwise.
1340
1341 const char *_tag_ Set to the name of the element tag that triggered this function call.
1342
1343 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1344
1345 const char *text The contents of the 'text' attribute (or NULL if not defined).
1346 ++++++++++++++++++++++++++++++++++++++*/
1347
1348 static int GPXStepType_function(const char *_tag_,int _type_,const char *text)
1349 {
1350 if(_type_&XMLPARSE_TAG_START && store)
1351 {
1352 char *xmltext;
1353
1354 XMLPARSE_ASSERT_STRING(_tag_,text);
1355
1356 xmltext=ParseXML_Encode_Safe_XML(text);
1357 loaded_translations[nloaded_translations-1]->gpx_step=strcpy(malloc(strlen(xmltext)+1),xmltext);
1358 }
1359
1360 return(0);
1361 }
1362
1363
1364 /*++++++++++++++++++++++++++++++++++++++
1365 The function that is called when the GPXFinalType XSD type is seen
1366
1367 int GPXFinalType_function Returns 0 if no error occured or something else otherwise.
1368
1369 const char *_tag_ Set to the name of the element tag that triggered this function call.
1370
1371 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1372
1373 const char *text The contents of the 'text' attribute (or NULL if not defined).
1374 ++++++++++++++++++++++++++++++++++++++*/
1375
1376 static int GPXFinalType_function(const char *_tag_,int _type_,const char *text)
1377 {
1378 if(_type_&XMLPARSE_TAG_START && store)
1379 {
1380 char *xmltext;
1381
1382 XMLPARSE_ASSERT_STRING(_tag_,text);
1383
1384 xmltext=ParseXML_Encode_Safe_XML(text);
1385 loaded_translations[nloaded_translations-1]->gpx_final=strcpy(malloc(strlen(xmltext)+1),xmltext);
1386 }
1387
1388 return(0);
1389 }
1390
1391
1392 /*++++++++++++++++++++++++++++++++++++++
1393 The XML translation parser.
1394
1395 int ParseXMLTranslations Returns 0 if OK or something else in case of an error.
1396
1397 const char *filename The name of the file to read.
1398
1399 const char *lang The abbreviated language name to search for (NULL means first in file).
1400
1401 int all Set to true to load all the translations.
1402 ++++++++++++++++++++++++++++++++++++++*/
1403
1404 int ParseXMLTranslations(const char *filename,const char *lang,int all)
1405 {
1406 int fd;
1407 int retval;
1408
1409 if(!ExistsFile(filename))
1410 return(1);
1411
1412 fd=OpenFile(filename);
1413
1414 /* Delete the existing translations */
1415
1416 if(nloaded_translations)
1417 FreeXMLTranslations();
1418
1419 /* Initialise variables used for parsing */
1420
1421 store_all=all;
1422
1423 store_lang=lang;
1424
1425 store=0;
1426 stored=0;
1427
1428 /* Parse the file */
1429
1430 retval=ParseXML(fd,xml_toplevel_tags,XMLPARSE_UNKNOWN_ATTR_ERRNONAME|XMLPARSE_RETURN_ATTR_ENCODED);
1431
1432 CloseFile(fd);
1433
1434 if(retval)
1435 {
1436 FreeXMLTranslations();
1437
1438 return(2);
1439 }
1440
1441 return(0);
1442 }
1443
1444
1445 /*++++++++++++++++++++++++++++++++++++++
1446 Return a list of the languages that have been loaded from the XML file.
1447
1448 char **GetTranslationLanguages Returns a NULL terminated list of strings - all allocated.
1449 ++++++++++++++++++++++++++++++++++++++*/
1450
1451 char **GetTranslationLanguages(void)
1452 {
1453 char **list=calloc(1+nloaded_translations,sizeof(char*));
1454 int i;
1455
1456 for(i=0;i<nloaded_translations;i++)
1457 list[i]=strcpy(malloc(strlen(loaded_translations[i]->lang)+1),loaded_translations[i]->lang);
1458
1459 return(list);
1460 }
1461
1462
1463 /*++++++++++++++++++++++++++++++++++++++
1464 Return a list of the full names of the languages that have been loaded from the XML file.
1465
1466 char **GetTranslationLanguageFullNames Returns a NULL terminated list of strings - all allocated.
1467 ++++++++++++++++++++++++++++++++++++++*/
1468
1469 char **GetTranslationLanguageFullNames(void)
1470 {
1471 char **list=calloc(1+nloaded_translations,sizeof(char*));
1472 int i;
1473
1474 for(i=0;i<nloaded_translations;i++)
1475 list[i]=strcpy(malloc(strlen(loaded_translations[i]->language)+1),loaded_translations[i]->language);
1476
1477 return(list);
1478 }
1479
1480
1481 /*++++++++++++++++++++++++++++++++++++++
1482 Get a named translation.
1483
1484 Translation *GetTranslation Returns a pointer to the translation.
1485
1486 const char *lang The abbreviated name of the language of the translation or NULL to get the default or an empty string to get the first one.
1487 ++++++++++++++++++++++++++++++++++++++*/
1488
1489 Translation *GetTranslation(const char *lang)
1490 {
1491 int i;
1492
1493 if(!lang)
1494 return(&default_translation);
1495
1496 if(!*lang && nloaded_translations>0)
1497 return(loaded_translations[0]);
1498
1499 for(i=0;i<nloaded_translations;i++)
1500 if(!strcmp(loaded_translations[i]->lang,lang))
1501 return(loaded_translations[i]);
1502
1503 return(NULL);
1504 }
1505
1506
1507 /*++++++++++++++++++++++++++++++++++++++
1508 Free the memory that has been allocated for the translations.
1509 ++++++++++++++++++++++++++++++++++++++*/
1510
1511 void FreeXMLTranslations()
1512 {
1513 int i,j;
1514
1515 if(!loaded_translations)
1516 return;
1517
1518 for(i=0;i<nloaded_translations;i++)
1519 {
1520 free(loaded_translations[i]->lang);
1521 free(loaded_translations[i]->language);
1522
1523 for(j=0;j<2;j++)
1524 {
1525 if(loaded_translations[i]->raw_copyright_creator[j] != default_translation.raw_copyright_creator[j]) free(loaded_translations[i]->raw_copyright_creator[j]);
1526 if(loaded_translations[i]->raw_copyright_source[j] != default_translation.raw_copyright_source[j]) free(loaded_translations[i]->raw_copyright_source[j]);
1527 if(loaded_translations[i]->raw_copyright_license[j] != default_translation.raw_copyright_license[j]) free(loaded_translations[i]->raw_copyright_license[j]);
1528
1529 if(loaded_translations[i]->xml_copyright_creator[j] != default_translation.xml_copyright_creator[j]) free(loaded_translations[i]->xml_copyright_creator[j]);
1530 if(loaded_translations[i]->xml_copyright_source[j] != default_translation.xml_copyright_source[j]) free(loaded_translations[i]->xml_copyright_source[j]);
1531 if(loaded_translations[i]->xml_copyright_license[j] != default_translation.xml_copyright_license[j]) free(loaded_translations[i]->xml_copyright_license[j]);
1532 }
1533
1534 for(j=0;j<9;j++)
1535 {
1536 if(loaded_translations[i]->xml_heading[j] != default_translation.xml_heading[j]) free(loaded_translations[i]->xml_heading[j]);
1537 if(loaded_translations[i]->xml_turn[j] != default_translation.xml_turn[j]) free(loaded_translations[i]->xml_turn[j]);
1538 }
1539
1540 for(j=0;j<10;j++)
1541 if(loaded_translations[i]->xml_ordinal[j] != default_translation.xml_ordinal[j]) free(loaded_translations[i]->xml_ordinal[j]);
1542
1543 for(j=0;j<9;j++)
1544 {
1545 if(loaded_translations[i]->notxml_heading[j] != default_translation.notxml_heading[j]) free(loaded_translations[i]->notxml_heading[j]);
1546 if(loaded_translations[i]->notxml_turn[j] != default_translation.notxml_turn[j]) free(loaded_translations[i]->notxml_turn[j]);
1547 }
1548
1549 for(j=0;j<10;j++)
1550 if(loaded_translations[i]->notxml_ordinal[j] != default_translation.notxml_ordinal[j]) free(loaded_translations[i]->notxml_ordinal[j]);
1551
1552 for(j=0;j<Highway_Count;j++)
1553 if(loaded_translations[i]->raw_highway[j] != default_translation.raw_highway[j]) free(loaded_translations[i]->raw_highway[j]);
1554
1555 if(loaded_translations[i]->xml_route_shortest != default_translation.xml_route_shortest) free(loaded_translations[i]->xml_route_shortest);
1556 if(loaded_translations[i]->xml_route_quickest != default_translation.xml_route_quickest) free(loaded_translations[i]->xml_route_quickest);
1557
1558 if(loaded_translations[i]->html_waypoint != default_translation.html_waypoint) free(loaded_translations[i]->html_waypoint);
1559 if(loaded_translations[i]->html_junction != default_translation.html_junction) free(loaded_translations[i]->html_junction);
1560 if(loaded_translations[i]->html_roundabout != default_translation.html_roundabout) free(loaded_translations[i]->html_roundabout);
1561
1562 if(loaded_translations[i]->html_title != default_translation.html_title) free(loaded_translations[i]->html_title);
1563
1564 if(loaded_translations[i]->html_start != default_translation.html_start) free(loaded_translations[i]->html_start);
1565 if(loaded_translations[i]->html_node != default_translation.html_node) free(loaded_translations[i]->html_node);
1566 if(loaded_translations[i]->html_rbnode != default_translation.html_rbnode) free(loaded_translations[i]->html_rbnode);
1567 if(loaded_translations[i]->html_segment != default_translation.html_segment) free(loaded_translations[i]->html_segment);
1568 if(loaded_translations[i]->html_stop != default_translation.html_stop) free(loaded_translations[i]->html_stop);
1569 if(loaded_translations[i]->html_total != default_translation.html_total) free(loaded_translations[i]->html_total);
1570 if(loaded_translations[i]->html_subtotal!= default_translation.html_subtotal)free(loaded_translations[i]->html_subtotal);
1571
1572 if(loaded_translations[i]->nothtml_waypoint != default_translation.nothtml_waypoint) free(loaded_translations[i]->nothtml_waypoint);
1573 if(loaded_translations[i]->nothtml_junction != default_translation.nothtml_junction) free(loaded_translations[i]->nothtml_junction);
1574 if(loaded_translations[i]->nothtml_roundabout != default_translation.nothtml_roundabout) free(loaded_translations[i]->nothtml_roundabout);
1575
1576 if(loaded_translations[i]->nothtml_title != default_translation.nothtml_title) free(loaded_translations[i]->nothtml_title);
1577
1578 if(loaded_translations[i]->nothtml_start != default_translation.nothtml_start) free(loaded_translations[i]->nothtml_start);
1579 if(loaded_translations[i]->nothtml_node != default_translation.nothtml_node) free(loaded_translations[i]->nothtml_node);
1580 if(loaded_translations[i]->nothtml_rbnode != default_translation.nothtml_rbnode) free(loaded_translations[i]->nothtml_rbnode);
1581 if(loaded_translations[i]->nothtml_segment != default_translation.nothtml_segment) free(loaded_translations[i]->nothtml_segment);
1582 if(loaded_translations[i]->nothtml_stop != default_translation.nothtml_stop) free(loaded_translations[i]->nothtml_stop);
1583 if(loaded_translations[i]->nothtml_total != default_translation.nothtml_total) free(loaded_translations[i]->nothtml_total);
1584 if(loaded_translations[i]->nothtml_subtotal!= default_translation.nothtml_subtotal)free(loaded_translations[i]->nothtml_subtotal);
1585
1586 if(loaded_translations[i]->gpx_desc != default_translation.gpx_desc) free(loaded_translations[i]->gpx_desc);
1587 if(loaded_translations[i]->gpx_name != default_translation.gpx_name) free(loaded_translations[i]->gpx_name);
1588 if(loaded_translations[i]->gpx_step != default_translation.gpx_step) free(loaded_translations[i]->gpx_step);
1589 if(loaded_translations[i]->gpx_final != default_translation.gpx_final) free(loaded_translations[i]->gpx_final);
1590
1591 if(loaded_translations[i]->gpx_waypt != default_translation.gpx_waypt) free(loaded_translations[i]->gpx_waypt);
1592 if(loaded_translations[i]->gpx_trip != default_translation.gpx_trip) free(loaded_translations[i]->gpx_trip);
1593
1594 free(loaded_translations[i]);
1595 }
1596
1597 free(loaded_translations);
1598
1599 loaded_translations=NULL;
1600 nloaded_translations=0;
1601 }

Properties

Name Value
cvs:description File containing translation parsing functions.