source: trunk/zoo-kernel/main_conf_read.y @ 216

Last change on this file since 216 was 216, checked in by djay, 13 years ago

Add WIN32 platform support. Fix for values containing @ passed as KVP.

File size: 9.8 KB
Line 
1%{
2//======================================================
3/**
4   Zoo main configuration file parser
5**/
6//======================================================
7
8#include <string>
9#include <stdio.h>
10#include <ctype.h>
11#include <service.h>
12#include <vector>
13
14static int defaultsc=0;
15static maps* my_maps=NULL;
16static maps* current_maps=NULL;
17static map* previous_content=NULL;
18static map* current_content=NULL;
19static elements* current_element=NULL;
20static map* scontent=NULL;
21static char* curr_key;
22static int debug=0;
23static int previous_data=0;
24static int current_data=0;
25using namespace std;
26
27extern void crerror(const char *s);
28
29void usage(void) ;
30
31extern int crdebug;
32
33extern char crtext[];
34
35extern int crlineno;
36
37extern FILE* crin;
38
39extern int crlex(void);
40extern int crlex_destroy(void);
41
42%}
43
44
45
46//======================================================
47/* le type des lval des jetons et des elements non terminaux bison */
48//======================================================
49%union
50{
51   char * s;
52}
53%union { char* chaine; char* key;char* val;}
54//======================================================
55
56// jetons //
57//======================================================
58/* les jetons que l on retrouve dans FLEX */
59//======================================================
60/* texte on a besoin de récupérer une valeur char* pour la comparer */
61%token <s> ID
62%token <s> CHAINE
63/* STARTXMLDECL et ENDXMLDECL qui sont <?xml et ?>*/
64%token STARTXMLDECL ENDXMLDECL
65//======================================================
66/* version="xxx" et encoding="xxx" */
67%token VERSIONDECL ENCODINGDECL SDDECL
68//======================================================
69/* < et > */
70%token INFCAR SUPCAR
71//======================================================
72/* / = a1  texte "texte" */
73%token SLASH Eq CHARDATA ATTVALUE PAIR SPAIR EPAIR EPAIRS ANID
74%type <chaine> PAIR
75%type <chaine> EPAIRS
76%type <chaine> EPAIR
77%type <chaine> SPAIR
78
79//======================================================
80/* <!-- xxx -> <? xxx yyy ?> */
81%token PI PIERROR /** COMMENT **/
82//======================================================
83/* <!-- xxx -> <? xxx yyy ?> */
84%token ERREURGENERALE CDATA WHITESPACE NEWLINE
85//======================================================
86// non terminaux typés
87//======================================================
88/* elements non terminaux de type char *     */
89/* uniquement ceux qui devrons etre comparés */
90//======================================================
91%type <s> STag
92%type <s> ETag
93%type <s> ANID
94//======================================================
95// %start
96//======================================================
97
98%%
99// document <//===
100//======================================================
101// regle 1
102// on est a la racine du fichier xml
103//======================================================
104document
105 : miscetoile element miscetoile {}
106 | contentetoile processid contentetoile document {}
107 ;
108
109miscetoile
110 : miscetoile PIERROR {crerror("processing instruction begining with <?xml ?> impossible\n");}
111 | miscetoile PI {}
112 | {}
113 ;
114// element
115//======================================================
116// regle 39
117// OUVRANTE CONTENU FERMANTE obligatoirement
118// ou neutre
119// on ne peut pas avoir Epsilon
120// un fichier xml ne peut pas etre vide ou seulement avec un prolog
121//======================================================
122element
123 : STag contentetoile ETag     
124{
125  /* les non terminaux rendent les valeurs de leur identifiants de balise */
126  /* en char*, donc on peut comparer ces valeurs avec la fonction C++ strcmp(const char*;const char*) */
127  /* de string */
128  if (strcmp($1,$3) != 0)
129    {
130      crerror("Opening and ending tag mismatch");
131      printf("\n  ::details : tag '%s' et '%s' \n",$1,$3);
132      return 1;
133      // on retourne different de 0
134      // sinon yyparse rendra 0
135      // et dans le main on croira a le fichier xml est valide !
136    }
137}
138// pour neutre
139// on a rien a faire, meme pas renvoyer l identificateur de balise
140// vu qu'il n y a pas de comparaison d'identificateurs avec un balise jumelle .
141 | EmptyElemTag          {}
142 ;
143//======================================================
144// STag
145//======================================================
146// regle 40
147// BALISE OUVRANTE
148// on est obligé de faire appel a infcar et supcar
149// pour acceder aux start conditions DANSBALISE et INITIAL
150//======================================================
151STag
152 : INFCAR ID Attributeetoile SUPCAR
153{       
154
155#ifdef DEBUG
156        printf("* Identifiant : %s\n",$2);
157#endif
158       
159        $$ = $2 ;
160}
161 ;
162//======================================================
163// Attributeetoile
164//======================================================
165// regle 41
166// une liste qui peut etre vide d'attributs
167// utiliser la récursivité a gauche
168//======================================================
169Attributeetoile
170 : Attributeetoile attribute  {}
171 |                                {/* Epsilon */}
172 ;
173//======================================================
174// attribute
175//======================================================
176// regle 41
177// un attribut est compose d'un identifiant
178// d'un "="
179// et d'une définition de chaine de caractere
180// ( "xxx" ou 'xxx' )
181//======================================================
182attribute
183 : ID Eq ATTVALUE               
184{
185        // on verifie que les attributst ne sont pas en double
186        // sinon on ajoute au vector
187}
188 ;
189//======================================================
190// EmptyElemTag
191//======================================================
192// regle 44
193// ICI ON DEFINIT NEUTRE
194// on ne renvoie pas de char*
195// parce qu'il n'y a pas de comparaisons a faire
196// avec un identifiant d'une balise jumelle
197//======================================================
198EmptyElemTag
199 : INFCAR ID Attributeetoile SLASH SUPCAR       {}
200 ;
201//======================================================
202// ETag
203//======================================================
204// regle 42
205// BALISE FERMANTE
206// les separateurs après ID sont filtrés
207//======================================================
208ETag
209 : INFCAR SLASH ID SUPCAR
210{
211  /* on renvoie l'identifiant de la balise pour pouvoir comparer les 2 */
212  /* /!\ une balise fermante n'a pas d'attributs (c.f. : W3C) */
213  $$ = $3;
214}
215 ;
216//======================================================
217// contentetoile
218//======================================================
219// regle 43
220// ENTRE 2 BALISES
221// entre 2 balises, on peut avoir :
222// --- OUVRANTE CONTENU FERMANTE (recursivement !)
223// --- DU TEXTE quelconque
224// --- COMMENTS
225// --- DES PROCESSES INSTRUCTIONS
226// --- /!\ il peut y avoir une processing instruction invalide ! <?xml
227// --- EPSILON
228// ### et/ou tout ca a la suite en nombre indeterminé
229// ### donc c'est un operateur etoile (*)
230//======================================================
231contentetoile
232: contentetoile element           {}
233 | contentetoile PIERROR                  {crerror("processing instruction <?xml ?> impossible\n");}
234 | contentetoile PI                       {}
235///// on filtre les commentaires | contentetoile comment              {}
236 | contentetoile NEWLINE {/*printf("NEWLINE FOUND !!");*/}
237 | contentetoile pair {}
238 | contentetoile processid {}
239 | contentetoile texteinterbalise         {}
240 | contentetoile CDATA {} 
241 | {/* Epsilon */}
242 ;
243//======================================================
244// texteinterbalise
245//======================================================
246// regle 14
247// DU TEXTE quelconque
248// c'est du CHARDATA
249// il y a eut un probleme avec ID,
250// on a mis des starts conditions,
251// maintenant on croise les ID dans les dbalises
252// et des CHARDATA hors des balises
253//======================================================
254texteinterbalise
255 : CHARDATA             {}
256 ;
257//======================================================
258
259pair: PAIR {curr_key=strdup($1);/*printf("START 0 PAIR FOUND !! \n [%s]\n",$1);*/}
260| EPAIR {
261  if(current_content==NULL)
262    current_content=createMap(curr_key,$1);
263  else{
264    addToMap(current_content,curr_key,$1);
265  }
266  if(debug){
267    printf("EPAIR FOUND !! \n");
268    printf("[%s=>%s]\n",curr_key,$1);
269  }
270  free(curr_key);
271  }
272| SPAIR  {curr_key=strdup($1);if(debug) printf("SPAIR FOUND !!\n"); }
273 ;
274
275
276processid
277: ANID  {
278   if(current_maps->name!=NULL){
279     addMapToMap(&current_maps->content,current_content);
280     freeMap(&current_content);
281     free(current_content);
282     current_maps->next=NULL;
283     current_maps->next=(maps*)malloc(MAPS_SIZE);
284     current_maps->next->name=strdup($1);
285     current_maps->next->content=NULL;
286     current_maps->next->next=NULL;
287     current_maps=current_maps->next;
288     current_content=current_maps->content;
289   }
290   else{
291     current_maps->name=(char*)malloc((strlen($1)+1)*sizeof(char));
292     snprintf(current_maps->name,(strlen($1)+1),"%s",$1);
293     current_maps->content=NULL;
294     current_maps->next=NULL;
295     current_content=NULL;
296   }
297 }
298 ;
299
300%%
301
302// crerror
303//======================================================
304/* fonction qui affiche l erreur si il y en a une */
305//======================================================
306void crerror(const char *s)
307{
308  if(debug)
309    printf("\nligne %d : %s\n",crlineno,s);
310}
311
312// main
313//======================================================
314/* fonction principale : entrée dans le programme */
315//======================================================
316int conf_read(const char* file,maps* my_map){
317 
318  crin = fopen(file,"r");
319  if (crin==NULL){
320    printf("error : le fichier specifie n'existe pas ou n'est pas accessible en lecture\n") ;
321    return 2 ;
322  }
323
324  my_maps=my_map;
325  my_maps->name=NULL;
326  current_maps=my_maps;
327 
328  int resultatYYParse = crparse() ;
329  if(current_content!=NULL){
330    addMapToMap(&current_maps->content,current_content);
331    current_maps->next=NULL;
332    freeMap(&current_content);
333    free(current_content);
334  }
335
336  fclose(crin);
337#ifndef WIN32
338  crlex_destroy();
339#endif
340
341  return resultatYYParse;
342}
343
344
345//======================================================
346// FIN //
347//======================================================
Note: See TracBrowser for help on using the repository browser.

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png