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