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 892 - (show annotations) (download) (as text)
Thu Nov 10 17:43:43 2011 UTC (13 years, 4 months ago) by amb
File MIME type: text/x-csrc
File size: 36882 byte(s)
Don't convert the highway types to XML numeric entities here (it is already done
in the output functions).

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

Properties

Name Value
cvs:description File containing translation parsing functions.