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 893 - (show annotations) (download) (as text)
Thu Nov 10 19:12:40 2011 UTC (13 years, 4 months ago) by amb
File MIME type: text/x-csrc
File size: 37632 byte(s)
Change the names of the variables for the XML and raw versions of the
translations.  Output the text files with the raw versions and not the XML
versions of the copyright information.  Update the documentation to say that
only the copyright information is translated in the text files.

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

Properties

Name Value
cvs:description File containing translation parsing functions.