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

Last change on this file was 917, checked in by djay, 5 years ago

Merge prototype-v0 branch in trunk

File size: 27.5 KB
RevLine 
[607]1/*
[1]2 * Author : Gérald FENOY
3 *
[621]4 * Copyright (c) 209-2015 GeoLabs SARL
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
[1]23 */
[607]24%{
[1]25
26#include <string>
27#include <stdio.h>
28#include <ctype.h>
29#include <service.h>
30
31static int tmp_count=1;
32static int defaultsc=0;
33static bool wait_maincontent=true;
34static bool wait_mainmetadata=false;
[917]35static bool wait_mainap=false;
[1]36static bool wait_metadata=false;
[917]37static bool wait_ap=false;
[790]38static bool wait_nested=false;
[1]39static bool wait_inputs=false;
40static bool wait_defaults=false;
41static bool wait_supporteds=false;
[618]42static bool wait_outputs=false;
[1]43static bool wait_data=false;
44static service* my_service=NULL;
45static map* current_content=NULL;
46static elements* current_element=NULL;
47static char* curr_key;
48static int debug=0;
49static int data=-1;
50static int previous_data=0;
51static int current_data=0;
[790]52static int nested_level=0;
[1]53// namespace
54using namespace std;
55
56// srerror
[114]57void srerror(const char *s);
[1]58
59// usage ()
60void usage(void) ;
61
62// srdebug
63extern int srdebug;
64
65extern char srtext[];
66
67// srlineno
68extern int srlineno;
69
70// srin
71extern FILE* srin;
72
73// srlex
74extern int srlex(void);
[9]75extern int srlex_destroy(void);
[1]76
77%}
78
79
80
81%union
82{char * s;char* chaine;char* key;char* val;}
83
84// jetons //
85%token <s> ID
86%token <s> CHAINE
[607]87
[1]88%token INFCAR SUPCAR
[607]89
[1]90/* / = a1  texte "texte" */
91%token SLASH Eq CHARDATA ATTVALUE PAIR SPAIR EPAIR ANID
92%type <chaine> PAIR
93%type <chaine> EPAIR
94%type <chaine> SPAIR
[607]95
[1]96/* <!-- xxx -> <? xxx yyy ?> */
97%token PI PIERROR /** COMMENT **/
[607]98
[1]99/* <!-- xxx -> <? xxx yyy ?> */
100%token ERREURGENERALE CDATA WHITESPACE NEWLINE
101%type <s> STag
102%type <s> ETag
103%type <s> ANID
104
[607]105// % start
106
[1]107%%
[607]108// document
[1]109// regle 1
110// on est a la racine du fichier xml
111document
112 : miscetoile element miscetoile {}
113 | contentetoile processid contentetoile document {}
114 ;
115
116miscetoile
[781]117 : miscetoile PIERROR {  srerror("processing instruction beginning with <?xml ?> impossible\n");}
[1]118 | miscetoile PI {}
119 | {}
120 ;
121// element
122// regle 39
123// OUVRANTE CONTENU FERMANTE obligatoirement
124// ou neutre
125// on ne peut pas avoir Epsilon
126// un fichier xml ne peut pas etre vide ou seulement avec un prolog
127element
128 : STag contentetoile ETag     
129{
130}
[20]131
[1]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 ;
[20]137
[1]138// STag
139// regle 40
140// BALISE OUVRANTE
141// on est obligé de faire appel a infcar et supcar
142// pour acceder aux start conditions DANSBALISE et INITIAL
143STag
144: INFCAR ID Attributeetoile SUPCAR
145{
[379]146#ifdef DEBUG_SERVICE_CONF
[621]147  fprintf(stderr,"STag (%s %d) %s %d %d \n",__FILE__,__LINE__,$2,current_data,previous_data);
[379]148  fflush(stderr);
[607]149  dumpMap(current_content);
[379]150#endif
[790]151  if(my_service->content==NULL && current_content!=NULL){
[1]152#ifdef DEBUG_SERVICE_CONF
153    fprintf(stderr,"NO CONTENT\n");
154#endif
[9]155    addMapToMap(&my_service->content,current_content);
156    freeMap(&current_content);
157    free(current_content);
[1]158    current_content=NULL;
159    my_service->metadata=NULL;
[917]160    my_service->additional_parameters=NULL;
[1]161    wait_maincontent=false;
162  }
[790]163  if(strncasecmp($2,"EndNested",9)==0){
164#ifdef DEBUG_SERVICE_CONF
[917]165    fprintf(stderr,"(ENDNESTED - %d) \n",__LINE__);
166    fflush(stderr);
[790]167#endif
[917]168    nested_level-=1;
169    if(nested_level==0){
170      wait_nested=false;
171    }
[790]172  }
173
[9]174  if(strncasecmp($2,"DataInputs",10)==0){
[1]175    if(current_element==NULL){
176#ifdef DEBUG_SERVICE_CONF
[104]177      fprintf(stderr,"(DATAINPUTS - %d) FREE current_element\n",__LINE__);
[1]178#endif
179      freeElements(&current_element);
180      free(current_element);
181#ifdef DEBUG_SERVICE_CONF
[104]182      fprintf(stderr,"(DATAINPUTS - %d) ALLOCATE current_element\n",__LINE__);
[1]183#endif
184      current_element=NULL;
[790]185      current_element=createEmptyElements();
[1]186    }
187    wait_inputs=true;
188    current_data=1;
189    previous_data=1;
190  }
191  else
[9]192    if(strncasecmp($2,"DataOutputs",11)==0){
[1]193      if(wait_inputs==true){
194#ifdef DEBUG_SERVICE_CONF
[104]195        fprintf(stderr,"(DATAOUTPUTS %d) DUP INPUTS current_element\n",__LINE__);
[9]196        fprintf(stderr,"CURRENT_ELEMENT\n");
197        dumpElements(current_element);
198        fprintf(stderr,"SERVICE INPUTS\n");
199        dumpElements(my_service->inputs);
200        dumpService(my_service);
[65]201#endif 
[469]202        if(my_service->inputs==NULL && current_element!=NULL && current_element->name!=NULL){
[1]203          my_service->inputs=dupElements(current_element);
[9]204          my_service->inputs->next=NULL;
[469]205          freeElements(&current_element);
[9]206        }
[57]207        else if(current_element!=NULL && current_element->name!=NULL){
[9]208          addToElements(&my_service->inputs,current_element);
[469]209          freeElements(&current_element);
[57]210        }
[1]211#ifdef DEBUG_SERVICE_CONF
[9]212        fprintf(stderr,"CURRENT_ELEMENT\n");
[1]213        dumpElements(current_element);
[9]214        fprintf(stderr,"SERVICE INPUTS\n");
[1]215        dumpElements(my_service->inputs);
216        fprintf(stderr,"(DATAOUTPUTS) FREE current_element\n");
217#endif
218        free(current_element);
219        current_element=NULL;
220        wait_inputs=false;
221      }
222      if(current_element==NULL){
223#ifdef DEBUG_SERVICE_CONF
[104]224        fprintf(stderr,"(DATAOUTPUTS - %d) ALLOCATE current_element (%s)\n",__LINE__,$2);
[379]225        fflush(stderr);
[1]226#endif
[790]227        current_element=createEmptyElements();
[1]228      }
[607]229      wait_outputs=1;
[1]230      current_data=2;
[65]231      previous_data=2;
[1]232    }
233    else
[917]234      if(strncasecmp($2,"MetaData",8)==0 ||
235         strncasecmp($2,"AdditionalParameters",8)==0){
236        if(strncasecmp($2,"AdditionalParameters",8)==0){
237          previous_data=current_data;
238          current_data=4;
239          if(current_element!=NULL){
[1]240#ifdef DEBUG_SERVICE_CONF
[917]241            fprintf(stderr,"add current_content to current_element->content\n");
242            fprintf(stderr,"LINE %d",__LINE__);
[1]243#endif
[917]244            if(wait_mainmetadata)
245              addMapToMap(&my_service->metadata,current_content);
246            else
247              if(wait_metadata)
248                addMapToMap(&current_element->metadata,current_content);
249              else
250                addMapToMap(&current_element->content,current_content);         
251            freeMap(&current_content);
252            free(current_content);
253            if(previous_data==1 || previous_data==2)
254              wait_ap=true;
255            else
256              wait_mainap=true;
257          }
258          else{
259            if(previous_data==1 || previous_data==2)
260              wait_ap=true;
261            else
262              wait_mainap=true;
263          }
264        }else{
265          previous_data=current_data;
266          current_data=3;
267          if(current_element!=NULL){
268#ifdef DEBUG_SERVICE_CONF
269            fprintf(stderr,"add current_content to current_element->content\n");
270            fprintf(stderr,"LINE %d",__LINE__);
271#endif
272            addMapToMap(&current_element->content,current_content);
273            freeMap(&current_content);
274            free(current_content);
275            if(previous_data==1 || previous_data==2)
276              wait_metadata=true;
277            else
278              wait_mainmetadata=true;
279          }
280          else{
281            if(previous_data==1 || previous_data==2)
282              wait_metadata=true;
283            else
284              wait_mainmetadata=true;
285          }
[1]286        }
287        current_content=NULL;
288      }
289      else
[9]290        if(strncasecmp($2,"ComplexData",11)==0 || strncasecmp($2,"LiteralData",10)==0
[76]291           || strncasecmp($2,"ComplexOutput",13)==0 || strncasecmp($2,"LiteralOutput",12)==0
292           || strncasecmp($2,"BoundingBoxOutput",13)==0 || strncasecmp($2,"BoundingBoxData",12)==0){
[1]293          current_data=4;
[621]294          addMapToMap(&current_element->content,current_content);
295          freeMap(&current_content);
296          free(current_content);
297          current_element->next=NULL;
298          if($2!=NULL)
299            current_element->format=zStrdup($2);
300          current_element->defaults=NULL;
301          current_element->supported=NULL;
[790]302          current_element->child=NULL;
[1]303          current_content=NULL;
304        }
305        else
[9]306          if(strncasecmp($2,"Default",7)==0){
[1]307            wait_defaults=true;
308            current_data=5;
309          }
310          else
[9]311            if(strncasecmp($2,"Supported",9)==0){
[1]312              wait_supporteds=true;
313              if(wait_defaults==true){
314                defaultsc++;
315              }
316              current_data=5;
317            }
318#ifdef DEBUG_SERVICE_CONF
[790]319  fprintf(stderr,"* Identifiant : %s\n",$2);
320  fflush(stderr);
[1]321#endif
322}
323 ;
[20]324
[1]325// Attributeetoile
326// regle 41
327// une liste qui peut etre vide d'attributs
328// utiliser la récursivité a gauche
329Attributeetoile
[621]330: Attributeetoile attribute  {}
[1]331 |                                {/* Epsilon */}
332 ;
[20]333
[1]334// attribute
335// regle 41
336// un attribut est compose d'un identifiant
337// d'un "="
338// et d'une définition de chaine de caractere
339// ( "xxx" ou 'xxx' )
340attribute
341 : ID Eq ATTVALUE               
342{
343#ifdef DEBUG_SERVICE_CONF
344  printf ("attribute : %s\n",$1) ;
345#endif
346}
347 ;
[20]348
[1]349// EmptyElemTag
350// regle 44
351// ICI ON DEFINIT NEUTRE
352// on ne renvoie pas de char*
353// parce qu'il n'y a pas de comparaisons a faire
354// avec un identifiant d'une balise jumelle
355EmptyElemTag
[226]356 : INFCAR ID Attributeetoile SLASH SUPCAR       {
[379]357#ifdef DEBUG_SERVICE_CONF
358  fprintf(stderr,"(%s %d)\n",__FILE__,__LINE__);
359#endif
[226]360   if(strncasecmp($2,"Default",7)==0){
361     wait_defaults=false;
362     current_data=previous_data;
363     if(current_element->defaults==NULL){
364       current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
365       current_element->defaults->content=NULL;
366     }
367     addMapToMap(&current_element->defaults->content,current_content);
368     freeMap(&current_content);
369     free(current_content);
370     current_element->defaults->next=NULL;
371     wait_defaults=false;
372     current_content=NULL;
373     current_element->supported=NULL;
[790]374     current_element->child=NULL;
[226]375     current_element->next=NULL;
376   }
[790]377   if(strncasecmp($2,"EndNested",9)==0){
378     if(current_data==1){
379       elements* cursor=my_service->inputs;
380       while(cursor->next!=NULL)
381         cursor=cursor->next;
382       if(nested_level>1){
383         for(int j=0;j<nested_level-1;j++){
384           cursor=cursor->child;
385           while(cursor->next!=NULL)
386             cursor=cursor->next;
387         }
388       }
389       if(cursor->child==NULL){
390         cursor->child=dupElements(current_element);
391       }else{
392         addToElements(&cursor->child,current_element);
393       }
394     }else{
395       if(current_element->name!=NULL){
396         elements* cursor=my_service->outputs;
397         while(cursor->next!=NULL)
398           cursor=cursor->next;
399         if(nested_level>1){
400           for(int j=0;j<nested_level-1;j++){
401             cursor=cursor->child;
402             while(cursor->next!=NULL)
403               cursor=cursor->next;
404           }
405         }
406         if(cursor->child==NULL){
407           cursor->child=dupElements(current_element);
408         }else
409           addToElements(&cursor->child,current_element);
410       }
411     }
412     freeElements(&current_element);
413     free(current_element);
414     current_element=NULL;
415     current_element=createEmptyElements();
416     nested_level-=1;
417     if(nested_level==0){
418       wait_nested=false;       
419     }
420   }
[226]421 }
[1]422 ;
[20]423
[1]424// ETag
425// BALISE FERMANTE
426// les separateurs après ID sont filtrés
427ETag
428 : INFCAR SLASH ID SUPCAR
429{
[379]430#ifdef DEBUG_SERVICE_CONF
[621]431  fprintf(stderr,"ETag %s (%s %d) %d %d \n",$3,__FILE__,__LINE__,current_data,previous_data);
[379]432#endif
[1]433  if(strcmp($3,"DataInputs")==0){
434    current_data=1;
[607]435    if(current_content!=NULL){
436      if(current_element->content==NULL){
437        addMapToMap(&current_element->content,current_content);
438      }
439      freeMap(&current_content);
440      free(current_content);
441      current_content=NULL;
442    }
443    if(current_element!=NULL){
444      if(my_service->content!=NULL && current_element->name!=NULL){
445        if(my_service->inputs==NULL){
446          my_service->inputs=dupElements(current_element);
447          my_service->inputs->next=NULL;
448          tmp_count++;
449        }
450        else{
451          addToElements(&my_service->inputs,current_element);
452        }
453        freeElements(&current_element);
454        free(current_element);
455        current_element=NULL;
456      }
457    }
[1]458  }
459  if(strcmp($3,"DataOutputs")==0){
460    current_data=2;
[917]461  } 
462  if(strcmp($3,"AdditionalParameters")==0){
463    if(current_content!=NULL){
464#ifdef DEBUG_SERVICE_CONF
465      fprintf(stderr,"add current_content to current_element->content\n");
466      fprintf(stderr,"LINE %d",__LINE__);
467#endif
468      if(wait_ap){
469        current_element->additional_parameters=NULL;
470        addMapToMap(&current_element->additional_parameters,current_content);
471        current_element->next=NULL;
472        current_element->defaults=NULL;
473        current_element->supported=NULL;
474        current_element->child=NULL;
475      }else{
476        if(wait_mainap){
477          addMapToMap(&my_service->additional_parameters,current_content);
478        }
479      }
480
481      freeMap(&current_content);
482      free(current_content);
483      current_content=NULL;
484    }
485    current_data=previous_data;
486    wait_mainap=false;
487    wait_ap=false;
[1]488  }
489  if(strcmp($3,"MetaData")==0){
[621]490    if(current_content!=NULL){
491#ifdef DEBUG_SERVICE_CONF
492      fprintf(stderr,"add current_content to current_element->content\n");
493      fprintf(stderr,"LINE %d",__LINE__);
494#endif
495      if(wait_metadata){
496        current_element->metadata=NULL;
497        addMapToMap(&current_element->metadata,current_content);
498        current_element->next=NULL;
499        current_element->defaults=NULL;
500        current_element->supported=NULL;
[790]501        current_element->child=NULL;
[621]502      }else{
503        if(wait_mainmetadata){
504          addMapToMap(&my_service->metadata,current_content);
505        }
506      }
507
508      freeMap(&current_content);
509      free(current_content);
510      current_content=NULL;
511    }
[1]512    current_data=previous_data;
[621]513    wait_mainmetadata=false;
514    wait_metadata=false;
[1]515  }
516  if(strcmp($3,"ComplexData")==0 || strcmp($3,"LiteralData")==0
517     || strcmp($3,"ComplexOutput")==0 || strcmp($3,"LiteralOutput")==0){
[621]518    if(current_element->format==NULL)
519      current_element->format=zStrdup($3);
[1]520    current_content=NULL;
521  }
522  if(strcmp($3,"Default")==0){
523    current_data=previous_data;
524    if(current_element->defaults==NULL){
[9]525      current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
526      current_element->defaults->content=NULL;
[1]527    }
[9]528    addMapToMap(&current_element->defaults->content,current_content);
529    freeMap(&current_content);
530    free(current_content);
[1]531    current_element->defaults->next=NULL;
532    wait_defaults=false;
533    current_content=NULL;
534    current_element->supported=NULL;
[790]535    current_element->child=NULL;
[57]536    current_element->next=NULL;
[1]537  }
538  if(strcmp($3,"Supported")==0){
539    current_data=previous_data;
540    if(current_element->supported==NULL){
[57]541      if(current_content!=NULL){
542        current_element->supported=(iotype*)malloc(IOTYPE_SIZE);
543        current_element->supported->content=NULL;
544        addMapToMap(&current_element->supported->content,current_content);
545        freeMap(&current_content);
546        free(current_content);
547        current_element->supported->next=NULL;
548        current_content=NULL;
549      }else{
550        current_element->supported=NULL;
[790]551        current_element->child=NULL;
[57]552        current_element->next=NULL;
553      }
[1]554    }
[9]555    else{
[57]556#ifdef DEBUG_SERVICE_CONF
[9]557      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
[1]558#endif
[57]559      addMapToIoType(&current_element->supported,current_content);
[9]560      freeMap(&current_content);
561      free(current_content);
562      current_content=NULL;
[57]563#ifdef DEBUG_SERVICE_CONF
564      dumpElements(current_element);
[9]565      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
566#endif
[1]567    }
568    current_content=NULL;
569  }
570}
571 ;
[20]572
[1]573//======================================================
574// contentetoile
575//======================================================
576// regle 43
577// ENTRE 2 BALISES
578// entre 2 balises, on peut avoir :
579// --- OUVRANTE CONTENU FERMANTE (recursivement !)
580// --- DU TEXTE quelconque
581// --- COMMENTS
582// --- DES PROCESSES INSTRUCTIONS
583// --- /!\ il peut y avoir une processing instruction invalide ! <?xml
584// --- EPSILON
585// ### et/ou tout ca a la suite en nombre indeterminé
586// ### donc c'est un operateur etoile (*)
587//======================================================
588contentetoile
589: contentetoile element           {}
590 | contentetoile PIERROR                  {srerror("processing instruction <?xml ?> impossible\n");}
591 | contentetoile PI                       {}
592///// on filtre les commentaires | contentetoile comment              {}
593 | contentetoile NEWLINE {/*printf("NEWLINE FOUND !!");*/}
594 | contentetoile pair {}
595 | contentetoile processid {}
596 | contentetoile texteinterbalise         {}
597 | contentetoile CDATA {} 
598 | {/* Epsilon */}
599 ;
[20]600
[1]601// texteinterbalise
602// regle 14
603// DU TEXTE quelconque
604// c'est du CHARDATA
605// il y a eut un probleme avec ID,
606// on a mis des starts conditions,
607// maintenant on croise les ID dans les dbalises
608// et des CHARDATA hors des balises
609texteinterbalise
610 : CHARDATA             {}
611 ;
612
[104]613pair: PAIR { if(debug) fprintf(stderr,"PAIR FOUND !!\n");if(curr_key!=NULL){free(curr_key);curr_key=NULL;} }
[1]614| EPAIR {
615#ifdef DEBUG_SERVICE_CONF
[621]616  fprintf(stderr,"EPAIR (%s %d)\n",__FILE__,__LINE__);
[104]617  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
618  dumpMap(current_content);
619  fflush(stderr);
[1]620#endif
[539]621  if($1!=NULL && curr_key!=NULL){
[104]622    if(current_content==NULL){
[1]623#ifdef DEBUG_SERVICE_CONF
[104]624      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
[1]625#endif
[104]626      current_content=createMap(curr_key,$1);
[1]627#ifdef DEBUG_SERVICE_CONF
[104]628      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
[1]629#endif
[104]630    }
631    else{
[1]632#ifdef DEBUG_SERVICE_CONF
[104]633      dumpMap(current_content);
634      fprintf(stderr,"addToMap(current_content,%s,%s) !! \n",curr_key,$1);
[1]635#endif
[104]636      addToMap(current_content,curr_key,$1);
[1]637#ifdef DEBUG_SERVICE_CONF
[104]638      fprintf(stderr,"addToMap(current_content,%s,%s) end !! \n",curr_key,$1);
[1]639#endif   
[104]640    }
[1]641  }
642#ifdef DEBUG_SERVICE_CONF
643  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
[93]644  fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
[379]645  dumpMap(current_content);
[1]646  fflush(stderr);
647#endif
[9]648  if(curr_key!=NULL){
649    free(curr_key);
650    curr_key=NULL;
[1]651  }
[9]652  }
[453]653| 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]654 ;
655
656
657processid
658: ANID  {
[379]659#ifdef DEBUG_SERVICE_CONF
[621]660  fprintf(stderr,"processid (%s %d) %s\n",__FILE__,__LINE__,$1);
[379]661#endif
[788]662  if(::data==-1){ // knut: add namespace to avoid ambiguous symbol
663    ::data=1;   
[104]664    if($1!=NULL){
[453]665      char *cen=zStrdup($1);
[104]666      cen[strlen(cen)-1]=0;
667      cen+=1;
[790]668      setServiceName(&my_service,cen);
[104]669      cen-=1;
670      free(cen);
671    }
[1]672  } else {
673    if(current_data==1){
674      if(my_service->content!=NULL && current_element->name!=NULL){
675        if(my_service->inputs==NULL){
676          my_service->inputs=dupElements(current_element);
[9]677          my_service->inputs->next=NULL;
[1]678          tmp_count++;
679        }
680        else{
[790]681          if(wait_nested){
682            elements* cursor=my_service->inputs;
683            while(cursor->next!=NULL)
684              cursor=cursor->next;
685            if(nested_level>1){
686              for(int j=0;j<nested_level-1;j++){
687                cursor=cursor->child;
688                while(cursor->next!=NULL)
689                  cursor=cursor->next;
690              }
691            }
692            if(cursor->child==NULL){
693              cursor->child=dupElements(current_element);
694            }else{
695              addToElements(&cursor->child,current_element);
696            }
697          }else
698            addToElements(&my_service->inputs,current_element);
[1]699        }
[790]700        if(current_element->format==NULL){
701          wait_nested=true;
702          nested_level+=1;
703          if(current_content!=NULL){
704            elements* cursor=my_service->inputs;
705            while(cursor->next!=NULL)
706              cursor=cursor->next;
707            if(nested_level>1){
708              for(int j=0;j<nested_level-1;j++){
709                cursor=cursor->child;
710                while(cursor->next!=NULL)
711                  cursor=cursor->next;
712              }
713            }
714            addMapToMap(&cursor->content,current_content);
715            freeMap(&current_content);
716            free(current_content);
717            current_content=NULL;
718          }
719        }
[1]720#ifdef DEBUG_SERVICE_CONF
[9]721        fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
722        dumpElements(current_element);
723        fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
[1]724        dumpElements(my_service->inputs);
725#endif
[9]726        freeElements(&current_element);
[1]727        free(current_element);
728        current_element=NULL;
729#ifdef DEBUG_SERVICE_CONF
730        fprintf(stderr,"(DATAINPUTS - 489) ALLOCATE current_element\n");
731#endif
[790]732        current_element=createEmptyElements();
[1]733      }
734      if(current_element->name==NULL){
735#ifdef DEBUG_SERVICE_CONF
736        fprintf(stderr,"NAME IN %s (current - %s)\n",
737                $1,current_element->name);
738#endif
739        wait_inputs=true;
740#ifdef DEBUG_SERVICE_CONF
741        fprintf(stderr,"(DATAINPUTS - 501) SET NAME OF current_element\n");
742#endif
[104]743        if($1!=NULL){
[453]744          char *cen=zStrdup($1);
[104]745          cen[strlen(cen)-1]=0;
746          cen+=1;
[790]747          setElementsName(&current_element,cen);
[104]748          cen-=1;
749          free(cen);
[1]750#ifdef DEBUG_SERVICE_CONF
[104]751          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
[1]752#endif
753#ifdef DEBUG_SERVICE_CONF
[104]754          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
[1]755#endif
[104]756        }
[1]757      }
758    }
759    else
760      if(current_data==2){
[607]761        wait_outputs=1;
[65]762        if(wait_inputs){
[57]763          if(current_element!=NULL && current_element->name!=NULL){
[65]764            if(my_service->outputs==NULL){
765              my_service->outputs=dupElements(current_element);
766              my_service->outputs->next=NULL;
[1]767            }
768            else{
769#ifdef DEBUG_SERVICE_CONF
770              fprintf(stderr,"LAST NAME IN %s (current - %s)\n",$1,current_element->name);
771#endif
[65]772              addToElements(&my_service->outputs,current_element);
[1]773            }
774#ifdef DEBUG_SERVICE_CONF
775            dumpElements(current_element);
[9]776            fprintf(stderr,"(DATAOUTPUTS) FREE current_element %s %i\n",__FILE__,__LINE__);
[1]777#endif
778            freeElements(&current_element);
[9]779            free(current_element);
[1]780            current_element=NULL;
781#ifdef DEBUG_SERVICE_CONF
[104]782            fprintf(stderr,"(DATAOUTPUTS -%d) ALLOCATE current_element %s \n",__LINE__,__FILE__);
[1]783#endif
[790]784            current_element=createEmptyElements();
[1]785          }
786          if(current_element->name==NULL){
787#ifdef DEBUG_SERVICE_CONF
788            fprintf(stderr,"NAME OUT %s\n",$1);
[104]789            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element\n",__LINE__);
[1]790#endif
[104]791            if($1!=NULL){
[453]792              char *cen=zStrdup($1);
[104]793              cen[strlen(cen)-1]=0;
794              cen+=1;
[790]795              setElementsName(&current_element,cen);
[104]796              cen-=1;
797              free(cen);
798            }
[1]799          }
[65]800
[1]801          current_content=NULL;
802        }
803        else
[65]804          if(current_element!=NULL && current_element->name!=NULL){
805            if(my_service->outputs==NULL)
806              my_service->outputs=dupElements(current_element);
[790]807            else{
808              if(wait_nested){
809                elements* cursor=my_service->outputs;
810                while(cursor->next!=NULL)
811                  cursor=cursor->next;
812                if(nested_level>1){
813                  for(int j=0;j<nested_level-1;j++){
814                    cursor=cursor->child;
815                    while(cursor->next!=NULL)
816                      cursor=cursor->next;
817                  }
818                }
819                if(cursor->child==NULL){
820                  cursor->child=dupElements(current_element);
821                }else
822                  addToElements(&cursor->child,current_element);
823              }else
824                addToElements(&my_service->outputs,current_element);
825            }
826            if(current_element->format==NULL){
827              wait_nested=true;
828              nested_level+=1;
829              if(current_content!=NULL){
830                elements* cursor=my_service->outputs;
831                while(cursor->next!=NULL)
832                  cursor=cursor->next;
833                if(nested_level>1){
834                  for(int j=0;j<nested_level-1;j++){
835                    cursor=cursor->child;
836                    while(cursor->next!=NULL)
837                      cursor=cursor->next;
838                  }
839                }
840                addMapToMap(&cursor->content,current_content);
841                freeMap(&current_content);
842                free(current_content);
843                current_content=NULL;
844              }
845            }
846
[92]847#ifdef DEBUG_SERVICE_CONF
[65]848            fprintf(stderr,"ADD TO OUTPUTS Elements\n");
849            dupElements(current_element);
[92]850#endif
[65]851            freeElements(&current_element);
852            free(current_element);
853            current_element=NULL;
[790]854           
[453]855            char *cen=zStrdup($1);
[379]856            cen[strlen(cen)-1]=0;
857            cen+=1;
[790]858            current_element=createElements(cen);
[379]859            cen-=1;
860            free(cen);
[65]861          }
862          else{
[1]863#ifdef DEBUG_SERVICE_CONF
864            fprintf(stderr,"NAME OUT %s\n",$1);
[379]865            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element %s\n",__LINE__,$1);
[1]866#endif
[104]867            if($1!=NULL){
[453]868              char *cen=zStrdup($1);
[104]869              cen[strlen(cen)-1]=0;
[9]870#ifdef DEBUG
[104]871              fprintf(stderr,"tmp %s\n",cen);
[9]872#endif
[104]873              cen+=1;
[790]874              setElementsName(&current_element,cen);
[104]875              cen-=1;
876              free(cen);
877            }
[1]878          }
[65]879        wait_inputs=false;
[607]880        wait_outputs=1;
[65]881        //wait_outputs=true;
[1]882      }
883  }
884 }
885 ;
886
887%%
888
[607]889/**
[781]890 * Print on stderr the message and the line number of the error which occurred.
[607]891 *
892 * @param s the error message
893 */
[114]894void srerror(const char *s)
[1]895{
896  if(debug)
897    fprintf(stderr,"\nligne %d : %s\n",srlineno,s);
898}
899
900/**
[607]901 * Parse a ZCFG file and fill the service structure.
902 *
903 * @param conf the conf maps containing the main.cfg settings
904 * @param file the fullpath to the ZCFG file
905 * @param service the service structure to fill
906 * @return 0 on success, -1 on failure
[1]907 */
[465]908int getServiceFromFile(maps* conf,const char* file,service** service){
909  if(current_content!=NULL){
910    freeMap(&current_content);
911    free(current_content);
912    current_content=NULL;
913  }
[1]914#ifdef DEBUG_SERVICE_CONF
[790]915  fprintf(stderr,"(STARTING)FREE current_element %s\n",file);
[1]916#endif
[790]917  fflush(stderr);
918  fflush(stdout);
[465]919  if(current_element!=NULL){
920    freeElements(&current_element);
921    free(current_element);
922    current_element=NULL;
923  }
[1]924  my_service=NULL;
925
926  wait_maincontent=true;
927  wait_mainmetadata=false;
928  wait_metadata=false;
[917]929  wait_mainap=false;
930  wait_ap=false;
[1]931  wait_inputs=false;
932  wait_defaults=false;
933  wait_supporteds=false;
[607]934  wait_outputs=-1;
[1]935  wait_data=false;
[790]936  wait_nested=false;
[788]937//data=-1;
938  ::data=-1; // knut: add namespace to avoid ambiguous symbol
[1]939  previous_data=1;
940  current_data=0;
941 
942  my_service=*service;
943
944  srin = fopen(file,"r");
945  if (srin==NULL){
[503]946    setMapInMaps(conf,"lenv","message","file not found");
[9]947    return -1;
[1]948  }
949
950  int resultatYYParse = srparse() ;
[476]951
[465]952#ifdef DEBUG_SERVICE_CONF
953  fprintf(stderr,"RESULT: %d %d\n",resultatYYParse,wait_outputs);
[607]954  dumpElements(current_element);
[465]955#endif
[618]956  if(wait_outputs && current_element!=NULL && current_element->name!=NULL){
[676]957    if(current_content!=NULL){
958      addMapToMap(&current_element->content,current_content);
959    }
[607]960    if(my_service->outputs==NULL){ 
[1]961#ifdef DEBUG_SERVICE_CONF
[104]962      fprintf(stderr,"(DATAOUTPUTS - %d) DUP current_element\n",__LINE__);
[1]963#endif
964      my_service->outputs=dupElements(current_element);
[9]965      my_service->outputs->next=NULL;
[1]966    }
967    else{
968#ifdef DEBUG_SERVICE_CONF
[104]969      fprintf(stderr,"(DATAOUTPUTS - %d) COPY current_element\n",__LINE__);
[1]970#endif
[790]971      if(wait_nested){
972        elements* cursor=my_service->outputs;
973        while(cursor->next!=NULL)
974          cursor=cursor->next;
975        if(nested_level>1){
976          for(int j=0;j<nested_level-1;j++){
977            cursor=cursor->child;
978            while(cursor->next!=NULL)
979              cursor=cursor->next;
980          }
981        }
982        if(cursor->child==NULL){
983          cursor->child=dupElements(current_element);
984        }else
985          addToElements(&cursor->child,current_element);
986      }else
987        addToElements(&my_service->outputs,current_element);
[1]988    }
989#ifdef DEBUG_SERVICE_CONF
[104]990    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
[1]991#endif
992    freeElements(&current_element);
[9]993    free(current_element);
994    current_element=NULL;
[57]995#ifdef DEBUG_SERVICE_CONF
[104]996    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
[57]997#endif
[1]998  }
999  if(current_element!=NULL){
1000    freeElements(&current_element);
[9]1001    free(current_element);
[1]1002    current_element=NULL;
1003  }
[618]1004  int contentOnly=false;
[1]1005  if(current_content!=NULL){
[607]1006    if(my_service->content==NULL){
1007      addMapToMap(&my_service->content,current_content);
[618]1008      contentOnly=true;
1009      wait_maincontent=false;
[607]1010    }
[1]1011    freeMap(&current_content);
[9]1012    free(current_content);
[1]1013    current_content=NULL;
1014  }
1015  fclose(srin);
1016#ifdef DEBUG_SERVICE_CONF
1017  dumpService(my_service);
1018#endif
[618]1019  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]1020    setMapInMaps(conf,"lenv","message",srlval.chaine);
1021#ifndef WIN32
1022    srlex_destroy();
1023#endif
1024    return -1;
1025  }
1026  else
1027    *service=my_service;
[1]1028
[216]1029#ifndef WIN32
[9]1030  srlex_destroy();
[216]1031#endif
[1]1032  return resultatYYParse;
1033}
Note: See TracBrowser for help on using the repository browser.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png