source: branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/main_conf_read.y @ 615

Last change on this file since 615 was 490, checked in by djay, 10 years ago

Remove memory leaks from ZOO-Kernel. Fix issue #99.

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