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

Last change on this file since 7 was 1, checked in by djay, 14 years ago

Initial ZOO SVN Repository Import.

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

Search

Context Navigation

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