source: branches/prototype-v0/zoo-project/zoo-kernel/service.c @ 854

Last change on this file since 854 was 854, checked in by djay, 6 years ago

HPC support update. Add inputs for create options in Gdal_Dem.

  • Property svn:keywords set to Id
File size: 37.4 KB
Line 
1/*
2 * Author : Gérald FENOY
3 *
4 * Copyright (c) 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#include "service.h"
26
27
28#if defined(_MSC_VER) && _MSC_VER < 1800
29#include <stdarg.h>
30/**
31 * snprintf for Visual Studio compiler.
32 *
33 * See https://dxr.mozilla.org/mozilla-central/source/media/mtransport/third_party/nrappkit/src/util/util.c
34 */
35int snprintf(char *buffer, size_t n, const char *format, ...)
36{
37  va_list argp;
38  int ret;
39  va_start(argp, format);
40  ret = _vscprintf(format, argp);
41  vsnprintf_s(buffer, n, _TRUNCATE, format, argp);
42  va_end(argp);
43  return ret;
44}
45#endif
46
47/**
48 * Dump a map on stderr
49 *
50 * @param t the map to dump
51 */
52void _dumpMap(map* t){
53  if(t!=NULL){
54    fprintf(stderr,"%s: %s\n",t->name,t->value);
55    fflush(stderr);
56  }else{
57    fprintf(stderr,"NULL\n");
58    fflush(stderr);
59  }
60}
61
62/**
63 * Dump a map on stderr, see _dumpMap()
64 *
65 * @param t the map to dump
66 */
67void dumpMap(map* t){
68  map* tmp=t;
69  while(tmp!=NULL){
70    _dumpMap(tmp);
71    tmp=tmp->next;
72  }
73}
74
75/**
76 * Dump a map to a file
77 *
78 * @param t the map to dump to file
79 * @param file the file pointer to store the map
80 */
81void dumpMapToFile(map* t,FILE* file){
82  map* tmp=t;
83  while(tmp!=NULL){
84    fprintf(file,"%s = %s\n",tmp->name,tmp->value);
85    tmp=tmp->next;
86  }
87}
88
89/**
90 * Dump a maps on stderr, see dumpMap().
91 *
92 * @param m the map to dump
93 */
94void dumpMaps(maps* m){
95  maps* tmp=m;
96  while(tmp!=NULL){
97    fprintf(stderr,"MAP => [%s] \n",tmp->name);
98    fprintf(stderr," * CONTENT [%s] \n",tmp->name);
99    dumpMap(tmp->content);
100    if(tmp->child!=NULL){
101      fprintf(stderr," * CHILD [%s] \n",tmp->name);
102      dumpMaps(tmp->child);
103      fprintf(stderr," * /CHILD [%s] \n",tmp->name);
104    }
105    tmp=tmp->next;
106  }
107}
108
109/**
110 * Dump a maps to a file, see dumpMapToFile().
111 *
112 * @param m the map to dump
113 * @param file the the file pointer to store the map
114 */
115void _dumpMapsToFile(maps* m,FILE* file,int limit){
116  maps* tmp=m;
117  int cnt=0;
118  while(tmp!=NULL){
119    fprintf(file,"[%s]\n",tmp->name);
120    if(tmp->child!=NULL){
121      _dumpMapsToFile(tmp->child,file,limit);
122    }else
123      dumpMapToFile(tmp->content,file);
124    fflush(file);
125    tmp=tmp->next;
126    if(limit>=0 && cnt==limit)
127      tmp=NULL;
128    cnt++;
129  }
130  fflush(file);
131}
132
133/**
134 * Dump a maps to a file, see _dumpMapsToFile().
135 *
136 * @param m the map to dump
137 * @param file_path the full path to the file name to store the map
138 * @param limit the number limiting the maps to be dumped
139 */
140void dumpMapsToFile(maps* m,char* file_path,int limit){
141  FILE* file=fopen(file_path,"w+");
142  _dumpMapsToFile(m,file,limit);
143  fflush(file);
144  fclose(file);
145}
146
147/**
148 * Create a new iotype*
149 *
150 * @return a pointer to the allocated iotype
151 */
152iotype* createIoType(){
153  iotype* io=(iotype*)malloc(IOTYPE_SIZE);
154  io->content=NULL;
155  io->next=NULL;
156  return io;
157}
158
159/**
160 * Create a new map
161 *
162 * @param name the key to add to the map
163 * @param value the corresponding value to add to the map
164 * @return a pointer to the allocated map
165 */
166map* createMap(const char* name,const char* value){
167  map* tmp=(map *)malloc(MAP_SIZE);
168  tmp->name=zStrdup(name);
169  tmp->value=zStrdup(value);
170  tmp->next=NULL;
171  return tmp;
172}
173
174/**
175 * Create a new maps with the given name
176 *
177 * @param name of the maps
178 * @return the allocated map
179 */
180maps* createMaps(const char* name){
181  maps* tmp = (maps *) malloc (MAPS_SIZE);
182  tmp->name = zStrdup (name);
183  tmp->content = NULL;
184  tmp->child = NULL;
185  tmp->next = NULL;
186  return tmp;
187}
188
189/**
190 * Count number of map in a map
191 *
192 * @param m the maps to count
193 * @return number of map in a map
194 */
195int count(map* m){
196  map* tmp=m;
197  int c=0;
198  while(tmp!=NULL){
199    c++;
200    tmp=tmp->next;
201  }
202  return c;
203}
204
205/**
206 * Verify if a key exist in a map
207 *
208 * @param m the map to search for the key
209 * @param key the key to search in the map
210 * @return true if the key wwas found, false in other case
211 */
212bool hasKey(map* m,const char *key){
213  map* tmp=m;
214  while(tmp!=NULL){
215    if(strcasecmp(tmp->name,key)==0)
216      return true;
217    tmp=tmp->next;
218  }
219#ifdef DEBUG_MAP
220  fprintf(stderr,"NOT FOUND \n");
221#endif
222  return false;
223}
224
225/**
226 * Access a specific maps
227 *
228 * @param m the maps to search for the key
229 * @param key the key to search in the maps
230 * @return a pointer on the maps found or NULL if not found
231 */
232maps* getMaps(maps* m,const char *key){
233  maps* tmp=m;
234  while(tmp!=NULL){
235    if(strcasecmp(tmp->name,key)==0){
236      return tmp;
237    }
238    tmp=tmp->next;
239  }
240  return NULL;
241}
242
243/**
244 * Access a specific map
245 *
246 * @param m the map to search for the key
247 * @param key the key to search in the map
248 * @return a pointer on the map found or NULL if not found
249 */
250map* getMap(map* m,const char *key){
251  map* tmp=m;
252  while(tmp!=NULL){
253    if(strcasecmp(tmp->name,key)==0){
254      return tmp;
255    }
256    tmp=tmp->next;
257  }
258  return NULL;
259}
260
261
262/**
263 * Access the last map
264 *
265 * @param m the map to search for the lastest map
266 * @return a pointer on the lastest map found or NULL if not found
267 */
268map* getLastMap(map* m){
269  map* tmp=m;
270  while(tmp!=NULL){
271    if(tmp->next==NULL){
272      return tmp;
273    }
274    tmp=tmp->next;
275  }
276  return NULL;
277}
278
279/**
280 * Access a specific map from a maps
281 *
282 * @param m the maps to search for the key
283 * @param key the key to search in the maps
284 * @param subkey the key to search in the map (found for the key, if any)
285 * @return a pointer on the map found or NULL if not found
286 */
287map* getMapFromMaps(maps* m,const char* key,const char* subkey){
288  maps* _tmpm=getMaps(m,key);
289  if(_tmpm!=NULL){
290    map* _ztmpm=getMap(_tmpm->content,subkey);
291    return _ztmpm;
292  }
293  else return NULL;
294}
295
296/**
297 * Free allocated memory of a map.
298 * Require to call free on mo after calling this function.
299 *
300 * @param mo the map to free
301 */
302void freeMap(map** mo){
303  map* _cursor=*mo;
304  if(_cursor!=NULL){
305#ifdef DEBUG
306    fprintf(stderr,"freeMap\n");
307#endif
308    free(_cursor->name);
309    free(_cursor->value);
310    if(_cursor->next!=NULL){
311      freeMap(&_cursor->next);
312      free(_cursor->next);
313    }
314  }
315}
316
317/**
318 * Free allocated memory of a maps.
319 * Require to call free on mo after calling this function.
320 *
321 * @param mo the maps to free
322 */
323void freeMaps(maps** mo){
324  maps* _cursor=*mo;
325  if(_cursor && _cursor!=NULL){
326#ifdef DEBUG
327    fprintf(stderr,"freeMaps\n");
328#endif
329    free(_cursor->name);
330    if(_cursor->content!=NULL){
331      freeMap(&_cursor->content);
332      free(_cursor->content);
333    }
334    if(_cursor->child!=NULL){
335      freeMaps(&_cursor->child);
336      free(_cursor->child);
337    }
338    if(_cursor->next!=NULL){
339      freeMaps(&_cursor->next);
340      free(_cursor->next);
341    }
342  }
343}
344
345/**
346 * Verify if an elements contains a name equal to the given key.
347 *
348 * @param e the elements to search for the key
349 * @param key the elements name to search
350 * @return true if the elements contains the name, false in other cases.
351 */ 
352bool hasElement(elements* e,const char* key){
353  elements* tmp=e;
354  while(tmp!=NULL){
355    if(strcasecmp(key,tmp->name)==0)
356      return true;
357    tmp=tmp->next;
358  }
359  return false;
360}
361
362/**
363 * Access a specific elements named key.
364 *
365 * @param m the elements to search
366 * @param key the elements name to search
367 * @return a pointer to the specific element if found, NULL in other case.
368 */ 
369elements* getElements(elements* m,char *key){
370  elements* tmp=m;
371  while(tmp!=NULL){
372    if(strcasecmp(tmp->name,key)==0)
373      return tmp;
374    tmp=tmp->next;
375  }
376  return NULL;
377}
378
379/**
380 * Free allocated memory of an iotype.
381 * Require to call free on i after calling this function.
382 *
383 * @param i the iotype to free
384 */
385void freeIOType(iotype** i){
386  iotype* _cursor=*i;
387  if(_cursor!=NULL){
388    if(_cursor->next!=NULL){
389      freeIOType(&_cursor->next);
390      free(_cursor->next);
391    }
392    freeMap(&_cursor->content);
393    free(_cursor->content);
394  }
395}
396
397/**
398 * Free allocated memory of an elements.
399 * Require to call free on e after calling this function.
400 *
401 * @param e the iotype to free
402 */
403void freeElements(elements** e){
404  elements* tmp=*e;
405  if(tmp!=NULL){
406    if(tmp->name!=NULL)
407      free(tmp->name);
408    freeMap(&tmp->content);
409    if(tmp->content!=NULL)
410      free(tmp->content);
411    freeMap(&tmp->metadata);
412    if(tmp->metadata!=NULL)
413      free(tmp->metadata);
414    freeMap(&tmp->additional_parameters);
415    if(tmp->additional_parameters!=NULL)
416      free(tmp->additional_parameters);
417    if(tmp->format!=NULL)
418      free(tmp->format);
419    freeElements(&tmp->child);
420    if(tmp->child!=NULL){
421      free(tmp->child);
422    }
423    if(tmp->defaults!=NULL){
424      freeIOType(&tmp->defaults);
425      free(tmp->defaults);
426    }
427    if(tmp->supported!=NULL){
428      freeIOType(&tmp->supported);
429      free(tmp->supported);
430    }
431    if(tmp->next!=NULL){
432      freeElements(&tmp->next);
433      free(tmp->next);
434    }
435  }
436}
437
438/**
439 * Free allocated memory of a service.
440 * Require to call free on e after calling this function.
441 *
442 * @param s the service to free
443 */
444void freeService(service** s){
445  service* tmp=*s;
446  if(tmp!=NULL){
447    if(tmp->name!=NULL)
448      free(tmp->name);
449    freeMap(&tmp->content);
450    if(tmp->content!=NULL)
451      free(tmp->content);
452    freeMap(&tmp->metadata);
453    if(tmp->metadata!=NULL)
454      free(tmp->metadata);
455    freeMap(&tmp->additional_parameters);
456    if(tmp->additional_parameters!=NULL)
457      free(tmp->additional_parameters);
458    freeElements(&tmp->inputs);
459    if(tmp->inputs!=NULL)
460      free(tmp->inputs);
461    freeElements(&tmp->outputs);
462    if(tmp->outputs!=NULL)
463      free(tmp->outputs);
464  }
465}
466
467/**
468 * Add key value pair to an existing map.
469 *
470 * @param m the map to add the KVP
471 * @param n the key to add
472 * @param v the corresponding value to add
473 */
474void addToMap(map* m,const char* n,const char* v){
475  if(hasKey(m,n)==false){
476    map* _cursor=m;
477    while(_cursor->next!=NULL){
478      _cursor=_cursor->next;
479    }
480    _cursor->next=createMap(n,v);
481  }
482  else{
483    map *tmp=getMap(m,n);
484    if(tmp->value!=NULL)
485      free(tmp->value);
486    tmp->value=zStrdup(v);
487  }
488}
489
490/**
491 * Add a key and an integer value to an existing map.
492 *
493 * @param m the map to add the KVP
494 * @param n the key to add
495 * @param v the corresponding value to add
496 */
497void addIntToMap(map* m,const char* n,const int v){
498  char svalue[10];
499  sprintf(svalue,"%d",v);
500  if(hasKey(m,n)==false){
501    map* _cursor=m;
502    while(_cursor->next!=NULL){
503      _cursor=_cursor->next;
504    }
505    _cursor->next=createMap(n,svalue);
506  }
507  else{
508    map *tmp=getMap(m,n);
509    if(tmp->value!=NULL)
510      free(tmp->value);
511    tmp->value=zStrdup(svalue);
512  }
513}
514
515/**
516 * Add a key and a binary value to an existing map.
517 *
518 * @param m the map to add the KVP
519 * @param n the key to add
520 * @param v the corresponding value to add
521 * @param size the size of the given value
522 * @return a pointer to the updated map m
523 */
524map* addToMapWithSize(map* m,const char* n,const char* v,int size){
525  if(hasKey(m,n)==false){
526    map* _cursor=m;
527    if(_cursor!=NULL){
528      addToMap(m,n,"");
529    }else{
530      m=createMap(n,"");
531    }
532  }
533  char sname[10]="size";
534  if(strlen(n)>5)
535    sprintf(sname,"size_%s",n+6);
536  map *tmp=getMap(m,n);
537  if(tmp->value!=NULL)
538    free(tmp->value);
539  tmp->value=(char*)malloc((size+1)*sizeof(char));
540  if(v!=NULL)
541    memmove(tmp->value,v,size*sizeof(char));
542  tmp->value[size]=0;
543  char sin[128];
544  sprintf(sin,"%d",size);
545  addToMap(m,sname,sin);
546  return m;
547}
548
549/**
550 * Add a map at the end of another map.
551 *
552 * @param mo the map to add mi
553 * @param mi the map to add to mo
554 */
555void addMapToMap(map** mo,map* mi){
556  map* tmp=mi;
557  map* _cursor=*mo;
558  while(tmp!=NULL){
559    if(_cursor==NULL){
560      *mo=createMap(tmp->name,tmp->value);
561      (*mo)->next=NULL;
562    }
563    else{
564#ifdef DEBUG
565      fprintf(stderr,"_CURSOR\n");
566      dumpMap(_cursor);
567#endif
568      while(_cursor->next!=NULL)
569        _cursor=_cursor->next;
570      map* tmp1=getMap(*mo,tmp->name);
571      if(tmp1==NULL){
572        _cursor->next=createMap(tmp->name,tmp->value);
573      }
574      else{
575        addToMap(*mo,tmp->name,tmp->value);
576      }
577    }
578    _cursor=*mo;
579    tmp=tmp->next;
580#ifdef DEBUG
581    fprintf(stderr,"MO\n");
582    dumpMap(*mo);
583#endif
584  }
585}
586
587/**
588 * Add a map to iotype.
589 *
590 * @param io the iotype to add the map
591 * @param mi the map to add to io
592 */
593void addMapToIoType(iotype** io,map* mi){
594  iotype* tmp=*io;
595  while(tmp->next!=NULL){
596    tmp=tmp->next;
597  }
598  tmp->next=(iotype*)malloc(IOTYPE_SIZE);
599  tmp->next->content=NULL;
600  addMapToMap(&tmp->next->content,mi);
601  tmp->next->next=NULL;
602}
603
604/**
605 * Access a specific map or set its value.
606 *
607 * @param m the map to search for the key
608 * @param key the key to search/add in the map
609 * @param value the value to add if the key does not exist
610 * @return a pointer on the map found or NULL if not found
611 */
612map* getMapOrFill(map** m,const char *key,const char* value){
613  map* tmp=*m;
614  map* tmpMap=getMap(tmp,key);
615  if(tmpMap==NULL){
616    if(tmp!=NULL){
617      addToMap((*m),key,value);
618    }
619    else
620      (*m)=createMap(key,value);
621    tmpMap=getMap(*m,key);
622  }
623  return tmpMap;
624}
625
626/**
627 * Verify if a map is contained in another map.
628 *
629 * @param m the map to search for i
630 * @param i the map to search in m
631 * @return true if i was found in m, false in other case
632 */
633bool contains(map* m,map* i){
634  while(i!=NULL){     
635    if(strcasecmp(i->name,"value")!=0 &&
636       strcasecmp(i->name,"xlink:href")!=0 &&
637       strcasecmp(i->name,"useMapServer")!=0 &&
638       strcasecmp(i->name,"asReference")!=0){
639      map *tmp;
640      if(hasKey(m,i->name) && (tmp=getMap(m,i->name))!=NULL && 
641         strcasecmp(i->value,tmp->value)!=0)
642        return false;
643    }
644    i=i->next;
645  }
646  return true;
647}
648
649/**
650 * Access a specific iotype from an elements.
651 *
652 * @param e the elements to search for the name
653 * @param name the name to search in the elements e
654 * @param values the map to verify it was contained in the defaults or
655 *  supported content of the elements e
656 * @return a pointer on the iotype found or NULL if not found
657 */
658iotype* getIoTypeFromElement(elements* e,char *name, map* values){
659  elements* cursor=e;
660  if(values!=NULL){
661    while(cursor!=NULL){
662      if(strcasecmp(cursor->name,name)==0 && (cursor->defaults!=NULL || cursor->supported!=NULL)){
663        if(contains(cursor->defaults->content,values)==true)
664          return cursor->defaults;
665        else{
666          iotype* tmp=cursor->supported;
667          while(tmp!=NULL){
668            if(contains(tmp->content,values)==true)
669              return tmp;           
670            tmp=tmp->next;
671          }
672        }
673      }
674      cursor=cursor->next;
675    }
676  }else{
677    while(cursor!=NULL){
678      if(strcasecmp(cursor->name,name)==0 && cursor->defaults!=NULL){
679        return cursor->defaults;
680      }
681      cursor=cursor->next;
682    }
683  }
684  return NULL;
685}
686
687/**
688 * Load binary values from a map (in) and add them to another map (out)
689 *
690 * @param out the map to add binaries values
691 * @param in the map containing the binary values to add ti out
692 * @param pos index of the binary in an array (in case of "MapArray")
693 */
694void loadMapBinary(map** out,map* in,int pos){
695  map* size=getMap(in,"size");
696  map *lout=*out;
697  if(size!=NULL && pos>0){
698    char tmp[11];
699    sprintf(tmp,"size_%d",pos);
700    size=getMap(in,tmp);
701    sprintf(tmp,"value_%d",pos);
702    map* tmpVin=getMap(in,tmp);
703    map* tmpVout=getMap(lout,tmp);
704    free(tmpVout->value);
705    tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
706    memmove(tmpVout->value,tmpVin->value,atoi(size->value)*sizeof(char));
707    tmpVout->value[atoi(size->value)]=0;
708  }else{
709    if(size!=NULL){
710      map* tmpVin=getMap(in,"value");
711      map* tmpVout=getMap(lout,"value");
712      free(tmpVout->value);
713      tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
714      memmove(tmpVout->value,tmpVin->value,atoi(size->value)*sizeof(char));
715      tmpVout->value[atoi(size->value)]=0;
716    }
717  }
718}
719 
720/**
721 * Load binary values from a map (in) and add them to another map (out).
722 * This function will take care of MapArray.
723 * @see loadMapBinary
724 *
725 * @param out the map to add binaries values
726 * @param in the map containing the binary values to add ti out
727 */
728void loadMapBinaries(map** out,map* in){
729  map* size=getMap(in,"size");
730  map* length=getMap(in,"length");
731  if(length!=NULL){
732    int len=atoi(length->value);
733    int i=0;
734    for(i=0;i<len;i++){
735      loadMapBinary(out,in,i);
736    }
737  }
738  else
739    if(size!=NULL)
740      loadMapBinary(out,in,-1);
741}
742
743/**
744 * Duplicate a Maps
745 *
746 * @param mo the maps to clone
747 * @return the allocated maps containing a copy of the mo maps
748 */
749maps* dupMaps(maps** mo){
750  maps* _cursor=*mo;
751  maps* res=NULL;
752  if(_cursor!=NULL){
753    res=createMaps(_cursor->name);
754    map* mc=_cursor->content;
755    if(mc!=NULL){
756      addMapToMap(&res->content,mc);
757      loadMapBinaries(&res->content,mc);
758    }
759    maps* mcs=_cursor->child;
760    if(mcs!=NULL){
761      res->child=dupMaps(&mcs);
762    }
763    res->next=dupMaps(&_cursor->next);
764  }
765  return res;
766}
767
768/**
769 * Add a maps at the end of another maps.
770 *
771 * @see addMapToMap, dupMaps, getMaps
772 * @param mo the maps to add mi
773 * @param mi the maps to add to mo
774 */
775void addMapsToMaps(maps** mo,maps* mi){
776  maps* tmp=mi;
777  maps* _cursor=*mo;
778  while(tmp!=NULL){
779    if(_cursor==NULL){
780      *mo=dupMaps(&mi);
781    }
782    else{
783      while(_cursor->next!=NULL)
784        _cursor=_cursor->next;
785      maps* tmp1=getMaps(*mo,tmp->name);
786      if(tmp1==NULL){
787        _cursor->next=dupMaps(&tmp);
788        if(tmp->child!=NULL)
789          _cursor->next->child=dupMaps(&tmp->child);
790        else
791          _cursor->next->child=NULL;
792      }
793      else{
794        addMapToMap(&tmp1->content,tmp->content);
795        if(tmp->child!=NULL)
796          tmp1->child=dupMaps(&tmp->child);
797        else
798          tmp1->child=NULL;
799      }
800      _cursor=*mo;
801    }
802    tmp=tmp->next;
803  }
804}
805
806/**
807 * Access a specific map array element
808 *
809 * @param m the map to search for the key
810 * @param key the key to search in the map
811 * @param index of the MapArray
812 * @return a pointer on the map found or NULL if not found
813 */
814map* getMapArray(map* m,const char* key,int index){
815  char tmp[1024];
816  if(index>0)
817    sprintf(tmp,"%s_%d",key,index);
818  else
819    sprintf(tmp,"%s",key);
820#ifdef DEBUG
821  fprintf(stderr,"** KEY %s\n",tmp);
822#endif
823  map* tmpMap=getMap(m,tmp);
824#ifdef DEBUG
825  if(tmpMap!=NULL)
826    dumpMap(tmpMap);
827#endif
828  return tmpMap;
829}
830
831/**
832 * Add a key value in a MapArray for a specific index
833 *
834 * @param m the map to search for the key
835 * @param key the key to search in the map
836 * @param index the index of the MapArray
837 * @param value the value to set in the MapArray
838 * @return a pointer on the map found or NULL if not found
839 */
840void setMapArray(map* m,const char* key,int index,const char* value){
841  char tmp[1024];
842  if(index>0){
843    sprintf(tmp,"%s_%d",key,index);
844    map* len=getMap(m,"length");
845    if((len!=NULL && atoi(len->value)<index+1) || len==NULL){
846      char tmp0[5];
847      sprintf(tmp0,"%d",index+1);
848      addToMap(m,"length",tmp0);
849    }
850  }
851  else{
852    sprintf(tmp,"%s",key);
853    addToMap(m,"length","1");
854  }
855  map* tmpSize=getMapArray(m,"size",index);
856  if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
857#ifdef DEBUG
858    fprintf(stderr,"%s\n",tmpSize->value);
859#endif
860    map* ptr=getMapOrFill(&m,tmp,(char *)"");
861    free(ptr->value);
862    ptr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char));
863    memcpy(ptr->value,value,atoi(tmpSize->value)); 
864  }
865  else
866    addToMap(m,tmp,value);
867}
868
869/**
870 * Access the map "type"
871 *
872 * @param mt the map
873 * @return a pointer on the map for mimeType/dataType/CRS if found, NULL in
874 *  other case
875 */
876map* getMapType(map* mt){
877  map* tmap=getMap(mt,(char *)"mimeType");
878  if(tmap==NULL){
879    tmap=getMap(mt,"dataType");
880    if(tmap==NULL){
881      tmap=getMap(mt,"CRS");
882    }
883  }
884#ifdef DEBUG
885  dumpMap(tmap);
886#endif
887  return tmap;
888}
889
890/**
891 * Add a Maps containing a MapArray to a Maps
892 *
893 * @see getMapType
894 * @param mo the maps
895 * @param mi the maps
896 * @param typ the map "type"
897 * @return
898 */
899int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){
900  maps* tmp=mi;   
901  maps* _cursor=getMaps(*mo,tmp->name);
902
903  if(_cursor==NULL)
904    return -1;
905
906  map* tmpLength=getMap(_cursor->content,"length");
907  char tmpLen[10];
908  int len=1;
909  if(tmpLength!=NULL){
910    len=atoi(tmpLength->value);
911  }
912
913  char *tmpV[12]={
914    (char*)"size",
915    (char*)"value",
916    (char*)"uom",
917    (char*)"Reference",
918    (char*)"Order",
919    (char*)"cache_file",
920    (char*)"fmimeType",
921    (char*)"xlink:href",
922    typ,
923    (char*)"schema",
924    (char*)"encoding",
925    (char*)"isCached"
926  };
927  sprintf(tmpLen,"%d",len+1);
928  addToMap(_cursor->content,"length",tmpLen);
929  int i=0;
930  for(i=0;i<12;i++){
931    map* tmpVI=getMap(tmp->content,tmpV[i]);
932    if(tmpVI!=NULL){
933#ifdef DEBUG
934      fprintf(stderr,"%s = %s\n",tmpV[i],tmpVI->value);
935#endif
936      setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
937    }
938  }
939   
940  addToMap(_cursor->content,"isArray","true");
941  return 0;
942}
943
944/**
945 * Set a key value pair to a map contained in a Maps
946 *
947 * @param m the maps
948 * @param key the maps name
949 * @param subkey the map name included in the maps corresponding to key
950 * @param value the corresponding value to add in the map
951 */
952void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){
953  maps* _tmpm=getMaps(m,key);
954  if(_tmpm!=NULL){
955    map* _ztmpm=getMap(_tmpm->content,subkey);
956    if(_ztmpm!=NULL){
957      if(_ztmpm->value!=NULL)
958        free(_ztmpm->value);
959      _ztmpm->value=zStrdup(value);
960    }else{
961      maps *tmp=createMaps(key);
962      tmp->content=createMap(subkey,value);
963      addMapsToMaps(&_tmpm,tmp);
964      freeMaps(&tmp);
965      free(tmp);
966    }
967  }else{
968    maps *tmp=createMaps(key);
969    tmp->content=createMap(subkey,value);
970    addMapsToMaps(&m,tmp);
971    freeMaps(&tmp);
972    free(tmp);
973  }
974}
975
976/**
977 * Create an empty elements
978 *
979 * @return a pointer to the allocated elements
980 */
981elements* createEmptyElements(){
982  elements* res=(elements*)malloc(ELEMENTS_SIZE);
983  res->name=NULL;
984  res->content=NULL;
985  res->metadata=NULL;
986  res->additional_parameters=NULL; 
987  res->format=NULL;
988  res->defaults=NULL;
989  res->supported=NULL;
990  res->child=NULL;
991  res->next=NULL;
992  return res;
993}
994
995/**
996 * Create a named elements
997 *
998 * @param name the elements name
999 * @return a pointer to the allocated elements
1000 */
1001elements* createElements(const char* name){
1002  elements* res=(elements*)malloc(ELEMENTS_SIZE);
1003  res->name=zStrdup(name);
1004  res->content=NULL;
1005  res->metadata=NULL;
1006  res->additional_parameters=NULL;
1007  res->format=NULL;
1008  res->defaults=NULL;
1009  res->supported=NULL;
1010  res->child=NULL;
1011  res->next=NULL;
1012  return res;
1013}
1014
1015/**
1016 * Set the name of an elements
1017 *
1018 * @param name the elements name
1019 * @return a pointer to the allocated elements
1020 */
1021void setElementsName(elements** elem,char* name){
1022  elements* res=*elem;
1023  res->name=zStrdup(name);
1024  res->content=NULL;
1025  res->metadata=NULL;
1026  res->format=NULL;
1027  res->defaults=NULL;
1028  res->supported=NULL;
1029  res->child=NULL;
1030  res->next=NULL;
1031}
1032
1033/**
1034 * Dump an elements on stderr
1035 *
1036 * @param e the elements to dump
1037 */
1038void dumpElements(elements* e){
1039  elements* tmp=e;
1040  while(tmp!=NULL){
1041    fprintf(stderr,"ELEMENT [%s]\n",tmp->name);
1042    fprintf(stderr," > CONTENT [%s]\n",tmp->name);
1043    dumpMap(tmp->content);
1044    fprintf(stderr," > METADATA [%s]\n",tmp->name);
1045    dumpMap(tmp->metadata);
1046    fprintf(stderr," > ADDITIONAL PARAMETERS [%s]\n",tmp->name);
1047    dumpMap(tmp->additional_parameters);
1048    fprintf(stderr," > FORMAT [%s]\n",tmp->format);
1049    iotype* tmpio=tmp->defaults;
1050    int ioc=0;
1051    while(tmpio!=NULL){
1052      fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc);
1053      dumpMap(tmpio->content);
1054      tmpio=tmpio->next;
1055      ioc++;
1056    }
1057    tmpio=tmp->supported;
1058    ioc=0;
1059    while(tmpio!=NULL){
1060      fprintf(stderr," > SUPPORTED [%s] (%i)\n",tmp->name,ioc);
1061      dumpMap(tmpio->content);
1062      tmpio=tmpio->next;
1063      ioc++;
1064    }
1065    if(tmp->child!=NULL){
1066      fprintf(stderr," > CHILD \n");
1067      dumpElements(tmp->child);
1068    }
1069    fprintf(stderr,"------------------\n");
1070    tmp=tmp->next;
1071  }
1072}
1073
1074/**
1075 * Dump an elements on stderr using the YAML syntaxe
1076 *
1077 * @param e the elements to dump
1078 */
1079void dumpElementsAsYAML(elements* e,int level){
1080  elements* tmp=e;
1081  int i;
1082  while(tmp!=NULL){
1083    for(i=0;i<2+(4*level);i++)
1084      fprintf(stderr," ");
1085    fprintf(stderr,"%s:\n",tmp->name);
1086    map* mcurs=tmp->content;
1087    while(mcurs!=NULL){
1088      for(i=0;i<4+(4*level);i++)
1089        fprintf(stderr," ");
1090      _dumpMap(mcurs);
1091      mcurs=mcurs->next;
1092    }
1093    mcurs=tmp->metadata;
1094    if(mcurs!=NULL){
1095      for(i=0;i<4+(4*level);i++)
1096        fprintf(stderr," ");
1097      fprintf(stderr,"MetaData:\n");
1098      while(mcurs!=NULL){
1099        for(i=0;i<6+(4*level);i++)
1100          fprintf(stderr," ");
1101        _dumpMap(mcurs);
1102        mcurs=mcurs->next;
1103      }
1104    }
1105    for(i=0;i<4+(4*level);i++)
1106      fprintf(stderr," ");
1107    if(tmp->format!=NULL)
1108      fprintf(stderr,"%s:\n",tmp->format);
1109    else{
1110      fprintf(stderr,"Child:\n");
1111      if(tmp->child!=NULL)
1112        dumpElementsAsYAML(tmp->child,level+1);
1113    }
1114    iotype* tmpio=tmp->defaults;
1115    int ioc=0;
1116    while(tmpio!=NULL){
1117      for(i=0;i<6+(4*level);i++)
1118        fprintf(stderr," ");
1119      fprintf(stderr,"default:\n");
1120      mcurs=tmpio->content;
1121      while(mcurs!=NULL){
1122        for(i=0;i<8+(4*level);i++)
1123          fprintf(stderr," ");
1124        if(strcasecmp(mcurs->name,"range")==0){
1125          fprintf(stderr,"range: \"%s\"\n",mcurs->value);
1126        }else
1127          _dumpMap(mcurs);
1128        mcurs=mcurs->next;
1129      }
1130      tmpio=tmpio->next;
1131      ioc++;
1132    }
1133    tmpio=tmp->supported;
1134    ioc=0;
1135    while(tmpio!=NULL){
1136      for(i=0;i<6+(4*level);i++)
1137        fprintf(stderr," ");
1138      fprintf(stderr,"supported:\n");
1139      mcurs=tmpio->content;
1140      while(mcurs!=NULL){
1141        for(i=0;i<8+(4*level);i++)
1142          fprintf(stderr," ");
1143        if(strcasecmp(mcurs->name,"range")==0){
1144          fprintf(stderr,"range: \"%s\"\n",mcurs->value);
1145        }else
1146          _dumpMap(mcurs);
1147        mcurs=mcurs->next;
1148      }
1149      tmpio=tmpio->next;
1150      ioc++;
1151    }
1152    tmp=tmp->next;
1153  }
1154}
1155
1156/**
1157 * Duplicate an elements
1158 *
1159 * @param e the elements to clone
1160 * @return the allocated elements containing a copy of the elements e
1161 */
1162elements* dupElements(elements* e){
1163  elements* cursor=e;
1164  elements* tmp=NULL;
1165  if(cursor!=NULL && cursor->name!=NULL){
1166#ifdef DEBUG
1167    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
1168    dumpElements(e);
1169    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
1170#endif
1171    tmp=(elements*)malloc(ELEMENTS_SIZE);
1172    tmp->name=zStrdup(cursor->name);
1173    tmp->content=NULL;
1174    addMapToMap(&tmp->content,cursor->content);
1175    tmp->metadata=NULL;
1176    addMapToMap(&tmp->metadata,cursor->metadata);
1177    tmp->additional_parameters=NULL;
1178    addMapToMap(&tmp->additional_parameters,cursor->additional_parameters);
1179    if(cursor->format!=NULL)
1180      tmp->format=zStrdup(cursor->format);
1181    else
1182      tmp->format=NULL;
1183    if(cursor->defaults!=NULL){
1184      tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
1185      tmp->defaults->content=NULL;
1186      addMapToMap(&tmp->defaults->content,cursor->defaults->content);
1187      tmp->defaults->next=NULL;
1188#ifdef DEBUG
1189      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
1190      dumpMap(tmp->defaults->content);
1191#endif
1192    }else
1193      tmp->defaults=NULL;
1194    if(cursor->supported!=NULL && cursor->supported->content!=NULL){
1195      tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
1196      tmp->supported->content=NULL;
1197      addMapToMap(&tmp->supported->content,cursor->supported->content);
1198      tmp->supported->next=NULL;
1199      iotype *tmp2=cursor->supported->next;
1200      while(tmp2!=NULL){
1201        addMapToIoType(&tmp->supported,tmp2->content);
1202#ifdef DEBUG
1203        fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
1204        dumpMap(tmp->defaults->content);
1205#endif
1206        tmp2=tmp2->next;
1207      }
1208    }
1209    else
1210      tmp->supported=NULL;
1211    if(cursor->child!=NULL)
1212      tmp->child=dupElements(cursor->child);
1213    else
1214      tmp->child=NULL;
1215    if(cursor->next!=NULL)
1216      tmp->next=dupElements(cursor->next);
1217    else
1218      tmp->next=NULL;
1219  }
1220  return tmp;
1221}
1222
1223/**
1224 * Add an elements to another elements.
1225 *
1226 * @see dupElements
1227 * @param m the elements to add the e
1228 * @param e the elements to be added to m
1229 */
1230void addToElements(elements** m,elements* e){
1231  elements* tmp=e;
1232  if(*m==NULL){
1233    (*m)=dupElements(tmp);
1234  }else{
1235    addToElements(&(*m)->next,tmp);
1236  }
1237}
1238
1239/**
1240 * Set the name of a service
1241 *
1242 * @param name the service name
1243 */
1244void setServiceName(service** serv,char* name){
1245  service* res=*serv;
1246  res->name=zStrdup(name);
1247  res->content=NULL;
1248  res->metadata=NULL;
1249  res->inputs=NULL;
1250  res->outputs=NULL;
1251}
1252
1253/**
1254 * Dump a service on stderr
1255 *
1256 * @param s the service to dump
1257 */
1258void dumpService(service* s){
1259  if(s==NULL)
1260    return;
1261  fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
1262  if(s->content!=NULL){
1263    fprintf(stderr,"CONTENT MAP\n");
1264    dumpMap(s->content);
1265    if(s->metadata!=NULL)
1266      fprintf(stderr,"CONTENT METADATA\n");
1267    dumpMap(s->metadata);
1268    if(s->additional_parameters!=NULL)
1269      fprintf(stderr,"CONTENT AdditionalParameters\n");
1270    dumpMap(s->additional_parameters);
1271  }
1272  if(s->inputs!=NULL){
1273    fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",s->name);
1274    dumpElements(s->inputs);
1275  }
1276  if(s->outputs!=NULL){
1277    fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",s->name);
1278    dumpElements(s->outputs);
1279  }
1280  fprintf(stderr,"++++++++++++++++++\n");
1281}
1282
1283/**
1284 * Dump a service on stderr using the YAML syntaxe
1285 *
1286 * @param s the service to dump
1287 */
1288void dumpServiceAsYAML(service* s){
1289  int i;
1290  fprintf(stderr,"# %s\n\n",s->name);
1291  if(s->content!=NULL){
1292    map* mcurs=s->content;
1293    dumpMap(mcurs);
1294    mcurs=s->metadata;
1295    if(mcurs!=NULL){
1296      fprintf(stderr,"MetaData:\n");
1297      while(mcurs!=NULL){
1298        for(i=0;i<2;i++)
1299          fprintf(stderr," ");
1300        _dumpMap(mcurs);
1301        mcurs=mcurs->next;
1302      }
1303    }
1304  }
1305  if(s->inputs!=NULL){
1306    fprintf(stderr,"\ninputs:\n");
1307    dumpElementsAsYAML(s->inputs,0);
1308  }
1309  if(s->outputs!=NULL){
1310    fprintf(stderr,"\noutputs:\n");
1311    dumpElementsAsYAML(s->outputs,0);
1312  }
1313}
1314
1315/**
1316 * Duplicate a service
1317 *
1318 * @param s the service to clone
1319 * @return the allocated service containing a copy of the serfvice s
1320 */
1321service* dupService(service* s){
1322  service *res=(service*)malloc(SERVICE_SIZE);
1323  res->name=zStrdup(s->name);
1324  res->content=NULL;
1325  addMapToMap(&res->content,s->content);
1326  res->metadata=NULL;
1327  addMapToMap(&res->metadata,s->metadata);
1328  res->additional_parameters=NULL;
1329  addMapToMap(&res->additional_parameters,s->additional_parameters);
1330  res->inputs=dupElements(s->inputs);
1331  res->outputs=dupElements(s->outputs);
1332  return res;
1333}
1334
1335/**
1336 * Print the registry on stderr.
1337 *
1338 * @param r the registry
1339 */
1340void dumpRegistry(registry* r){
1341  registry* p=r;
1342  while(p!=NULL){
1343    fprintf(stderr,"%s \n",p->name);
1344    services* s=p->content;
1345    s=p->content;
1346    while(s!=NULL){
1347      dumpService(s->content);
1348      s=s->next;
1349    }
1350    p=p->next;
1351  }
1352}
1353
1354/**
1355 * Add a service to the registry
1356 *
1357 * @param reg the resgitry to add the service
1358 * @param name the registry name to update
1359 * @param content the service to add
1360 */
1361bool addServiceToRegistry(registry** reg,char* name,service* content){
1362  registry *l=*reg;
1363  int isInitial=-1;
1364  if(l==NULL){
1365    l=(registry*)malloc(REGISTRY_SIZE);
1366    isInitial=1;
1367  }
1368  if(l!=NULL){
1369    int hasLevel=-1;
1370    while(isInitial<0 && l!=NULL){
1371      if(l->name!=NULL && strcasecmp(name,l->name)==0){
1372        hasLevel=1;
1373        break;
1374      }
1375      l=l->next;
1376    }
1377    if(hasLevel<0){
1378      if(isInitial<0)
1379        l=(registry*)malloc(REGISTRY_SIZE);
1380      l->name=zStrdup(name);
1381      l->content=NULL;
1382      l->next=NULL;
1383    }
1384    if(l->content==NULL){
1385      l->content=(services*)malloc(SERVICES_SIZE);
1386      l->content->content=dupService(content);
1387      l->content->next=NULL;
1388    }
1389    else{
1390      services* s=l->content;
1391      while(s->next!=NULL)
1392        s=s->next;
1393      s->next=(services*)malloc(SERVICES_SIZE);
1394      s->next->content=dupService(content);
1395      s->next->next=NULL;
1396    }
1397    l->next=NULL;
1398    if(isInitial>0)
1399      *reg=l;
1400    else{
1401      registry *r=*reg;
1402      while(r->next!=NULL)
1403        r=r->next;
1404      r->next=l;
1405      r->next->next=NULL;
1406    }
1407    return true;
1408  }
1409  else
1410    return false;
1411}
1412
1413/**
1414 * Free memory allocated for the registry
1415 *
1416 * @param r the registry
1417 */
1418void freeRegistry(registry** r){
1419  registry* lr=*r;
1420  while(lr!=NULL){
1421    services* s=lr->content;
1422    free(lr->name);
1423    while(s!=NULL){
1424      service* s1=s->content;
1425      s=s->next;
1426      if(s1!=NULL){
1427        freeService(&s1);
1428        free(s1);
1429        s1=NULL;
1430      }
1431    }
1432    lr=lr->next;
1433  }   
1434}
1435
1436/**
1437 * Access a service in the registry
1438 *
1439 * @param r the registry
1440 * @param level the regitry to search ("concept", "generic" or "implementation")
1441 * @param sname the service name
1442 * @return the service pointer if a corresponding service was found or NULL
1443 */
1444service* getServiceFromRegistry(registry* r,char  *level,char* sname){
1445  registry *lr=r;
1446  while(lr!=NULL){
1447    if(strcasecmp(lr->name,level)==0){
1448      services* s=lr->content;
1449      while(s!=NULL){
1450        if(s->content!=NULL && strcasecmp(s->content->name,sname)==0)
1451          return s->content;
1452        s=s->next;
1453      }
1454      break;
1455    }
1456    lr=lr->next;
1457  }
1458  return NULL;
1459}
1460
1461/**
1462 * Apply inheritance to an out map from a reference in map
1463 *
1464 * @param out the map to update
1465 * @param in the reference map (containing inherited properties)
1466 */
1467void inheritMap(map** out,map* in){
1468  map* content=in;
1469  if((*out)==NULL){
1470    addMapToMap(out,in);
1471    return;
1472  }
1473  while(content!=NULL){
1474    map* cmap=getMap(*out,content->name);
1475    if(cmap==NULL)
1476      addToMap(*out,content->name,content->value);
1477    content=content->next;
1478  }
1479}
1480
1481/**
1482 * Apply inheritance to an out iotype from a reference in iotype
1483 *
1484 * @param out the iotype to update
1485 * @param in the reference iotype (containing inherited properties)
1486 */
1487void inheritIOType(iotype** out,iotype* in){
1488  iotype* io=in;
1489  iotype* oio=*out;
1490  if(io!=NULL){
1491    if(*out==NULL){
1492      *out=(iotype*)malloc(IOTYPE_SIZE);
1493      (*out)->content=NULL;
1494      addMapToMap(&(*out)->content,io->content);
1495      (*out)->next=NULL;
1496      oio=*out;
1497      inheritIOType(&oio->next,io->next);
1498    }else{
1499      inheritIOType(&oio->next,io->next);
1500    }
1501  }
1502}
1503
1504/**
1505 * Apply inheritance to an out elements from a reference in elements
1506 *
1507 * @param out the elements to update
1508 * @param in the reference elements (containing inherited properties)
1509 */
1510void inheritElements(elements** out,elements* in){
1511  elements* content=in;
1512  while(content!=NULL && *out!=NULL){
1513    elements* cmap=getElements(*out,content->name);
1514    if(cmap==NULL)
1515      addToElements(out,content);
1516    else{
1517      inheritMap(&cmap->content,content->content);
1518      inheritMap(&cmap->metadata,content->metadata);
1519      if(cmap->format==NULL && content->format!=NULL)
1520        cmap->format=zStrdup(content->format);
1521      inheritIOType(&cmap->defaults,content->defaults);
1522      if(cmap->supported==NULL)
1523        inheritIOType(&cmap->supported,content->supported);
1524      else{
1525        iotype* p=content->supported;
1526        while(p!=NULL){
1527          addMapToIoType(&cmap->supported,p->content);
1528          p=p->next;
1529        }
1530      }
1531    }
1532    content=content->next;
1533  }
1534}
1535
1536/**
1537 * Apply inheritance to a service based on a registry
1538 *
1539 * @param r the registry storing profiles hierarchy
1540 * @param s the service to update depending on its inheritance
1541 */
1542void inheritance(registry *r,service** s){
1543  if(r==NULL)
1544    return;
1545  service* ls=*s;
1546  if(ls->content==NULL)
1547    return;
1548  map* profile=getMap(ls->content,"extend");
1549  map* level=getMap(ls->content,"level");
1550  if(profile!=NULL&&level!=NULL){
1551    service* s1;
1552    if(strncasecmp(level->value,"profile",7)==0)
1553      s1=getServiceFromRegistry(r,(char*)"generic",profile->value);
1554    else
1555      s1=getServiceFromRegistry(r,level->value,profile->value);
1556     
1557    inheritMap(&ls->content,s1->content);
1558    inheritMap(&ls->metadata,s1->metadata);
1559    if(ls->inputs==NULL && s1->inputs!=NULL){
1560      ls->inputs=dupElements(s1->inputs);
1561    }else{
1562      inheritElements(&ls->inputs,s1->inputs);
1563    }
1564    if(ls->outputs==NULL && s1->outputs!=NULL){
1565      ls->outputs=dupElements(s1->outputs);
1566    }else
1567      inheritElements(&ls->outputs,s1->outputs);
1568  }
1569}
1570
1571/**
1572 * Convert a maps to a char*** (only used for Fortran support)
1573 *
1574 * @param m the maps to convert
1575 * @param c the resulting array
1576 */
1577void mapsToCharXXX(maps* m,char*** c){
1578  maps* tm=m;
1579  int i=0;
1580  int j=0;
1581  char tmp[10][30][1024];
1582  memset(tmp,0,1024*10*10);
1583  while(tm!=NULL){
1584    if(i>=10)
1585      break;
1586    strcpy(tmp[i][j],"name");
1587    j++;
1588    strcpy(tmp[i][j],tm->name);
1589    j++;
1590    map* tc=tm->content;
1591    while(tc!=NULL){
1592      if(j>=30)
1593        break;
1594      strcpy(tmp[i][j],tc->name);
1595      j++;
1596      strcpy(tmp[i][j],tc->value);
1597      j++;
1598      tc=tc->next;
1599    }
1600    tm=tm->next;
1601    j=0;
1602    i++;
1603  }
1604  memcpy(c,tmp,10*10*1024);
1605}
1606
1607/**
1608 * Convert a char*** to a maps (only used for Fortran support)
1609 *
1610 * @param c the array to convert
1611 * @param m the resulting maps
1612 */
1613void charxxxToMaps(char*** c,maps**m){
1614  maps* trorf=*m;
1615  int i,j;
1616  char tmp[10][30][1024];
1617  memcpy(tmp,c,10*30*1024);
1618  for(i=0;i<10;i++){
1619    if(strlen(tmp[i][1])==0)
1620      break;
1621    trorf->name=tmp[i][1];
1622    trorf->content=NULL;
1623    trorf->next=NULL;
1624    for(j=2;j<29;j+=2){
1625      if(strlen(tmp[i][j+1])==0)
1626        break;
1627      if(trorf->content==NULL)
1628        trorf->content=createMap(tmp[i][j],tmp[i][j+1]);
1629      else
1630        addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
1631    }
1632    trorf=trorf->next;
1633  }
1634  m=&trorf;
1635}
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