Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/translations.c
Parent Directory
|
Revision Log
Revision 375 -
(hide annotations)
(download)
(as text)
Sat Apr 24 12:42:57 2010 UTC (14 years, 10 months ago) by amb
File MIME type: text/x-csrc
File size: 23145 byte(s)
Sat Apr 24 12:42:57 2010 UTC (14 years, 10 months ago) by amb
File MIME type: text/x-csrc
File size: 23145 byte(s)
Add the copyright information into the translations.xml file instead of the separate copyright.txt file.
1 | amb | 361 | /*************************************** |
2 | amb | 375 | $Header: /home/amb/CVS/routino/src/translations.c,v 1.6 2010-04-24 12:42:38 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 | #include "functions.h" | ||
30 | #include "translations.h" | ||
31 | #include "xmlparse.h" | ||
32 | |||
33 | |||
34 | /* Global variables - default English values */ | ||
35 | |||
36 | amb | 375 | char *translate_copyright_creator[2]={"Creator","Routino - http://www.gedanken.org.uk/mapping/routino/"}; |
37 | 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 | 361 | char *translate_gpx_desc ="%s between 'start' and 'finish' waypoints"; |
44 | char *translate_gpx_name ="%s Route"; | ||
45 | char *translate_gpx_step ="%s on '%s' for %.3f km, %.1 min"; | ||
46 | char *translate_gpx_final="Total Journey %.1f km, %d minutes"; | ||
47 | |||
48 | char *translate_gpx_shortest="Shortest"; | ||
49 | char *translate_gpx_quickest="Quickest"; | ||
50 | |||
51 | char *translate_gpx_start="START"; | ||
52 | char *translate_gpx_inter="INTER"; | ||
53 | char *translate_gpx_trip="TRIP"; | ||
54 | char *translate_gpx_finish="FINISH"; | ||
55 | |||
56 | |||
57 | /* Local variables */ | ||
58 | |||
59 | /*+ The language that is to be stored. +*/ | ||
60 | static const char *store_lang=NULL; | ||
61 | |||
62 | /*+ This current language is to be stored. +*/ | ||
63 | static int store=0; | ||
64 | |||
65 | /*+ The chosen language has been stored. +*/ | ||
66 | static int stored=0; | ||
67 | |||
68 | |||
69 | /* The XML tag processing function prototypes */ | ||
70 | |||
71 | amb | 373 | //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding); |
72 | //static int RoutinoTranslationsType_function(const char *_tag_,int _type_); | ||
73 | static int languageType_function(const char *_tag_,int _type_,const char *lang); | ||
74 | //static int GPXType_function(const char *_tag_,int _type_); | ||
75 | static int GPXFinalType_function(const char *_tag_,int _type_,const char *text); | ||
76 | static int GPXStepType_function(const char *_tag_,int _type_,const char *text); | ||
77 | static int GPXNameType_function(const char *_tag_,int _type_,const char *text); | ||
78 | static int GPXDescType_function(const char *_tag_,int _type_,const char *text); | ||
79 | static int GPXWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string); | ||
80 | amb | 375 | //static int CopyrightType_function(const char *_tag_,int _type_); |
81 | amb | 373 | static int GPXRouteType_function(const char *_tag_,int _type_,const char *type,const char *string); |
82 | //static int HTMLType_function(const char *_tag_,int _type_); | ||
83 | static int HeadingType_function(const char *_tag_,int _type_,const char *direction,const char *string); | ||
84 | static int TurnType_function(const char *_tag_,int _type_,const char *direction,const char *string); | ||
85 | amb | 375 | static int CopyrightLicenseType_function(const char *_tag_,int _type_,const char *string,const char *text); |
86 | static int CopyrightSourceType_function(const char *_tag_,int _type_,const char *string,const char *text); | ||
87 | static int CopyrightCreatorType_function(const char *_tag_,int _type_,const char *string,const char *text); | ||
88 | amb | 361 | |
89 | |||
90 | /* The XML tag definitions */ | ||
91 | |||
92 | amb | 375 | /*+ The CopyrightCreatorType type tag. +*/ |
93 | static xmltag CopyrightCreatorType_tag= | ||
94 | {"creator", | ||
95 | 2, {"string","text"}, | ||
96 | CopyrightCreatorType_function, | ||
97 | {NULL}}; | ||
98 | |||
99 | /*+ The CopyrightSourceType type tag. +*/ | ||
100 | static xmltag CopyrightSourceType_tag= | ||
101 | {"source", | ||
102 | 2, {"string","text"}, | ||
103 | CopyrightSourceType_function, | ||
104 | {NULL}}; | ||
105 | |||
106 | /*+ The CopyrightLicenseType type tag. +*/ | ||
107 | static xmltag CopyrightLicenseType_tag= | ||
108 | {"license", | ||
109 | 2, {"string","text"}, | ||
110 | CopyrightLicenseType_function, | ||
111 | {NULL}}; | ||
112 | |||
113 | amb | 361 | /*+ The TurnType type tag. +*/ |
114 | amb | 367 | static xmltag TurnType_tag= |
115 | amb | 361 | {"turn", |
116 | 2, {"direction","string"}, | ||
117 | amb | 367 | TurnType_function, |
118 | amb | 361 | {NULL}}; |
119 | |||
120 | /*+ The HeadingType type tag. +*/ | ||
121 | amb | 367 | static xmltag HeadingType_tag= |
122 | amb | 361 | {"heading", |
123 | 2, {"direction","string"}, | ||
124 | amb | 367 | HeadingType_function, |
125 | amb | 361 | {NULL}}; |
126 | |||
127 | /*+ The HTMLType type tag. +*/ | ||
128 | amb | 367 | static xmltag HTMLType_tag= |
129 | amb | 361 | {"output-html", |
130 | 0, {NULL}, | ||
131 | NULL, | ||
132 | {NULL}}; | ||
133 | |||
134 | /*+ The GPXRouteType type tag. +*/ | ||
135 | amb | 367 | static xmltag GPXRouteType_tag= |
136 | amb | 361 | {"route", |
137 | 2, {"type","string"}, | ||
138 | amb | 367 | GPXRouteType_function, |
139 | amb | 361 | {NULL}}; |
140 | |||
141 | amb | 375 | /*+ The CopyrightType type tag. +*/ |
142 | static xmltag CopyrightType_tag= | ||
143 | {"copyright", | ||
144 | 0, {NULL}, | ||
145 | NULL, | ||
146 | {&CopyrightCreatorType_tag,&CopyrightSourceType_tag,&CopyrightLicenseType_tag,NULL}}; | ||
147 | |||
148 | amb | 361 | /*+ The GPXWaypointType type tag. +*/ |
149 | amb | 367 | static xmltag GPXWaypointType_tag= |
150 | amb | 361 | {"waypoint", |
151 | 2, {"type","string"}, | ||
152 | amb | 367 | GPXWaypointType_function, |
153 | amb | 361 | {NULL}}; |
154 | |||
155 | /*+ The GPXDescType type tag. +*/ | ||
156 | amb | 367 | static xmltag GPXDescType_tag= |
157 | amb | 361 | {"desc", |
158 | 1, {"text"}, | ||
159 | amb | 367 | GPXDescType_function, |
160 | amb | 361 | {NULL}}; |
161 | |||
162 | /*+ The GPXNameType type tag. +*/ | ||
163 | amb | 367 | static xmltag GPXNameType_tag= |
164 | amb | 361 | {"name", |
165 | 1, {"text"}, | ||
166 | amb | 367 | GPXNameType_function, |
167 | amb | 361 | {NULL}}; |
168 | |||
169 | /*+ The GPXStepType type tag. +*/ | ||
170 | amb | 367 | static xmltag GPXStepType_tag= |
171 | amb | 361 | {"step", |
172 | 1, {"text"}, | ||
173 | amb | 367 | GPXStepType_function, |
174 | amb | 361 | {NULL}}; |
175 | |||
176 | /*+ The GPXFinalType type tag. +*/ | ||
177 | amb | 367 | static xmltag GPXFinalType_tag= |
178 | amb | 361 | {"final", |
179 | 1, {"text"}, | ||
180 | amb | 367 | GPXFinalType_function, |
181 | amb | 361 | {NULL}}; |
182 | |||
183 | /*+ The GPXType type tag. +*/ | ||
184 | amb | 367 | static xmltag GPXType_tag= |
185 | amb | 361 | {"output-gpx", |
186 | 0, {NULL}, | ||
187 | NULL, | ||
188 | amb | 367 | {&GPXRouteType_tag,&GPXWaypointType_tag,&GPXDescType_tag,&GPXNameType_tag,&GPXStepType_tag,&GPXFinalType_tag,NULL}}; |
189 | amb | 361 | |
190 | /*+ The languageType type tag. +*/ | ||
191 | amb | 367 | static xmltag languageType_tag= |
192 | amb | 361 | {"language", |
193 | 1, {"lang"}, | ||
194 | amb | 367 | languageType_function, |
195 | amb | 375 | {&CopyrightType_tag,&TurnType_tag,&HeadingType_tag,&HTMLType_tag,&GPXType_tag,NULL}}; |
196 | amb | 361 | |
197 | /*+ The RoutinoTranslationsType type tag. +*/ | ||
198 | amb | 367 | static xmltag RoutinoTranslationsType_tag= |
199 | amb | 361 | {"routino-translations", |
200 | 0, {NULL}, | ||
201 | NULL, | ||
202 | amb | 367 | {&languageType_tag,NULL}}; |
203 | amb | 361 | |
204 | amb | 367 | /*+ The xmlDeclaration type tag. +*/ |
205 | static xmltag xmlDeclaration_tag= | ||
206 | amb | 361 | {"xml", |
207 | 2, {"version","encoding"}, | ||
208 | NULL, | ||
209 | {NULL}}; | ||
210 | |||
211 | |||
212 | /*+ The complete set of tags at the top level. +*/ | ||
213 | amb | 367 | static xmltag *xml_toplevel_tags[]={&xmlDeclaration_tag,&RoutinoTranslationsType_tag,NULL}; |
214 | amb | 361 | |
215 | |||
216 | /* The XML tag processing functions */ | ||
217 | |||
218 | |||
219 | /*++++++++++++++++++++++++++++++++++++++ | ||
220 | amb | 375 | The function that is called when the CopyrightCreatorType XSD type is seen |
221 | |||
222 | int CopyrightCreatorType_function Returns 0 if no error occured or something else otherwise. | ||
223 | |||
224 | const char *_tag_ Set to the name of the element tag that triggered this function call. | ||
225 | |||
226 | int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag. | ||
227 | |||
228 | const char *string The contents of the 'string' attribute (or NULL if not defined). | ||
229 | |||
230 | const char *text The contents of the 'text' attribute (or NULL if not defined). | ||
231 | ++++++++++++++++++++++++++++++++++++++*/ | ||
232 | |||
233 | static int CopyrightCreatorType_function(const char *_tag_,int _type_,const char *string,const char *text) | ||
234 | { | ||
235 | if(_type_&XMLPARSE_TAG_START && store) | ||
236 | { | ||
237 | XMLPARSE_ASSERT_STRING(_tag_,string); | ||
238 | XMLPARSE_ASSERT_STRING(_tag_,text); | ||
239 | |||
240 | translate_copyright_creator[0]=strcpy(malloc(strlen(string)+1),string); | ||
241 | translate_copyright_creator[1]=strcpy(malloc(strlen(text)+1),text); | ||
242 | } | ||
243 | |||
244 | return(0); | ||
245 | } | ||
246 | |||
247 | |||
248 | /*++++++++++++++++++++++++++++++++++++++ | ||
249 | The function that is called when the CopyrightSourceType XSD type is seen | ||
250 | |||
251 | int CopyrightSourceType_function Returns 0 if no error occured or something else otherwise. | ||
252 | |||
253 | const char *_tag_ Set to the name of the element tag that triggered this function call. | ||
254 | |||
255 | int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag. | ||
256 | |||
257 | const char *string The contents of the 'string' attribute (or NULL if not defined). | ||
258 | |||
259 | const char *text The contents of the 'text' attribute (or NULL if not defined). | ||
260 | ++++++++++++++++++++++++++++++++++++++*/ | ||
261 | |||
262 | static int CopyrightSourceType_function(const char *_tag_,int _type_,const char *string,const char *text) | ||
263 | { | ||
264 | if(_type_&XMLPARSE_TAG_START && store) | ||
265 | { | ||
266 | XMLPARSE_ASSERT_STRING(_tag_,string); | ||
267 | XMLPARSE_ASSERT_STRING(_tag_,text); | ||
268 | |||
269 | translate_copyright_source[0]=strcpy(malloc(strlen(string)+1),string); | ||
270 | translate_copyright_source[1]=strcpy(malloc(strlen(text)+1),text); | ||
271 | } | ||
272 | |||
273 | return(0); | ||
274 | } | ||
275 | |||
276 | |||
277 | /*++++++++++++++++++++++++++++++++++++++ | ||
278 | The function that is called when the CopyrightLicenseType XSD type is seen | ||
279 | |||
280 | int CopyrightLicenseType_function Returns 0 if no error occured or something else otherwise. | ||
281 | |||
282 | const char *_tag_ Set to the name of the element tag that triggered this function call. | ||
283 | |||
284 | int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag. | ||
285 | |||
286 | const char *string The contents of the 'string' attribute (or NULL if not defined). | ||
287 | |||
288 | const char *text The contents of the 'text' attribute (or NULL if not defined). | ||
289 | ++++++++++++++++++++++++++++++++++++++*/ | ||
290 | |||
291 | static int CopyrightLicenseType_function(const char *_tag_,int _type_,const char *string,const char *text) | ||
292 | { | ||
293 | if(_type_&XMLPARSE_TAG_START && store) | ||
294 | { | ||
295 | XMLPARSE_ASSERT_STRING(_tag_,string); | ||
296 | XMLPARSE_ASSERT_STRING(_tag_,text); | ||
297 | |||
298 | translate_copyright_license[0]=strcpy(malloc(strlen(string)+1),string); | ||
299 | translate_copyright_license[1]=strcpy(malloc(strlen(text)+1),text); | ||
300 | } | ||
301 | |||
302 | return(0); | ||
303 | } | ||
304 | |||
305 | |||
306 | /*++++++++++++++++++++++++++++++++++++++ | ||
307 | amb | 361 | The function that is called when the TurnType XSD type is seen |
308 | |||
309 | amb | 367 | int TurnType_function Returns 0 if no error occured or something else otherwise. |
310 | amb | 363 | |
311 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
312 | |||
313 | 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. |
314 | |||
315 | const char *direction The contents of the 'direction' attribute (or NULL if not defined). | ||
316 | |||
317 | const char *string The contents of the 'string' attribute (or NULL if not defined). | ||
318 | ++++++++++++++++++++++++++++++++++++++*/ | ||
319 | |||
320 | amb | 373 | static int TurnType_function(const char *_tag_,int _type_,const char *direction,const char *string) |
321 | amb | 361 | { |
322 | if(_type_&XMLPARSE_TAG_START && store) | ||
323 | { | ||
324 | int d; | ||
325 | |||
326 | amb | 373 | XMLPARSE_ASSERT_INTEGER(_tag_,direction,d); |
327 | XMLPARSE_ASSERT_STRING(_tag_,string); | ||
328 | amb | 361 | |
329 | amb | 363 | d+=4; |
330 | amb | 361 | |
331 | if(d<0 || d>8) | ||
332 | amb | 373 | XMLPARSE_INVALID(_tag_,direction); |
333 | amb | 361 | |
334 | translate_turn[d]=strcpy(malloc(strlen(string)+1),string); | ||
335 | } | ||
336 | amb | 363 | |
337 | return(0); | ||
338 | amb | 361 | } |
339 | |||
340 | |||
341 | /*++++++++++++++++++++++++++++++++++++++ | ||
342 | The function that is called when the HeadingType XSD type is seen | ||
343 | |||
344 | amb | 367 | int HeadingType_function Returns 0 if no error occured or something else otherwise. |
345 | amb | 363 | |
346 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
347 | |||
348 | 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. |
349 | |||
350 | const char *direction The contents of the 'direction' attribute (or NULL if not defined). | ||
351 | |||
352 | const char *string The contents of the 'string' attribute (or NULL if not defined). | ||
353 | ++++++++++++++++++++++++++++++++++++++*/ | ||
354 | |||
355 | amb | 373 | static int HeadingType_function(const char *_tag_,int _type_,const char *direction,const char *string) |
356 | amb | 361 | { |
357 | if(_type_&XMLPARSE_TAG_START && store) | ||
358 | { | ||
359 | int d; | ||
360 | |||
361 | amb | 373 | XMLPARSE_ASSERT_INTEGER(_tag_,direction,d); |
362 | XMLPARSE_ASSERT_STRING(_tag_,string); | ||
363 | amb | 361 | |
364 | amb | 363 | d+=4; |
365 | amb | 361 | |
366 | if(d<0 || d>8) | ||
367 | amb | 373 | XMLPARSE_INVALID(_tag_,direction); |
368 | amb | 361 | |
369 | translate_heading[d]=strcpy(malloc(strlen(string)+1),string); | ||
370 | } | ||
371 | amb | 363 | |
372 | return(0); | ||
373 | amb | 361 | } |
374 | |||
375 | |||
376 | /*++++++++++++++++++++++++++++++++++++++ | ||
377 | amb | 363 | The function that is called when the HTMLType XSD type is seen |
378 | |||
379 | amb | 367 | int HTMLType_function Returns 0 if no error occured or something else otherwise. |
380 | amb | 363 | |
381 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
382 | |||
383 | 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. |
384 | ++++++++++++++++++++++++++++++++++++++*/ | ||
385 | |||
386 | amb | 373 | //static int HTMLType_function(const char *_tag_,int _type_) |
387 | amb | 363 | //{ |
388 | amb | 375 | // return(0); |
389 | amb | 363 | //} |
390 | |||
391 | |||
392 | /*++++++++++++++++++++++++++++++++++++++ | ||
393 | amb | 361 | The function that is called when the GPXRouteType XSD type is seen |
394 | |||
395 | amb | 367 | int GPXRouteType_function Returns 0 if no error occured or something else otherwise. |
396 | amb | 363 | |
397 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
398 | |||
399 | 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. |
400 | |||
401 | const char *type The contents of the 'type' attribute (or NULL if not defined). | ||
402 | |||
403 | const char *string The contents of the 'string' attribute (or NULL if not defined). | ||
404 | ++++++++++++++++++++++++++++++++++++++*/ | ||
405 | |||
406 | amb | 373 | static int GPXRouteType_function(const char *_tag_,int _type_,const char *type,const char *string) |
407 | amb | 361 | { |
408 | if(_type_&XMLPARSE_TAG_START && store) | ||
409 | { | ||
410 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,type); |
411 | XMLPARSE_ASSERT_STRING(_tag_,string); | ||
412 | amb | 361 | |
413 | if(!strcmp(type,"shortest")) | ||
414 | translate_gpx_shortest=strcpy(malloc(strlen(string)+1),string); | ||
415 | else if(!strcmp(type,"quickest")) | ||
416 | translate_gpx_quickest=strcpy(malloc(strlen(string)+1),string); | ||
417 | else | ||
418 | amb | 373 | XMLPARSE_INVALID(_tag_,type); |
419 | amb | 361 | } |
420 | amb | 363 | |
421 | return(0); | ||
422 | amb | 361 | } |
423 | |||
424 | |||
425 | /*++++++++++++++++++++++++++++++++++++++ | ||
426 | amb | 375 | The function that is called when the CopyrightType XSD type is seen |
427 | |||
428 | int CopyrightType_function Returns 0 if no error occured or something else otherwise. | ||
429 | |||
430 | const char *_tag_ Set to the name of the element tag that triggered this function call. | ||
431 | |||
432 | int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag. | ||
433 | ++++++++++++++++++++++++++++++++++++++*/ | ||
434 | |||
435 | //static int CopyrightType_function(const char *_tag_,int _type_) | ||
436 | //{ | ||
437 | // return(0); | ||
438 | //} | ||
439 | |||
440 | |||
441 | /*++++++++++++++++++++++++++++++++++++++ | ||
442 | amb | 361 | The function that is called when the GPXWaypointType XSD type is seen |
443 | |||
444 | amb | 367 | int GPXWaypointType_function Returns 0 if no error occured or something else otherwise. |
445 | amb | 363 | |
446 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
447 | |||
448 | 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. |
449 | |||
450 | const char *type The contents of the 'type' attribute (or NULL if not defined). | ||
451 | |||
452 | const char *string The contents of the 'string' attribute (or NULL if not defined). | ||
453 | ++++++++++++++++++++++++++++++++++++++*/ | ||
454 | |||
455 | amb | 373 | static int GPXWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string) |
456 | amb | 361 | { |
457 | if(_type_&XMLPARSE_TAG_START && store) | ||
458 | { | ||
459 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,type); |
460 | XMLPARSE_ASSERT_STRING(_tag_,string); | ||
461 | amb | 361 | |
462 | if(!strcmp(type,"start")) | ||
463 | translate_gpx_start=strcpy(malloc(strlen(string)+1),string); | ||
464 | else if(!strcmp(type,"inter")) | ||
465 | translate_gpx_inter=strcpy(malloc(strlen(string)+1),string); | ||
466 | else if(!strcmp(type,"trip")) | ||
467 | translate_gpx_trip=strcpy(malloc(strlen(string)+1),string); | ||
468 | else if(!strcmp(type,"finish")) | ||
469 | translate_gpx_finish=strcpy(malloc(strlen(string)+1),string); | ||
470 | else | ||
471 | amb | 373 | XMLPARSE_INVALID(_tag_,type); |
472 | amb | 361 | } |
473 | amb | 363 | |
474 | return(0); | ||
475 | amb | 361 | } |
476 | |||
477 | |||
478 | /*++++++++++++++++++++++++++++++++++++++ | ||
479 | The function that is called when the GPXDescType XSD type is seen | ||
480 | |||
481 | amb | 367 | int GPXDescType_function Returns 0 if no error occured or something else otherwise. |
482 | amb | 363 | |
483 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
484 | |||
485 | 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. |
486 | |||
487 | const char *text The contents of the 'text' attribute (or NULL if not defined). | ||
488 | ++++++++++++++++++++++++++++++++++++++*/ | ||
489 | |||
490 | amb | 373 | static int GPXDescType_function(const char *_tag_,int _type_,const char *text) |
491 | amb | 361 | { |
492 | if(_type_&XMLPARSE_TAG_START && store) | ||
493 | { | ||
494 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,text); |
495 | amb | 361 | |
496 | translate_gpx_desc=strcpy(malloc(strlen(text)+1),text); | ||
497 | } | ||
498 | amb | 363 | |
499 | return(0); | ||
500 | amb | 361 | } |
501 | |||
502 | |||
503 | /*++++++++++++++++++++++++++++++++++++++ | ||
504 | The function that is called when the GPXNameType XSD type is seen | ||
505 | |||
506 | amb | 367 | int GPXNameType_function Returns 0 if no error occured or something else otherwise. |
507 | amb | 363 | |
508 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
509 | |||
510 | 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. |
511 | |||
512 | const char *text The contents of the 'text' attribute (or NULL if not defined). | ||
513 | ++++++++++++++++++++++++++++++++++++++*/ | ||
514 | |||
515 | amb | 373 | static int GPXNameType_function(const char *_tag_,int _type_,const char *text) |
516 | amb | 361 | { |
517 | if(_type_&XMLPARSE_TAG_START && store) | ||
518 | { | ||
519 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,text); |
520 | amb | 361 | |
521 | translate_gpx_name=strcpy(malloc(strlen(text)+1),text); | ||
522 | } | ||
523 | amb | 363 | |
524 | return(0); | ||
525 | amb | 361 | } |
526 | |||
527 | |||
528 | /*++++++++++++++++++++++++++++++++++++++ | ||
529 | The function that is called when the GPXStepType XSD type is seen | ||
530 | |||
531 | amb | 367 | int GPXStepType_function Returns 0 if no error occured or something else otherwise. |
532 | amb | 363 | |
533 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
534 | |||
535 | 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. |
536 | |||
537 | const char *text The contents of the 'text' attribute (or NULL if not defined). | ||
538 | ++++++++++++++++++++++++++++++++++++++*/ | ||
539 | |||
540 | amb | 373 | static int GPXStepType_function(const char *_tag_,int _type_,const char *text) |
541 | amb | 361 | { |
542 | if(_type_&XMLPARSE_TAG_START && store) | ||
543 | { | ||
544 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,text); |
545 | amb | 361 | |
546 | translate_gpx_step=strcpy(malloc(strlen(text)+1),text); | ||
547 | } | ||
548 | amb | 363 | |
549 | return(0); | ||
550 | amb | 361 | } |
551 | |||
552 | |||
553 | /*++++++++++++++++++++++++++++++++++++++ | ||
554 | The function that is called when the GPXFinalType XSD type is seen | ||
555 | |||
556 | amb | 367 | int GPXFinalType_function Returns 0 if no error occured or something else otherwise. |
557 | amb | 363 | |
558 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
559 | |||
560 | 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. |
561 | |||
562 | const char *text The contents of the 'text' attribute (or NULL if not defined). | ||
563 | ++++++++++++++++++++++++++++++++++++++*/ | ||
564 | |||
565 | amb | 373 | static int GPXFinalType_function(const char *_tag_,int _type_,const char *text) |
566 | amb | 361 | { |
567 | if(_type_&XMLPARSE_TAG_START && store) | ||
568 | { | ||
569 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,text); |
570 | amb | 361 | |
571 | translate_gpx_final=strcpy(malloc(strlen(text)+1),text); | ||
572 | } | ||
573 | amb | 363 | |
574 | return(0); | ||
575 | amb | 361 | } |
576 | |||
577 | |||
578 | /*++++++++++++++++++++++++++++++++++++++ | ||
579 | amb | 363 | The function that is called when the GPXType XSD type is seen |
580 | |||
581 | amb | 367 | int GPXType_function Returns 0 if no error occured or something else otherwise. |
582 | amb | 363 | |
583 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
584 | |||
585 | 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. |
586 | ++++++++++++++++++++++++++++++++++++++*/ | ||
587 | |||
588 | amb | 373 | //static int GPXType_function(const char *_tag_,int _type_) |
589 | amb | 363 | //{ |
590 | amb | 375 | // return(0); |
591 | amb | 363 | //} |
592 | |||
593 | |||
594 | /*++++++++++++++++++++++++++++++++++++++ | ||
595 | amb | 361 | The function that is called when the languageType XSD type is seen |
596 | |||
597 | amb | 367 | int languageType_function Returns 0 if no error occured or something else otherwise. |
598 | amb | 363 | |
599 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
600 | |||
601 | 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. |
602 | |||
603 | const char *lang The contents of the 'lang' attribute (or NULL if not defined). | ||
604 | ++++++++++++++++++++++++++++++++++++++*/ | ||
605 | |||
606 | amb | 373 | static int languageType_function(const char *_tag_,int _type_,const char *lang) |
607 | amb | 361 | { |
608 | static int first=1; | ||
609 | |||
610 | if(_type_&XMLPARSE_TAG_START) | ||
611 | { | ||
612 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,lang); |
613 | amb | 361 | |
614 | if(!store_lang && first) | ||
615 | store=1; | ||
616 | else if(!strcmp(store_lang,lang)) | ||
617 | store=1; | ||
618 | else | ||
619 | store=0; | ||
620 | |||
621 | first=0; | ||
622 | } | ||
623 | |||
624 | if(_type_&XMLPARSE_TAG_END && store) | ||
625 | { | ||
626 | store=0; | ||
627 | stored=1; | ||
628 | } | ||
629 | amb | 363 | |
630 | return(0); | ||
631 | amb | 361 | } |
632 | |||
633 | |||
634 | /*++++++++++++++++++++++++++++++++++++++ | ||
635 | amb | 363 | The function that is called when the RoutinoTranslationsType XSD type is seen |
636 | |||
637 | amb | 367 | int RoutinoTranslationsType_function Returns 0 if no error occured or something else otherwise. |
638 | amb | 363 | |
639 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
640 | |||
641 | 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. |
642 | ++++++++++++++++++++++++++++++++++++++*/ | ||
643 | |||
644 | amb | 373 | //static int RoutinoTranslationsType_function(const char *_tag_,int _type_) |
645 | amb | 363 | //{ |
646 | amb | 375 | // return(0); |
647 | amb | 363 | //} |
648 | |||
649 | |||
650 | /*++++++++++++++++++++++++++++++++++++++ | ||
651 | amb | 367 | The function that is called when the XML declaration is seen |
652 | amb | 363 | |
653 | amb | 367 | int xmlDeclaration_function Returns 0 if no error occured or something else otherwise. |
654 | amb | 363 | |
655 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
656 | |||
657 | 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. |
658 | |||
659 | const char *version The contents of the 'version' attribute (or NULL if not defined). | ||
660 | |||
661 | const char *encoding The contents of the 'encoding' attribute (or NULL if not defined). | ||
662 | ++++++++++++++++++++++++++++++++++++++*/ | ||
663 | |||
664 | amb | 373 | //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding) |
665 | amb | 363 | //{ |
666 | amb | 375 | // return(0); |
667 | amb | 363 | //} |
668 | |||
669 | |||
670 | /*++++++++++++++++++++++++++++++++++++++ | ||
671 | amb | 361 | The XML translation parser. |
672 | |||
673 | int ParseXMLTranslations Returns 0 if OK or something else in case of an error. | ||
674 | |||
675 | const char *filename The name of the file to read. | ||
676 | |||
677 | const char *language The language to search for (NULL means first in file). | ||
678 | ++++++++++++++++++++++++++++++++++++++*/ | ||
679 | |||
680 | int ParseXMLTranslations(const char *filename,const char *language) | ||
681 | { | ||
682 | int retval; | ||
683 | |||
684 | store_lang=language; | ||
685 | |||
686 | if(!ExistsFile(filename)) | ||
687 | { | ||
688 | fprintf(stderr,"Error: Specified translations file '%s' does not exist.\n",filename); | ||
689 | return(1); | ||
690 | } | ||
691 | |||
692 | FILE *file=fopen(filename,"r"); | ||
693 | |||
694 | if(!file) | ||
695 | { | ||
696 | fprintf(stderr,"Error: Cannot open translations file '%s' for reading.\n",filename); | ||
697 | return(1); | ||
698 | } | ||
699 | |||
700 | amb | 375 | retval=ParseXML(file,xml_toplevel_tags,XMLPARSE_UNKNOWN_ATTR_ERRNONAME|XMLPARSE_RETURN_ATTR_ENCODED); |
701 | amb | 361 | |
702 | fclose(file); | ||
703 | |||
704 | amb | 363 | if(retval) |
705 | amb | 361 | return(1); |
706 | |||
707 | if(language && !stored) | ||
708 | fprintf(stderr,"Warning: Cannot find translations for language '%s' using English instead.\n",language); | ||
709 | |||
710 | return(0); | ||
711 | } |
Properties
Name | Value |
---|---|
cvs:description | File containing translation parsing functions. |