Imported Upstream version 1.4.1
[routino] / src / translations.c
1 /***************************************
2  $Header: /home/amb/routino/src/RCS/translations.c,v 1.10 2010/07/03 10:58:37 amb Exp $
3
4  Load the translations from a file and the functions for handling them.
5
6  Part of the Routino routing software.
7  ******************/ /******************
8  This file Copyright 2010 Andrew M. Bishop
9
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.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU Affero General Public License for more details.
19
20  You should have received a copy of the GNU Affero General Public License
21  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  ***************************************/
23
24
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28
29 #include "functions.h"
30 #include "translations.h"
31 #include "xmlparse.h"
32
33
34 /* Global variables - default English values */
35
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};
39
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"};
42
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"};
44
45 char *translate_route_shortest="Shortest";
46 char *translate_route_quickest="Quickest";
47
48 char *translate_html_waypoint="<span class='w'>Waypoint</span>";
49 char *translate_html_junction="Junction";
50
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"};
57
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";
62
63 char *translate_gpx_start="START";
64 char *translate_gpx_inter="INTER";
65 char *translate_gpx_trip="TRIP";
66 char *translate_gpx_finish="FINISH";
67
68
69 /* Local variables */
70
71 /*+ The language that is to be stored. +*/
72 static const char *store_lang=NULL;
73
74 /*+ This current language is to be stored. +*/
75 static int store=0;
76
77 /*+ The chosen language has been stored. +*/
78 static int stored=0;
79
80
81 /* The XML tag processing function prototypes */
82
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);
108
109
110 /* The XML tag definitions */
111
112 /*+ The CopyrightCreatorType type tag. +*/
113 static xmltag CopyrightCreatorType_tag=
114               {"creator",
115                2, {"string","text"},
116                CopyrightCreatorType_function,
117                {NULL}};
118
119 /*+ The CopyrightSourceType type tag. +*/
120 static xmltag CopyrightSourceType_tag=
121               {"source",
122                2, {"string","text"},
123                CopyrightSourceType_function,
124                {NULL}};
125
126 /*+ The CopyrightLicenseType type tag. +*/
127 static xmltag CopyrightLicenseType_tag=
128               {"license",
129                2, {"string","text"},
130                CopyrightLicenseType_function,
131                {NULL}};
132
133 /*+ The TurnType type tag. +*/
134 static xmltag TurnType_tag=
135               {"turn",
136                2, {"direction","string"},
137                TurnType_function,
138                {NULL}};
139
140 /*+ The HeadingType type tag. +*/
141 static xmltag HeadingType_tag=
142               {"heading",
143                2, {"direction","string"},
144                HeadingType_function,
145                {NULL}};
146
147 /*+ The HighwayType type tag. +*/
148 static xmltag HighwayType_tag=
149               {"highway",
150                2, {"type","string"},
151                HighwayType_function,
152                {NULL}};
153
154 /*+ The RouteType type tag. +*/
155 static xmltag RouteType_tag=
156               {"route",
157                2, {"type","string"},
158                RouteType_function,
159                {NULL}};
160
161 /*+ The HTMLWaypointType type tag. +*/
162 static xmltag HTMLWaypointType_tag=
163               {"waypoint",
164                2, {"type","string"},
165                HTMLWaypointType_function,
166                {NULL}};
167
168 /*+ The GPXWaypointType type tag. +*/
169 static xmltag GPXWaypointType_tag=
170               {"waypoint",
171                2, {"type","string"},
172                GPXWaypointType_function,
173                {NULL}};
174
175 /*+ The CopyrightType type tag. +*/
176 static xmltag CopyrightType_tag=
177               {"copyright",
178                0, {NULL},
179                NULL,
180                {&CopyrightCreatorType_tag,&CopyrightSourceType_tag,&CopyrightLicenseType_tag,NULL}};
181
182 /*+ The HTMLTitleType type tag. +*/
183 static xmltag HTMLTitleType_tag=
184               {"title",
185                1, {"text"},
186                HTMLTitleType_function,
187                {NULL}};
188
189 /*+ The HTMLStartType type tag. +*/
190 static xmltag HTMLStartType_tag=
191               {"start",
192                2, {"string","text"},
193                HTMLStartType_function,
194                {NULL}};
195
196 /*+ The HTMLNodeType type tag. +*/
197 static xmltag HTMLNodeType_tag=
198               {"node",
199                2, {"string","text"},
200                HTMLNodeType_function,
201                {NULL}};
202
203 /*+ The HTMLSegmentType type tag. +*/
204 static xmltag HTMLSegmentType_tag=
205               {"segment",
206                2, {"string","text"},
207                HTMLSegmentType_function,
208                {NULL}};
209
210 /*+ The HTMLStopType type tag. +*/
211 static xmltag HTMLStopType_tag=
212               {"stop",
213                2, {"string","text"},
214                HTMLStopType_function,
215                {NULL}};
216
217 /*+ The HTMLTotalType type tag. +*/
218 static xmltag HTMLTotalType_tag=
219               {"total",
220                2, {"string","text"},
221                HTMLTotalType_function,
222                {NULL}};
223
224 /*+ The HTMLType type tag. +*/
225 static xmltag HTMLType_tag=
226               {"output-html",
227                0, {NULL},
228                NULL,
229                {&HTMLWaypointType_tag,&HTMLTitleType_tag,&HTMLStartType_tag,&HTMLNodeType_tag,&HTMLSegmentType_tag,&HTMLStopType_tag,&HTMLTotalType_tag,NULL}};
230
231 /*+ The GPXDescType type tag. +*/
232 static xmltag GPXDescType_tag=
233               {"desc",
234                1, {"text"},
235                GPXDescType_function,
236                {NULL}};
237
238 /*+ The GPXNameType type tag. +*/
239 static xmltag GPXNameType_tag=
240               {"name",
241                1, {"text"},
242                GPXNameType_function,
243                {NULL}};
244
245 /*+ The GPXStepType type tag. +*/
246 static xmltag GPXStepType_tag=
247               {"step",
248                1, {"text"},
249                GPXStepType_function,
250                {NULL}};
251
252 /*+ The GPXFinalType type tag. +*/
253 static xmltag GPXFinalType_tag=
254               {"final",
255                1, {"text"},
256                GPXFinalType_function,
257                {NULL}};
258
259 /*+ The GPXType type tag. +*/
260 static 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 languageType type tag. +*/
267 static xmltag languageType_tag=
268               {"language",
269                1, {"lang"},
270                languageType_function,
271                {&CopyrightType_tag,&TurnType_tag,&HeadingType_tag,&HighwayType_tag,&RouteType_tag,&HTMLType_tag,&GPXType_tag,NULL}};
272
273 /*+ The RoutinoTranslationsType type tag. +*/
274 static xmltag RoutinoTranslationsType_tag=
275               {"routino-translations",
276                0, {NULL},
277                NULL,
278                {&languageType_tag,NULL}};
279
280 /*+ The xmlDeclaration type tag. +*/
281 static xmltag xmlDeclaration_tag=
282               {"xml",
283                2, {"version","encoding"},
284                NULL,
285                {NULL}};
286
287
288 /*+ The complete set of tags at the top level. +*/
289 static xmltag *xml_toplevel_tags[]={&xmlDeclaration_tag,&RoutinoTranslationsType_tag,NULL};
290
291
292 /* The XML tag processing functions */
293
294
295 /*++++++++++++++++++++++++++++++++++++++
296   The function that is called when the CopyrightCreatorType XSD type is seen
297
298   int CopyrightCreatorType_function Returns 0 if no error occured or something else otherwise.
299
300   const char *_tag_ Set to the name of the element tag that triggered this function call.
301
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.
303
304   const char *string The contents of the 'string' attribute (or NULL if not defined).
305
306   const char *text The contents of the 'text' attribute (or NULL if not defined).
307   ++++++++++++++++++++++++++++++++++++++*/
308
309 static int CopyrightCreatorType_function(const char *_tag_,int _type_,const char *string,const char *text)
310 {
311  if(_type_&XMLPARSE_TAG_START && store)
312    {
313     XMLPARSE_ASSERT_STRING(_tag_,string);
314     XMLPARSE_ASSERT_STRING(_tag_,text);
315
316     translate_copyright_creator[0]=strcpy(malloc(strlen(string)+1),string);
317     translate_copyright_creator[1]=strcpy(malloc(strlen(text)+1),text);
318    }
319
320  return(0);
321 }
322
323
324 /*++++++++++++++++++++++++++++++++++++++
325   The function that is called when the CopyrightSourceType XSD type is seen
326
327   int CopyrightSourceType_function Returns 0 if no error occured or something else otherwise.
328
329   const char *_tag_ Set to the name of the element tag that triggered this function call.
330
331   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
332
333   const char *string The contents of the 'string' attribute (or NULL if not defined).
334
335   const char *text The contents of the 'text' attribute (or NULL if not defined).
336   ++++++++++++++++++++++++++++++++++++++*/
337
338 static int CopyrightSourceType_function(const char *_tag_,int _type_,const char *string,const char *text)
339 {
340  if(_type_&XMLPARSE_TAG_START && store)
341    {
342     XMLPARSE_ASSERT_STRING(_tag_,string);
343     XMLPARSE_ASSERT_STRING(_tag_,text);
344
345     translate_copyright_source[0]=strcpy(malloc(strlen(string)+1),string);
346     translate_copyright_source[1]=strcpy(malloc(strlen(text)+1),text);
347    }
348
349  return(0);
350 }
351
352
353 /*++++++++++++++++++++++++++++++++++++++
354   The function that is called when the CopyrightLicenseType XSD type is seen
355
356   int CopyrightLicenseType_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 CopyrightLicenseType_function(const char *_tag_,int _type_,const char *string,const char *text)
368 {
369  if(_type_&XMLPARSE_TAG_START && store)
370    {
371     XMLPARSE_ASSERT_STRING(_tag_,string);
372     XMLPARSE_ASSERT_STRING(_tag_,text);
373
374     translate_copyright_license[0]=strcpy(malloc(strlen(string)+1),string);
375     translate_copyright_license[1]=strcpy(malloc(strlen(text)+1),text);
376    }
377
378  return(0);
379 }
380
381
382 /*++++++++++++++++++++++++++++++++++++++
383   The function that is called when the TurnType XSD type is seen
384
385   int TurnType_function Returns 0 if no error occured or something else otherwise.
386
387   const char *_tag_ Set to the name of the element tag that triggered this function call.
388
389   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
390
391   const char *direction The contents of the 'direction' attribute (or NULL if not defined).
392
393   const char *string The contents of the 'string' attribute (or NULL if not defined).
394   ++++++++++++++++++++++++++++++++++++++*/
395
396 static int TurnType_function(const char *_tag_,int _type_,const char *direction,const char *string)
397 {
398  if(_type_&XMLPARSE_TAG_START && store)
399    {
400     int d;
401
402     XMLPARSE_ASSERT_INTEGER(_tag_,direction,d);
403     XMLPARSE_ASSERT_STRING(_tag_,string);
404
405     d+=4;
406
407     if(d<0 || d>8)
408        XMLPARSE_INVALID(_tag_,direction);
409
410     translate_turn[d]=strcpy(malloc(strlen(string)+1),string);
411    }
412
413  return(0);
414 }
415
416
417 /*++++++++++++++++++++++++++++++++++++++
418   The function that is called when the HeadingType XSD type is seen
419
420   int HeadingType_function Returns 0 if no error occured or something else otherwise.
421
422   const char *_tag_ Set to the name of the element tag that triggered this function call.
423
424   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
425
426   const char *direction The contents of the 'direction' attribute (or NULL if not defined).
427
428   const char *string The contents of the 'string' attribute (or NULL if not defined).
429   ++++++++++++++++++++++++++++++++++++++*/
430
431 static int HeadingType_function(const char *_tag_,int _type_,const char *direction,const char *string)
432 {
433  if(_type_&XMLPARSE_TAG_START && store)
434    {
435     int d;
436
437     XMLPARSE_ASSERT_INTEGER(_tag_,direction,d);
438     XMLPARSE_ASSERT_STRING(_tag_,string);
439
440     d+=4;
441
442     if(d<0 || d>8)
443        XMLPARSE_INVALID(_tag_,direction);
444
445     translate_heading[d]=strcpy(malloc(strlen(string)+1),string);
446    }
447
448  return(0);
449 }
450
451
452 /*++++++++++++++++++++++++++++++++++++++
453   The function that is called when the HighwayType XSD type is seen
454
455   int HighwayType_function Returns 0 if no error occured or something else otherwise.
456
457   const char *_tag_ Set to the name of the element tag that triggered this function call.
458
459   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
460
461   const char *type The contents of the 'type' attribute (or NULL if not defined).
462
463   const char *string The contents of the 'string' attribute (or NULL if not defined).
464   ++++++++++++++++++++++++++++++++++++++*/
465
466 static int HighwayType_function(const char *_tag_,int _type_,const char *type,const char *string)
467 {
468  if(_type_&XMLPARSE_TAG_START && store)
469    {
470     Highway highway;
471
472     XMLPARSE_ASSERT_STRING(_tag_,type);
473     XMLPARSE_ASSERT_STRING(_tag_,string);
474
475     highway=HighwayType(type);
476
477     if(highway==Way_Count)
478        XMLPARSE_INVALID(_tag_,type);
479
480     translate_highway[highway]=strcpy(malloc(strlen(string)+1),string);
481    }
482
483  return(0);
484 }
485
486
487 /*++++++++++++++++++++++++++++++++++++++
488   The function that is called when the RouteType XSD type is seen
489
490   int RouteType_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   const char *type The contents of the 'type' attribute (or NULL if not defined).
497
498   const char *string The contents of the 'string' attribute (or NULL if not defined).
499   ++++++++++++++++++++++++++++++++++++++*/
500
501 static int RouteType_function(const char *_tag_,int _type_,const char *type,const char *string)
502 {
503  if(_type_&XMLPARSE_TAG_START && store)
504    {
505     XMLPARSE_ASSERT_STRING(_tag_,type);
506     XMLPARSE_ASSERT_STRING(_tag_,string);
507
508     if(!strcmp(type,"shortest"))
509        translate_route_shortest=strcpy(malloc(strlen(string)+1),string);
510     else if(!strcmp(type,"quickest"))
511        translate_route_quickest=strcpy(malloc(strlen(string)+1),string);
512     else
513        XMLPARSE_INVALID(_tag_,type);
514    }
515
516  return(0);
517 }
518
519
520 /*++++++++++++++++++++++++++++++++++++++
521   The function that is called when the HTMLWaypointType XSD type is seen
522
523   int HTMLWaypointType_function Returns 0 if no error occured or something else otherwise.
524
525   const char *_tag_ Set to the name of the element tag that triggered this function call.
526
527   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
528
529   const char *type The contents of the 'type' attribute (or NULL if not defined).
530
531   const char *string The contents of the 'string' attribute (or NULL if not defined).
532   ++++++++++++++++++++++++++++++++++++++*/
533
534 static int HTMLWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string)
535 {
536  if(_type_&XMLPARSE_TAG_START && store)
537    {
538     XMLPARSE_ASSERT_STRING(_tag_,type);
539     XMLPARSE_ASSERT_STRING(_tag_,string);
540
541     if(!strcmp(type,"waypoint"))
542       {
543        translate_html_waypoint=malloc(strlen(string)+1+sizeof("<span class='w'>")+sizeof("</span>"));
544        sprintf(translate_html_waypoint,"<span class='w'>%s</span>",string);
545       }
546     else if(!strcmp(type,"junction"))
547        translate_html_junction=strcpy(malloc(strlen(string)+1),string);
548     else
549        XMLPARSE_INVALID(_tag_,type);
550    }
551
552  return(0);
553 }
554
555
556 /*++++++++++++++++++++++++++++++++++++++
557   The function that is called when the GPXWaypointType XSD type is seen
558
559   int GPXWaypointType_function Returns 0 if no error occured or something else otherwise.
560
561   const char *_tag_ Set to the name of the element tag that triggered this function call.
562
563   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
564
565   const char *type The contents of the 'type' attribute (or NULL if not defined).
566
567   const char *string The contents of the 'string' attribute (or NULL if not defined).
568   ++++++++++++++++++++++++++++++++++++++*/
569
570 static int GPXWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string)
571 {
572  if(_type_&XMLPARSE_TAG_START && store)
573    {
574     XMLPARSE_ASSERT_STRING(_tag_,type);
575     XMLPARSE_ASSERT_STRING(_tag_,string);
576
577     if(!strcmp(type,"start"))
578        translate_gpx_start=strcpy(malloc(strlen(string)+1),string);
579     else if(!strcmp(type,"inter"))
580        translate_gpx_inter=strcpy(malloc(strlen(string)+1),string);
581     else if(!strcmp(type,"trip"))
582        translate_gpx_trip=strcpy(malloc(strlen(string)+1),string);
583     else if(!strcmp(type,"finish"))
584        translate_gpx_finish=strcpy(malloc(strlen(string)+1),string);
585     else
586        XMLPARSE_INVALID(_tag_,type);
587    }
588
589  return(0);
590 }
591
592
593 /*++++++++++++++++++++++++++++++++++++++
594   The function that is called when the CopyrightType XSD type is seen
595
596   int CopyrightType_function Returns 0 if no error occured or something else otherwise.
597
598   const char *_tag_ Set to the name of the element tag that triggered this function call.
599
600   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
601   ++++++++++++++++++++++++++++++++++++++*/
602
603 //static int CopyrightType_function(const char *_tag_,int _type_)
604 //{
605 // return(0);
606 //}
607
608
609 /*++++++++++++++++++++++++++++++++++++++
610   The function that is called when the HTMLTitleType XSD type is seen
611
612   int HTMLTitleType_function Returns 0 if no error occured or something else otherwise.
613
614   const char *_tag_ Set to the name of the element tag that triggered this function call.
615
616   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
617
618   const char *text The contents of the 'text' attribute (or NULL if not defined).
619   ++++++++++++++++++++++++++++++++++++++*/
620
621 static int HTMLTitleType_function(const char *_tag_,int _type_,const char *text)
622 {
623  if(_type_&XMLPARSE_TAG_START && store)
624    {
625     XMLPARSE_ASSERT_STRING(_tag_,text);
626
627     translate_html_title=strcpy(malloc(strlen(text)+1),text);
628    }
629
630  return(0);
631 }
632
633
634 /*++++++++++++++++++++++++++++++++++++++
635   The function that is called when the HTMLStartType XSD type is seen
636
637   int HTMLStartType_function Returns 0 if no error occured or something else otherwise.
638
639   const char *_tag_ Set to the name of the element tag that triggered this function call.
640
641   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
642
643   const char *string The contents of the 'string' attribute (or NULL if not defined).
644
645   const char *text The contents of the 'text' attribute (or NULL if not defined).
646   ++++++++++++++++++++++++++++++++++++++*/
647
648 static int HTMLStartType_function(const char *_tag_,int _type_,const char *string,const char *text)
649 {
650  if(_type_&XMLPARSE_TAG_START && store)
651    {
652     XMLPARSE_ASSERT_STRING(_tag_,string);
653     XMLPARSE_ASSERT_STRING(_tag_,text);
654
655     translate_html_start[0]=strcpy(malloc(strlen(string)+1),string);
656     translate_html_start[1]=malloc(strlen(text)+1+sizeof("<span class='b'>")+sizeof("</span>"));
657     sprintf(translate_html_start[1],text,"%s","<span class='b'>%s</span>");
658    }
659
660  return(0);
661 }
662
663
664 /*++++++++++++++++++++++++++++++++++++++
665   The function that is called when the HTMLNodeType XSD type is seen
666
667   int HTMLNodeType_function Returns 0 if no error occured or something else otherwise.
668
669   const char *_tag_ Set to the name of the element tag that triggered this function call.
670
671   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
672
673   const char *string The contents of the 'string' attribute (or NULL if not defined).
674
675   const char *text The contents of the 'text' attribute (or NULL if not defined).
676   ++++++++++++++++++++++++++++++++++++++*/
677
678 static int HTMLNodeType_function(const char *_tag_,int _type_,const char *string,const char *text)
679 {
680  if(_type_&XMLPARSE_TAG_START && store)
681    {
682     XMLPARSE_ASSERT_STRING(_tag_,string);
683     XMLPARSE_ASSERT_STRING(_tag_,text);
684
685     translate_html_node[0]=strcpy(malloc(strlen(string)+1),string);
686     translate_html_node[1]=malloc(strlen(text)+1+2*sizeof("<span class='b'>")+2*sizeof("</span>"));
687     sprintf(translate_html_node[1],text,"%s","<span class='t'>%s</span>","<span class='b'>%s</span>");
688    }
689
690  return(0);
691 }
692
693
694 /*++++++++++++++++++++++++++++++++++++++
695   The function that is called when the HTMLSegmentType XSD type is seen
696
697   int HTMLSegmentType_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   const char *string The contents of the 'string' attribute (or NULL if not defined).
704
705   const char *text The contents of the 'text' attribute (or NULL if not defined).
706   ++++++++++++++++++++++++++++++++++++++*/
707
708 static int HTMLSegmentType_function(const char *_tag_,int _type_,const char *string,const char *text)
709 {
710  if(_type_&XMLPARSE_TAG_START && store)
711    {
712     const char *p;
713     char *q;
714
715     XMLPARSE_ASSERT_STRING(_tag_,string);
716     XMLPARSE_ASSERT_STRING(_tag_,text);
717
718     translate_html_segment[0]=strcpy(malloc(strlen(string)+1),string);
719     translate_html_segment[1]=malloc(strlen(text)+1+2*sizeof("<span class='b'>")+2*sizeof("</span>"));
720
721     p=text;
722     q=translate_html_segment[1];
723
724     while(*p!='%' && *(p+1)!='s')
725        *q++=*p++;
726
727     p+=2;
728     strcpy(q,"<span class='h'>%s</span>"); q+=sizeof("<span class='h'>%s</span>")-1;
729
730     while(*p!='%')
731        *q++=*p++;
732
733     strcpy(q,"<span class='d'>"); q+=sizeof("<span class='d'>")-1;
734
735     strcpy(q,p);
736     strcat(q,"</span>");
737    }
738
739  return(0);
740 }
741
742
743 /*++++++++++++++++++++++++++++++++++++++
744   The function that is called when the HTMLStopType XSD type is seen
745
746   int HTMLStopType_function Returns 0 if no error occured or something else otherwise.
747
748   const char *_tag_ Set to the name of the element tag that triggered this function call.
749
750   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
751
752   const char *string The contents of the 'string' attribute (or NULL if not defined).
753
754   const char *text The contents of the 'text' attribute (or NULL if not defined).
755   ++++++++++++++++++++++++++++++++++++++*/
756
757 static int HTMLStopType_function(const char *_tag_,int _type_,const char *string,const char *text)
758 {
759  if(_type_&XMLPARSE_TAG_START && store)
760    {
761     XMLPARSE_ASSERT_STRING(_tag_,string);
762     XMLPARSE_ASSERT_STRING(_tag_,text);
763
764     translate_html_stop[0]=strcpy(malloc(strlen(string)+1),string);
765     translate_html_stop[1]=strcpy(malloc(strlen(text)+1),text);
766    }
767
768  return(0);
769 }
770
771
772 /*++++++++++++++++++++++++++++++++++++++
773   The function that is called when the HTMLTotalType XSD type is seen
774
775   int HTMLTotalType_function Returns 0 if no error occured or something else otherwise.
776
777   const char *_tag_ Set to the name of the element tag that triggered this function call.
778
779   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
780
781   const char *string The contents of the 'string' attribute (or NULL if not defined).
782
783   const char *text The contents of the 'text' attribute (or NULL if not defined).
784   ++++++++++++++++++++++++++++++++++++++*/
785
786 static int HTMLTotalType_function(const char *_tag_,int _type_,const char *string,const char *text)
787 {
788  if(_type_&XMLPARSE_TAG_START && store)
789    {
790     XMLPARSE_ASSERT_STRING(_tag_,string);
791     XMLPARSE_ASSERT_STRING(_tag_,text);
792
793     translate_html_total[0]=strcpy(malloc(strlen(string)+1),string);
794     translate_html_total[1]=strcpy(malloc(strlen(text)+1),text);
795    }
796
797  return(0);
798 }
799
800
801 /*++++++++++++++++++++++++++++++++++++++
802   The function that is called when the HTMLType XSD type is seen
803
804   int HTMLType_function Returns 0 if no error occured or something else otherwise.
805
806   const char *_tag_ Set to the name of the element tag that triggered this function call.
807
808   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
809   ++++++++++++++++++++++++++++++++++++++*/
810
811 //static int HTMLType_function(const char *_tag_,int _type_)
812 //{
813 // return(0);
814 //}
815
816
817 /*++++++++++++++++++++++++++++++++++++++
818   The function that is called when the GPXDescType XSD type is seen
819
820   int GPXDescType_function Returns 0 if no error occured or something else otherwise.
821
822   const char *_tag_ Set to the name of the element tag that triggered this function call.
823
824   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
825
826   const char *text The contents of the 'text' attribute (or NULL if not defined).
827   ++++++++++++++++++++++++++++++++++++++*/
828
829 static int GPXDescType_function(const char *_tag_,int _type_,const char *text)
830 {
831  if(_type_&XMLPARSE_TAG_START && store)
832    {
833     XMLPARSE_ASSERT_STRING(_tag_,text);
834
835     translate_gpx_desc=strcpy(malloc(strlen(text)+1),text);
836    }
837
838  return(0);
839 }
840
841
842 /*++++++++++++++++++++++++++++++++++++++
843   The function that is called when the GPXNameType XSD type is seen
844
845   int GPXNameType_function Returns 0 if no error occured or something else otherwise.
846
847   const char *_tag_ Set to the name of the element tag that triggered this function call.
848
849   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
850
851   const char *text The contents of the 'text' attribute (or NULL if not defined).
852   ++++++++++++++++++++++++++++++++++++++*/
853
854 static int GPXNameType_function(const char *_tag_,int _type_,const char *text)
855 {
856  if(_type_&XMLPARSE_TAG_START && store)
857    {
858     XMLPARSE_ASSERT_STRING(_tag_,text);
859
860     translate_gpx_name=strcpy(malloc(strlen(text)+1),text);
861    }
862
863  return(0);
864 }
865
866
867 /*++++++++++++++++++++++++++++++++++++++
868   The function that is called when the GPXStepType XSD type is seen
869
870   int GPXStepType_function Returns 0 if no error occured or something else otherwise.
871
872   const char *_tag_ Set to the name of the element tag that triggered this function call.
873
874   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
875
876   const char *text The contents of the 'text' attribute (or NULL if not defined).
877   ++++++++++++++++++++++++++++++++++++++*/
878
879 static int GPXStepType_function(const char *_tag_,int _type_,const char *text)
880 {
881  if(_type_&XMLPARSE_TAG_START && store)
882    {
883     XMLPARSE_ASSERT_STRING(_tag_,text);
884
885     translate_gpx_step=strcpy(malloc(strlen(text)+1),text);
886    }
887
888  return(0);
889 }
890
891
892 /*++++++++++++++++++++++++++++++++++++++
893   The function that is called when the GPXFinalType XSD type is seen
894
895   int GPXFinalType_function Returns 0 if no error occured or something else otherwise.
896
897   const char *_tag_ Set to the name of the element tag that triggered this function call.
898
899   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
900
901   const char *text The contents of the 'text' attribute (or NULL if not defined).
902   ++++++++++++++++++++++++++++++++++++++*/
903
904 static int GPXFinalType_function(const char *_tag_,int _type_,const char *text)
905 {
906  if(_type_&XMLPARSE_TAG_START && store)
907    {
908     XMLPARSE_ASSERT_STRING(_tag_,text);
909
910     translate_gpx_final=strcpy(malloc(strlen(text)+1),text);
911    }
912
913  return(0);
914 }
915
916
917 /*++++++++++++++++++++++++++++++++++++++
918   The function that is called when the GPXType XSD type is seen
919
920   int GPXType_function Returns 0 if no error occured or something else otherwise.
921
922   const char *_tag_ Set to the name of the element tag that triggered this function call.
923
924   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
925   ++++++++++++++++++++++++++++++++++++++*/
926
927 //static int GPXType_function(const char *_tag_,int _type_)
928 //{
929 // return(0);
930 //}
931
932
933 /*++++++++++++++++++++++++++++++++++++++
934   The function that is called when the languageType XSD type is seen
935
936   int languageType_function Returns 0 if no error occured or something else otherwise.
937
938   const char *_tag_ Set to the name of the element tag that triggered this function call.
939
940   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
941
942   const char *lang The contents of the 'lang' attribute (or NULL if not defined).
943   ++++++++++++++++++++++++++++++++++++++*/
944
945 static int languageType_function(const char *_tag_,int _type_,const char *lang)
946 {
947  static int first=1;
948
949  if(_type_&XMLPARSE_TAG_START)
950    {
951     XMLPARSE_ASSERT_STRING(_tag_,lang);
952
953     if(!store_lang && first)
954        store=1;
955     else if(store_lang && !strcmp(store_lang,lang))
956        store=1;
957     else
958        store=0;
959
960     first=0;
961    }
962
963  if(_type_&XMLPARSE_TAG_END && store)
964    {
965     store=0;
966     stored=1;
967    }
968
969  return(0);
970 }
971
972
973 /*++++++++++++++++++++++++++++++++++++++
974   The function that is called when the RoutinoTranslationsType XSD type is seen
975
976   int RoutinoTranslationsType_function Returns 0 if no error occured or something else otherwise.
977
978   const char *_tag_ Set to the name of the element tag that triggered this function call.
979
980   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
981   ++++++++++++++++++++++++++++++++++++++*/
982
983 //static int RoutinoTranslationsType_function(const char *_tag_,int _type_)
984 //{
985 // return(0);
986 //}
987
988
989 /*++++++++++++++++++++++++++++++++++++++
990   The function that is called when the XML declaration is seen
991
992   int xmlDeclaration_function Returns 0 if no error occured or something else otherwise.
993
994   const char *_tag_ Set to the name of the element tag that triggered this function call.
995
996   int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
997
998   const char *version The contents of the 'version' attribute (or NULL if not defined).
999
1000   const char *encoding The contents of the 'encoding' attribute (or NULL if not defined).
1001   ++++++++++++++++++++++++++++++++++++++*/
1002
1003 //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding)
1004 //{
1005 // return(0);
1006 //}
1007
1008
1009 /*++++++++++++++++++++++++++++++++++++++
1010   The XML translation parser.
1011
1012   int ParseXMLTranslations Returns 0 if OK or something else in case of an error.
1013
1014   const char *filename The name of the file to read.
1015
1016   const char *language The language to search for (NULL means first in file).
1017   ++++++++++++++++++++++++++++++++++++++*/
1018
1019 int ParseXMLTranslations(const char *filename,const char *language)
1020 {
1021  int retval;
1022
1023  store_lang=language;
1024
1025  if(!ExistsFile(filename))
1026    {
1027     fprintf(stderr,"Error: Specified translations file '%s' does not exist.\n",filename);
1028     return(1);
1029    }
1030
1031  FILE *file=fopen(filename,"r");
1032
1033  if(!file)
1034    {
1035     fprintf(stderr,"Error: Cannot open translations file '%s' for reading.\n",filename);
1036     return(1);
1037    }
1038
1039  retval=ParseXML(file,xml_toplevel_tags,XMLPARSE_UNKNOWN_ATTR_ERRNONAME|XMLPARSE_RETURN_ATTR_ENCODED);
1040
1041  fclose(file);
1042
1043  if(retval)
1044     return(1);
1045
1046  if(language && !stored)
1047     fprintf(stderr,"Warning: Cannot find translations for language '%s' using English instead.\n",language);
1048
1049  return(0);
1050 }