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 925 - (show annotations) (download) (as text)
Tue Dec 6 17:18:22 2011 UTC (13 years, 3 months ago) by amb
File MIME type: text/x-csrc
File size: 41035 byte(s)
Add new translate-able strings for roundabouts.

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-2011 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 /* Global variables - default English values - Must not require any UTF-8 encoding */
33
34 char *translate_raw_copyright_creator[2]={"Creator","Routino - http://www.routino.org/"};
35 char *translate_raw_copyright_source[2] ={NULL,NULL};
36 char *translate_raw_copyright_license[2]={NULL,NULL};
37
38 char *translate_xml_copyright_creator[2]={"Creator","Routino - http://www.routino.org/"};
39 char *translate_xml_copyright_source[2] ={NULL,NULL};
40 char *translate_xml_copyright_license[2]={NULL,NULL};
41
42 char *translate_xml_heading[9] ={"South","South-West","West","North-West","North","North-East","East","South-East","South"};
43 char *translate_xml_turn[9] ={"Very sharp left","Sharp left","Left","Slight left","Straight on","Slight right","Right","Sharp right","Very sharp right"};
44 char *translate_xml_ordinal[10]={"First","Second","Third","Fourth","Fifth","Sixth","Seventh","Eighth","Ninth","Tenth"};
45
46 char *translate_raw_highway[Way_Count]={"","motorway","trunk road","primary road","secondary road","tertiary road","unclassified road","residential road","service road","track","cycleway","path","steps","ferry"};
47
48 char *translate_xml_route_shortest="Shortest";
49 char *translate_xml_route_quickest="Quickest";
50
51 char *translate_html_waypoint ="<span class='w'>Waypoint</span>";
52 char *translate_html_junction ="Junction";
53 char *translate_html_roundabout="Roundabout";
54
55 char *translate_html_title ="%s Route";
56 char *translate_html_start[2] ={"Start","At %s, head %s"};
57 char *translate_html_segment[2]={"Follow","%s for %.3f km, %.1f min"};
58 char *translate_html_node[2] ={"At","%s, go %s heading %s"};
59 char *translate_html_rbnode[2] ={"Leave","%s, take the %s exit heading %s"};
60 char *translate_html_stop[2] ={"Stop","At %s"};
61 char *translate_html_total[2] ={"Total","%.1f km, %.0f minutes"};
62
63 char *translate_gpx_desc ="%s between 'start' and 'finish' waypoints";
64 char *translate_gpx_name ="%s Route";
65 char *translate_gpx_step ="%s on '%s' for %.3f km, %.1 min";
66 char *translate_gpx_final="Total Journey %.1f km, %d minutes";
67
68 char *translate_gpx_start ="START";
69 char *translate_gpx_inter ="INTER";
70 char *translate_gpx_trip ="TRIP";
71 char *translate_gpx_finish="FINISH";
72
73
74 /* Local variables */
75
76 /*+ The language that is to be stored. +*/
77 static const char *store_lang=NULL;
78
79 /*+ This current language is to be stored. +*/
80 static int store=0;
81
82 /*+ The chosen language has been stored. +*/
83 static int stored=0;
84
85
86 /* The XML tag processing function prototypes */
87
88 //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding);
89 //static int RoutinoTranslationsType_function(const char *_tag_,int _type_);
90 static int languageType_function(const char *_tag_,int _type_,const char *lang);
91 //static int GPXType_function(const char *_tag_,int _type_);
92 static int GPXFinalType_function(const char *_tag_,int _type_,const char *text);
93 static int GPXStepType_function(const char *_tag_,int _type_,const char *text);
94 static int GPXNameType_function(const char *_tag_,int _type_,const char *text);
95 static int GPXDescType_function(const char *_tag_,int _type_,const char *text);
96 //static int HTMLType_function(const char *_tag_,int _type_);
97 static int HTMLTotalType_function(const char *_tag_,int _type_,const char *string,const char *text);
98 static int HTMLStopType_function(const char *_tag_,int _type_,const char *string,const char *text);
99 static int HTMLSegmentType_function(const char *_tag_,int _type_,const char *string,const char *text);
100 static int HTMLRBNodeType_function(const char *_tag_,int _type_,const char *string,const char *text);
101 static int HTMLNodeType_function(const char *_tag_,int _type_,const char *string,const char *text);
102 static int HTMLStartType_function(const char *_tag_,int _type_,const char *string,const char *text);
103 static int HTMLTitleType_function(const char *_tag_,int _type_,const char *text);
104 //static int CopyrightType_function(const char *_tag_,int _type_);
105 static int GPXWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string);
106 static int HTMLWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string);
107 static int RouteType_function(const char *_tag_,int _type_,const char *type,const char *string);
108 static int HighwayType_function(const char *_tag_,int _type_,const char *type,const char *string);
109 static int OrdinalType_function(const char *_tag_,int _type_,const char *number,const char *string);
110 static int HeadingType_function(const char *_tag_,int _type_,const char *direction,const char *string);
111 static int TurnType_function(const char *_tag_,int _type_,const char *direction,const char *string);
112 static int CopyrightLicenseType_function(const char *_tag_,int _type_,const char *string,const char *text);
113 static int CopyrightSourceType_function(const char *_tag_,int _type_,const char *string,const char *text);
114 static int CopyrightCreatorType_function(const char *_tag_,int _type_,const char *string,const char *text);
115
116
117 /* The XML tag definitions */
118
119 /*+ The CopyrightCreatorType type tag. +*/
120 static xmltag CopyrightCreatorType_tag=
121 {"creator",
122 2, {"string","text"},
123 CopyrightCreatorType_function,
124 {NULL}};
125
126 /*+ The CopyrightSourceType type tag. +*/
127 static xmltag CopyrightSourceType_tag=
128 {"source",
129 2, {"string","text"},
130 CopyrightSourceType_function,
131 {NULL}};
132
133 /*+ The CopyrightLicenseType type tag. +*/
134 static xmltag CopyrightLicenseType_tag=
135 {"license",
136 2, {"string","text"},
137 CopyrightLicenseType_function,
138 {NULL}};
139
140 /*+ The TurnType type tag. +*/
141 static xmltag TurnType_tag=
142 {"turn",
143 2, {"direction","string"},
144 TurnType_function,
145 {NULL}};
146
147 /*+ The HeadingType type tag. +*/
148 static xmltag HeadingType_tag=
149 {"heading",
150 2, {"direction","string"},
151 HeadingType_function,
152 {NULL}};
153
154 /*+ The OrdinalType type tag. +*/
155 static xmltag OrdinalType_tag=
156 {"ordinal",
157 2, {"number","string"},
158 OrdinalType_function,
159 {NULL}};
160
161 /*+ The HighwayType type tag. +*/
162 static xmltag HighwayType_tag=
163 {"highway",
164 2, {"type","string"},
165 HighwayType_function,
166 {NULL}};
167
168 /*+ The RouteType type tag. +*/
169 static xmltag RouteType_tag=
170 {"route",
171 2, {"type","string"},
172 RouteType_function,
173 {NULL}};
174
175 /*+ The HTMLWaypointType type tag. +*/
176 static xmltag HTMLWaypointType_tag=
177 {"waypoint",
178 2, {"type","string"},
179 HTMLWaypointType_function,
180 {NULL}};
181
182 /*+ The GPXWaypointType type tag. +*/
183 static xmltag GPXWaypointType_tag=
184 {"waypoint",
185 2, {"type","string"},
186 GPXWaypointType_function,
187 {NULL}};
188
189 /*+ The CopyrightType type tag. +*/
190 static xmltag CopyrightType_tag=
191 {"copyright",
192 0, {NULL},
193 NULL,
194 {&CopyrightCreatorType_tag,&CopyrightSourceType_tag,&CopyrightLicenseType_tag,NULL}};
195
196 /*+ The HTMLTitleType type tag. +*/
197 static xmltag HTMLTitleType_tag=
198 {"title",
199 1, {"text"},
200 HTMLTitleType_function,
201 {NULL}};
202
203 /*+ The HTMLStartType type tag. +*/
204 static xmltag HTMLStartType_tag=
205 {"start",
206 2, {"string","text"},
207 HTMLStartType_function,
208 {NULL}};
209
210 /*+ The HTMLNodeType type tag. +*/
211 static xmltag HTMLNodeType_tag=
212 {"node",
213 2, {"string","text"},
214 HTMLNodeType_function,
215 {NULL}};
216
217 /*+ The HTMLRBNodeType type tag. +*/
218 static xmltag HTMLRBNodeType_tag=
219 {"rbnode",
220 2, {"string","text"},
221 HTMLRBNodeType_function,
222 {NULL}};
223
224 /*+ The HTMLSegmentType type tag. +*/
225 static xmltag HTMLSegmentType_tag=
226 {"segment",
227 2, {"string","text"},
228 HTMLSegmentType_function,
229 {NULL}};
230
231 /*+ The HTMLStopType type tag. +*/
232 static xmltag HTMLStopType_tag=
233 {"stop",
234 2, {"string","text"},
235 HTMLStopType_function,
236 {NULL}};
237
238 /*+ The HTMLTotalType type tag. +*/
239 static xmltag HTMLTotalType_tag=
240 {"total",
241 2, {"string","text"},
242 HTMLTotalType_function,
243 {NULL}};
244
245 /*+ The HTMLType type tag. +*/
246 static xmltag HTMLType_tag=
247 {"output-html",
248 0, {NULL},
249 NULL,
250 {&HTMLWaypointType_tag,&HTMLTitleType_tag,&HTMLStartType_tag,&HTMLNodeType_tag,&HTMLRBNodeType_tag,&HTMLSegmentType_tag,&HTMLStopType_tag,&HTMLTotalType_tag,NULL}};
251
252 /*+ The GPXDescType type tag. +*/
253 static xmltag GPXDescType_tag=
254 {"desc",
255 1, {"text"},
256 GPXDescType_function,
257 {NULL}};
258
259 /*+ The GPXNameType type tag. +*/
260 static xmltag GPXNameType_tag=
261 {"name",
262 1, {"text"},
263 GPXNameType_function,
264 {NULL}};
265
266 /*+ The GPXStepType type tag. +*/
267 static xmltag GPXStepType_tag=
268 {"step",
269 1, {"text"},
270 GPXStepType_function,
271 {NULL}};
272
273 /*+ The GPXFinalType type tag. +*/
274 static xmltag GPXFinalType_tag=
275 {"final",
276 1, {"text"},
277 GPXFinalType_function,
278 {NULL}};
279
280 /*+ The GPXType type tag. +*/
281 static xmltag GPXType_tag=
282 {"output-gpx",
283 0, {NULL},
284 NULL,
285 {&GPXWaypointType_tag,&GPXDescType_tag,&GPXNameType_tag,&GPXStepType_tag,&GPXFinalType_tag,NULL}};
286
287 /*+ The languageType type tag. +*/
288 static xmltag languageType_tag=
289 {"language",
290 1, {"lang"},
291 languageType_function,
292 {&CopyrightType_tag,&TurnType_tag,&HeadingType_tag,&OrdinalType_tag,&HighwayType_tag,&RouteType_tag,&HTMLType_tag,&GPXType_tag,NULL}};
293
294 /*+ The RoutinoTranslationsType type tag. +*/
295 static xmltag RoutinoTranslationsType_tag=
296 {"routino-translations",
297 0, {NULL},
298 NULL,
299 {&languageType_tag,NULL}};
300
301 /*+ The xmlDeclaration type tag. +*/
302 static xmltag xmlDeclaration_tag=
303 {"xml",
304 2, {"version","encoding"},
305 NULL,
306 {NULL}};
307
308
309 /*+ The complete set of tags at the top level. +*/
310 static xmltag *xml_toplevel_tags[]={&xmlDeclaration_tag,&RoutinoTranslationsType_tag,NULL};
311
312
313 /* The XML tag processing functions */
314
315
316 /*++++++++++++++++++++++++++++++++++++++
317 The function that is called when the CopyrightCreatorType XSD type is seen
318
319 int CopyrightCreatorType_function Returns 0 if no error occured or something else otherwise.
320
321 const char *_tag_ Set to the name of the element tag that triggered this function call.
322
323 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
324
325 const char *string The contents of the 'string' attribute (or NULL if not defined).
326
327 const char *text The contents of the 'text' attribute (or NULL if not defined).
328 ++++++++++++++++++++++++++++++++++++++*/
329
330 static int CopyrightCreatorType_function(const char *_tag_,int _type_,const char *string,const char *text)
331 {
332 if(_type_&XMLPARSE_TAG_START && store)
333 {
334 char *xmlstring,*xmltext;
335
336 XMLPARSE_ASSERT_STRING(_tag_,string);
337 XMLPARSE_ASSERT_STRING(_tag_,text);
338
339 translate_raw_copyright_creator[0]=strcpy(malloc(strlen(string)+1),string);
340 translate_raw_copyright_creator[1]=strcpy(malloc(strlen(text)+1) ,text);
341
342 xmlstring=ParseXML_Encode_Safe_XML(string);
343 xmltext =ParseXML_Encode_Safe_XML(text);
344
345 translate_xml_copyright_creator[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
346 translate_xml_copyright_creator[1]=strcpy(malloc(strlen(xmltext)+1) ,xmltext);
347 }
348
349 return(0);
350 }
351
352
353 /*++++++++++++++++++++++++++++++++++++++
354 The function that is called when the CopyrightSourceType XSD type is seen
355
356 int CopyrightSourceType_function Returns 0 if no error occured or something else otherwise.
357
358 const char *_tag_ Set to the name of the element tag that triggered this function call.
359
360 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
361
362 const char *string The contents of the 'string' attribute (or NULL if not defined).
363
364 const char *text The contents of the 'text' attribute (or NULL if not defined).
365 ++++++++++++++++++++++++++++++++++++++*/
366
367 static int CopyrightSourceType_function(const char *_tag_,int _type_,const char *string,const char *text)
368 {
369 if(_type_&XMLPARSE_TAG_START && store)
370 {
371 char *xmlstring,*xmltext;
372
373 XMLPARSE_ASSERT_STRING(_tag_,string);
374 XMLPARSE_ASSERT_STRING(_tag_,text);
375
376 translate_raw_copyright_source[0]=strcpy(malloc(strlen(string)+1),string);
377 translate_raw_copyright_source[1]=strcpy(malloc(strlen(text)+1) ,text);
378
379 xmlstring=ParseXML_Encode_Safe_XML(string);
380 xmltext =ParseXML_Encode_Safe_XML(text);
381
382 translate_xml_copyright_source[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
383 translate_xml_copyright_source[1]=strcpy(malloc(strlen(xmltext)+1) ,xmltext);
384 }
385
386 return(0);
387 }
388
389
390 /*++++++++++++++++++++++++++++++++++++++
391 The function that is called when the CopyrightLicenseType XSD type is seen
392
393 int CopyrightLicenseType_function Returns 0 if no error occured or something else otherwise.
394
395 const char *_tag_ Set to the name of the element tag that triggered this function call.
396
397 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
398
399 const char *string The contents of the 'string' attribute (or NULL if not defined).
400
401 const char *text The contents of the 'text' attribute (or NULL if not defined).
402 ++++++++++++++++++++++++++++++++++++++*/
403
404 static int CopyrightLicenseType_function(const char *_tag_,int _type_,const char *string,const char *text)
405 {
406 if(_type_&XMLPARSE_TAG_START && store)
407 {
408 char *xmlstring,*xmltext;
409
410 XMLPARSE_ASSERT_STRING(_tag_,string);
411 XMLPARSE_ASSERT_STRING(_tag_,text);
412
413 translate_raw_copyright_license[0]=strcpy(malloc(strlen(string)+1),string);
414 translate_raw_copyright_license[1]=strcpy(malloc(strlen(text)+1) ,text);
415
416 xmlstring=ParseXML_Encode_Safe_XML(string);
417 xmltext =ParseXML_Encode_Safe_XML(text);
418
419 translate_xml_copyright_license[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
420 translate_xml_copyright_license[1]=strcpy(malloc(strlen(xmltext)+1) ,xmltext);
421 }
422
423 return(0);
424 }
425
426
427 /*++++++++++++++++++++++++++++++++++++++
428 The function that is called when the TurnType XSD type is seen
429
430 int TurnType_function Returns 0 if no error occured or something else otherwise.
431
432 const char *_tag_ Set to the name of the element tag that triggered this function call.
433
434 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
435
436 const char *direction The contents of the 'direction' attribute (or NULL if not defined).
437
438 const char *string The contents of the 'string' attribute (or NULL if not defined).
439 ++++++++++++++++++++++++++++++++++++++*/
440
441 static int TurnType_function(const char *_tag_,int _type_,const char *direction,const char *string)
442 {
443 if(_type_&XMLPARSE_TAG_START && store)
444 {
445 char *xmlstring;
446 int d;
447
448 XMLPARSE_ASSERT_INTEGER(_tag_,direction); d=atoi(direction);
449 XMLPARSE_ASSERT_STRING(_tag_,string);
450
451 d+=4;
452
453 if(d<0 || d>8)
454 XMLPARSE_INVALID(_tag_,direction);
455
456 xmlstring=ParseXML_Encode_Safe_XML(string);
457
458 translate_xml_turn[d]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
459 }
460
461 return(0);
462 }
463
464
465 /*++++++++++++++++++++++++++++++++++++++
466 The function that is called when the HeadingType XSD type is seen
467
468 int HeadingType_function Returns 0 if no error occured or something else otherwise.
469
470 const char *_tag_ Set to the name of the element tag that triggered this function call.
471
472 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
473
474 const char *direction The contents of the 'direction' attribute (or NULL if not defined).
475
476 const char *string The contents of the 'string' attribute (or NULL if not defined).
477 ++++++++++++++++++++++++++++++++++++++*/
478
479 static int HeadingType_function(const char *_tag_,int _type_,const char *direction,const char *string)
480 {
481 if(_type_&XMLPARSE_TAG_START && store)
482 {
483 char *xmlstring;
484 int d;
485
486 XMLPARSE_ASSERT_INTEGER(_tag_,direction); d=atoi(direction);
487 XMLPARSE_ASSERT_STRING(_tag_,string);
488
489 d+=4;
490
491 if(d<0 || d>8)
492 XMLPARSE_INVALID(_tag_,direction);
493
494 xmlstring=ParseXML_Encode_Safe_XML(string);
495
496 translate_xml_heading[d]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
497 }
498
499 return(0);
500 }
501
502
503 /*++++++++++++++++++++++++++++++++++++++
504 The function that is called when the OrdinalType XSD type is seen
505
506 int OrdinalType_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 *number The contents of the 'number' 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 OrdinalType_function(const char *_tag_,int _type_,const char *number,const char *string)
518 {
519 if(_type_&XMLPARSE_TAG_START && store)
520 {
521 char *xmlstring;
522 int n;
523
524 XMLPARSE_ASSERT_INTEGER(_tag_,number); n=atoi(number);
525 XMLPARSE_ASSERT_STRING(_tag_,string);
526
527 if(n<1 || n>10)
528 XMLPARSE_INVALID(_tag_,number);
529
530 xmlstring=ParseXML_Encode_Safe_XML(string);
531
532 translate_xml_ordinal[n-1]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
533 }
534
535 return(0);
536 }
537
538
539 /*++++++++++++++++++++++++++++++++++++++
540 The function that is called when the HighwayType XSD type is seen
541
542 int HighwayType_function Returns 0 if no error occured or something else otherwise.
543
544 const char *_tag_ Set to the name of the element tag that triggered this function call.
545
546 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
547
548 const char *type The contents of the 'type' attribute (or NULL if not defined).
549
550 const char *string The contents of the 'string' attribute (or NULL if not defined).
551 ++++++++++++++++++++++++++++++++++++++*/
552
553 static int HighwayType_function(const char *_tag_,int _type_,const char *type,const char *string)
554 {
555 if(_type_&XMLPARSE_TAG_START && store)
556 {
557 Highway highway;
558
559 XMLPARSE_ASSERT_STRING(_tag_,type);
560 XMLPARSE_ASSERT_STRING(_tag_,string);
561
562 highway=HighwayType(type);
563
564 if(highway==Way_Count)
565 XMLPARSE_INVALID(_tag_,type);
566
567 translate_raw_highway[highway]=strcpy(malloc(strlen(string)+1),string);
568 }
569
570 return(0);
571 }
572
573
574 /*++++++++++++++++++++++++++++++++++++++
575 The function that is called when the RouteType XSD type is seen
576
577 int RouteType_function Returns 0 if no error occured or something else otherwise.
578
579 const char *_tag_ Set to the name of the element tag that triggered this function call.
580
581 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
582
583 const char *type The contents of the 'type' attribute (or NULL if not defined).
584
585 const char *string The contents of the 'string' attribute (or NULL if not defined).
586 ++++++++++++++++++++++++++++++++++++++*/
587
588 static int RouteType_function(const char *_tag_,int _type_,const char *type,const char *string)
589 {
590 if(_type_&XMLPARSE_TAG_START && store)
591 {
592 char *xmlstring;
593
594 XMLPARSE_ASSERT_STRING(_tag_,type);
595 XMLPARSE_ASSERT_STRING(_tag_,string);
596
597 xmlstring=ParseXML_Encode_Safe_XML(string);
598
599 if(!strcmp(type,"shortest"))
600 translate_xml_route_shortest=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
601 else if(!strcmp(type,"quickest"))
602 translate_xml_route_quickest=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
603 else
604 XMLPARSE_INVALID(_tag_,type);
605 }
606
607 return(0);
608 }
609
610
611 /*++++++++++++++++++++++++++++++++++++++
612 The function that is called when the HTMLWaypointType XSD type is seen
613
614 int HTMLWaypointType_function Returns 0 if no error occured or something else otherwise.
615
616 const char *_tag_ Set to the name of the element tag that triggered this function call.
617
618 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
619
620 const char *type The contents of the 'type' attribute (or NULL if not defined).
621
622 const char *string The contents of the 'string' attribute (or NULL if not defined).
623 ++++++++++++++++++++++++++++++++++++++*/
624
625 static int HTMLWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string)
626 {
627 if(_type_&XMLPARSE_TAG_START && store)
628 {
629 char *xmlstring;
630
631 XMLPARSE_ASSERT_STRING(_tag_,type);
632 XMLPARSE_ASSERT_STRING(_tag_,string);
633
634 xmlstring=ParseXML_Encode_Safe_XML(string);
635
636 if(!strcmp(type,"waypoint"))
637 {
638 translate_html_waypoint=malloc(strlen(xmlstring)+1+sizeof("<span class='w'>")+sizeof("</span>"));
639 sprintf(translate_html_waypoint,"<span class='w'>%s</span>",xmlstring);
640 }
641 else if(!strcmp(type,"junction"))
642 translate_html_junction=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
643 else if(!strcmp(type,"roundabout"))
644 translate_html_roundabout=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
645 else
646 XMLPARSE_INVALID(_tag_,type);
647 }
648
649 return(0);
650 }
651
652
653 /*++++++++++++++++++++++++++++++++++++++
654 The function that is called when the GPXWaypointType XSD type is seen
655
656 int GPXWaypointType_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 GPXWaypointType_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,"start"))
679 translate_gpx_start=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
680 else if(!strcmp(type,"inter"))
681 translate_gpx_inter=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
682 else if(!strcmp(type,"trip"))
683 translate_gpx_trip=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
684 else if(!strcmp(type,"finish"))
685 translate_gpx_finish=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
686 else
687 XMLPARSE_INVALID(_tag_,type);
688 }
689
690 return(0);
691 }
692
693
694 /*++++++++++++++++++++++++++++++++++++++
695 The function that is called when the CopyrightType XSD type is seen
696
697 int CopyrightType_function Returns 0 if no error occured or something else otherwise.
698
699 const char *_tag_ Set to the name of the element tag that triggered this function call.
700
701 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
702 ++++++++++++++++++++++++++++++++++++++*/
703
704 //static int CopyrightType_function(const char *_tag_,int _type_)
705 //{
706 // return(0);
707 //}
708
709
710 /*++++++++++++++++++++++++++++++++++++++
711 The function that is called when the HTMLTitleType XSD type is seen
712
713 int HTMLTitleType_function Returns 0 if no error occured or something else otherwise.
714
715 const char *_tag_ Set to the name of the element tag that triggered this function call.
716
717 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
718
719 const char *text The contents of the 'text' attribute (or NULL if not defined).
720 ++++++++++++++++++++++++++++++++++++++*/
721
722 static int HTMLTitleType_function(const char *_tag_,int _type_,const char *text)
723 {
724 if(_type_&XMLPARSE_TAG_START && store)
725 {
726 char *xmltext;
727
728 XMLPARSE_ASSERT_STRING(_tag_,text);
729
730 xmltext=ParseXML_Encode_Safe_XML(text);
731
732 translate_html_title=strcpy(malloc(strlen(xmltext)+1),xmltext);
733 }
734
735 return(0);
736 }
737
738
739 /*++++++++++++++++++++++++++++++++++++++
740 The function that is called when the HTMLStartType XSD type is seen
741
742 int HTMLStartType_function Returns 0 if no error occured or something else otherwise.
743
744 const char *_tag_ Set to the name of the element tag that triggered this function call.
745
746 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
747
748 const char *string The contents of the 'string' attribute (or NULL if not defined).
749
750 const char *text The contents of the 'text' attribute (or NULL if not defined).
751 ++++++++++++++++++++++++++++++++++++++*/
752
753 static int HTMLStartType_function(const char *_tag_,int _type_,const char *string,const char *text)
754 {
755 if(_type_&XMLPARSE_TAG_START && store)
756 {
757 char *xmlstring,*xmltext;
758
759 XMLPARSE_ASSERT_STRING(_tag_,string);
760 XMLPARSE_ASSERT_STRING(_tag_,text);
761
762 xmlstring=ParseXML_Encode_Safe_XML(string);
763 xmltext =ParseXML_Encode_Safe_XML(text);
764
765 translate_html_start[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
766 translate_html_start[1]=malloc(strlen(xmltext)+1+sizeof("<span class='b'>")+sizeof("</span>"));
767 sprintf(translate_html_start[1],xmltext,"%s","<span class='b'>%s</span>");
768 }
769
770 return(0);
771 }
772
773
774 /*++++++++++++++++++++++++++++++++++++++
775 The function that is called when the HTMLNodeType XSD type is seen
776
777 int HTMLNodeType_function Returns 0 if no error occured or something else otherwise.
778
779 const char *_tag_ Set to the name of the element tag that triggered this function call.
780
781 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
782
783 const char *string The contents of the 'string' attribute (or NULL if not defined).
784
785 const char *text The contents of the 'text' attribute (or NULL if not defined).
786 ++++++++++++++++++++++++++++++++++++++*/
787
788 static int HTMLNodeType_function(const char *_tag_,int _type_,const char *string,const char *text)
789 {
790 if(_type_&XMLPARSE_TAG_START && store)
791 {
792 char *xmlstring,*xmltext;
793
794 XMLPARSE_ASSERT_STRING(_tag_,string);
795 XMLPARSE_ASSERT_STRING(_tag_,text);
796
797 xmlstring=ParseXML_Encode_Safe_XML(string);
798 xmltext =ParseXML_Encode_Safe_XML(text);
799
800 translate_html_node[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
801 translate_html_node[1]=malloc(strlen(xmltext)+1+2*sizeof("<span class='b'>")+2*sizeof("</span>"));
802 sprintf(translate_html_node[1],xmltext,"%s","<span class='t'>%s</span>","<span class='b'>%s</span>");
803 }
804
805 return(0);
806 }
807
808
809 /*++++++++++++++++++++++++++++++++++++++
810 The function that is called when the HTMLRBNodeType XSD type is seen
811
812 int HTMLRBNodeType_function Returns 0 if no error occured or something else otherwise.
813
814 const char *_tag_ Set to the name of the element tag that triggered this function call.
815
816 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
817
818 const char *string The contents of the 'string' attribute (or NULL if not defined).
819
820 const char *text The contents of the 'text' attribute (or NULL if not defined).
821 ++++++++++++++++++++++++++++++++++++++*/
822
823 static int HTMLRBNodeType_function(const char *_tag_,int _type_,const char *string,const char *text)
824 {
825 if(_type_&XMLPARSE_TAG_START && store)
826 {
827 char *xmlstring,*xmltext;
828
829 XMLPARSE_ASSERT_STRING(_tag_,string);
830 XMLPARSE_ASSERT_STRING(_tag_,text);
831
832 xmlstring=ParseXML_Encode_Safe_XML(string);
833 xmltext =ParseXML_Encode_Safe_XML(text);
834
835 translate_html_rbnode[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
836 translate_html_rbnode[1]=malloc(strlen(xmltext)+1+2*sizeof("<span class='b'>")+2*sizeof("</span>"));
837 sprintf(translate_html_rbnode[1],xmltext,"%s","<span class='t'>%s</span>","<span class='b'>%s</span>");
838 }
839
840 return(0);
841 }
842
843
844 /*++++++++++++++++++++++++++++++++++++++
845 The function that is called when the HTMLSegmentType XSD type is seen
846
847 int HTMLSegmentType_function Returns 0 if no error occured or something else otherwise.
848
849 const char *_tag_ Set to the name of the element tag that triggered this function call.
850
851 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
852
853 const char *string The contents of the 'string' attribute (or NULL if not defined).
854
855 const char *text The contents of the 'text' attribute (or NULL if not defined).
856 ++++++++++++++++++++++++++++++++++++++*/
857
858 static int HTMLSegmentType_function(const char *_tag_,int _type_,const char *string,const char *text)
859 {
860 if(_type_&XMLPARSE_TAG_START && store)
861 {
862 char *xmlstring,*xmltext;
863 const char *p;
864 char *q;
865
866 XMLPARSE_ASSERT_STRING(_tag_,string);
867 XMLPARSE_ASSERT_STRING(_tag_,text);
868
869 xmlstring=ParseXML_Encode_Safe_XML(string);
870 xmltext =ParseXML_Encode_Safe_XML(text);
871
872 translate_html_segment[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
873 translate_html_segment[1]=malloc(strlen(xmltext)+1+2*sizeof("<span class='b'>")+2*sizeof("</span>"));
874
875 p=xmltext;
876 q=translate_html_segment[1];
877
878 while(*p!='%' && *(p+1)!='s')
879 *q++=*p++;
880
881 p+=2;
882 strcpy(q,"<span class='h'>%s</span>"); q+=sizeof("<span class='h'>%s</span>")-1;
883
884 while(*p!='%')
885 *q++=*p++;
886
887 strcpy(q,"<span class='d'>"); q+=sizeof("<span class='d'>")-1;
888
889 strcpy(q,p);
890 strcat(q,"</span>");
891 }
892
893 return(0);
894 }
895
896
897 /*++++++++++++++++++++++++++++++++++++++
898 The function that is called when the HTMLStopType XSD type is seen
899
900 int HTMLStopType_function Returns 0 if no error occured or something else otherwise.
901
902 const char *_tag_ Set to the name of the element tag that triggered this function call.
903
904 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
905
906 const char *string The contents of the 'string' attribute (or NULL if not defined).
907
908 const char *text The contents of the 'text' attribute (or NULL if not defined).
909 ++++++++++++++++++++++++++++++++++++++*/
910
911 static int HTMLStopType_function(const char *_tag_,int _type_,const char *string,const char *text)
912 {
913 if(_type_&XMLPARSE_TAG_START && store)
914 {
915 char *xmlstring,*xmltext;
916
917 XMLPARSE_ASSERT_STRING(_tag_,string);
918 XMLPARSE_ASSERT_STRING(_tag_,text);
919
920 xmlstring=ParseXML_Encode_Safe_XML(string);
921 xmltext =ParseXML_Encode_Safe_XML(text);
922
923 translate_html_stop[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
924 translate_html_stop[1]=strcpy(malloc(strlen(xmltext)+1) ,xmltext);
925 }
926
927 return(0);
928 }
929
930
931 /*++++++++++++++++++++++++++++++++++++++
932 The function that is called when the HTMLTotalType XSD type is seen
933
934 int HTMLTotalType_function Returns 0 if no error occured or something else otherwise.
935
936 const char *_tag_ Set to the name of the element tag that triggered this function call.
937
938 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
939
940 const char *string The contents of the 'string' attribute (or NULL if not defined).
941
942 const char *text The contents of the 'text' attribute (or NULL if not defined).
943 ++++++++++++++++++++++++++++++++++++++*/
944
945 static int HTMLTotalType_function(const char *_tag_,int _type_,const char *string,const char *text)
946 {
947 if(_type_&XMLPARSE_TAG_START && store)
948 {
949 char *xmlstring,*xmltext;
950
951 XMLPARSE_ASSERT_STRING(_tag_,string);
952 XMLPARSE_ASSERT_STRING(_tag_,text);
953
954 xmlstring=ParseXML_Encode_Safe_XML(string);
955 xmltext =ParseXML_Encode_Safe_XML(text);
956
957 translate_html_total[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
958 translate_html_total[1]=strcpy(malloc(strlen(xmltext)+1) ,xmltext);
959 }
960
961 return(0);
962 }
963
964
965 /*++++++++++++++++++++++++++++++++++++++
966 The function that is called when the HTMLType XSD type is seen
967
968 int HTMLType_function Returns 0 if no error occured or something else otherwise.
969
970 const char *_tag_ Set to the name of the element tag that triggered this function call.
971
972 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
973 ++++++++++++++++++++++++++++++++++++++*/
974
975 //static int HTMLType_function(const char *_tag_,int _type_)
976 //{
977 // return(0);
978 //}
979
980
981 /*++++++++++++++++++++++++++++++++++++++
982 The function that is called when the GPXDescType XSD type is seen
983
984 int GPXDescType_function Returns 0 if no error occured or something else otherwise.
985
986 const char *_tag_ Set to the name of the element tag that triggered this function call.
987
988 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
989
990 const char *text The contents of the 'text' attribute (or NULL if not defined).
991 ++++++++++++++++++++++++++++++++++++++*/
992
993 static int GPXDescType_function(const char *_tag_,int _type_,const char *text)
994 {
995 if(_type_&XMLPARSE_TAG_START && store)
996 {
997 char *xmltext;
998
999 XMLPARSE_ASSERT_STRING(_tag_,text);
1000
1001 xmltext=ParseXML_Encode_Safe_XML(text);
1002
1003 translate_gpx_desc=strcpy(malloc(strlen(xmltext)+1),xmltext);
1004 }
1005
1006 return(0);
1007 }
1008
1009
1010 /*++++++++++++++++++++++++++++++++++++++
1011 The function that is called when the GPXNameType XSD type is seen
1012
1013 int GPXNameType_function Returns 0 if no error occured or something else otherwise.
1014
1015 const char *_tag_ Set to the name of the element tag that triggered this function call.
1016
1017 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1018
1019 const char *text The contents of the 'text' attribute (or NULL if not defined).
1020 ++++++++++++++++++++++++++++++++++++++*/
1021
1022 static int GPXNameType_function(const char *_tag_,int _type_,const char *text)
1023 {
1024 if(_type_&XMLPARSE_TAG_START && store)
1025 {
1026 char *xmltext;
1027
1028 XMLPARSE_ASSERT_STRING(_tag_,text);
1029
1030 xmltext=ParseXML_Encode_Safe_XML(text);
1031
1032 translate_gpx_name=strcpy(malloc(strlen(xmltext)+1),xmltext);
1033 }
1034
1035 return(0);
1036 }
1037
1038
1039 /*++++++++++++++++++++++++++++++++++++++
1040 The function that is called when the GPXStepType XSD type is seen
1041
1042 int GPXStepType_function Returns 0 if no error occured or something else otherwise.
1043
1044 const char *_tag_ Set to the name of the element tag that triggered this function call.
1045
1046 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1047
1048 const char *text The contents of the 'text' attribute (or NULL if not defined).
1049 ++++++++++++++++++++++++++++++++++++++*/
1050
1051 static int GPXStepType_function(const char *_tag_,int _type_,const char *text)
1052 {
1053 if(_type_&XMLPARSE_TAG_START && store)
1054 {
1055 char *xmltext;
1056
1057 XMLPARSE_ASSERT_STRING(_tag_,text);
1058
1059 xmltext=ParseXML_Encode_Safe_XML(text);
1060
1061 translate_gpx_step=strcpy(malloc(strlen(xmltext)+1),xmltext);
1062 }
1063
1064 return(0);
1065 }
1066
1067
1068 /*++++++++++++++++++++++++++++++++++++++
1069 The function that is called when the GPXFinalType XSD type is seen
1070
1071 int GPXFinalType_function Returns 0 if no error occured or something else otherwise.
1072
1073 const char *_tag_ Set to the name of the element tag that triggered this function call.
1074
1075 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1076
1077 const char *text The contents of the 'text' attribute (or NULL if not defined).
1078 ++++++++++++++++++++++++++++++++++++++*/
1079
1080 static int GPXFinalType_function(const char *_tag_,int _type_,const char *text)
1081 {
1082 if(_type_&XMLPARSE_TAG_START && store)
1083 {
1084 char *xmltext;
1085
1086 XMLPARSE_ASSERT_STRING(_tag_,text);
1087
1088 xmltext=ParseXML_Encode_Safe_XML(text);
1089
1090 translate_gpx_final=strcpy(malloc(strlen(xmltext)+1),xmltext);
1091 }
1092
1093 return(0);
1094 }
1095
1096
1097 /*++++++++++++++++++++++++++++++++++++++
1098 The function that is called when the GPXType XSD type is seen
1099
1100 int GPXType_function Returns 0 if no error occured or something else otherwise.
1101
1102 const char *_tag_ Set to the name of the element tag that triggered this function call.
1103
1104 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1105 ++++++++++++++++++++++++++++++++++++++*/
1106
1107 //static int GPXType_function(const char *_tag_,int _type_)
1108 //{
1109 // return(0);
1110 //}
1111
1112
1113 /*++++++++++++++++++++++++++++++++++++++
1114 The function that is called when the languageType XSD type is seen
1115
1116 int languageType_function Returns 0 if no error occured or something else otherwise.
1117
1118 const char *_tag_ Set to the name of the element tag that triggered this function call.
1119
1120 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1121
1122 const char *lang The contents of the 'lang' attribute (or NULL if not defined).
1123 ++++++++++++++++++++++++++++++++++++++*/
1124
1125 static int languageType_function(const char *_tag_,int _type_,const char *lang)
1126 {
1127 static int first=1;
1128
1129 if(_type_&XMLPARSE_TAG_START)
1130 {
1131 XMLPARSE_ASSERT_STRING(_tag_,lang);
1132
1133 if(!store_lang && first)
1134 store=1;
1135 else if(store_lang && !strcmp(store_lang,lang))
1136 store=1;
1137 else
1138 store=0;
1139
1140 first=0;
1141 }
1142
1143 if(_type_&XMLPARSE_TAG_END && store)
1144 {
1145 store=0;
1146 stored=1;
1147 }
1148
1149 return(0);
1150 }
1151
1152
1153 /*++++++++++++++++++++++++++++++++++++++
1154 The function that is called when the RoutinoTranslationsType XSD type is seen
1155
1156 int RoutinoTranslationsType_function Returns 0 if no error occured or something else otherwise.
1157
1158 const char *_tag_ Set to the name of the element tag that triggered this function call.
1159
1160 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1161 ++++++++++++++++++++++++++++++++++++++*/
1162
1163 //static int RoutinoTranslationsType_function(const char *_tag_,int _type_)
1164 //{
1165 // return(0);
1166 //}
1167
1168
1169 /*++++++++++++++++++++++++++++++++++++++
1170 The function that is called when the XML declaration is seen
1171
1172 int xmlDeclaration_function Returns 0 if no error occured or something else otherwise.
1173
1174 const char *_tag_ Set to the name of the element tag that triggered this function call.
1175
1176 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1177
1178 const char *version The contents of the 'version' attribute (or NULL if not defined).
1179
1180 const char *encoding The contents of the 'encoding' attribute (or NULL if not defined).
1181 ++++++++++++++++++++++++++++++++++++++*/
1182
1183 //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding)
1184 //{
1185 // return(0);
1186 //}
1187
1188
1189 /*++++++++++++++++++++++++++++++++++++++
1190 The XML translation parser.
1191
1192 int ParseXMLTranslations Returns 0 if OK or something else in case of an error.
1193
1194 const char *filename The name of the file to read.
1195
1196 const char *language The language to search for (NULL means first in file).
1197 ++++++++++++++++++++++++++++++++++++++*/
1198
1199 int ParseXMLTranslations(const char *filename,const char *language)
1200 {
1201 FILE *file;
1202 int retval;
1203
1204 store_lang=language;
1205
1206 if(!ExistsFile(filename))
1207 {
1208 fprintf(stderr,"Error: Specified translations file '%s' does not exist.\n",filename);
1209 return(1);
1210 }
1211
1212 file=fopen(filename,"r");
1213
1214 if(!file)
1215 {
1216 fprintf(stderr,"Error: Cannot open translations file '%s' for reading.\n",filename);
1217 return(1);
1218 }
1219
1220 retval=ParseXML(file,xml_toplevel_tags,XMLPARSE_UNKNOWN_ATTR_ERRNONAME|XMLPARSE_RETURN_ATTR_ENCODED);
1221
1222 fclose(file);
1223
1224 if(retval)
1225 return(1);
1226
1227 if(language && !stored)
1228 fprintf(stderr,"Warning: Cannot find translations for language '%s' using English instead.\n",language);
1229
1230 return(0);
1231 }

Properties

Name Value
cvs:description File containing translation parsing functions.