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 373 -
(hide annotations)
(download)
(as text)
Fri Apr 23 18:41:20 2010 UTC (14 years, 10 months ago) by amb
File MIME type: text/x-csrc
File size: 17927 byte(s)
Fri Apr 23 18:41:20 2010 UTC (14 years, 10 months ago) by amb
File MIME type: text/x-csrc
File size: 17927 byte(s)
Pass the tag name to the tag function.
1 | amb | 361 | /*************************************** |
2 | amb | 373 | $Header: /home/amb/CVS/routino/src/translations.c,v 1.5 2010-04-23 18:41:09 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 | char *translate_heading[9] ={"South","South-West","West","North-West","North","North-East","East","South-East","South"}; | ||
37 | char *translate_turn[9] ={"Very sharp left","Sharp left","Left","Slight left","Straight on","Slight right","Right","Sharp right","Very sharp right"}; | ||
38 | |||
39 | char *translate_gpx_desc ="%s between 'start' and 'finish' waypoints"; | ||
40 | char *translate_gpx_name ="%s Route"; | ||
41 | char *translate_gpx_step ="%s on '%s' for %.3f km, %.1 min"; | ||
42 | char *translate_gpx_final="Total Journey %.1f km, %d minutes"; | ||
43 | |||
44 | char *translate_gpx_shortest="Shortest"; | ||
45 | char *translate_gpx_quickest="Quickest"; | ||
46 | |||
47 | char *translate_gpx_start="START"; | ||
48 | char *translate_gpx_inter="INTER"; | ||
49 | char *translate_gpx_trip="TRIP"; | ||
50 | char *translate_gpx_finish="FINISH"; | ||
51 | |||
52 | |||
53 | /* Local variables */ | ||
54 | |||
55 | /*+ The language that is to be stored. +*/ | ||
56 | static const char *store_lang=NULL; | ||
57 | |||
58 | /*+ This current language is to be stored. +*/ | ||
59 | static int store=0; | ||
60 | |||
61 | /*+ The chosen language has been stored. +*/ | ||
62 | static int stored=0; | ||
63 | |||
64 | |||
65 | /* The XML tag processing function prototypes */ | ||
66 | |||
67 | amb | 373 | //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding); |
68 | //static int RoutinoTranslationsType_function(const char *_tag_,int _type_); | ||
69 | static int languageType_function(const char *_tag_,int _type_,const char *lang); | ||
70 | //static int GPXType_function(const char *_tag_,int _type_); | ||
71 | static int GPXFinalType_function(const char *_tag_,int _type_,const char *text); | ||
72 | static int GPXStepType_function(const char *_tag_,int _type_,const char *text); | ||
73 | static int GPXNameType_function(const char *_tag_,int _type_,const char *text); | ||
74 | static int GPXDescType_function(const char *_tag_,int _type_,const char *text); | ||
75 | static int GPXWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string); | ||
76 | static int GPXRouteType_function(const char *_tag_,int _type_,const char *type,const char *string); | ||
77 | //static int HTMLType_function(const char *_tag_,int _type_); | ||
78 | static int HeadingType_function(const char *_tag_,int _type_,const char *direction,const char *string); | ||
79 | static int TurnType_function(const char *_tag_,int _type_,const char *direction,const char *string); | ||
80 | amb | 361 | |
81 | |||
82 | /* The XML tag definitions */ | ||
83 | |||
84 | /*+ The TurnType type tag. +*/ | ||
85 | amb | 367 | static xmltag TurnType_tag= |
86 | amb | 361 | {"turn", |
87 | 2, {"direction","string"}, | ||
88 | amb | 367 | TurnType_function, |
89 | amb | 361 | {NULL}}; |
90 | |||
91 | /*+ The HeadingType type tag. +*/ | ||
92 | amb | 367 | static xmltag HeadingType_tag= |
93 | amb | 361 | {"heading", |
94 | 2, {"direction","string"}, | ||
95 | amb | 367 | HeadingType_function, |
96 | amb | 361 | {NULL}}; |
97 | |||
98 | /*+ The HTMLType type tag. +*/ | ||
99 | amb | 367 | static xmltag HTMLType_tag= |
100 | amb | 361 | {"output-html", |
101 | 0, {NULL}, | ||
102 | NULL, | ||
103 | {NULL}}; | ||
104 | |||
105 | /*+ The GPXRouteType type tag. +*/ | ||
106 | amb | 367 | static xmltag GPXRouteType_tag= |
107 | amb | 361 | {"route", |
108 | 2, {"type","string"}, | ||
109 | amb | 367 | GPXRouteType_function, |
110 | amb | 361 | {NULL}}; |
111 | |||
112 | /*+ The GPXWaypointType type tag. +*/ | ||
113 | amb | 367 | static xmltag GPXWaypointType_tag= |
114 | amb | 361 | {"waypoint", |
115 | 2, {"type","string"}, | ||
116 | amb | 367 | GPXWaypointType_function, |
117 | amb | 361 | {NULL}}; |
118 | |||
119 | /*+ The GPXDescType type tag. +*/ | ||
120 | amb | 367 | static xmltag GPXDescType_tag= |
121 | amb | 361 | {"desc", |
122 | 1, {"text"}, | ||
123 | amb | 367 | GPXDescType_function, |
124 | amb | 361 | {NULL}}; |
125 | |||
126 | /*+ The GPXNameType type tag. +*/ | ||
127 | amb | 367 | static xmltag GPXNameType_tag= |
128 | amb | 361 | {"name", |
129 | 1, {"text"}, | ||
130 | amb | 367 | GPXNameType_function, |
131 | amb | 361 | {NULL}}; |
132 | |||
133 | /*+ The GPXStepType type tag. +*/ | ||
134 | amb | 367 | static xmltag GPXStepType_tag= |
135 | amb | 361 | {"step", |
136 | 1, {"text"}, | ||
137 | amb | 367 | GPXStepType_function, |
138 | amb | 361 | {NULL}}; |
139 | |||
140 | /*+ The GPXFinalType type tag. +*/ | ||
141 | amb | 367 | static xmltag GPXFinalType_tag= |
142 | amb | 361 | {"final", |
143 | 1, {"text"}, | ||
144 | amb | 367 | GPXFinalType_function, |
145 | amb | 361 | {NULL}}; |
146 | |||
147 | /*+ The GPXType type tag. +*/ | ||
148 | amb | 367 | static xmltag GPXType_tag= |
149 | amb | 361 | {"output-gpx", |
150 | 0, {NULL}, | ||
151 | NULL, | ||
152 | amb | 367 | {&GPXRouteType_tag,&GPXWaypointType_tag,&GPXDescType_tag,&GPXNameType_tag,&GPXStepType_tag,&GPXFinalType_tag,NULL}}; |
153 | amb | 361 | |
154 | /*+ The languageType type tag. +*/ | ||
155 | amb | 367 | static xmltag languageType_tag= |
156 | amb | 361 | {"language", |
157 | 1, {"lang"}, | ||
158 | amb | 367 | languageType_function, |
159 | {&TurnType_tag,&HeadingType_tag,&HTMLType_tag,&GPXType_tag,NULL}}; | ||
160 | amb | 361 | |
161 | /*+ The RoutinoTranslationsType type tag. +*/ | ||
162 | amb | 367 | static xmltag RoutinoTranslationsType_tag= |
163 | amb | 361 | {"routino-translations", |
164 | 0, {NULL}, | ||
165 | NULL, | ||
166 | amb | 367 | {&languageType_tag,NULL}}; |
167 | amb | 361 | |
168 | amb | 367 | /*+ The xmlDeclaration type tag. +*/ |
169 | static xmltag xmlDeclaration_tag= | ||
170 | amb | 361 | {"xml", |
171 | 2, {"version","encoding"}, | ||
172 | NULL, | ||
173 | {NULL}}; | ||
174 | |||
175 | |||
176 | /*+ The complete set of tags at the top level. +*/ | ||
177 | amb | 367 | static xmltag *xml_toplevel_tags[]={&xmlDeclaration_tag,&RoutinoTranslationsType_tag,NULL}; |
178 | amb | 361 | |
179 | |||
180 | /* The XML tag processing functions */ | ||
181 | |||
182 | |||
183 | /*++++++++++++++++++++++++++++++++++++++ | ||
184 | The function that is called when the TurnType XSD type is seen | ||
185 | |||
186 | amb | 367 | int TurnType_function Returns 0 if no error occured or something else otherwise. |
187 | amb | 363 | |
188 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
189 | |||
190 | 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. |
191 | |||
192 | const char *direction The contents of the 'direction' attribute (or NULL if not defined). | ||
193 | |||
194 | const char *string The contents of the 'string' attribute (or NULL if not defined). | ||
195 | ++++++++++++++++++++++++++++++++++++++*/ | ||
196 | |||
197 | amb | 373 | static int TurnType_function(const char *_tag_,int _type_,const char *direction,const char *string) |
198 | amb | 361 | { |
199 | if(_type_&XMLPARSE_TAG_START && store) | ||
200 | { | ||
201 | int d; | ||
202 | |||
203 | amb | 373 | XMLPARSE_ASSERT_INTEGER(_tag_,direction,d); |
204 | XMLPARSE_ASSERT_STRING(_tag_,string); | ||
205 | amb | 361 | |
206 | amb | 363 | d+=4; |
207 | amb | 361 | |
208 | if(d<0 || d>8) | ||
209 | amb | 373 | XMLPARSE_INVALID(_tag_,direction); |
210 | amb | 361 | |
211 | translate_turn[d]=strcpy(malloc(strlen(string)+1),string); | ||
212 | } | ||
213 | amb | 363 | |
214 | return(0); | ||
215 | amb | 361 | } |
216 | |||
217 | |||
218 | /*++++++++++++++++++++++++++++++++++++++ | ||
219 | The function that is called when the HeadingType XSD type is seen | ||
220 | |||
221 | amb | 367 | int HeadingType_function Returns 0 if no error occured or something else otherwise. |
222 | amb | 363 | |
223 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
224 | |||
225 | 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. |
226 | |||
227 | const char *direction The contents of the 'direction' attribute (or NULL if not defined). | ||
228 | |||
229 | const char *string The contents of the 'string' attribute (or NULL if not defined). | ||
230 | ++++++++++++++++++++++++++++++++++++++*/ | ||
231 | |||
232 | amb | 373 | static int HeadingType_function(const char *_tag_,int _type_,const char *direction,const char *string) |
233 | amb | 361 | { |
234 | if(_type_&XMLPARSE_TAG_START && store) | ||
235 | { | ||
236 | int d; | ||
237 | |||
238 | amb | 373 | XMLPARSE_ASSERT_INTEGER(_tag_,direction,d); |
239 | XMLPARSE_ASSERT_STRING(_tag_,string); | ||
240 | amb | 361 | |
241 | amb | 363 | d+=4; |
242 | amb | 361 | |
243 | if(d<0 || d>8) | ||
244 | amb | 373 | XMLPARSE_INVALID(_tag_,direction); |
245 | amb | 361 | |
246 | translate_heading[d]=strcpy(malloc(strlen(string)+1),string); | ||
247 | } | ||
248 | amb | 363 | |
249 | return(0); | ||
250 | amb | 361 | } |
251 | |||
252 | |||
253 | /*++++++++++++++++++++++++++++++++++++++ | ||
254 | amb | 363 | The function that is called when the HTMLType XSD type is seen |
255 | |||
256 | amb | 367 | int HTMLType_function Returns 0 if no error occured or something else otherwise. |
257 | amb | 363 | |
258 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
259 | |||
260 | 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. |
261 | ++++++++++++++++++++++++++++++++++++++*/ | ||
262 | |||
263 | amb | 373 | //static int HTMLType_function(const char *_tag_,int _type_) |
264 | amb | 363 | //{ |
265 | //} | ||
266 | |||
267 | |||
268 | /*++++++++++++++++++++++++++++++++++++++ | ||
269 | amb | 361 | The function that is called when the GPXRouteType XSD type is seen |
270 | |||
271 | amb | 367 | int GPXRouteType_function Returns 0 if no error occured or something else otherwise. |
272 | amb | 363 | |
273 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
274 | |||
275 | 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. |
276 | |||
277 | const char *type The contents of the 'type' attribute (or NULL if not defined). | ||
278 | |||
279 | const char *string The contents of the 'string' attribute (or NULL if not defined). | ||
280 | ++++++++++++++++++++++++++++++++++++++*/ | ||
281 | |||
282 | amb | 373 | static int GPXRouteType_function(const char *_tag_,int _type_,const char *type,const char *string) |
283 | amb | 361 | { |
284 | if(_type_&XMLPARSE_TAG_START && store) | ||
285 | { | ||
286 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,type); |
287 | XMLPARSE_ASSERT_STRING(_tag_,string); | ||
288 | amb | 361 | |
289 | if(!strcmp(type,"shortest")) | ||
290 | translate_gpx_shortest=strcpy(malloc(strlen(string)+1),string); | ||
291 | else if(!strcmp(type,"quickest")) | ||
292 | translate_gpx_quickest=strcpy(malloc(strlen(string)+1),string); | ||
293 | else | ||
294 | amb | 373 | XMLPARSE_INVALID(_tag_,type); |
295 | amb | 361 | } |
296 | amb | 363 | |
297 | return(0); | ||
298 | amb | 361 | } |
299 | |||
300 | |||
301 | /*++++++++++++++++++++++++++++++++++++++ | ||
302 | The function that is called when the GPXWaypointType XSD type is seen | ||
303 | |||
304 | amb | 367 | int GPXWaypointType_function Returns 0 if no error occured or something else otherwise. |
305 | amb | 363 | |
306 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
307 | |||
308 | 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. |
309 | |||
310 | const char *type The contents of the 'type' attribute (or NULL if not defined). | ||
311 | |||
312 | const char *string The contents of the 'string' attribute (or NULL if not defined). | ||
313 | ++++++++++++++++++++++++++++++++++++++*/ | ||
314 | |||
315 | amb | 373 | static int GPXWaypointType_function(const char *_tag_,int _type_,const char *type,const char *string) |
316 | amb | 361 | { |
317 | if(_type_&XMLPARSE_TAG_START && store) | ||
318 | { | ||
319 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,type); |
320 | XMLPARSE_ASSERT_STRING(_tag_,string); | ||
321 | amb | 361 | |
322 | if(!strcmp(type,"start")) | ||
323 | translate_gpx_start=strcpy(malloc(strlen(string)+1),string); | ||
324 | else if(!strcmp(type,"inter")) | ||
325 | translate_gpx_inter=strcpy(malloc(strlen(string)+1),string); | ||
326 | else if(!strcmp(type,"trip")) | ||
327 | translate_gpx_trip=strcpy(malloc(strlen(string)+1),string); | ||
328 | else if(!strcmp(type,"finish")) | ||
329 | translate_gpx_finish=strcpy(malloc(strlen(string)+1),string); | ||
330 | else | ||
331 | amb | 373 | XMLPARSE_INVALID(_tag_,type); |
332 | amb | 361 | } |
333 | amb | 363 | |
334 | return(0); | ||
335 | amb | 361 | } |
336 | |||
337 | |||
338 | /*++++++++++++++++++++++++++++++++++++++ | ||
339 | The function that is called when the GPXDescType XSD type is seen | ||
340 | |||
341 | amb | 367 | int GPXDescType_function Returns 0 if no error occured or something else otherwise. |
342 | amb | 363 | |
343 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
344 | |||
345 | 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. |
346 | |||
347 | const char *text The contents of the 'text' attribute (or NULL if not defined). | ||
348 | ++++++++++++++++++++++++++++++++++++++*/ | ||
349 | |||
350 | amb | 373 | static int GPXDescType_function(const char *_tag_,int _type_,const char *text) |
351 | amb | 361 | { |
352 | if(_type_&XMLPARSE_TAG_START && store) | ||
353 | { | ||
354 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,text); |
355 | amb | 361 | |
356 | translate_gpx_desc=strcpy(malloc(strlen(text)+1),text); | ||
357 | } | ||
358 | amb | 363 | |
359 | return(0); | ||
360 | amb | 361 | } |
361 | |||
362 | |||
363 | /*++++++++++++++++++++++++++++++++++++++ | ||
364 | The function that is called when the GPXNameType XSD type is seen | ||
365 | |||
366 | amb | 367 | int GPXNameType_function Returns 0 if no error occured or something else otherwise. |
367 | amb | 363 | |
368 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
369 | |||
370 | 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. |
371 | |||
372 | const char *text The contents of the 'text' attribute (or NULL if not defined). | ||
373 | ++++++++++++++++++++++++++++++++++++++*/ | ||
374 | |||
375 | amb | 373 | static int GPXNameType_function(const char *_tag_,int _type_,const char *text) |
376 | amb | 361 | { |
377 | if(_type_&XMLPARSE_TAG_START && store) | ||
378 | { | ||
379 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,text); |
380 | amb | 361 | |
381 | translate_gpx_name=strcpy(malloc(strlen(text)+1),text); | ||
382 | } | ||
383 | amb | 363 | |
384 | return(0); | ||
385 | amb | 361 | } |
386 | |||
387 | |||
388 | /*++++++++++++++++++++++++++++++++++++++ | ||
389 | The function that is called when the GPXStepType XSD type is seen | ||
390 | |||
391 | amb | 367 | int GPXStepType_function Returns 0 if no error occured or something else otherwise. |
392 | amb | 363 | |
393 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
394 | |||
395 | 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. |
396 | |||
397 | const char *text The contents of the 'text' attribute (or NULL if not defined). | ||
398 | ++++++++++++++++++++++++++++++++++++++*/ | ||
399 | |||
400 | amb | 373 | static int GPXStepType_function(const char *_tag_,int _type_,const char *text) |
401 | amb | 361 | { |
402 | if(_type_&XMLPARSE_TAG_START && store) | ||
403 | { | ||
404 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,text); |
405 | amb | 361 | |
406 | translate_gpx_step=strcpy(malloc(strlen(text)+1),text); | ||
407 | } | ||
408 | amb | 363 | |
409 | return(0); | ||
410 | amb | 361 | } |
411 | |||
412 | |||
413 | /*++++++++++++++++++++++++++++++++++++++ | ||
414 | The function that is called when the GPXFinalType XSD type is seen | ||
415 | |||
416 | amb | 367 | int GPXFinalType_function Returns 0 if no error occured or something else otherwise. |
417 | amb | 363 | |
418 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
419 | |||
420 | 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. |
421 | |||
422 | const char *text The contents of the 'text' attribute (or NULL if not defined). | ||
423 | ++++++++++++++++++++++++++++++++++++++*/ | ||
424 | |||
425 | amb | 373 | static int GPXFinalType_function(const char *_tag_,int _type_,const char *text) |
426 | amb | 361 | { |
427 | if(_type_&XMLPARSE_TAG_START && store) | ||
428 | { | ||
429 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,text); |
430 | amb | 361 | |
431 | translate_gpx_final=strcpy(malloc(strlen(text)+1),text); | ||
432 | } | ||
433 | amb | 363 | |
434 | return(0); | ||
435 | amb | 361 | } |
436 | |||
437 | |||
438 | /*++++++++++++++++++++++++++++++++++++++ | ||
439 | amb | 363 | The function that is called when the GPXType XSD type is seen |
440 | |||
441 | amb | 367 | int GPXType_function Returns 0 if no error occured or something else otherwise. |
442 | amb | 363 | |
443 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
444 | |||
445 | 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. |
446 | ++++++++++++++++++++++++++++++++++++++*/ | ||
447 | |||
448 | amb | 373 | //static int GPXType_function(const char *_tag_,int _type_) |
449 | amb | 363 | //{ |
450 | //} | ||
451 | |||
452 | |||
453 | /*++++++++++++++++++++++++++++++++++++++ | ||
454 | amb | 361 | The function that is called when the languageType XSD type is seen |
455 | |||
456 | amb | 367 | int languageType_function Returns 0 if no error occured or something else otherwise. |
457 | amb | 363 | |
458 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
459 | |||
460 | 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. |
461 | |||
462 | const char *lang The contents of the 'lang' attribute (or NULL if not defined). | ||
463 | ++++++++++++++++++++++++++++++++++++++*/ | ||
464 | |||
465 | amb | 373 | static int languageType_function(const char *_tag_,int _type_,const char *lang) |
466 | amb | 361 | { |
467 | static int first=1; | ||
468 | |||
469 | if(_type_&XMLPARSE_TAG_START) | ||
470 | { | ||
471 | amb | 373 | XMLPARSE_ASSERT_STRING(_tag_,lang); |
472 | amb | 361 | |
473 | if(!store_lang && first) | ||
474 | store=1; | ||
475 | else if(!strcmp(store_lang,lang)) | ||
476 | store=1; | ||
477 | else | ||
478 | store=0; | ||
479 | |||
480 | first=0; | ||
481 | } | ||
482 | |||
483 | if(_type_&XMLPARSE_TAG_END && store) | ||
484 | { | ||
485 | store=0; | ||
486 | stored=1; | ||
487 | } | ||
488 | amb | 363 | |
489 | return(0); | ||
490 | amb | 361 | } |
491 | |||
492 | |||
493 | /*++++++++++++++++++++++++++++++++++++++ | ||
494 | amb | 363 | The function that is called when the RoutinoTranslationsType XSD type is seen |
495 | |||
496 | amb | 367 | int RoutinoTranslationsType_function Returns 0 if no error occured or something else otherwise. |
497 | amb | 363 | |
498 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
499 | |||
500 | 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. |
501 | ++++++++++++++++++++++++++++++++++++++*/ | ||
502 | |||
503 | amb | 373 | //static int RoutinoTranslationsType_function(const char *_tag_,int _type_) |
504 | amb | 363 | //{ |
505 | //} | ||
506 | |||
507 | |||
508 | /*++++++++++++++++++++++++++++++++++++++ | ||
509 | amb | 367 | The function that is called when the XML declaration is seen |
510 | amb | 363 | |
511 | amb | 367 | int xmlDeclaration_function Returns 0 if no error occured or something else otherwise. |
512 | amb | 363 | |
513 | amb | 373 | const char *_tag_ Set to the name of the element tag that triggered this function call. |
514 | |||
515 | 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. |
516 | |||
517 | const char *version The contents of the 'version' attribute (or NULL if not defined). | ||
518 | |||
519 | const char *encoding The contents of the 'encoding' attribute (or NULL if not defined). | ||
520 | ++++++++++++++++++++++++++++++++++++++*/ | ||
521 | |||
522 | amb | 373 | //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding) |
523 | amb | 363 | //{ |
524 | //} | ||
525 | |||
526 | |||
527 | /*++++++++++++++++++++++++++++++++++++++ | ||
528 | amb | 361 | The XML translation parser. |
529 | |||
530 | int ParseXMLTranslations Returns 0 if OK or something else in case of an error. | ||
531 | |||
532 | const char *filename The name of the file to read. | ||
533 | |||
534 | const char *language The language to search for (NULL means first in file). | ||
535 | ++++++++++++++++++++++++++++++++++++++*/ | ||
536 | |||
537 | int ParseXMLTranslations(const char *filename,const char *language) | ||
538 | { | ||
539 | int retval; | ||
540 | |||
541 | store_lang=language; | ||
542 | |||
543 | if(!ExistsFile(filename)) | ||
544 | { | ||
545 | fprintf(stderr,"Error: Specified translations file '%s' does not exist.\n",filename); | ||
546 | return(1); | ||
547 | } | ||
548 | |||
549 | FILE *file=fopen(filename,"r"); | ||
550 | |||
551 | if(!file) | ||
552 | { | ||
553 | fprintf(stderr,"Error: Cannot open translations file '%s' for reading.\n",filename); | ||
554 | return(1); | ||
555 | } | ||
556 | |||
557 | amb | 366 | retval=ParseXML(file,xml_toplevel_tags,XMLPARSE_UNKNOWN_ATTR_ERRNONAME); |
558 | amb | 361 | |
559 | fclose(file); | ||
560 | |||
561 | amb | 363 | if(retval) |
562 | amb | 361 | return(1); |
563 | |||
564 | if(language && !stored) | ||
565 | fprintf(stderr,"Warning: Cannot find translations for language '%s' using English instead.\n",language); | ||
566 | |||
567 | return(0); | ||
568 | } |
Properties
Name | Value |
---|---|
cvs:description | File containing translation parsing functions. |