1 /***************************************
2 $Header: /home/amb/routino/src/RCS/translations.c,v 1.13 2010/09/15 18:30:08 amb Exp $
4 Load the translations from a file and the functions for handling them.
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2010 Andrew M. Bishop
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU Affero General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Affero General Public License for more details.
20 You should have received a copy of the GNU Affero General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ***************************************/
30 #include "translations.h"
34 /* Global variables - default English values - Must not require any UTF-8 encoding */
36 char *translate_copyright_creator[2]={"Creator","Routino - http://www.routino.org/"};
37 char *translate_copyright_source[2] ={NULL,NULL};
38 char *translate_copyright_license[2]={NULL,NULL};
40 char *translate_heading[9]={"South","South-West","West","North-West","North","North-East","East","South-East","South"};
41 char *translate_turn[9] ={"Very sharp left","Sharp left","Left","Slight left","Straight on","Slight right","Right","Sharp right","Very sharp right"};
43 char *translate_highway[Way_Count]={"","motorway","trunk road","primary road","secondary road","tertiary road","unclassified road","residential road","service road","track","cycleway","path","steps","ferry"};
45 char *translate_route_shortest="Shortest";
46 char *translate_route_quickest="Quickest";
48 char *translate_html_waypoint="<span class='w'>Waypoint</span>";
49 char *translate_html_junction="Junction";
51 char *translate_html_title="%s Route";
52 char *translate_html_start[2]={"Start","At %s, head %s"};
53 char *translate_html_segment[2]={"Follow","%s for %.3f km, %.1f min"};
54 char *translate_html_node[2]={"At","%s, go %s heading %s"};
55 char *translate_html_stop[2]={"Stop","At %s"};
56 char *translate_html_total[2]={"Total","%.1f km, %.0f minutes"};
58 char *translate_gpx_desc ="%s between 'start' and 'finish' waypoints";
59 char *translate_gpx_name ="%s Route";
60 char *translate_gpx_step ="%s on '%s' for %.3f km, %.1 min";
61 char *translate_gpx_final="Total Journey %.1f km, %d minutes";
63 char *translate_gpx_start="START";
64 char *translate_gpx_inter="INTER";
65 char *translate_gpx_trip="TRIP";
66 char *translate_gpx_finish="FINISH";
71 /*+ The language that is to be stored. +*/
72 static const char *store_lang=NULL;
74 /*+ This current language is to be stored. +*/
77 /*+ The chosen language has been stored. +*/
81 /* The XML tag processing function prototypes */
83 //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding);
84 //static int RoutinoTranslationsType_function(const char *_tag_,int _type_);
85 static int languageType_function(const char *_tag_,int _type_,const char *lang);
86 //static int GPXType_function(const char *_tag_,int _type_);
87 static int GPXFinalType_function(const char *_tag_,int _type_,const char *text);
88 static int GPXStepType_function(const char *_tag_,int _type_,const char *text);
89 static int GPXNameType_function(const char *_tag_,int _type_,const char *text);
90 static int GPXDescType_function(const char *_tag_,int _type_,const char *text);
91 //static int HTMLType_function(const char *_tag_,int _type_);
92 static int HTMLTotalType_function(const char *_tag_,int _type_,const char *string,const char *text);
93 static int HTMLStopType_function(const char *_tag_,int _type_,const char *string,const char *text);
94 static int HTMLSegmentType_function(const char *_tag_,int _type_,const char *string,const char *text);
95 static int HTMLNodeType_function(const char *_tag_,int _type_,const char *string,const char *text);
96 static int HTMLStartType_function(const char *_tag_,int _type_,const char *string,const char *text);
97 static int HTMLTitleType_function(const char *_tag_,int _type_,const char *text);
98 //static int CopyrightType_function(const char *_tag_,int _type_);
99 static int GPXWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string);
100 static int HTMLWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string);
101 static int RouteType_function(const char *_tag_,int _type_,const char *type,const char *string);
102 static int HighwayType_function(const char *_tag_,int _type_,const char *type,const char *string);
103 static int HeadingType_function(const char *_tag_,int _type_,const char *direction,const char *string);
104 static int TurnType_function(const char *_tag_,int _type_,const char *direction,const char *string);
105 static int CopyrightLicenseType_function(const char *_tag_,int _type_,const char *string,const char *text);
106 static int CopyrightSourceType_function(const char *_tag_,int _type_,const char *string,const char *text);
107 static int CopyrightCreatorType_function(const char *_tag_,int _type_,const char *string,const char *text);
110 /* The XML tag definitions */
112 /*+ The CopyrightCreatorType type tag. +*/
113 static xmltag CopyrightCreatorType_tag=
115 2, {"string","text"},
116 CopyrightCreatorType_function,
119 /*+ The CopyrightSourceType type tag. +*/
120 static xmltag CopyrightSourceType_tag=
122 2, {"string","text"},
123 CopyrightSourceType_function,
126 /*+ The CopyrightLicenseType type tag. +*/
127 static xmltag CopyrightLicenseType_tag=
129 2, {"string","text"},
130 CopyrightLicenseType_function,
133 /*+ The TurnType type tag. +*/
134 static xmltag TurnType_tag=
136 2, {"direction","string"},
140 /*+ The HeadingType type tag. +*/
141 static xmltag HeadingType_tag=
143 2, {"direction","string"},
144 HeadingType_function,
147 /*+ The HighwayType type tag. +*/
148 static xmltag HighwayType_tag=
150 2, {"type","string"},
151 HighwayType_function,
154 /*+ The RouteType type tag. +*/
155 static xmltag RouteType_tag=
157 2, {"type","string"},
161 /*+ The HTMLWaypointType type tag. +*/
162 static xmltag HTMLWaypointType_tag=
164 2, {"type","string"},
165 HTMLWaypointType_function,
168 /*+ The GPXWaypointType type tag. +*/
169 static xmltag GPXWaypointType_tag=
171 2, {"type","string"},
172 GPXWaypointType_function,
175 /*+ The CopyrightType type tag. +*/
176 static xmltag CopyrightType_tag=
180 {&CopyrightCreatorType_tag,&CopyrightSourceType_tag,&CopyrightLicenseType_tag,NULL}};
182 /*+ The HTMLTitleType type tag. +*/
183 static xmltag HTMLTitleType_tag=
186 HTMLTitleType_function,
189 /*+ The HTMLStartType type tag. +*/
190 static xmltag HTMLStartType_tag=
192 2, {"string","text"},
193 HTMLStartType_function,
196 /*+ The HTMLNodeType type tag. +*/
197 static xmltag HTMLNodeType_tag=
199 2, {"string","text"},
200 HTMLNodeType_function,
203 /*+ The HTMLSegmentType type tag. +*/
204 static xmltag HTMLSegmentType_tag=
206 2, {"string","text"},
207 HTMLSegmentType_function,
210 /*+ The HTMLStopType type tag. +*/
211 static xmltag HTMLStopType_tag=
213 2, {"string","text"},
214 HTMLStopType_function,
217 /*+ The HTMLTotalType type tag. +*/
218 static xmltag HTMLTotalType_tag=
220 2, {"string","text"},
221 HTMLTotalType_function,
224 /*+ The HTMLType type tag. +*/
225 static xmltag HTMLType_tag=
229 {&HTMLWaypointType_tag,&HTMLTitleType_tag,&HTMLStartType_tag,&HTMLNodeType_tag,&HTMLSegmentType_tag,&HTMLStopType_tag,&HTMLTotalType_tag,NULL}};
231 /*+ The GPXDescType type tag. +*/
232 static xmltag GPXDescType_tag=
235 GPXDescType_function,
238 /*+ The GPXNameType type tag. +*/
239 static xmltag GPXNameType_tag=
242 GPXNameType_function,
245 /*+ The GPXStepType type tag. +*/
246 static xmltag GPXStepType_tag=
249 GPXStepType_function,
252 /*+ The GPXFinalType type tag. +*/
253 static xmltag GPXFinalType_tag=
256 GPXFinalType_function,
259 /*+ The GPXType type tag. +*/
260 static xmltag GPXType_tag=
264 {&GPXWaypointType_tag,&GPXDescType_tag,&GPXNameType_tag,&GPXStepType_tag,&GPXFinalType_tag,NULL}};
266 /*+ The languageType type tag. +*/
267 static xmltag languageType_tag=
270 languageType_function,
271 {&CopyrightType_tag,&TurnType_tag,&HeadingType_tag,&HighwayType_tag,&RouteType_tag,&HTMLType_tag,&GPXType_tag,NULL}};
273 /*+ The RoutinoTranslationsType type tag. +*/
274 static xmltag RoutinoTranslationsType_tag=
275 {"routino-translations",
278 {&languageType_tag,NULL}};
280 /*+ The xmlDeclaration type tag. +*/
281 static xmltag xmlDeclaration_tag=
283 2, {"version","encoding"},
288 /*+ The complete set of tags at the top level. +*/
289 static xmltag *xml_toplevel_tags[]={&xmlDeclaration_tag,&RoutinoTranslationsType_tag,NULL};
292 /* The XML tag processing functions */
295 /*++++++++++++++++++++++++++++++++++++++
296 The function that is called when the CopyrightCreatorType XSD type is seen
298 int CopyrightCreatorType_function Returns 0 if no error occured or something else otherwise.
300 const char *_tag_ Set to the name of the element tag that triggered this function call.
302 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
304 const char *string The contents of the 'string' attribute (or NULL if not defined).
306 const char *text The contents of the 'text' attribute (or NULL if not defined).
307 ++++++++++++++++++++++++++++++++++++++*/
309 static int CopyrightCreatorType_function(const char *_tag_,int _type_,const char *string,const char *text)
311 if(_type_&XMLPARSE_TAG_START && store)
313 char *xmlstring,*xmltext;
315 XMLPARSE_ASSERT_STRING(_tag_,string);
316 XMLPARSE_ASSERT_STRING(_tag_,text);
318 xmlstring=ParseXML_Encode_Safe_XML(string);
319 xmltext =ParseXML_Encode_Safe_XML(text);
321 translate_copyright_creator[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
322 translate_copyright_creator[1]=strcpy(malloc(strlen(xmltext)+1) ,xmltext);
329 /*++++++++++++++++++++++++++++++++++++++
330 The function that is called when the CopyrightSourceType XSD type is seen
332 int CopyrightSourceType_function Returns 0 if no error occured or something else otherwise.
334 const char *_tag_ Set to the name of the element tag that triggered this function call.
336 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
338 const char *string The contents of the 'string' attribute (or NULL if not defined).
340 const char *text The contents of the 'text' attribute (or NULL if not defined).
341 ++++++++++++++++++++++++++++++++++++++*/
343 static int CopyrightSourceType_function(const char *_tag_,int _type_,const char *string,const char *text)
345 if(_type_&XMLPARSE_TAG_START && store)
347 char *xmlstring,*xmltext;
349 XMLPARSE_ASSERT_STRING(_tag_,string);
350 XMLPARSE_ASSERT_STRING(_tag_,text);
352 xmlstring=ParseXML_Encode_Safe_XML(string);
353 xmltext =ParseXML_Encode_Safe_XML(text);
355 translate_copyright_source[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
356 translate_copyright_source[1]=strcpy(malloc(strlen(xmltext)+1) ,xmltext);
363 /*++++++++++++++++++++++++++++++++++++++
364 The function that is called when the CopyrightLicenseType XSD type is seen
366 int CopyrightLicenseType_function Returns 0 if no error occured or something else otherwise.
368 const char *_tag_ Set to the name of the element tag that triggered this function call.
370 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
372 const char *string The contents of the 'string' attribute (or NULL if not defined).
374 const char *text The contents of the 'text' attribute (or NULL if not defined).
375 ++++++++++++++++++++++++++++++++++++++*/
377 static int CopyrightLicenseType_function(const char *_tag_,int _type_,const char *string,const char *text)
379 if(_type_&XMLPARSE_TAG_START && store)
381 char *xmlstring,*xmltext;
383 XMLPARSE_ASSERT_STRING(_tag_,string);
384 XMLPARSE_ASSERT_STRING(_tag_,text);
386 xmlstring=ParseXML_Encode_Safe_XML(string);
387 xmltext =ParseXML_Encode_Safe_XML(text);
389 translate_copyright_license[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
390 translate_copyright_license[1]=strcpy(malloc(strlen(xmltext)+1) ,xmltext);
397 /*++++++++++++++++++++++++++++++++++++++
398 The function that is called when the TurnType XSD type is seen
400 int TurnType_function Returns 0 if no error occured or something else otherwise.
402 const char *_tag_ Set to the name of the element tag that triggered this function call.
404 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
406 const char *direction The contents of the 'direction' attribute (or NULL if not defined).
408 const char *string The contents of the 'string' attribute (or NULL if not defined).
409 ++++++++++++++++++++++++++++++++++++++*/
411 static int TurnType_function(const char *_tag_,int _type_,const char *direction,const char *string)
413 if(_type_&XMLPARSE_TAG_START && store)
419 XMLPARSE_ASSERT_INTEGER(_tag_,direction,d);
420 XMLPARSE_ASSERT_STRING(_tag_,string);
425 XMLPARSE_INVALID(_tag_,direction);
427 xmlstring=ParseXML_Encode_Safe_XML(string);
429 translate_turn[d]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
436 /*++++++++++++++++++++++++++++++++++++++
437 The function that is called when the HeadingType XSD type is seen
439 int HeadingType_function Returns 0 if no error occured or something else otherwise.
441 const char *_tag_ Set to the name of the element tag that triggered this function call.
443 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
445 const char *direction The contents of the 'direction' attribute (or NULL if not defined).
447 const char *string The contents of the 'string' attribute (or NULL if not defined).
448 ++++++++++++++++++++++++++++++++++++++*/
450 static int HeadingType_function(const char *_tag_,int _type_,const char *direction,const char *string)
452 if(_type_&XMLPARSE_TAG_START && store)
457 XMLPARSE_ASSERT_INTEGER(_tag_,direction,d);
458 XMLPARSE_ASSERT_STRING(_tag_,string);
463 XMLPARSE_INVALID(_tag_,direction);
465 xmlstring=ParseXML_Encode_Safe_XML(string);
467 translate_heading[d]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
474 /*++++++++++++++++++++++++++++++++++++++
475 The function that is called when the HighwayType XSD type is seen
477 int HighwayType_function Returns 0 if no error occured or something else otherwise.
479 const char *_tag_ Set to the name of the element tag that triggered this function call.
481 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
483 const char *type The contents of the 'type' attribute (or NULL if not defined).
485 const char *string The contents of the 'string' attribute (or NULL if not defined).
486 ++++++++++++++++++++++++++++++++++++++*/
488 static int HighwayType_function(const char *_tag_,int _type_,const char *type,const char *string)
490 if(_type_&XMLPARSE_TAG_START && store)
495 XMLPARSE_ASSERT_STRING(_tag_,type);
496 XMLPARSE_ASSERT_STRING(_tag_,string);
498 highway=HighwayType(type);
500 if(highway==Way_Count)
501 XMLPARSE_INVALID(_tag_,type);
503 xmlstring=ParseXML_Encode_Safe_XML(string);
505 translate_highway[highway]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
512 /*++++++++++++++++++++++++++++++++++++++
513 The function that is called when the RouteType XSD type is seen
515 int RouteType_function Returns 0 if no error occured or something else otherwise.
517 const char *_tag_ Set to the name of the element tag that triggered this function call.
519 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
521 const char *type The contents of the 'type' attribute (or NULL if not defined).
523 const char *string The contents of the 'string' attribute (or NULL if not defined).
524 ++++++++++++++++++++++++++++++++++++++*/
526 static int RouteType_function(const char *_tag_,int _type_,const char *type,const char *string)
528 if(_type_&XMLPARSE_TAG_START && store)
532 XMLPARSE_ASSERT_STRING(_tag_,type);
533 XMLPARSE_ASSERT_STRING(_tag_,string);
535 xmlstring=ParseXML_Encode_Safe_XML(string);
537 if(!strcmp(type,"shortest"))
538 translate_route_shortest=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
539 else if(!strcmp(type,"quickest"))
540 translate_route_quickest=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
542 XMLPARSE_INVALID(_tag_,type);
549 /*++++++++++++++++++++++++++++++++++++++
550 The function that is called when the HTMLWaypointType XSD type is seen
552 int HTMLWaypointType_function Returns 0 if no error occured or something else otherwise.
554 const char *_tag_ Set to the name of the element tag that triggered this function call.
556 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
558 const char *type The contents of the 'type' attribute (or NULL if not defined).
560 const char *string The contents of the 'string' attribute (or NULL if not defined).
561 ++++++++++++++++++++++++++++++++++++++*/
563 static int HTMLWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string)
565 if(_type_&XMLPARSE_TAG_START && store)
569 XMLPARSE_ASSERT_STRING(_tag_,type);
570 XMLPARSE_ASSERT_STRING(_tag_,string);
572 xmlstring=ParseXML_Encode_Safe_XML(string);
574 if(!strcmp(type,"waypoint"))
576 translate_html_waypoint=malloc(strlen(xmlstring)+1+sizeof("<span class='w'>")+sizeof("</span>"));
577 sprintf(translate_html_waypoint,"<span class='w'>%s</span>",xmlstring);
579 else if(!strcmp(type,"junction"))
580 translate_html_junction=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
582 XMLPARSE_INVALID(_tag_,type);
589 /*++++++++++++++++++++++++++++++++++++++
590 The function that is called when the GPXWaypointType XSD type is seen
592 int GPXWaypointType_function Returns 0 if no error occured or something else otherwise.
594 const char *_tag_ Set to the name of the element tag that triggered this function call.
596 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
598 const char *type The contents of the 'type' attribute (or NULL if not defined).
600 const char *string The contents of the 'string' attribute (or NULL if not defined).
601 ++++++++++++++++++++++++++++++++++++++*/
603 static int GPXWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string)
605 if(_type_&XMLPARSE_TAG_START && store)
609 XMLPARSE_ASSERT_STRING(_tag_,type);
610 XMLPARSE_ASSERT_STRING(_tag_,string);
612 xmlstring=ParseXML_Encode_Safe_XML(string);
614 if(!strcmp(type,"start"))
615 translate_gpx_start=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
616 else if(!strcmp(type,"inter"))
617 translate_gpx_inter=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
618 else if(!strcmp(type,"trip"))
619 translate_gpx_trip=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
620 else if(!strcmp(type,"finish"))
621 translate_gpx_finish=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
623 XMLPARSE_INVALID(_tag_,type);
630 /*++++++++++++++++++++++++++++++++++++++
631 The function that is called when the CopyrightType XSD type is seen
633 int CopyrightType_function Returns 0 if no error occured or something else otherwise.
635 const char *_tag_ Set to the name of the element tag that triggered this function call.
637 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
638 ++++++++++++++++++++++++++++++++++++++*/
640 //static int CopyrightType_function(const char *_tag_,int _type_)
646 /*++++++++++++++++++++++++++++++++++++++
647 The function that is called when the HTMLTitleType XSD type is seen
649 int HTMLTitleType_function Returns 0 if no error occured or something else otherwise.
651 const char *_tag_ Set to the name of the element tag that triggered this function call.
653 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
655 const char *text The contents of the 'text' attribute (or NULL if not defined).
656 ++++++++++++++++++++++++++++++++++++++*/
658 static int HTMLTitleType_function(const char *_tag_,int _type_,const char *text)
660 if(_type_&XMLPARSE_TAG_START && store)
664 XMLPARSE_ASSERT_STRING(_tag_,text);
666 xmltext=ParseXML_Encode_Safe_XML(text);
668 translate_html_title=strcpy(malloc(strlen(xmltext)+1),xmltext);
675 /*++++++++++++++++++++++++++++++++++++++
676 The function that is called when the HTMLStartType XSD type is seen
678 int HTMLStartType_function Returns 0 if no error occured or something else otherwise.
680 const char *_tag_ Set to the name of the element tag that triggered this function call.
682 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
684 const char *string The contents of the 'string' attribute (or NULL if not defined).
686 const char *text The contents of the 'text' attribute (or NULL if not defined).
687 ++++++++++++++++++++++++++++++++++++++*/
689 static int HTMLStartType_function(const char *_tag_,int _type_,const char *string,const char *text)
691 if(_type_&XMLPARSE_TAG_START && store)
693 char *xmlstring,*xmltext;
695 XMLPARSE_ASSERT_STRING(_tag_,string);
696 XMLPARSE_ASSERT_STRING(_tag_,text);
698 xmlstring=ParseXML_Encode_Safe_XML(string);
699 xmltext =ParseXML_Encode_Safe_XML(text);
701 translate_html_start[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
702 translate_html_start[1]=malloc(strlen(xmltext)+1+sizeof("<span class='b'>")+sizeof("</span>"));
703 sprintf(translate_html_start[1],xmltext,"%s","<span class='b'>%s</span>");
710 /*++++++++++++++++++++++++++++++++++++++
711 The function that is called when the HTMLNodeType XSD type is seen
713 int HTMLNodeType_function Returns 0 if no error occured or something else otherwise.
715 const char *_tag_ Set to the name of the element tag that triggered this function call.
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.
719 const char *string The contents of the 'string' attribute (or NULL if not defined).
721 const char *text The contents of the 'text' attribute (or NULL if not defined).
722 ++++++++++++++++++++++++++++++++++++++*/
724 static int HTMLNodeType_function(const char *_tag_,int _type_,const char *string,const char *text)
726 if(_type_&XMLPARSE_TAG_START && store)
728 char *xmlstring,*xmltext;
730 XMLPARSE_ASSERT_STRING(_tag_,string);
731 XMLPARSE_ASSERT_STRING(_tag_,text);
733 xmlstring=ParseXML_Encode_Safe_XML(string);
734 xmltext =ParseXML_Encode_Safe_XML(text);
736 translate_html_node[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
737 translate_html_node[1]=malloc(strlen(xmltext)+1+2*sizeof("<span class='b'>")+2*sizeof("</span>"));
738 sprintf(translate_html_node[1],xmltext,"%s","<span class='t'>%s</span>","<span class='b'>%s</span>");
745 /*++++++++++++++++++++++++++++++++++++++
746 The function that is called when the HTMLSegmentType XSD type is seen
748 int HTMLSegmentType_function Returns 0 if no error occured or something else otherwise.
750 const char *_tag_ Set to the name of the element tag that triggered this function call.
752 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
754 const char *string The contents of the 'string' attribute (or NULL if not defined).
756 const char *text The contents of the 'text' attribute (or NULL if not defined).
757 ++++++++++++++++++++++++++++++++++++++*/
759 static int HTMLSegmentType_function(const char *_tag_,int _type_,const char *string,const char *text)
761 if(_type_&XMLPARSE_TAG_START && store)
763 char *xmlstring,*xmltext;
767 XMLPARSE_ASSERT_STRING(_tag_,string);
768 XMLPARSE_ASSERT_STRING(_tag_,text);
770 xmlstring=ParseXML_Encode_Safe_XML(string);
771 xmltext =ParseXML_Encode_Safe_XML(text);
773 translate_html_segment[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
774 translate_html_segment[1]=malloc(strlen(xmltext)+1+2*sizeof("<span class='b'>")+2*sizeof("</span>"));
777 q=translate_html_segment[1];
779 while(*p!='%' && *(p+1)!='s')
783 strcpy(q,"<span class='h'>%s</span>"); q+=sizeof("<span class='h'>%s</span>")-1;
788 strcpy(q,"<span class='d'>"); q+=sizeof("<span class='d'>")-1;
798 /*++++++++++++++++++++++++++++++++++++++
799 The function that is called when the HTMLStopType XSD type is seen
801 int HTMLStopType_function Returns 0 if no error occured or something else otherwise.
803 const char *_tag_ Set to the name of the element tag that triggered this function call.
805 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
807 const char *string The contents of the 'string' attribute (or NULL if not defined).
809 const char *text The contents of the 'text' attribute (or NULL if not defined).
810 ++++++++++++++++++++++++++++++++++++++*/
812 static int HTMLStopType_function(const char *_tag_,int _type_,const char *string,const char *text)
814 if(_type_&XMLPARSE_TAG_START && store)
816 char *xmlstring,*xmltext;
818 XMLPARSE_ASSERT_STRING(_tag_,string);
819 XMLPARSE_ASSERT_STRING(_tag_,text);
821 xmlstring=ParseXML_Encode_Safe_XML(string);
822 xmltext =ParseXML_Encode_Safe_XML(text);
824 translate_html_stop[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
825 translate_html_stop[1]=strcpy(malloc(strlen(xmltext)+1) ,xmltext);
832 /*++++++++++++++++++++++++++++++++++++++
833 The function that is called when the HTMLTotalType XSD type is seen
835 int HTMLTotalType_function Returns 0 if no error occured or something else otherwise.
837 const char *_tag_ Set to the name of the element tag that triggered this function call.
839 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 const char *string The contents of the 'string' attribute (or NULL if not defined).
843 const char *text The contents of the 'text' attribute (or NULL if not defined).
844 ++++++++++++++++++++++++++++++++++++++*/
846 static int HTMLTotalType_function(const char *_tag_,int _type_,const char *string,const char *text)
848 if(_type_&XMLPARSE_TAG_START && store)
850 char *xmlstring,*xmltext;
852 XMLPARSE_ASSERT_STRING(_tag_,string);
853 XMLPARSE_ASSERT_STRING(_tag_,text);
855 xmlstring=ParseXML_Encode_Safe_XML(string);
856 xmltext =ParseXML_Encode_Safe_XML(text);
858 translate_html_total[0]=strcpy(malloc(strlen(xmlstring)+1),xmlstring);
859 translate_html_total[1]=strcpy(malloc(strlen(xmltext)+1) ,xmltext);
866 /*++++++++++++++++++++++++++++++++++++++
867 The function that is called when the HTMLType XSD type is seen
869 int HTMLType_function Returns 0 if no error occured or something else otherwise.
871 const char *_tag_ Set to the name of the element tag that triggered this function call.
873 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
874 ++++++++++++++++++++++++++++++++++++++*/
876 //static int HTMLType_function(const char *_tag_,int _type_)
882 /*++++++++++++++++++++++++++++++++++++++
883 The function that is called when the GPXDescType XSD type is seen
885 int GPXDescType_function Returns 0 if no error occured or something else otherwise.
887 const char *_tag_ Set to the name of the element tag that triggered this function call.
889 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
891 const char *text The contents of the 'text' attribute (or NULL if not defined).
892 ++++++++++++++++++++++++++++++++++++++*/
894 static int GPXDescType_function(const char *_tag_,int _type_,const char *text)
896 if(_type_&XMLPARSE_TAG_START && store)
900 XMLPARSE_ASSERT_STRING(_tag_,text);
902 xmltext=ParseXML_Encode_Safe_XML(text);
904 translate_gpx_desc=strcpy(malloc(strlen(xmltext)+1),xmltext);
911 /*++++++++++++++++++++++++++++++++++++++
912 The function that is called when the GPXNameType XSD type is seen
914 int GPXNameType_function Returns 0 if no error occured or something else otherwise.
916 const char *_tag_ Set to the name of the element tag that triggered this function call.
918 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
920 const char *text The contents of the 'text' attribute (or NULL if not defined).
921 ++++++++++++++++++++++++++++++++++++++*/
923 static int GPXNameType_function(const char *_tag_,int _type_,const char *text)
925 if(_type_&XMLPARSE_TAG_START && store)
929 XMLPARSE_ASSERT_STRING(_tag_,text);
931 xmltext=ParseXML_Encode_Safe_XML(text);
933 translate_gpx_name=strcpy(malloc(strlen(xmltext)+1),xmltext);
940 /*++++++++++++++++++++++++++++++++++++++
941 The function that is called when the GPXStepType XSD type is seen
943 int GPXStepType_function Returns 0 if no error occured or something else otherwise.
945 const char *_tag_ Set to the name of the element tag that triggered this function call.
947 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
949 const char *text The contents of the 'text' attribute (or NULL if not defined).
950 ++++++++++++++++++++++++++++++++++++++*/
952 static int GPXStepType_function(const char *_tag_,int _type_,const char *text)
954 if(_type_&XMLPARSE_TAG_START && store)
958 XMLPARSE_ASSERT_STRING(_tag_,text);
960 xmltext=ParseXML_Encode_Safe_XML(text);
962 translate_gpx_step=strcpy(malloc(strlen(xmltext)+1),xmltext);
969 /*++++++++++++++++++++++++++++++++++++++
970 The function that is called when the GPXFinalType XSD type is seen
972 int GPXFinalType_function Returns 0 if no error occured or something else otherwise.
974 const char *_tag_ Set to the name of the element tag that triggered this function call.
976 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
978 const char *text The contents of the 'text' attribute (or NULL if not defined).
979 ++++++++++++++++++++++++++++++++++++++*/
981 static int GPXFinalType_function(const char *_tag_,int _type_,const char *text)
983 if(_type_&XMLPARSE_TAG_START && store)
987 XMLPARSE_ASSERT_STRING(_tag_,text);
989 xmltext=ParseXML_Encode_Safe_XML(text);
991 translate_gpx_final=strcpy(malloc(strlen(xmltext)+1),xmltext);
998 /*++++++++++++++++++++++++++++++++++++++
999 The function that is called when the GPXType XSD type is seen
1001 int GPXType_function Returns 0 if no error occured or something else otherwise.
1003 const char *_tag_ Set to the name of the element tag that triggered this function call.
1005 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1006 ++++++++++++++++++++++++++++++++++++++*/
1008 //static int GPXType_function(const char *_tag_,int _type_)
1014 /*++++++++++++++++++++++++++++++++++++++
1015 The function that is called when the languageType XSD type is seen
1017 int languageType_function Returns 0 if no error occured or something else otherwise.
1019 const char *_tag_ Set to the name of the element tag that triggered this function call.
1021 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1023 const char *lang The contents of the 'lang' attribute (or NULL if not defined).
1024 ++++++++++++++++++++++++++++++++++++++*/
1026 static int languageType_function(const char *_tag_,int _type_,const char *lang)
1030 if(_type_&XMLPARSE_TAG_START)
1032 XMLPARSE_ASSERT_STRING(_tag_,lang);
1034 if(!store_lang && first)
1036 else if(store_lang && !strcmp(store_lang,lang))
1044 if(_type_&XMLPARSE_TAG_END && store)
1054 /*++++++++++++++++++++++++++++++++++++++
1055 The function that is called when the RoutinoTranslationsType XSD type is seen
1057 int RoutinoTranslationsType_function Returns 0 if no error occured or something else otherwise.
1059 const char *_tag_ Set to the name of the element tag that triggered this function call.
1061 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1062 ++++++++++++++++++++++++++++++++++++++*/
1064 //static int RoutinoTranslationsType_function(const char *_tag_,int _type_)
1070 /*++++++++++++++++++++++++++++++++++++++
1071 The function that is called when the XML declaration is seen
1073 int xmlDeclaration_function Returns 0 if no error occured or something else otherwise.
1075 const char *_tag_ Set to the name of the element tag that triggered this function call.
1077 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
1079 const char *version The contents of the 'version' attribute (or NULL if not defined).
1081 const char *encoding The contents of the 'encoding' attribute (or NULL if not defined).
1082 ++++++++++++++++++++++++++++++++++++++*/
1084 //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding)
1090 /*++++++++++++++++++++++++++++++++++++++
1091 The XML translation parser.
1093 int ParseXMLTranslations Returns 0 if OK or something else in case of an error.
1095 const char *filename The name of the file to read.
1097 const char *language The language to search for (NULL means first in file).
1098 ++++++++++++++++++++++++++++++++++++++*/
1100 int ParseXMLTranslations(const char *filename,const char *language)
1104 store_lang=language;
1106 if(!ExistsFile(filename))
1108 fprintf(stderr,"Error: Specified translations file '%s' does not exist.\n",filename);
1112 FILE *file=fopen(filename,"r");
1116 fprintf(stderr,"Error: Cannot open translations file '%s' for reading.\n",filename);
1120 retval=ParseXML(file,xml_toplevel_tags,XMLPARSE_UNKNOWN_ATTR_ERRNONAME|XMLPARSE_RETURN_ATTR_ENCODED);
1127 if(language && !stored)
1128 fprintf(stderr,"Warning: Cannot find translations for language '%s' using English instead.\n",language);