| 1 | %{ |
|---|
| 2 | //====================================================== |
|---|
| 3 | /** |
|---|
| 4 | * Thx to Jean-Marie CODOL and Naitan GROLLEMUND |
|---|
| 5 | * copyright 2009 GeoLabs SARL |
|---|
| 6 | * Author : Gérald FENOY |
|---|
| 7 | * |
|---|
| 8 | */ |
|---|
| 9 | //====================================================== |
|---|
| 10 | |
|---|
| 11 | #include <string> |
|---|
| 12 | #include <stdio.h> |
|---|
| 13 | #include <ctype.h> |
|---|
| 14 | #include <service.h> |
|---|
| 15 | //#include <vector> |
|---|
| 16 | |
|---|
| 17 | static int tmp_count=1; |
|---|
| 18 | static int defaultsc=0; |
|---|
| 19 | static bool wait_maincontent=true; |
|---|
| 20 | static bool wait_mainmetadata=false; |
|---|
| 21 | static bool wait_metadata=false; |
|---|
| 22 | static bool wait_inputs=false; |
|---|
| 23 | static bool wait_defaults=false; |
|---|
| 24 | static bool wait_supporteds=false; |
|---|
| 25 | static bool wait_outputs=false; |
|---|
| 26 | static bool wait_data=false; |
|---|
| 27 | static int services_c=0; |
|---|
| 28 | static service* my_service=NULL; |
|---|
| 29 | static map* previous_content=NULL; |
|---|
| 30 | static map* current_content=NULL; |
|---|
| 31 | static elements* current_element=NULL; |
|---|
| 32 | static map* scontent=NULL; |
|---|
| 33 | static char* curr_key; |
|---|
| 34 | static int debug=0; |
|---|
| 35 | static int data=-1; |
|---|
| 36 | static int previous_data=0; |
|---|
| 37 | static int current_data=0; |
|---|
| 38 | // namespace |
|---|
| 39 | using namespace std; |
|---|
| 40 | //====================================================== |
|---|
| 41 | |
|---|
| 42 | // srerror |
|---|
| 43 | void srerror(const char *s); |
|---|
| 44 | //====================================================== |
|---|
| 45 | |
|---|
| 46 | // usage () |
|---|
| 47 | void usage(void) ; |
|---|
| 48 | //====================================================== |
|---|
| 49 | |
|---|
| 50 | // srdebug |
|---|
| 51 | extern int srdebug; |
|---|
| 52 | //====================================================== |
|---|
| 53 | |
|---|
| 54 | extern char srtext[]; |
|---|
| 55 | |
|---|
| 56 | // srlineno |
|---|
| 57 | extern int srlineno; |
|---|
| 58 | //====================================================== |
|---|
| 59 | |
|---|
| 60 | // srin |
|---|
| 61 | extern FILE* srin; |
|---|
| 62 | //====================================================== |
|---|
| 63 | |
|---|
| 64 | // srlex |
|---|
| 65 | extern int srlex(void); |
|---|
| 66 | extern int srlex_destroy(void); |
|---|
| 67 | |
|---|
| 68 | //vector<char*> lattribute; |
|---|
| 69 | |
|---|
| 70 | %} |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | %union |
|---|
| 75 | {char * s;char* chaine;char* key;char* val;} |
|---|
| 76 | |
|---|
| 77 | // jetons // |
|---|
| 78 | %token <s> ID |
|---|
| 79 | %token <s> CHAINE |
|---|
| 80 | /* STARTXMLDECL et ENDXMLDECL qui sont <?xml et ?>*/ |
|---|
| 81 | %token STARTXMLDECL ENDXMLDECL |
|---|
| 82 | //====================================================== |
|---|
| 83 | /* version="xxx" et encoding="xxx" */ |
|---|
| 84 | %token VERSIONDECL ENCODINGDECL SDDECL |
|---|
| 85 | //====================================================== |
|---|
| 86 | /* < et > */ |
|---|
| 87 | %token INFCAR SUPCAR |
|---|
| 88 | //====================================================== |
|---|
| 89 | /* / = a1 texte "texte" */ |
|---|
| 90 | %token SLASH Eq CHARDATA ATTVALUE PAIR SPAIR EPAIR ANID |
|---|
| 91 | %type <chaine> PAIR |
|---|
| 92 | %type <chaine> EPAIR |
|---|
| 93 | %type <chaine> SPAIR |
|---|
| 94 | //====================================================== |
|---|
| 95 | /* <!-- xxx -> <? xxx yyy ?> */ |
|---|
| 96 | %token PI PIERROR /** COMMENT **/ |
|---|
| 97 | //====================================================== |
|---|
| 98 | /* <!-- xxx -> <? xxx yyy ?> */ |
|---|
| 99 | %token ERREURGENERALE CDATA WHITESPACE NEWLINE |
|---|
| 100 | %type <s> STag |
|---|
| 101 | %type <s> ETag |
|---|
| 102 | %type <s> ANID |
|---|
| 103 | //====================================================== |
|---|
| 104 | // %start |
|---|
| 105 | //====================================================== |
|---|
| 106 | |
|---|
| 107 | %% |
|---|
| 108 | // document <//=== |
|---|
| 109 | //====================================================== |
|---|
| 110 | // regle 1 |
|---|
| 111 | // on est a la racine du fichier xml |
|---|
| 112 | //====================================================== |
|---|
| 113 | document |
|---|
| 114 | : miscetoile element miscetoile {} |
|---|
| 115 | | contentetoile processid contentetoile document {} |
|---|
| 116 | ; |
|---|
| 117 | |
|---|
| 118 | miscetoile |
|---|
| 119 | : miscetoile PIERROR { srerror("processing instruction begining with <?xml ?> impossible\n");} |
|---|
| 120 | | miscetoile PI {} |
|---|
| 121 | | {} |
|---|
| 122 | ; |
|---|
| 123 | // element |
|---|
| 124 | //====================================================== |
|---|
| 125 | // regle 39 |
|---|
| 126 | // OUVRANTE CONTENU FERMANTE obligatoirement |
|---|
| 127 | // ou neutre |
|---|
| 128 | // on ne peut pas avoir Epsilon |
|---|
| 129 | // un fichier xml ne peut pas etre vide ou seulement avec un prolog |
|---|
| 130 | //====================================================== |
|---|
| 131 | element |
|---|
| 132 | : STag contentetoile ETag |
|---|
| 133 | { |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | // pour neutre |
|---|
| 137 | // on a rien a faire, meme pas renvoyer l identificateur de balise |
|---|
| 138 | // vu qu'il n y a pas de comparaison d'identificateurs avec un balise jumelle . |
|---|
| 139 | | EmptyElemTag {} |
|---|
| 140 | ; |
|---|
| 141 | |
|---|
| 142 | //====================================================== |
|---|
| 143 | // STag |
|---|
| 144 | //====================================================== |
|---|
| 145 | // regle 40 |
|---|
| 146 | // BALISE OUVRANTE |
|---|
| 147 | // on est obligé de faire appel a infcar et supcar |
|---|
| 148 | // pour acceder aux start conditions DANSBALISE et INITIAL |
|---|
| 149 | //====================================================== |
|---|
| 150 | STag |
|---|
| 151 | : INFCAR ID Attributeetoile SUPCAR |
|---|
| 152 | { |
|---|
| 153 | if(my_service->content==NULL){ |
|---|
| 154 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 155 | fprintf(stderr,"NO CONTENT\n"); |
|---|
| 156 | #endif |
|---|
| 157 | addMapToMap(&my_service->content,current_content); |
|---|
| 158 | freeMap(¤t_content); |
|---|
| 159 | free(current_content); |
|---|
| 160 | current_content=NULL; |
|---|
| 161 | my_service->metadata=NULL; |
|---|
| 162 | wait_maincontent=false; |
|---|
| 163 | } |
|---|
| 164 | if(strncasecmp($2,"DataInputs",10)==0){ |
|---|
| 165 | if(wait_mainmetadata==true){ |
|---|
| 166 | addMapToMap(&my_service->metadata,current_content); |
|---|
| 167 | freeMap(¤t_content); |
|---|
| 168 | free(current_content); |
|---|
| 169 | current_content=NULL; |
|---|
| 170 | wait_mainmetadata=false; |
|---|
| 171 | } |
|---|
| 172 | if(current_element==NULL){ |
|---|
| 173 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 174 | fprintf(stderr,"(DATAINPUTS - %d) FREE current_element\n",__LINE__); |
|---|
| 175 | #endif |
|---|
| 176 | freeElements(¤t_element); |
|---|
| 177 | free(current_element); |
|---|
| 178 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 179 | fprintf(stderr,"(DATAINPUTS - %d) ALLOCATE current_element\n",__LINE__); |
|---|
| 180 | #endif |
|---|
| 181 | current_element=NULL; |
|---|
| 182 | current_element=(elements*)malloc(ELEMENTS_SIZE); |
|---|
| 183 | current_element->name=NULL; |
|---|
| 184 | current_element->content=NULL; |
|---|
| 185 | current_element->metadata=NULL; |
|---|
| 186 | current_element->format=NULL; |
|---|
| 187 | current_element->defaults=NULL; |
|---|
| 188 | current_element->supported=NULL; |
|---|
| 189 | current_element->next=NULL; |
|---|
| 190 | } |
|---|
| 191 | wait_inputs=true; |
|---|
| 192 | current_data=1; |
|---|
| 193 | previous_data=1; |
|---|
| 194 | } |
|---|
| 195 | else |
|---|
| 196 | if(strncasecmp($2,"DataOutputs",11)==0){ |
|---|
| 197 | if(wait_inputs==true){ |
|---|
| 198 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 199 | fprintf(stderr,"(DATAOUTPUTS %d) DUP INPUTS current_element\n",__LINE__); |
|---|
| 200 | fprintf(stderr,"CURRENT_ELEMENT\n"); |
|---|
| 201 | dumpElements(current_element); |
|---|
| 202 | fprintf(stderr,"SERVICE INPUTS\n"); |
|---|
| 203 | dumpElements(my_service->inputs); |
|---|
| 204 | dumpService(my_service); |
|---|
| 205 | #endif |
|---|
| 206 | if(my_service->inputs==NULL){ |
|---|
| 207 | my_service->inputs=dupElements(current_element); |
|---|
| 208 | my_service->inputs->next=NULL; |
|---|
| 209 | } |
|---|
| 210 | else if(current_element!=NULL && current_element->name!=NULL){ |
|---|
| 211 | addToElements(&my_service->inputs,current_element); |
|---|
| 212 | } |
|---|
| 213 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 214 | fprintf(stderr,"CURRENT_ELEMENT\n"); |
|---|
| 215 | dumpElements(current_element); |
|---|
| 216 | fprintf(stderr,"SERVICE INPUTS\n"); |
|---|
| 217 | dumpElements(my_service->inputs); |
|---|
| 218 | fprintf(stderr,"(DATAOUTPUTS) FREE current_element\n"); |
|---|
| 219 | #endif |
|---|
| 220 | freeElements(¤t_element); |
|---|
| 221 | free(current_element); |
|---|
| 222 | current_element=NULL; |
|---|
| 223 | wait_inputs=false; |
|---|
| 224 | } |
|---|
| 225 | if(current_element==NULL){ |
|---|
| 226 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 227 | fprintf(stderr,"(DATAOUTPUTS - %d) ALLOCATE current_element (%s)\n",__LINE__,$2); |
|---|
| 228 | #endif |
|---|
| 229 | current_element=(elements*)malloc(ELEMENTS_SIZE); |
|---|
| 230 | current_element->name=NULL; |
|---|
| 231 | current_element->content=NULL; |
|---|
| 232 | current_element->metadata=NULL; |
|---|
| 233 | current_element->format=NULL; |
|---|
| 234 | current_element->defaults=NULL; |
|---|
| 235 | current_element->supported=NULL; |
|---|
| 236 | current_element->next=NULL; |
|---|
| 237 | } |
|---|
| 238 | wait_outputs=true; |
|---|
| 239 | current_data=2; |
|---|
| 240 | previous_data=2; |
|---|
| 241 | } |
|---|
| 242 | else |
|---|
| 243 | if(strncasecmp($2,"MetaData",8)==0){ |
|---|
| 244 | previous_data=current_data; |
|---|
| 245 | current_data=3; |
|---|
| 246 | if(current_element!=NULL){ |
|---|
| 247 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 248 | fprintf(stderr,"add current_content to current_element->content\n"); |
|---|
| 249 | fprintf(stderr,"LINE %d",__LINE__); |
|---|
| 250 | #endif |
|---|
| 251 | addMapToMap(¤t_element->content,current_content); |
|---|
| 252 | freeMap(¤t_content); |
|---|
| 253 | free(current_content); |
|---|
| 254 | if(previous_data==1 || previous_data==2) |
|---|
| 255 | wait_metadata=true; |
|---|
| 256 | else |
|---|
| 257 | wait_mainmetadata=true; |
|---|
| 258 | } |
|---|
| 259 | else{ |
|---|
| 260 | if(previous_data==1 || previous_data==2) |
|---|
| 261 | wait_metadata=true; |
|---|
| 262 | else |
|---|
| 263 | wait_mainmetadata=true; |
|---|
| 264 | } |
|---|
| 265 | current_content=NULL; |
|---|
| 266 | } |
|---|
| 267 | else |
|---|
| 268 | if(strncasecmp($2,"ComplexData",11)==0 || strncasecmp($2,"LiteralData",10)==0 |
|---|
| 269 | || strncasecmp($2,"ComplexOutput",13)==0 || strncasecmp($2,"LiteralOutput",12)==0 |
|---|
| 270 | || strncasecmp($2,"BoundingBoxOutput",13)==0 || strncasecmp($2,"BoundingBoxData",12)==0){ |
|---|
| 271 | current_data=4; |
|---|
| 272 | if(wait_metadata==true){ |
|---|
| 273 | if(current_content!=NULL){ |
|---|
| 274 | addMapToMap(¤t_element->metadata,current_content); |
|---|
| 275 | current_element->next=NULL; |
|---|
| 276 | if($2!=NULL) |
|---|
| 277 | current_element->format=strdup($2); |
|---|
| 278 | |
|---|
| 279 | current_element->defaults=NULL; |
|---|
| 280 | current_element->supported=NULL; |
|---|
| 281 | freeMap(¤t_content); |
|---|
| 282 | free(current_content); |
|---|
| 283 | } |
|---|
| 284 | }else{ |
|---|
| 285 | // No MainMetaData |
|---|
| 286 | addMapToMap(¤t_element->content,current_content); |
|---|
| 287 | freeMap(¤t_content); |
|---|
| 288 | free(current_content); |
|---|
| 289 | current_element->metadata=NULL; |
|---|
| 290 | current_element->next=NULL; |
|---|
| 291 | if($2!=NULL) |
|---|
| 292 | current_element->format=strdup($2); |
|---|
| 293 | current_element->defaults=NULL; |
|---|
| 294 | current_element->supported=NULL; |
|---|
| 295 | } |
|---|
| 296 | current_content=NULL; |
|---|
| 297 | wait_metadata=false; |
|---|
| 298 | } |
|---|
| 299 | else |
|---|
| 300 | if(strncasecmp($2,"Default",7)==0){ |
|---|
| 301 | wait_defaults=true; |
|---|
| 302 | current_data=5; |
|---|
| 303 | } |
|---|
| 304 | else |
|---|
| 305 | if(strncasecmp($2,"Supported",9)==0){ |
|---|
| 306 | wait_supporteds=true; |
|---|
| 307 | if(wait_defaults==true){ |
|---|
| 308 | defaultsc++; |
|---|
| 309 | } |
|---|
| 310 | current_data=5; |
|---|
| 311 | } |
|---|
| 312 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 313 | printf("* Identifiant : %s\n",$2); |
|---|
| 314 | #endif |
|---|
| 315 | } |
|---|
| 316 | ; |
|---|
| 317 | |
|---|
| 318 | //====================================================== |
|---|
| 319 | // Attributeetoile |
|---|
| 320 | //====================================================== |
|---|
| 321 | // regle 41 |
|---|
| 322 | // une liste qui peut etre vide d'attributs |
|---|
| 323 | // utiliser la récursivité a gauche |
|---|
| 324 | //====================================================== |
|---|
| 325 | Attributeetoile |
|---|
| 326 | : Attributeetoile attribute {} |
|---|
| 327 | | {/* Epsilon */} |
|---|
| 328 | ; |
|---|
| 329 | |
|---|
| 330 | //====================================================== |
|---|
| 331 | // attribute |
|---|
| 332 | //====================================================== |
|---|
| 333 | // regle 41 |
|---|
| 334 | // un attribut est compose d'un identifiant |
|---|
| 335 | // d'un "=" |
|---|
| 336 | // et d'une définition de chaine de caractere |
|---|
| 337 | // ( "xxx" ou 'xxx' ) |
|---|
| 338 | //====================================================== |
|---|
| 339 | attribute |
|---|
| 340 | : ID Eq ATTVALUE |
|---|
| 341 | { |
|---|
| 342 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 343 | printf ("attribute : %s\n",$1) ; |
|---|
| 344 | #endif |
|---|
| 345 | } |
|---|
| 346 | ; |
|---|
| 347 | |
|---|
| 348 | //====================================================== |
|---|
| 349 | // EmptyElemTag |
|---|
| 350 | //====================================================== |
|---|
| 351 | // regle 44 |
|---|
| 352 | // ICI ON DEFINIT NEUTRE |
|---|
| 353 | // on ne renvoie pas de char* |
|---|
| 354 | // parce qu'il n'y a pas de comparaisons a faire |
|---|
| 355 | // avec un identifiant d'une balise jumelle |
|---|
| 356 | //====================================================== |
|---|
| 357 | EmptyElemTag |
|---|
| 358 | : INFCAR ID Attributeetoile SLASH SUPCAR { |
|---|
| 359 | if(strncasecmp($2,"Default",7)==0){ |
|---|
| 360 | wait_defaults=false; |
|---|
| 361 | current_data=previous_data; |
|---|
| 362 | if(current_element->defaults==NULL){ |
|---|
| 363 | current_element->defaults=(iotype*)malloc(IOTYPE_SIZE); |
|---|
| 364 | current_element->defaults->content=NULL; |
|---|
| 365 | } |
|---|
| 366 | addMapToMap(¤t_element->defaults->content,current_content); |
|---|
| 367 | freeMap(¤t_content); |
|---|
| 368 | free(current_content); |
|---|
| 369 | current_element->defaults->next=NULL; |
|---|
| 370 | wait_defaults=false; |
|---|
| 371 | current_content=NULL; |
|---|
| 372 | current_element->supported=NULL; |
|---|
| 373 | current_element->next=NULL; |
|---|
| 374 | } |
|---|
| 375 | } |
|---|
| 376 | ; |
|---|
| 377 | |
|---|
| 378 | //====================================================== |
|---|
| 379 | // ETag |
|---|
| 380 | //====================================================== |
|---|
| 381 | // regle 42 |
|---|
| 382 | // BALISE FERMANTE |
|---|
| 383 | // les separateurs après ID sont filtrés |
|---|
| 384 | //====================================================== |
|---|
| 385 | ETag |
|---|
| 386 | : INFCAR SLASH ID SUPCAR |
|---|
| 387 | { |
|---|
| 388 | if(strcmp($3,"DataInputs")==0){ |
|---|
| 389 | current_data=1; |
|---|
| 390 | } |
|---|
| 391 | if(strcmp($3,"DataOutputs")==0){ |
|---|
| 392 | current_data=2; |
|---|
| 393 | } |
|---|
| 394 | if(strcmp($3,"MetaData")==0){ |
|---|
| 395 | current_data=previous_data; |
|---|
| 396 | } |
|---|
| 397 | if(strcmp($3,"ComplexData")==0 || strcmp($3,"LiteralData")==0 |
|---|
| 398 | || strcmp($3,"ComplexOutput")==0 || strcmp($3,"LiteralOutput")==0){ |
|---|
| 399 | current_content=NULL; |
|---|
| 400 | } |
|---|
| 401 | if(strcmp($3,"Default")==0){ |
|---|
| 402 | current_data=previous_data; |
|---|
| 403 | if(current_element->defaults==NULL){ |
|---|
| 404 | current_element->defaults=(iotype*)malloc(IOTYPE_SIZE); |
|---|
| 405 | current_element->defaults->content=NULL; |
|---|
| 406 | } |
|---|
| 407 | addMapToMap(¤t_element->defaults->content,current_content); |
|---|
| 408 | freeMap(¤t_content); |
|---|
| 409 | free(current_content); |
|---|
| 410 | current_element->defaults->next=NULL; |
|---|
| 411 | wait_defaults=false; |
|---|
| 412 | current_content=NULL; |
|---|
| 413 | current_element->supported=NULL; |
|---|
| 414 | current_element->next=NULL; |
|---|
| 415 | } |
|---|
| 416 | if(strcmp($3,"Supported")==0){ |
|---|
| 417 | current_data=previous_data; |
|---|
| 418 | if(current_element->supported==NULL){ |
|---|
| 419 | if(current_content!=NULL){ |
|---|
| 420 | current_element->supported=(iotype*)malloc(IOTYPE_SIZE); |
|---|
| 421 | current_element->supported->content=NULL; |
|---|
| 422 | addMapToMap(¤t_element->supported->content,current_content); |
|---|
| 423 | freeMap(¤t_content); |
|---|
| 424 | free(current_content); |
|---|
| 425 | current_element->supported->next=NULL; |
|---|
| 426 | current_content=NULL; |
|---|
| 427 | }else{ |
|---|
| 428 | current_element->supported=NULL; |
|---|
| 429 | current_element->next=NULL; |
|---|
| 430 | } |
|---|
| 431 | } |
|---|
| 432 | else{ |
|---|
| 433 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 434 | fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n"); |
|---|
| 435 | #endif |
|---|
| 436 | addMapToIoType(¤t_element->supported,current_content); |
|---|
| 437 | freeMap(¤t_content); |
|---|
| 438 | free(current_content); |
|---|
| 439 | current_content=NULL; |
|---|
| 440 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 441 | dumpElements(current_element); |
|---|
| 442 | fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n"); |
|---|
| 443 | #endif |
|---|
| 444 | } |
|---|
| 445 | current_content=NULL; |
|---|
| 446 | } |
|---|
| 447 | } |
|---|
| 448 | ; |
|---|
| 449 | |
|---|
| 450 | //====================================================== |
|---|
| 451 | // contentetoile |
|---|
| 452 | //====================================================== |
|---|
| 453 | // regle 43 |
|---|
| 454 | // ENTRE 2 BALISES |
|---|
| 455 | // entre 2 balises, on peut avoir : |
|---|
| 456 | // --- OUVRANTE CONTENU FERMANTE (recursivement !) |
|---|
| 457 | // --- DU TEXTE quelconque |
|---|
| 458 | // --- COMMENTS |
|---|
| 459 | // --- DES PROCESSES INSTRUCTIONS |
|---|
| 460 | // --- /!\ il peut y avoir une processing instruction invalide ! <?xml |
|---|
| 461 | // --- EPSILON |
|---|
| 462 | // ### et/ou tout ca a la suite en nombre indeterminé |
|---|
| 463 | // ### donc c'est un operateur etoile (*) |
|---|
| 464 | //====================================================== |
|---|
| 465 | contentetoile |
|---|
| 466 | : contentetoile element {} |
|---|
| 467 | | contentetoile PIERROR {srerror("processing instruction <?xml ?> impossible\n");} |
|---|
| 468 | | contentetoile PI {} |
|---|
| 469 | ///// on filtre les commentaires | contentetoile comment {} |
|---|
| 470 | | contentetoile NEWLINE {/*printf("NEWLINE FOUND !!");*/} |
|---|
| 471 | | contentetoile pair {} |
|---|
| 472 | | contentetoile processid {} |
|---|
| 473 | | contentetoile texteinterbalise {} |
|---|
| 474 | | contentetoile CDATA {} |
|---|
| 475 | | {/* Epsilon */} |
|---|
| 476 | ; |
|---|
| 477 | |
|---|
| 478 | //====================================================== |
|---|
| 479 | // texteinterbalise |
|---|
| 480 | //====================================================== |
|---|
| 481 | // regle 14 |
|---|
| 482 | // DU TEXTE quelconque |
|---|
| 483 | // c'est du CHARDATA |
|---|
| 484 | // il y a eut un probleme avec ID, |
|---|
| 485 | // on a mis des starts conditions, |
|---|
| 486 | // maintenant on croise les ID dans les dbalises |
|---|
| 487 | // et des CHARDATA hors des balises |
|---|
| 488 | //====================================================== |
|---|
| 489 | texteinterbalise |
|---|
| 490 | : CHARDATA {} |
|---|
| 491 | ; |
|---|
| 492 | //====================================================== |
|---|
| 493 | |
|---|
| 494 | pair: PAIR { if(debug) fprintf(stderr,"PAIR FOUND !!\n");if(curr_key!=NULL){free(curr_key);curr_key=NULL;} } |
|---|
| 495 | | EPAIR { |
|---|
| 496 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 497 | fprintf(stderr,"EPAIR FOUND !! \n"); |
|---|
| 498 | fprintf(stderr,"[%s=>%s]\n",curr_key,$1); |
|---|
| 499 | fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key); |
|---|
| 500 | dumpMap(current_content); |
|---|
| 501 | fflush(stderr); |
|---|
| 502 | #endif |
|---|
| 503 | if($1!=NULL){ |
|---|
| 504 | if(current_content==NULL){ |
|---|
| 505 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 506 | fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key); |
|---|
| 507 | #endif |
|---|
| 508 | current_content=createMap(curr_key,$1); |
|---|
| 509 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 510 | fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key); |
|---|
| 511 | #endif |
|---|
| 512 | //current_content->next=NULL; |
|---|
| 513 | } |
|---|
| 514 | else{ |
|---|
| 515 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 516 | dumpMap(current_content); |
|---|
| 517 | fprintf(stderr,"addToMap(current_content,%s,%s) !! \n",curr_key,$1); |
|---|
| 518 | #endif |
|---|
| 519 | addToMap(current_content,curr_key,$1); |
|---|
| 520 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 521 | fprintf(stderr,"addToMap(current_content,%s,%s) end !! \n",curr_key,$1); |
|---|
| 522 | #endif |
|---|
| 523 | } |
|---|
| 524 | } |
|---|
| 525 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 526 | fprintf(stderr,"EPAIR FOUND !! \n"); |
|---|
| 527 | fprintf(stderr,"[%s=>%s]\n",curr_key,$1); |
|---|
| 528 | fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key); |
|---|
| 529 | fflush(stderr); |
|---|
| 530 | #endif |
|---|
| 531 | if(curr_key!=NULL){ |
|---|
| 532 | free(curr_key); |
|---|
| 533 | curr_key=NULL; |
|---|
| 534 | } |
|---|
| 535 | } |
|---|
| 536 | | SPAIR { if(curr_key!=NULL) {free(curr_key);curr_key=NULL;} if($1!=NULL) curr_key=strdup($1);if(debug) fprintf(stderr,"SPAIR FOUND !!\n"); } |
|---|
| 537 | ; |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | processid |
|---|
| 541 | : ANID { |
|---|
| 542 | if(data==-1){ |
|---|
| 543 | data=1; |
|---|
| 544 | if($1!=NULL){ |
|---|
| 545 | char *cen=strdup($1); |
|---|
| 546 | my_service->name=(char*)malloc((strlen(cen)-1)*sizeof(char*)); |
|---|
| 547 | cen[strlen(cen)-1]=0; |
|---|
| 548 | cen+=1; |
|---|
| 549 | sprintf(my_service->name,"%s",cen); |
|---|
| 550 | cen-=1; |
|---|
| 551 | free(cen); |
|---|
| 552 | my_service->content=NULL; |
|---|
| 553 | my_service->metadata=NULL; |
|---|
| 554 | my_service->inputs=NULL; |
|---|
| 555 | my_service->outputs=NULL; |
|---|
| 556 | } |
|---|
| 557 | } else { |
|---|
| 558 | if(current_data==1){ |
|---|
| 559 | if(my_service->content!=NULL && current_element->name!=NULL){ |
|---|
| 560 | if(my_service->inputs==NULL){ |
|---|
| 561 | my_service->inputs=dupElements(current_element); |
|---|
| 562 | my_service->inputs->next=NULL; |
|---|
| 563 | tmp_count++; |
|---|
| 564 | } |
|---|
| 565 | else{ |
|---|
| 566 | addToElements(&my_service->inputs,current_element); |
|---|
| 567 | } |
|---|
| 568 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 569 | fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__); |
|---|
| 570 | dumpElements(current_element); |
|---|
| 571 | fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__); |
|---|
| 572 | dumpElements(my_service->inputs); |
|---|
| 573 | #endif |
|---|
| 574 | freeElements(¤t_element); |
|---|
| 575 | free(current_element); |
|---|
| 576 | current_element=NULL; |
|---|
| 577 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 578 | fprintf(stderr,"(DATAINPUTS - 489) ALLOCATE current_element\n"); |
|---|
| 579 | #endif |
|---|
| 580 | current_element=(elements*)malloc(ELEMENTS_SIZE); |
|---|
| 581 | current_element->name=NULL; |
|---|
| 582 | current_element->content=NULL; |
|---|
| 583 | current_element->metadata=NULL; |
|---|
| 584 | current_element->format=NULL; |
|---|
| 585 | current_element->defaults=NULL; |
|---|
| 586 | current_element->supported=NULL; |
|---|
| 587 | current_element->next=NULL; |
|---|
| 588 | } |
|---|
| 589 | if(current_element->name==NULL){ |
|---|
| 590 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 591 | fprintf(stderr,"NAME IN %s (current - %s)\n", |
|---|
| 592 | $1,current_element->name); |
|---|
| 593 | #endif |
|---|
| 594 | wait_inputs=true; |
|---|
| 595 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 596 | fprintf(stderr,"(DATAINPUTS - 501) SET NAME OF current_element\n"); |
|---|
| 597 | #endif |
|---|
| 598 | if($1!=NULL){ |
|---|
| 599 | char *cen=strdup($1); |
|---|
| 600 | current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char*)); |
|---|
| 601 | cen[strlen(cen)-1]=0; |
|---|
| 602 | cen+=1; |
|---|
| 603 | sprintf(current_element->name,"%s",cen); |
|---|
| 604 | cen-=1; |
|---|
| 605 | free(cen); |
|---|
| 606 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 607 | fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name); |
|---|
| 608 | #endif |
|---|
| 609 | current_element->content=NULL; |
|---|
| 610 | current_element->metadata=NULL; |
|---|
| 611 | current_element->format=NULL; |
|---|
| 612 | current_element->defaults=NULL; |
|---|
| 613 | current_element->supported=NULL; |
|---|
| 614 | current_element->next=NULL; |
|---|
| 615 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 616 | fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name); |
|---|
| 617 | #endif |
|---|
| 618 | } |
|---|
| 619 | } |
|---|
| 620 | } |
|---|
| 621 | else |
|---|
| 622 | if(current_data==2){ |
|---|
| 623 | wait_outputs=true; |
|---|
| 624 | if(wait_inputs){ |
|---|
| 625 | if(current_element!=NULL && current_element->name!=NULL){ |
|---|
| 626 | if(my_service->outputs==NULL){ |
|---|
| 627 | my_service->outputs=dupElements(current_element); |
|---|
| 628 | my_service->outputs->next=NULL; |
|---|
| 629 | } |
|---|
| 630 | else{ |
|---|
| 631 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 632 | fprintf(stderr,"LAST NAME IN %s (current - %s)\n",$1,current_element->name); |
|---|
| 633 | #endif |
|---|
| 634 | addToElements(&my_service->outputs,current_element); |
|---|
| 635 | } |
|---|
| 636 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 637 | dumpElements(current_element); |
|---|
| 638 | fprintf(stderr,"(DATAOUTPUTS) FREE current_element %s %i\n",__FILE__,__LINE__); |
|---|
| 639 | #endif |
|---|
| 640 | freeElements(¤t_element); |
|---|
| 641 | free(current_element); |
|---|
| 642 | current_element=NULL; |
|---|
| 643 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 644 | fprintf(stderr,"(DATAOUTPUTS -%d) ALLOCATE current_element %s \n",__LINE__,__FILE__); |
|---|
| 645 | #endif |
|---|
| 646 | current_element=(elements*)malloc(ELEMENTS_SIZE); |
|---|
| 647 | current_element->name=NULL; |
|---|
| 648 | current_element->content=NULL; |
|---|
| 649 | current_element->metadata=NULL; |
|---|
| 650 | current_element->format=NULL; |
|---|
| 651 | current_element->defaults=NULL; |
|---|
| 652 | current_element->supported=NULL; |
|---|
| 653 | current_element->next=NULL; |
|---|
| 654 | } |
|---|
| 655 | if(current_element->name==NULL){ |
|---|
| 656 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 657 | fprintf(stderr,"NAME OUT %s\n",$1); |
|---|
| 658 | fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element\n",__LINE__); |
|---|
| 659 | #endif |
|---|
| 660 | if($1!=NULL){ |
|---|
| 661 | char *cen=strdup($1); |
|---|
| 662 | current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char)); |
|---|
| 663 | cen[strlen(cen)-1]=0; |
|---|
| 664 | cen+=1; |
|---|
| 665 | sprintf(current_element->name,"%s",cen); |
|---|
| 666 | cen-=1; |
|---|
| 667 | free(cen); |
|---|
| 668 | current_element->content=NULL; |
|---|
| 669 | current_element->metadata=NULL; |
|---|
| 670 | current_element->format=NULL; |
|---|
| 671 | current_element->defaults=NULL; |
|---|
| 672 | current_element->supported=NULL; |
|---|
| 673 | current_element->next=NULL; |
|---|
| 674 | } |
|---|
| 675 | } |
|---|
| 676 | |
|---|
| 677 | current_content=NULL; |
|---|
| 678 | } |
|---|
| 679 | else |
|---|
| 680 | if(current_element!=NULL && current_element->name!=NULL){ |
|---|
| 681 | if(my_service->outputs==NULL) |
|---|
| 682 | my_service->outputs=dupElements(current_element); |
|---|
| 683 | else |
|---|
| 684 | addToElements(&my_service->outputs,current_element); |
|---|
| 685 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 686 | fprintf(stderr,"ADD TO OUTPUTS Elements\n"); |
|---|
| 687 | dupElements(current_element); |
|---|
| 688 | #endif |
|---|
| 689 | freeElements(¤t_element); |
|---|
| 690 | free(current_element); |
|---|
| 691 | current_element=NULL; |
|---|
| 692 | } |
|---|
| 693 | else{ |
|---|
| 694 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 695 | fprintf(stderr,"NAME OUT %s\n",$1); |
|---|
| 696 | fprintf(stderr,"(DATAOUTPUTS - 545) SET NAME OF current_element\n"); |
|---|
| 697 | #endif |
|---|
| 698 | if($1!=NULL){ |
|---|
| 699 | char *cen=strdup($1); |
|---|
| 700 | current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char*)); |
|---|
| 701 | cen[strlen(cen)-1]=0; |
|---|
| 702 | #ifdef DEBUG |
|---|
| 703 | fprintf(stderr,"tmp %s\n",cen); |
|---|
| 704 | #endif |
|---|
| 705 | cen+=1; |
|---|
| 706 | sprintf(current_element->name,"%s",cen); |
|---|
| 707 | cen-=1; |
|---|
| 708 | free(cen); |
|---|
| 709 | current_element->content=NULL; |
|---|
| 710 | current_element->metadata=NULL; |
|---|
| 711 | current_element->format=NULL; |
|---|
| 712 | current_element->defaults=NULL; |
|---|
| 713 | current_element->supported=NULL; |
|---|
| 714 | current_element->next=NULL; |
|---|
| 715 | } |
|---|
| 716 | } |
|---|
| 717 | wait_inputs=false; |
|---|
| 718 | wait_outputs=true; |
|---|
| 719 | //wait_outputs=true; |
|---|
| 720 | } |
|---|
| 721 | } |
|---|
| 722 | } |
|---|
| 723 | ; |
|---|
| 724 | |
|---|
| 725 | %% |
|---|
| 726 | |
|---|
| 727 | // srerror |
|---|
| 728 | //====================================================== |
|---|
| 729 | /* fonction qui affiche l erreur si il y en a une */ |
|---|
| 730 | //====================================================== |
|---|
| 731 | void srerror(const char *s) |
|---|
| 732 | { |
|---|
| 733 | if(debug) |
|---|
| 734 | fprintf(stderr,"\nligne %d : %s\n",srlineno,s); |
|---|
| 735 | } |
|---|
| 736 | |
|---|
| 737 | /** |
|---|
| 738 | * getServiceFromFile : |
|---|
| 739 | * set service given as second parameter with informations extracted from the |
|---|
| 740 | * definition file. |
|---|
| 741 | */ |
|---|
| 742 | int getServiceFromFile(const char* file,service** service){ |
|---|
| 743 | |
|---|
| 744 | freeMap(&previous_content); |
|---|
| 745 | previous_content=NULL; |
|---|
| 746 | freeMap(¤t_content); |
|---|
| 747 | current_content=NULL; |
|---|
| 748 | freeMap(&scontent); |
|---|
| 749 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 750 | fprintf(stderr,"(STARTING)FREE current_element\n"); |
|---|
| 751 | #endif |
|---|
| 752 | freeElements(¤t_element); |
|---|
| 753 | free(current_element); |
|---|
| 754 | current_element=NULL; |
|---|
| 755 | my_service=NULL; |
|---|
| 756 | scontent=NULL; |
|---|
| 757 | |
|---|
| 758 | wait_maincontent=true; |
|---|
| 759 | wait_mainmetadata=false; |
|---|
| 760 | wait_metadata=false; |
|---|
| 761 | wait_inputs=false; |
|---|
| 762 | wait_defaults=false; |
|---|
| 763 | wait_supporteds=false; |
|---|
| 764 | wait_outputs=false; |
|---|
| 765 | wait_data=false; |
|---|
| 766 | data=-1; |
|---|
| 767 | previous_data=1; |
|---|
| 768 | current_data=0; |
|---|
| 769 | |
|---|
| 770 | my_service=*service; |
|---|
| 771 | |
|---|
| 772 | srin = fopen(file,"r"); |
|---|
| 773 | if (srin==NULL){ |
|---|
| 774 | fprintf(stderr,"error : file not found\n") ; |
|---|
| 775 | return -1; |
|---|
| 776 | } |
|---|
| 777 | |
|---|
| 778 | int resultatYYParse = srparse() ; |
|---|
| 779 | |
|---|
| 780 | if(wait_outputs && current_element!=NULL && current_element->name!=NULL){ |
|---|
| 781 | if(my_service->outputs==NULL){ |
|---|
| 782 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 783 | fprintf(stderr,"(DATAOUTPUTS - %d) DUP current_element\n",__LINE__); |
|---|
| 784 | #endif |
|---|
| 785 | my_service->outputs=dupElements(current_element); |
|---|
| 786 | my_service->outputs->next=NULL; |
|---|
| 787 | } |
|---|
| 788 | else{ |
|---|
| 789 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 790 | fprintf(stderr,"(DATAOUTPUTS - %d) COPY current_element\n",__LINE__); |
|---|
| 791 | #endif |
|---|
| 792 | addToElements(&my_service->outputs,current_element); |
|---|
| 793 | } |
|---|
| 794 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 795 | fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__); |
|---|
| 796 | #endif |
|---|
| 797 | freeElements(¤t_element); |
|---|
| 798 | free(current_element); |
|---|
| 799 | current_element=NULL; |
|---|
| 800 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 801 | fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__); |
|---|
| 802 | #endif |
|---|
| 803 | } |
|---|
| 804 | if(current_element!=NULL){ |
|---|
| 805 | freeElements(¤t_element); |
|---|
| 806 | free(current_element); |
|---|
| 807 | current_element=NULL; |
|---|
| 808 | } |
|---|
| 809 | if(current_content!=NULL){ |
|---|
| 810 | freeMap(¤t_content); |
|---|
| 811 | free(current_content); |
|---|
| 812 | current_content=NULL; |
|---|
| 813 | } |
|---|
| 814 | fclose(srin); |
|---|
| 815 | #ifdef DEBUG_SERVICE_CONF |
|---|
| 816 | dumpService(my_service); |
|---|
| 817 | #endif |
|---|
| 818 | *service=my_service; |
|---|
| 819 | |
|---|
| 820 | #ifndef WIN32 |
|---|
| 821 | srlex_destroy(); |
|---|
| 822 | #endif |
|---|
| 823 | return resultatYYParse; |
|---|
| 824 | } |
|---|