Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Annotation of /trunk/src/translations.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 492 - (hide annotations) (download) (as text)
Wed Sep 15 18:30:37 2010 UTC (14 years, 6 months ago) by amb
File MIME type: text/x-csrc
File size: 37002 byte(s)
Add routing on ferries.

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

Properties

Name Value
cvs:description File containing translation parsing functions.