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

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

Add support for nested inputs and outputs.

File size: 25.7 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;
35static bool wait_metadata=false;
[790]36static bool wait_nested=false;
[1]37static bool wait_inputs=false;
38static bool wait_defaults=false;
39static bool wait_supporteds=false;
[618]40static bool wait_outputs=false;
[1]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;
[790]50static int nested_level=0;
[1]51// namespace
52using namespace std;
53
54// srerror
[114]55void srerror(const char *s);
[1]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);
[9]73extern int srlex_destroy(void);
[1]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
[607]85
[1]86%token INFCAR SUPCAR
[607]87
[1]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
[607]93
[1]94/* <!-- xxx -> <? xxx yyy ?> */
95%token PI PIERROR /** COMMENT **/
[607]96
[1]97/* <!-- xxx -> <? xxx yyy ?> */
98%token ERREURGENERALE CDATA WHITESPACE NEWLINE
99%type <s> STag
100%type <s> ETag
101%type <s> ANID
102
[607]103// % start
104
[1]105%%
[607]106// document
[1]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
[781]115 : miscetoile PIERROR {  srerror("processing instruction beginning with <?xml ?> impossible\n");}
[1]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}
[20]129
[1]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 ;
[20]135
[1]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{
[379]144#ifdef DEBUG_SERVICE_CONF
[621]145  fprintf(stderr,"STag (%s %d) %s %d %d \n",__FILE__,__LINE__,$2,current_data,previous_data);
[379]146  fflush(stderr);
[607]147  dumpMap(current_content);
[379]148#endif
[790]149  if(my_service->content==NULL && current_content!=NULL){
[1]150#ifdef DEBUG_SERVICE_CONF
151    fprintf(stderr,"NO CONTENT\n");
152#endif
[9]153    addMapToMap(&my_service->content,current_content);
154    freeMap(&current_content);
155    free(current_content);
[1]156    current_content=NULL;
157    my_service->metadata=NULL;
158    wait_maincontent=false;
159  }
[790]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
[9]171  if(strncasecmp($2,"DataInputs",10)==0){
[1]172    if(current_element==NULL){
173#ifdef DEBUG_SERVICE_CONF
[104]174      fprintf(stderr,"(DATAINPUTS - %d) FREE current_element\n",__LINE__);
[1]175#endif
176      freeElements(&current_element);
177      free(current_element);
178#ifdef DEBUG_SERVICE_CONF
[104]179      fprintf(stderr,"(DATAINPUTS - %d) ALLOCATE current_element\n",__LINE__);
[1]180#endif
181      current_element=NULL;
[790]182      current_element=createEmptyElements();
[1]183    }
184    wait_inputs=true;
185    current_data=1;
186    previous_data=1;
187  }
188  else
[9]189    if(strncasecmp($2,"DataOutputs",11)==0){
[1]190      if(wait_inputs==true){
191#ifdef DEBUG_SERVICE_CONF
[104]192        fprintf(stderr,"(DATAOUTPUTS %d) DUP INPUTS current_element\n",__LINE__);
[9]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);
[65]198#endif 
[469]199        if(my_service->inputs==NULL && current_element!=NULL && current_element->name!=NULL){
[1]200          my_service->inputs=dupElements(current_element);
[9]201          my_service->inputs->next=NULL;
[469]202          freeElements(&current_element);
[9]203        }
[57]204        else if(current_element!=NULL && current_element->name!=NULL){
[9]205          addToElements(&my_service->inputs,current_element);
[469]206          freeElements(&current_element);
[57]207        }
[1]208#ifdef DEBUG_SERVICE_CONF
[9]209        fprintf(stderr,"CURRENT_ELEMENT\n");
[1]210        dumpElements(current_element);
[9]211        fprintf(stderr,"SERVICE INPUTS\n");
[1]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
[104]221        fprintf(stderr,"(DATAOUTPUTS - %d) ALLOCATE current_element (%s)\n",__LINE__,$2);
[379]222        fflush(stderr);
[1]223#endif
[790]224        current_element=createEmptyElements();
[1]225      }
[607]226      wait_outputs=1;
[1]227      current_data=2;
[65]228      previous_data=2;
[1]229    }
230    else
[9]231      if(strncasecmp($2,"MetaData",8)==0){
[73]232        previous_data=current_data;
[1]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");
[104]237          fprintf(stderr,"LINE %d",__LINE__);
[1]238#endif
239          addMapToMap(&current_element->content,current_content);
240          freeMap(&current_content);
241          free(current_content);
[104]242          if(previous_data==1 || previous_data==2)
243            wait_metadata=true;
244          else
245            wait_mainmetadata=true;
[1]246        }
247        else{
[104]248          if(previous_data==1 || previous_data==2)
249            wait_metadata=true;
250          else
251            wait_mainmetadata=true;
[1]252        }
253        current_content=NULL;
254      }
255      else
[9]256        if(strncasecmp($2,"ComplexData",11)==0 || strncasecmp($2,"LiteralData",10)==0
[76]257           || strncasecmp($2,"ComplexOutput",13)==0 || strncasecmp($2,"LiteralOutput",12)==0
258           || strncasecmp($2,"BoundingBoxOutput",13)==0 || strncasecmp($2,"BoundingBoxData",12)==0){
[1]259          current_data=4;
[621]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;
[790]268          current_element->child=NULL;
[1]269          current_content=NULL;
270        }
271        else
[9]272          if(strncasecmp($2,"Default",7)==0){
[1]273            wait_defaults=true;
274            current_data=5;
275          }
276          else
[9]277            if(strncasecmp($2,"Supported",9)==0){
[1]278              wait_supporteds=true;
279              if(wait_defaults==true){
280                defaultsc++;
281              }
282              current_data=5;
283            }
284#ifdef DEBUG_SERVICE_CONF
[790]285  fprintf(stderr,"* Identifiant : %s\n",$2);
286  fflush(stderr);
[1]287#endif
288}
289 ;
[20]290
[1]291// Attributeetoile
292// regle 41
293// une liste qui peut etre vide d'attributs
294// utiliser la récursivité a gauche
295Attributeetoile
[621]296: Attributeetoile attribute  {}
[1]297 |                                {/* Epsilon */}
298 ;
[20]299
[1]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 ;
[20]314
[1]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
[226]322 : INFCAR ID Attributeetoile SLASH SUPCAR       {
[379]323#ifdef DEBUG_SERVICE_CONF
324  fprintf(stderr,"(%s %d)\n",__FILE__,__LINE__);
325#endif
[226]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;
[790]340     current_element->child=NULL;
[226]341     current_element->next=NULL;
342   }
[790]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   }
[226]387 }
[1]388 ;
[20]389
[1]390// ETag
391// BALISE FERMANTE
392// les separateurs après ID sont filtrés
393ETag
394 : INFCAR SLASH ID SUPCAR
395{
[379]396#ifdef DEBUG_SERVICE_CONF
[621]397  fprintf(stderr,"ETag %s (%s %d) %d %d \n",$3,__FILE__,__LINE__,current_data,previous_data);
[379]398#endif
[1]399  if(strcmp($3,"DataInputs")==0){
400    current_data=1;
[607]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    }
[1]424  }
425  if(strcmp($3,"DataOutputs")==0){
426    current_data=2;
427  }
428  if(strcmp($3,"MetaData")==0){
[621]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;
[790]440        current_element->child=NULL;
[621]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    }
[1]451    current_data=previous_data;
[621]452    wait_mainmetadata=false;
453    wait_metadata=false;
[1]454  }
455  if(strcmp($3,"ComplexData")==0 || strcmp($3,"LiteralData")==0
456     || strcmp($3,"ComplexOutput")==0 || strcmp($3,"LiteralOutput")==0){
[621]457    if(current_element->format==NULL)
458      current_element->format=zStrdup($3);
[1]459    current_content=NULL;
460  }
461  if(strcmp($3,"Default")==0){
462    current_data=previous_data;
463    if(current_element->defaults==NULL){
[9]464      current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
465      current_element->defaults->content=NULL;
[1]466    }
[9]467    addMapToMap(&current_element->defaults->content,current_content);
468    freeMap(&current_content);
469    free(current_content);
[1]470    current_element->defaults->next=NULL;
471    wait_defaults=false;
472    current_content=NULL;
473    current_element->supported=NULL;
[790]474    current_element->child=NULL;
[57]475    current_element->next=NULL;
[1]476  }
477  if(strcmp($3,"Supported")==0){
478    current_data=previous_data;
479    if(current_element->supported==NULL){
[57]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;
[790]490        current_element->child=NULL;
[57]491        current_element->next=NULL;
492      }
[1]493    }
[9]494    else{
[57]495#ifdef DEBUG_SERVICE_CONF
[9]496      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
[1]497#endif
[57]498      addMapToIoType(&current_element->supported,current_content);
[9]499      freeMap(&current_content);
500      free(current_content);
501      current_content=NULL;
[57]502#ifdef DEBUG_SERVICE_CONF
503      dumpElements(current_element);
[9]504      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
505#endif
[1]506    }
507    current_content=NULL;
508  }
509}
510 ;
[20]511
[1]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 ;
[20]539
[1]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
[104]552pair: PAIR { if(debug) fprintf(stderr,"PAIR FOUND !!\n");if(curr_key!=NULL){free(curr_key);curr_key=NULL;} }
[1]553| EPAIR {
554#ifdef DEBUG_SERVICE_CONF
[621]555  fprintf(stderr,"EPAIR (%s %d)\n",__FILE__,__LINE__);
[104]556  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
557  dumpMap(current_content);
558  fflush(stderr);
[1]559#endif
[539]560  if($1!=NULL && curr_key!=NULL){
[104]561    if(current_content==NULL){
[1]562#ifdef DEBUG_SERVICE_CONF
[104]563      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
[1]564#endif
[104]565      current_content=createMap(curr_key,$1);
[1]566#ifdef DEBUG_SERVICE_CONF
[104]567      fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
[1]568#endif
[104]569    }
570    else{
[1]571#ifdef DEBUG_SERVICE_CONF
[104]572      dumpMap(current_content);
573      fprintf(stderr,"addToMap(current_content,%s,%s) !! \n",curr_key,$1);
[1]574#endif
[104]575      addToMap(current_content,curr_key,$1);
[1]576#ifdef DEBUG_SERVICE_CONF
[104]577      fprintf(stderr,"addToMap(current_content,%s,%s) end !! \n",curr_key,$1);
[1]578#endif   
[104]579    }
[1]580  }
581#ifdef DEBUG_SERVICE_CONF
582  fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
[93]583  fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
[379]584  dumpMap(current_content);
[1]585  fflush(stderr);
586#endif
[9]587  if(curr_key!=NULL){
588    free(curr_key);
589    curr_key=NULL;
[1]590  }
[9]591  }
[453]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"); }
[1]593 ;
594
595
596processid
597: ANID  {
[379]598#ifdef DEBUG_SERVICE_CONF
[621]599  fprintf(stderr,"processid (%s %d) %s\n",__FILE__,__LINE__,$1);
[379]600#endif
[788]601  if(::data==-1){ // knut: add namespace to avoid ambiguous symbol
602    ::data=1;   
[104]603    if($1!=NULL){
[453]604      char *cen=zStrdup($1);
[104]605      cen[strlen(cen)-1]=0;
606      cen+=1;
[790]607      setServiceName(&my_service,cen);
[104]608      cen-=1;
609      free(cen);
610    }
[1]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);
[9]616          my_service->inputs->next=NULL;
[1]617          tmp_count++;
618        }
619        else{
[790]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);
[1]638        }
[790]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        }
[1]659#ifdef DEBUG_SERVICE_CONF
[9]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__);
[1]663        dumpElements(my_service->inputs);
664#endif
[9]665        freeElements(&current_element);
[1]666        free(current_element);
667        current_element=NULL;
668#ifdef DEBUG_SERVICE_CONF
669        fprintf(stderr,"(DATAINPUTS - 489) ALLOCATE current_element\n");
670#endif
[790]671        current_element=createEmptyElements();
[1]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
[104]682        if($1!=NULL){
[453]683          char *cen=zStrdup($1);
[104]684          cen[strlen(cen)-1]=0;
685          cen+=1;
[790]686          setElementsName(&current_element,cen);
[104]687          cen-=1;
688          free(cen);
[1]689#ifdef DEBUG_SERVICE_CONF
[104]690          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
[1]691#endif
692#ifdef DEBUG_SERVICE_CONF
[104]693          fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
[1]694#endif
[104]695        }
[1]696      }
697    }
698    else
699      if(current_data==2){
[607]700        wait_outputs=1;
[65]701        if(wait_inputs){
[57]702          if(current_element!=NULL && current_element->name!=NULL){
[65]703            if(my_service->outputs==NULL){
704              my_service->outputs=dupElements(current_element);
705              my_service->outputs->next=NULL;
[1]706            }
707            else{
708#ifdef DEBUG_SERVICE_CONF
709              fprintf(stderr,"LAST NAME IN %s (current - %s)\n",$1,current_element->name);
710#endif
[65]711              addToElements(&my_service->outputs,current_element);
[1]712            }
713#ifdef DEBUG_SERVICE_CONF
714            dumpElements(current_element);
[9]715            fprintf(stderr,"(DATAOUTPUTS) FREE current_element %s %i\n",__FILE__,__LINE__);
[1]716#endif
717            freeElements(&current_element);
[9]718            free(current_element);
[1]719            current_element=NULL;
720#ifdef DEBUG_SERVICE_CONF
[104]721            fprintf(stderr,"(DATAOUTPUTS -%d) ALLOCATE current_element %s \n",__LINE__,__FILE__);
[1]722#endif
[790]723            current_element=createEmptyElements();
[1]724          }
725          if(current_element->name==NULL){
726#ifdef DEBUG_SERVICE_CONF
727            fprintf(stderr,"NAME OUT %s\n",$1);
[104]728            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element\n",__LINE__);
[1]729#endif
[104]730            if($1!=NULL){
[453]731              char *cen=zStrdup($1);
[104]732              cen[strlen(cen)-1]=0;
733              cen+=1;
[790]734              setElementsName(&current_element,cen);
[104]735              cen-=1;
736              free(cen);
737            }
[1]738          }
[65]739
[1]740          current_content=NULL;
741        }
742        else
[65]743          if(current_element!=NULL && current_element->name!=NULL){
744            if(my_service->outputs==NULL)
745              my_service->outputs=dupElements(current_element);
[790]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
[92]786#ifdef DEBUG_SERVICE_CONF
[65]787            fprintf(stderr,"ADD TO OUTPUTS Elements\n");
788            dupElements(current_element);
[92]789#endif
[65]790            freeElements(&current_element);
791            free(current_element);
792            current_element=NULL;
[790]793           
[453]794            char *cen=zStrdup($1);
[379]795            cen[strlen(cen)-1]=0;
796            cen+=1;
[790]797            current_element=createElements(cen);
[379]798            cen-=1;
799            free(cen);
[65]800          }
801          else{
[1]802#ifdef DEBUG_SERVICE_CONF
803            fprintf(stderr,"NAME OUT %s\n",$1);
[379]804            fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element %s\n",__LINE__,$1);
[1]805#endif
[104]806            if($1!=NULL){
[453]807              char *cen=zStrdup($1);
[104]808              cen[strlen(cen)-1]=0;
[9]809#ifdef DEBUG
[104]810              fprintf(stderr,"tmp %s\n",cen);
[9]811#endif
[104]812              cen+=1;
[790]813              setElementsName(&current_element,cen);
[104]814              cen-=1;
815              free(cen);
816            }
[1]817          }
[65]818        wait_inputs=false;
[607]819        wait_outputs=1;
[65]820        //wait_outputs=true;
[1]821      }
822  }
823 }
824 ;
825
826%%
827
[607]828/**
[781]829 * Print on stderr the message and the line number of the error which occurred.
[607]830 *
831 * @param s the error message
832 */
[114]833void srerror(const char *s)
[1]834{
835  if(debug)
836    fprintf(stderr,"\nligne %d : %s\n",srlineno,s);
837}
838
839/**
[607]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
[1]846 */
[465]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  }
[1]853#ifdef DEBUG_SERVICE_CONF
[790]854  fprintf(stderr,"(STARTING)FREE current_element %s\n",file);
[1]855#endif
[790]856  fflush(stderr);
857  fflush(stdout);
[465]858  if(current_element!=NULL){
859    freeElements(&current_element);
860    free(current_element);
861    current_element=NULL;
862  }
[1]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;
[607]871  wait_outputs=-1;
[1]872  wait_data=false;
[790]873  wait_nested=false;
[788]874//data=-1;
875  ::data=-1; // knut: add namespace to avoid ambiguous symbol
[1]876  previous_data=1;
877  current_data=0;
878 
879  my_service=*service;
880
881  srin = fopen(file,"r");
882  if (srin==NULL){
[503]883    setMapInMaps(conf,"lenv","message","file not found");
[9]884    return -1;
[1]885  }
886
887  int resultatYYParse = srparse() ;
[476]888
[465]889#ifdef DEBUG_SERVICE_CONF
890  fprintf(stderr,"RESULT: %d %d\n",resultatYYParse,wait_outputs);
[607]891  dumpElements(current_element);
[465]892#endif
[618]893  if(wait_outputs && current_element!=NULL && current_element->name!=NULL){
[676]894    if(current_content!=NULL){
895      addMapToMap(&current_element->content,current_content);
896    }
[607]897    if(my_service->outputs==NULL){ 
[1]898#ifdef DEBUG_SERVICE_CONF
[104]899      fprintf(stderr,"(DATAOUTPUTS - %d) DUP current_element\n",__LINE__);
[1]900#endif
901      my_service->outputs=dupElements(current_element);
[9]902      my_service->outputs->next=NULL;
[1]903    }
904    else{
905#ifdef DEBUG_SERVICE_CONF
[104]906      fprintf(stderr,"(DATAOUTPUTS - %d) COPY current_element\n",__LINE__);
[1]907#endif
[790]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);
[1]925    }
926#ifdef DEBUG_SERVICE_CONF
[104]927    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
[1]928#endif
929    freeElements(&current_element);
[9]930    free(current_element);
931    current_element=NULL;
[57]932#ifdef DEBUG_SERVICE_CONF
[104]933    fprintf(stderr,"(DATAOUTPUTS - %d) FREE current_element\n",__LINE__);
[57]934#endif
[1]935  }
936  if(current_element!=NULL){
937    freeElements(&current_element);
[9]938    free(current_element);
[1]939    current_element=NULL;
940  }
[618]941  int contentOnly=false;
[1]942  if(current_content!=NULL){
[607]943    if(my_service->content==NULL){
944      addMapToMap(&my_service->content,current_content);
[618]945      contentOnly=true;
946      wait_maincontent=false;
[607]947    }
[1]948    freeMap(&current_content);
[9]949    free(current_content);
[1]950    current_content=NULL;
951  }
952  fclose(srin);
953#ifdef DEBUG_SERVICE_CONF
954  dumpService(my_service);
955#endif
[618]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))){
[465]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;
[1]965
[216]966#ifndef WIN32
[9]967  srlex_destroy();
[216]968#endif
[1]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