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

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

Fix for OTB support when input was passed by value rather than reference.

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