source: trunk/zoo-project/zoo-kernel/main_conf_read.y @ 618

Last change on this file since 618 was 607, checked in by djay, 9 years ago

Introduce the Process Profiles Registry with its documentation.

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