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

Last change on this file since 844 was 790, checked in by djay, 8 years ago

Add support for nested inputs and outputs.

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