Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill old $Id$ command dating from CVS
[simgrid.git] / src / xbt / config.c
1 /* config - Dictionnary where the type of each variable is provided.            */
2
3 /* This is useful to build named structs, like option or property sets.     */
4
5 /* Copyright (c) 2001,2002,2003,2004 Martin Quinson. All rights reserved.   */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #include <stdio.h>
11 #include "xbt/misc.h"
12 #include "xbt/sysdep.h"
13 #include "xbt/log.h"
14 #include "xbt/ex.h"
15 #include "xbt/dynar.h"
16 #include "xbt/dict.h"
17 #include "xbt/peer.h"
18
19 #include "xbt/config.h"         /* prototypes of this module */
20
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_cfg, xbt, "configuration support");
22
23 /* xbt_cfgelm_t: the typedef corresponding to a config variable.
24
25    Both data and DTD are mixed, but fixing it now would prevent me to ever
26    defend my thesis. */
27
28 typedef struct {
29   /* Description */
30   char *desc;
31
32   /* Allowed type of the variable */
33   e_xbt_cfgelm_type_t type;
34   int min, max;
35   int isdefault:1;
36
37   /* Callbacks */
38   xbt_cfg_cb_t cb_set;
39   xbt_cfg_cb_t cb_rm;
40
41   /* actual content
42      (cannot be an union because type peer uses both str and i) */
43   xbt_dynar_t content;
44 } s_xbt_cfgelm_t, *xbt_cfgelm_t;
45
46 static const char *xbt_cfgelm_type_name[xbt_cfgelm_type_count] =
47   { "int", "double", "string", "peer", "any" };
48
49 /* Internal stuff used in cache to free a variable */
50 static void xbt_cfgelm_free(void *data);
51
52 /* Retrieve the variable we'll modify */
53 static xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg, const char *name,
54                                    e_xbt_cfgelm_type_t type);
55
56 /*----[ Memory management ]-----------------------------------------------*/
57
58 /** @brief Constructor
59  *
60  * Initialise an config set
61  */
62
63
64 xbt_cfg_t xbt_cfg_new(void)
65 {
66   return (xbt_cfg_t) xbt_dict_new();
67 }
68
69 /** \brief Copy an existing configuration set
70  *
71  * \arg whereto the config set to be created
72  * \arg tocopy the source data
73  *
74  * This only copy the registrations, not the actual content
75  */
76
77 void xbt_cfg_cpy(xbt_cfg_t tocopy, xbt_cfg_t * whereto)
78 {
79   xbt_dict_cursor_t cursor = NULL;
80   xbt_cfgelm_t variable = NULL;
81   char *name = NULL;
82
83   DEBUG1("Copy cfg set %p", tocopy);
84   *whereto = NULL;
85   xbt_assert0(tocopy, "cannot copy NULL config");
86
87   xbt_dict_foreach((xbt_dict_t) tocopy, cursor, name, variable) {
88     xbt_cfg_register(whereto, name, variable->desc, variable->type, NULL,
89                      variable->min, variable->max, variable->cb_set,
90                      variable->cb_rm);
91   }
92 }
93
94 /** @brief Destructor */
95 void xbt_cfg_free(xbt_cfg_t * cfg)
96 {
97   DEBUG1("Frees cfg set %p", cfg);
98   xbt_dict_free((xbt_dict_t *) cfg);
99 }
100
101 /** @brief Dump a config set for debuging purpose
102  *
103  * \arg name The name to give to this config set
104  * \arg indent what to write at the begining of each line (right number of spaces)
105  * \arg cfg the config set
106  */
107 void xbt_cfg_dump(const char *name, const char *indent, xbt_cfg_t cfg)
108 {
109   xbt_dict_t dict = (xbt_dict_t) cfg;
110   xbt_dict_cursor_t cursor = NULL;
111   xbt_cfgelm_t variable = NULL;
112   char *key = NULL;
113   int i;
114   int size;
115   int ival;
116   char *sval;
117   double dval;
118   xbt_peer_t hval;
119
120   if (name)
121     printf("%s>> Dumping of the config set '%s':\n", indent, name);
122   xbt_dict_foreach(dict, cursor, key, variable) {
123
124     printf("%s  %s:", indent, key);
125
126     size = xbt_dynar_length(variable->content);
127     printf
128       ("%d_to_%d_%s. Actual size=%d. prerm=%p,postset=%p, List of values:\n",
129        variable->min, variable->max, xbt_cfgelm_type_name[variable->type],
130        size, variable->cb_rm, variable->cb_set);
131
132     switch (variable->type) {
133
134     case xbt_cfgelm_int:
135       for (i = 0; i < size; i++) {
136         ival = xbt_dynar_get_as(variable->content, i, int);
137         printf("%s    %d\n", indent, ival);
138       }
139       break;
140
141     case xbt_cfgelm_double:
142       for (i = 0; i < size; i++) {
143         dval = xbt_dynar_get_as(variable->content, i, double);
144         printf("%s    %f\n", indent, dval);
145       }
146       break;
147
148     case xbt_cfgelm_string:
149       for (i = 0; i < size; i++) {
150         sval = xbt_dynar_get_as(variable->content, i, char *);
151         printf("%s    %s\n", indent, sval);
152       }
153       break;
154
155     case xbt_cfgelm_peer:
156       for (i = 0; i < size; i++) {
157         hval = xbt_dynar_get_as(variable->content, i, xbt_peer_t);
158         printf("%s    %s:%d\n", indent, hval->name, hval->port);
159       }
160       break;
161
162     default:
163       printf("%s    Invalid type!!\n", indent);
164     }
165
166   }
167
168   if (name)
169     printf("%s<< End of the config set '%s'\n", indent, name);
170   fflush(stdout);
171
172   xbt_dict_cursor_free(&cursor);
173   return;
174 }
175
176 /*
177  * free an config element
178  */
179
180 void xbt_cfgelm_free(void *data)
181 {
182   xbt_cfgelm_t c = (xbt_cfgelm_t) data;
183
184   DEBUG1("Frees cfgelm %p", c);
185   if (!c)
186     return;
187   xbt_free(c->desc);
188   xbt_dynar_free(&(c->content));
189   free(c);
190 }
191
192 /*----[ Registering stuff ]-----------------------------------------------*/
193
194 /** @brief Register an element within a config set
195  *
196  *  @arg cfg the config set
197  *  @arg type the type of the config element
198  *  @arg min the minimum
199  *  @arg max the maximum
200  */
201
202 void
203 xbt_cfg_register(xbt_cfg_t * cfg,
204                  const char *name, const char *desc, e_xbt_cfgelm_type_t type,
205                  void *default_value, int min, int max, xbt_cfg_cb_t cb_set,
206                  xbt_cfg_cb_t cb_rm)
207 {
208   xbt_cfgelm_t res;
209
210   if (*cfg == NULL)
211     *cfg = xbt_cfg_new();
212   xbt_assert4(type >= xbt_cfgelm_int && type <= xbt_cfgelm_peer,
213               "type of %s not valid (%d should be between %d and %d)",
214               name, type, xbt_cfgelm_int, xbt_cfgelm_peer);
215   res = xbt_dict_get_or_null((xbt_dict_t) * cfg, name);
216
217   if (res) {
218     WARN1("Config elem %s registered twice.", name);
219     /* Will be removed by the insertion of the new one */
220   }
221
222   res = xbt_new(s_xbt_cfgelm_t, 1);
223   DEBUG8("Register cfg elm %s (%s) (%d to %d %s (=%d) @%p in set %p)",
224          name, desc, min, max, xbt_cfgelm_type_name[type], type, res, *cfg);
225
226   res->desc = xbt_strdup(desc);
227   res->type = type;
228   res->min = min;
229   res->max = max;
230   res->cb_set = cb_set;
231   res->cb_rm = cb_rm;
232   res->isdefault = 1;
233
234   switch (type) {
235   case xbt_cfgelm_int:
236     res->content = xbt_dynar_new(sizeof(int), NULL);
237     if (default_value)
238       xbt_dynar_push(res->content, default_value);
239     break;
240
241   case xbt_cfgelm_double:
242     res->content = xbt_dynar_new(sizeof(double), NULL);
243     if (default_value)
244       xbt_dynar_push(res->content, default_value);
245     break;
246
247   case xbt_cfgelm_string:
248     res->content = xbt_dynar_new(sizeof(char *), xbt_free_ref);
249     if (default_value)
250       xbt_dynar_push(res->content, default_value);
251     break;
252
253   case xbt_cfgelm_peer:
254     res->content = xbt_dynar_new(sizeof(xbt_peer_t), xbt_peer_free_voidp);
255     if (default_value)
256       xbt_dynar_push(res->content, default_value);
257     break;
258
259   default:
260     ERROR1("%d is an invalide type code", type);
261   }
262
263   xbt_dict_set((xbt_dict_t) * cfg, name, res, &xbt_cfgelm_free);
264 }
265
266 /** @brief Unregister an element from a config set.
267  *
268  *  @arg cfg the config set
269  *  @arg name the name of the elem to be freed
270  *
271  *  Note that it removes both the description and the actual content.
272  *  Throws not_found when no such element exists.
273  */
274
275 void xbt_cfg_unregister(xbt_cfg_t cfg, const char *name)
276 {
277   DEBUG2("Unregister elm '%s' from set %p", name, cfg);
278   xbt_dict_remove((xbt_dict_t) cfg, name);
279 }
280
281 /**
282  * @brief Parse a string and register the stuff described.
283  *
284  * @arg cfg the config set
285  * @arg entry a string describing the element to register
286  *
287  * The string may consist in several variable descriptions separated by a space.
288  * Each of them must use the following syntax: \<name\>:\<min nb\>_to_\<max nb\>_\<type\>
289  * with type being one of  'string','int', 'peer' or 'double'.
290  *
291  * @fixme: this does not allow to set the description
292  */
293
294 void xbt_cfg_register_str(xbt_cfg_t * cfg, const char *entry)
295 {
296   char *entrycpy = xbt_strdup(entry);
297   char *tok;
298
299   int min, max;
300   e_xbt_cfgelm_type_t type;
301   DEBUG1("Register string '%s'", entry);
302
303   tok = strchr(entrycpy, ':');
304   xbt_assert2(tok, "Invalid config element descriptor: %s%s",
305               entry, "; Should be <name>:<min nb>_to_<max nb>_<type>");
306   *(tok++) = '\0';
307
308   min = strtol(tok, &tok, 10);
309   xbt_assert1(tok, "Invalid minimum in config element descriptor %s", entry);
310
311   xbt_assert2(strcmp(tok, "_to_"),
312               "Invalid config element descriptor : %s%s",
313               entry, "; Should be <name>:<min nb>_to_<max nb>_<type>");
314   tok += strlen("_to_");
315
316   max = strtol(tok, &tok, 10);
317   xbt_assert1(tok, "Invalid maximum in config element descriptor %s", entry);
318
319   xbt_assert2(*(tok++) == '_',
320               "Invalid config element descriptor: %s%s", entry,
321               "; Should be <name>:<min nb>_to_<max nb>_<type>");
322
323   for (type = 0;
324        type < xbt_cfgelm_type_count
325        && strcmp(tok, xbt_cfgelm_type_name[type]); type++);
326   xbt_assert2(type < xbt_cfgelm_type_count,
327               "Invalid type in config element descriptor: %s%s", entry,
328               "; Should be one of 'string', 'int', 'peer' or 'double'.");
329
330   xbt_cfg_register(cfg, entrycpy, NULL, type, NULL, min, max, NULL, NULL);
331
332   free(entrycpy);               /* strdup'ed by dict mechanism, but cannot be const */
333 }
334
335 /** @brief Displays the declared options and their description */
336 void xbt_cfg_help(xbt_cfg_t cfg)
337 {
338   xbt_dict_cursor_t cursor;
339   xbt_cfgelm_t variable;
340   char *name;
341
342   int i;
343   int size;
344
345   xbt_dict_foreach((xbt_dict_t) cfg, cursor, name, variable) {
346     printf("   %s: %s\n", name, variable->desc);
347     printf("       Type: %s; ", xbt_cfgelm_type_name[variable->type]);
348     if (variable->min != 1 || variable->max != 1) {
349       if (variable->min == 0 && variable->max == 0)
350         printf("Arity: no bound; ");
351       else
352         printf("Arity: min:%d to max:%d; ", variable->min, variable->max);
353     }
354     printf("Current value: ");
355     size = xbt_dynar_length(variable->content);
356
357     switch (variable->type) {
358       int ival;
359       char *sval;
360       double dval;
361       xbt_peer_t hval;
362
363     case xbt_cfgelm_int:
364       for (i = 0; i < size; i++) {
365         ival = xbt_dynar_get_as(variable->content, i, int);
366         printf("%s%d\n", (i == 0 ? "" : "              "), ival);
367       }
368       break;
369
370     case xbt_cfgelm_double:
371       for (i = 0; i < size; i++) {
372         dval = xbt_dynar_get_as(variable->content, i, double);
373         printf("%s%f\n", (i == 0 ? "" : "              "), dval);
374       }
375       break;
376
377     case xbt_cfgelm_string:
378       for (i = 0; i < size; i++) {
379         sval = xbt_dynar_get_as(variable->content, i, char *);
380         printf("%s'%s'\n", (i == 0 ? "" : "              "), sval);
381       }
382       break;
383
384     case xbt_cfgelm_peer:
385       for (i = 0; i < size; i++) {
386         hval = xbt_dynar_get_as(variable->content, i, xbt_peer_t);
387         printf("%s%s:%d\n", (i == 0 ? "" : "              "), hval->name,
388                hval->port);
389       }
390       break;
391
392     default:
393       printf("Invalid type!!\n");
394     }
395
396   }
397 }
398
399 /** @brief Check that each variable have the right amount of values */
400 void xbt_cfg_check(xbt_cfg_t cfg)
401 {
402   xbt_dict_cursor_t cursor;
403   xbt_cfgelm_t variable;
404   char *name;
405   int size;
406
407   xbt_assert0(cfg, "NULL config set.");
408   DEBUG1("Check cfg set %p", cfg);
409
410   xbt_dict_foreach((xbt_dict_t) cfg, cursor, name, variable) {
411     size = xbt_dynar_length(variable->content);
412     if (variable->min > size) {
413       xbt_dict_cursor_free(&cursor);
414       THROW4(mismatch_error, 0,
415              "Config elem %s needs at least %d %s, but there is only %d values.",
416              name, variable->min, xbt_cfgelm_type_name[variable->type], size);
417     }
418
419     if (variable->max > 0 && variable->max < size) {
420       xbt_dict_cursor_free(&cursor);
421       THROW4(mismatch_error, 0,
422              "Config elem %s accepts at most %d %s, but there is %d values.",
423              name, variable->max, xbt_cfgelm_type_name[variable->type], size);
424     }
425   }
426
427   xbt_dict_cursor_free(&cursor);
428 }
429
430 static xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg,
431                                    const char *name, e_xbt_cfgelm_type_t type)
432 {
433   xbt_cfgelm_t res = NULL;
434
435   res = xbt_dict_get_or_null((xbt_dict_t) cfg, name);
436   if (!res) {
437     xbt_cfg_help(cfg);
438     THROW1(not_found_error, 0,
439            "No registered variable '%s' in this config set", name);
440   }
441
442   xbt_assert3(type == xbt_cfgelm_any || res->type == type,
443               "You tried to access to the config element %s as an %s, but its type is %s.",
444               name,
445               xbt_cfgelm_type_name[type], xbt_cfgelm_type_name[res->type]);
446
447   return res;
448 }
449
450 /** @brief Get the type of this variable in that configuration set
451  *
452  * \arg cfg the config set
453  * \arg name the name of the element
454  * \arg type the result
455  *
456  */
457
458 e_xbt_cfgelm_type_t xbt_cfg_get_type(xbt_cfg_t cfg, const char *name)
459 {
460
461   xbt_cfgelm_t variable = NULL;
462
463   variable = xbt_dict_get_or_null((xbt_dict_t) cfg, name);
464   if (!variable)
465     THROW1(not_found_error, 0,
466            "Can't get the type of '%s' since this variable does not exist",
467            name);
468
469   INFO1("type in variable = %d", variable->type);
470
471   return variable->type;
472 }
473
474 /*----[ Setting ]---------------------------------------------------------*/
475 /**  @brief va_args version of xbt_cfg_set
476  *
477  * \arg cfg config set to fill
478  * \arg n   variable name
479  * \arg pa  variable value
480  *
481  * Add some values to the config set.
482  */
483 void xbt_cfg_set_vargs(xbt_cfg_t cfg, const char *name, va_list pa)
484 {
485   char *str;
486   int i;
487   double d;
488   e_xbt_cfgelm_type_t type = 0; /* Set a dummy value to make gcc happy. It cannot get uninitialized */
489
490   xbt_ex_t e;
491
492   TRY {
493     type = xbt_cfg_get_type(cfg, name);
494   } CATCH(e) {
495     if (e.category == not_found_error) {
496       xbt_ex_free(e);
497       THROW1(not_found_error, 0,
498              "Can't set the property '%s' since it's not registered", name);
499     }
500     RETHROW;
501   }
502
503   switch (type) {
504   case xbt_cfgelm_peer:
505     str = va_arg(pa, char *);
506     i = va_arg(pa, int);
507     xbt_cfg_set_peer(cfg, name, str, i);
508     break;
509
510   case xbt_cfgelm_string:
511     str = va_arg(pa, char *);
512     xbt_cfg_set_string(cfg, name, str);
513     break;
514
515   case xbt_cfgelm_int:
516     i = va_arg(pa, int);
517     xbt_cfg_set_int(cfg, name, i);
518     break;
519
520   case xbt_cfgelm_double:
521     d = va_arg(pa, double);
522     xbt_cfg_set_double(cfg, name, d);
523     break;
524
525   default:
526     xbt_assert2(0, "Config element variable %s not valid (type=%d)", name,
527                 type);
528   }
529 }
530
531 /** @brief Add a NULL-terminated list of pairs {(char*)key, value} to the set
532  *
533  * \arg cfg config set to fill
534  * \arg name variable name
535  * \arg varargs variable value
536  *
537  */
538 void xbt_cfg_set(xbt_cfg_t cfg, const char *name, ...)
539 {
540   va_list pa;
541
542   va_start(pa, name);
543   xbt_cfg_set_vargs(cfg, name, pa);
544   va_end(pa);
545 }
546
547 /** @brief Add values parsed from a string into a config set
548  *
549  * \arg cfg config set to fill
550  * \arg options a string containing the content to add to the config set. This
551  * is a '\\t',' ' or '\\n' or ',' separated list of variables. Each individual variable is
552  * like "[name]:[value]" where [name] is the name of an already registred
553  * variable, and [value] conforms to the data type under which this variable was
554  * registred.
555  *
556  * @todo This is a crude manual parser, it should be a proper lexer.
557  */
558
559 void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options)
560 {
561   xbt_ex_t e;
562
563   int i;
564   double d;
565   char *str;
566
567   xbt_cfgelm_t variable = NULL;
568   char *optionlist_cpy;
569   char *option, *name, *val;
570
571   int len;
572
573   XBT_IN;
574   if (!options || !strlen(options)) {   /* nothing to do */
575     return;
576   }
577   optionlist_cpy = xbt_strdup(options);
578
579   DEBUG1("List to parse and set:'%s'", options);
580   option = optionlist_cpy;
581   while (1) {                   /* breaks in the code */
582
583     if (!option)
584       break;
585     name = option;
586     len = strlen(name);
587     DEBUG3("Still to parse and set: '%s'. len=%d; option-name=%ld",
588            name, len, (long) (option - name));
589
590     /* Pass the value */
591     while (option - name <= (len - 1) && *option != ' ' && *option != '\n'
592            && *option != '\t' && *option != ',') {
593       DEBUG1("Take %c.", *option);
594       option++;
595     }
596     if (option - name == len) {
597       DEBUG0("Boundary=EOL");
598       option = NULL;            /* don't do next iteration */
599
600     } else {
601       DEBUG3("Boundary on '%c'. len=%d;option-name=%ld",
602              *option, len, (long) (option - name));
603
604       /* Pass the following blank chars */
605       *(option++) = '\0';
606       while (option - name < (len - 1) &&
607              (*option == ' ' || *option == '\n' || *option == '\t')) {
608         /*      fprintf(stderr,"Ignore a blank char.\n"); */
609         option++;
610       }
611       if (option - name == len - 1)
612         option = NULL;          /* don't do next iteration */
613     }
614     DEBUG2("parse now:'%s'; parse later:'%s'", name, option);
615
616     if (name[0] == ' ' || name[0] == '\n' || name[0] == '\t')
617       continue;
618     if (!strlen(name))
619       break;
620
621     val = strchr(name, ':');
622     if (!val) {
623       free(optionlist_cpy);
624       xbt_assert1(FALSE,
625                   "Option '%s' badly formated. Should be of the form 'name:value'",
626                   name);
627     }
628     *(val++) = '\0';
629
630     INFO2("Configuration change: Set '%s' to '%s'", name, val);
631
632     TRY {
633       variable = xbt_dict_get((xbt_dict_t) cfg, name);
634     }
635     CATCH(e) {
636       /* put it back on what won't get freed, ie within "options" and out of "optionlist_cpy" */
637       name = (char *) (optionlist_cpy - name + options);
638       free(optionlist_cpy);
639       if (e.category == not_found_error) {
640         xbt_ex_free(e);
641         THROW1(not_found_error, 0,
642                "No registered variable corresponding to '%s'.", name);
643       }
644       RETHROW;
645     }
646
647     TRY {
648       switch (variable->type) {
649       case xbt_cfgelm_string:
650         xbt_cfg_set_string(cfg, name, val);     /* throws */
651         break;
652
653       case xbt_cfgelm_int:
654         i = strtol(val, &val, 0);
655         if (val == NULL) {
656           free(optionlist_cpy);
657           xbt_assert1(FALSE,
658                       "Value of option %s not valid. Should be an integer",
659                       name);
660         }
661
662         xbt_cfg_set_int(cfg, name, i);  /* throws */
663         break;
664
665       case xbt_cfgelm_double:
666         d = strtod(val, &val);
667         if (val == NULL) {
668           free(optionlist_cpy);
669           xbt_assert1(FALSE,
670                       "Value of option %s not valid. Should be a double",
671                       name);
672         }
673
674         xbt_cfg_set_double(cfg, name, d);       /* throws */
675         break;
676
677       case xbt_cfgelm_peer:
678         str = val;
679         val = strchr(val, ':');
680         if (!val) {
681           free(optionlist_cpy);
682           xbt_assert1(FALSE,
683                       "Value of option %s not valid. Should be an peer (machine:port)",
684                       name);
685         }
686
687         *(val++) = '\0';
688         i = strtol(val, &val, 0);
689         if (val == NULL) {
690           free(optionlist_cpy);
691           xbt_assert1(FALSE,
692                       "Value of option %s not valid. Should be an peer (machine:port)",
693                       name);
694         }
695
696         xbt_cfg_set_peer(cfg, name, str, i);    /* throws */
697         break;
698
699       default:
700         THROW1(unknown_error, 0, "Type of config element %s is not valid.",
701                name);
702       }
703     }
704     CATCH(e) {
705       free(optionlist_cpy);
706       RETHROW;
707     }
708   }
709   free(optionlist_cpy);
710
711 }
712
713 /** @brief Set an integer value to \a name within \a cfg if it wasn't changed yet
714  *
715  * This is useful to change the default value of a variable while allowing
716  * users to override it with command line arguments
717  */
718 void xbt_cfg_setdefault_int(xbt_cfg_t cfg, const char *name, int val) {
719   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_int);
720
721   if (variable->isdefault)
722     xbt_cfg_set_int(cfg, name,val);
723   else
724     DEBUG2("Do not override configuration variable '%s' with value '%d' because it was already set.",name,val);
725 }
726 /** @brief Set an integer value to \a name within \a cfg if it wasn't changed yet
727  *
728  * This is useful to change the default value of a variable while allowing
729  * users to override it with command line arguments
730  */
731 void xbt_cfg_setdefault_double(xbt_cfg_t cfg, const char *name, double val) {
732   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_double);
733
734   if (variable->isdefault)
735     xbt_cfg_set_double(cfg, name, val);
736   else
737     DEBUG2("Do not override configuration variable '%s' with value '%lf' because it was already set.",name,val);
738 }
739 /** @brief Set a string value to \a name within \a cfg if it wasn't changed yet
740  *
741  * This is useful to change the default value of a variable while allowing
742  * users to override it with command line arguments
743  */
744 void xbt_cfg_setdefault_string(xbt_cfg_t cfg, const char *name, const char* val) {
745   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_string);
746
747   if (variable->isdefault)
748     xbt_cfg_set_string(cfg, name,val);
749   else
750     DEBUG2("Do not override configuration variable '%s' with value '%s' because it was already set.",name,val);
751 }
752 /** @brief Set a peer value to \a name within \a cfg if it wasn't changed yet
753  *
754  * This is useful to change the default value of a variable while allowing
755  * users to override it with command line arguments
756  */
757 void xbt_cfg_setdefault_peer(xbt_cfg_t cfg, const char *name, const char* host, int port) {
758   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_peer);
759
760   if (variable->isdefault)
761     xbt_cfg_set_peer(cfg, name, host, port);
762   else
763     DEBUG3("Do not override configuration variable '%s' with value '%s:%d' because it was already set.",
764         name,host,port);
765 }
766
767 /** @brief Set or add an integer value to \a name within \a cfg
768  *
769  * \arg cfg the config set
770  * \arg name the name of the variable
771  * \arg val the value of the variable
772  */
773 void xbt_cfg_set_int(xbt_cfg_t cfg, const char *name, int val)
774 {
775   xbt_cfgelm_t variable;
776
777   VERB2("Configuration setting: %s=%d", name, val);
778   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_int);
779
780   if (variable->max == 1) {
781     if (variable->cb_rm && xbt_dynar_length(variable->content))
782       (*variable->cb_rm) (name, 0);
783
784     xbt_dynar_set(variable->content, 0, &val);
785   } else {
786     if (variable->max
787         && xbt_dynar_length(variable->content) ==
788         (unsigned long) variable->max)
789       THROW3(mismatch_error, 0,
790              "Cannot add value %d to the config element %s since it's already full (size=%d)",
791              val, name, variable->max);
792
793     xbt_dynar_push(variable->content, &val);
794   }
795
796   if (variable->cb_set)
797     (*variable->cb_set) (name, xbt_dynar_length(variable->content) - 1);
798   variable->isdefault = 0;
799 }
800
801 /** @brief Set or add a double value to \a name within \a cfg
802  *
803  * \arg cfg the config set
804  * \arg name the name of the variable
805  * \arg val the doule to set
806  */
807
808 void xbt_cfg_set_double(xbt_cfg_t cfg, const char *name, double val)
809 {
810   xbt_cfgelm_t variable;
811
812   VERB2("Configuration setting: %s=%f", name, val);
813   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_double);
814
815   if (variable->max == 1) {
816     if (variable->cb_rm && xbt_dynar_length(variable->content))
817       (*variable->cb_rm) (name, 0);
818
819     xbt_dynar_set(variable->content, 0, &val);
820   } else {
821     if (variable->max && xbt_dynar_length(variable->content) == variable->max)
822       THROW3(mismatch_error, 0,
823              "Cannot add value %f to the config element %s since it's already full (size=%d)",
824              val, name, variable->max);
825
826     xbt_dynar_push(variable->content, &val);
827   }
828
829   if (variable->cb_set)
830     (*variable->cb_set) (name, xbt_dynar_length(variable->content) - 1);
831   variable->isdefault = 0;
832 }
833
834 /** @brief Set or add a string value to \a name within \a cfg
835  *
836  * \arg cfg the config set
837  * \arg name the name of the variable
838  * \arg val the value to be added
839  *
840  */
841
842 void xbt_cfg_set_string(xbt_cfg_t cfg, const char *name, const char *val)
843 {
844   xbt_cfgelm_t variable;
845   char *newval = xbt_strdup(val);
846
847   VERB2("Configuration setting: %s=%s", name, val);
848   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_string);
849   DEBUG5("Variable: %d to %d %s (=%d) @%p",
850          variable->min, variable->max, xbt_cfgelm_type_name[variable->type],
851          variable->type, variable);
852
853   if (variable->max == 1) {
854     if (xbt_dynar_length(variable->content)) {
855       if (variable->cb_rm)
856         (*variable->cb_rm) (name, 0);
857       else if (variable->type == xbt_cfgelm_string) {
858         char *sval = xbt_dynar_get_as(variable->content, 0, char *);
859         free(sval);
860       }
861     }
862
863     xbt_dynar_set(variable->content, 0, &newval);
864   } else {
865     if (variable->max && xbt_dynar_length(variable->content) == variable->max)
866       THROW3(mismatch_error, 0,
867              "Cannot add value %s to the config element %s since it's already full (size=%d)",
868              name, val, variable->max);
869
870     xbt_dynar_push(variable->content, &newval);
871   }
872
873   if (variable->cb_set)
874     (*variable->cb_set) (name, xbt_dynar_length(variable->content) - 1);
875   variable->isdefault = 0;
876 }
877
878 /** @brief Set or add an peer value to \a name within \a cfg
879  *
880  * \arg cfg the config set
881  * \arg name the name of the variable
882  * \arg peer the peer
883  * \arg port the port number
884  *
885  * \e peer values are composed of a string (peername) and an integer (port)
886  */
887
888 void
889 xbt_cfg_set_peer(xbt_cfg_t cfg, const char *name, const char *peer, int port)
890 {
891   xbt_cfgelm_t variable;
892   xbt_peer_t val = xbt_peer_new(peer, port);
893
894   VERB3("Configuration setting: %s=%s:%d", name, peer, port);
895
896   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_peer);
897
898   if (variable->max == 1) {
899     if (variable->cb_rm && xbt_dynar_length(variable->content))
900       (*variable->cb_rm) (name, 0);
901
902     xbt_dynar_set(variable->content, 0, &val);
903   } else {
904     if (variable->max && xbt_dynar_length(variable->content) == variable->max)
905       THROW4(mismatch_error, 0,
906              "Cannot add value %s:%d to the config element %s since it's already full (size=%d)",
907              peer, port, name, variable->max);
908
909     xbt_dynar_push(variable->content, &val);
910   }
911
912   if (variable->cb_set)
913     (*variable->cb_set) (name, xbt_dynar_length(variable->content) - 1);
914   variable->isdefault = 0;
915 }
916
917 /* ---- [ Removing ] ---- */
918
919 /** @brief Remove the provided \e val integer value from a variable
920  *
921  * \arg cfg the config set
922  * \arg name the name of the variable
923  * \arg val the value to be removed
924  */
925 void xbt_cfg_rm_int(xbt_cfg_t cfg, const char *name, int val)
926 {
927
928   xbt_cfgelm_t variable;
929   unsigned int cpt;
930   int seen;
931
932   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_int);
933
934   if (xbt_dynar_length(variable->content) == variable->min)
935     THROW3(mismatch_error, 0,
936            "Cannot remove value %d from the config element %s since it's already at its minimal size (=%d)",
937            val, name, variable->min);
938
939   xbt_dynar_foreach(variable->content, cpt, seen) {
940     if (seen == val) {
941       if (variable->cb_rm)
942         (*variable->cb_rm) (name, cpt);
943       xbt_dynar_cursor_rm(variable->content, &cpt);
944       return;
945     }
946   }
947
948   THROW2(not_found_error, 0,
949          "Can't remove the value %d of config element %s: value not found.",
950          val, name);
951 }
952
953 /** @brief Remove the provided \e val double value from a variable
954  *
955  * \arg cfg the config set
956  * \arg name the name of the variable
957  * \arg val the value to be removed
958  */
959
960 void xbt_cfg_rm_double(xbt_cfg_t cfg, const char *name, double val)
961 {
962   xbt_cfgelm_t variable;
963   unsigned int cpt;
964   double seen;
965
966   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_double);
967
968   if (xbt_dynar_length(variable->content) == variable->min)
969     THROW3(mismatch_error, 0,
970            "Cannot remove value %f from the config element %s since it's already at its minimal size (=%d)",
971            val, name, variable->min);
972
973   xbt_dynar_foreach(variable->content, cpt, seen) {
974     if (seen == val) {
975       xbt_dynar_cursor_rm(variable->content, &cpt);
976       if (variable->cb_rm)
977         (*variable->cb_rm) (name, cpt);
978       return;
979     }
980   }
981
982   THROW2(not_found_error, 0,
983          "Can't remove the value %f of config element %s: value not found.",
984          val, name);
985 }
986
987 /** @brief Remove the provided \e val string value from a variable
988  *
989  * \arg cfg the config set
990  * \arg name the name of the variable
991  * \arg val the value of the string which will be removed
992  */
993 void xbt_cfg_rm_string(xbt_cfg_t cfg, const char *name, const char *val)
994 {
995   xbt_cfgelm_t variable;
996   unsigned int cpt;
997   char *seen;
998
999   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_string);
1000
1001   if (xbt_dynar_length(variable->content) == variable->min)
1002     THROW3(mismatch_error, 0,
1003            "Cannot remove value %s from the config element %s since it's already at its minimal size (=%d)",
1004            name, val, variable->min);
1005
1006   xbt_dynar_foreach(variable->content, cpt, seen) {
1007     if (!strcpy(seen, val)) {
1008       if (variable->cb_rm)
1009         (*variable->cb_rm) (name, cpt);
1010       xbt_dynar_cursor_rm(variable->content, &cpt);
1011       return;
1012     }
1013   }
1014
1015   THROW2(not_found_error, 0,
1016          "Can't remove the value %s of config element %s: value not found.",
1017          val, name);
1018 }
1019
1020 /** @brief Remove the provided \e val peer value from a variable
1021  *
1022  * \arg cfg the config set
1023  * \arg name the name of the variable
1024  * \arg peer the peername
1025  * \arg port the port number
1026  */
1027
1028 void
1029 xbt_cfg_rm_peer(xbt_cfg_t cfg, const char *name, const char *peer, int port)
1030 {
1031   xbt_cfgelm_t variable;
1032   unsigned int cpt;
1033   xbt_peer_t seen;
1034
1035   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_peer);
1036
1037   if (xbt_dynar_length(variable->content) == variable->min)
1038     THROW4(mismatch_error, 0,
1039            "Cannot remove value %s:%d from the config element %s since it's already at its minimal size (=%d)",
1040            peer, port, name, variable->min);
1041
1042   xbt_dynar_foreach(variable->content, cpt, seen) {
1043     if (!strcpy(seen->name, peer) && seen->port == port) {
1044       if (variable->cb_rm)
1045         (*variable->cb_rm) (name, cpt);
1046       xbt_dynar_cursor_rm(variable->content, &cpt);
1047       return;
1048     }
1049   }
1050
1051   THROW3(not_found_error, 0,
1052          "Can't remove the value %s:%d of config element %s: value not found.",
1053          peer, port, name);
1054 }
1055
1056 /** @brief Remove the \e pos th value from the provided variable */
1057
1058 void xbt_cfg_rm_at(xbt_cfg_t cfg, const char *name, int pos)
1059 {
1060
1061   xbt_cfgelm_t variable;
1062
1063   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_any);
1064
1065   if (xbt_dynar_length(variable->content) == variable->min)
1066     THROW3(mismatch_error, 0,
1067            "Cannot remove %dth value from the config element %s since it's already at its minimal size (=%d)",
1068            pos, name, variable->min);
1069
1070   if (variable->cb_rm)
1071     (*variable->cb_rm) (name, pos);
1072   xbt_dynar_remove_at(variable->content, pos, NULL);
1073 }
1074
1075 /** @brief Remove all the values from a variable
1076  *
1077  * \arg cfg the config set
1078  * \arg name the name of the variable
1079  */
1080
1081 void xbt_cfg_empty(xbt_cfg_t cfg, const char *name)
1082 {
1083   xbt_cfgelm_t variable = NULL;
1084   xbt_ex_t e;
1085
1086   TRY {
1087     variable = xbt_dict_get((xbt_dict_t) cfg, name);
1088   } CATCH(e) {
1089     if (e.category != not_found_error)
1090       RETHROW;
1091
1092     xbt_ex_free(e);
1093     THROW1(not_found_error, 0,
1094            "Can't empty  '%s' since this config element does not exist",
1095            name);
1096   }
1097
1098   if (variable) {
1099     if (variable->cb_rm) {
1100       unsigned int cpt;
1101       void *ignored;
1102       xbt_dynar_foreach(variable->content, cpt, ignored) {
1103         (*variable->cb_rm) (name, cpt);
1104       }
1105     }
1106     xbt_dynar_reset(variable->content);
1107   }
1108 }
1109
1110 /*----[ Getting ]---------------------------------------------------------*/
1111
1112 /** @brief Retrieve an integer value of a variable (get a warning if not uniq)
1113  *
1114  * \arg cfg the config set
1115  * \arg name the name of the variable
1116  * \arg val the wanted value
1117  *
1118  * Returns the first value from the config set under the given name.
1119  * If there is more than one value, it will issue a warning. Consider using
1120  * xbt_cfg_get_dynar() instead.
1121  *
1122  * \warning the returned value is the actual content of the config set
1123  */
1124 int xbt_cfg_get_int(xbt_cfg_t cfg, const char *name)
1125 {
1126   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_int);
1127
1128   if (xbt_dynar_length(variable->content) > 1) {
1129     WARN2
1130       ("You asked for the first value of the config element '%s', but there is %lu values",
1131        name, xbt_dynar_length(variable->content));
1132   }
1133
1134   return xbt_dynar_get_as(variable->content, 0, int);
1135 }
1136
1137 /** @brief Retrieve a double value of a variable (get a warning if not uniq)
1138  *
1139  * \arg cfg the config set
1140  * \arg name the name of the variable
1141  * \arg val the wanted value
1142  *
1143  * Returns the first value from the config set under the given name.
1144  * If there is more than one value, it will issue a warning. Consider using
1145  * xbt_cfg_get_dynar() instead.
1146  *
1147  * \warning the returned value is the actual content of the config set
1148  */
1149
1150 double xbt_cfg_get_double(xbt_cfg_t cfg, const char *name)
1151 {
1152   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_double);
1153
1154   if (xbt_dynar_length(variable->content) > 1) {
1155     WARN2
1156       ("You asked for the first value of the config element '%s', but there is %lu values\n",
1157        name, xbt_dynar_length(variable->content));
1158   }
1159
1160   return xbt_dynar_get_as(variable->content, 0, double);
1161 }
1162
1163 /** @brief Retrieve a string value of a variable (get a warning if not uniq)
1164  *
1165  * \arg th the config set
1166  * \arg name the name of the variable
1167  * \arg val the wanted value
1168  *
1169  * Returns the first value from the config set under the given name.
1170  * If there is more than one value, it will issue a warning. Consider using
1171  * xbt_cfg_get_dynar() instead. Returns NULL if there is no value.
1172  *
1173  * \warning the returned value is the actual content of the config set
1174  */
1175
1176 char *xbt_cfg_get_string(xbt_cfg_t cfg, const char *name)
1177 {
1178   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_string);
1179
1180   if (xbt_dynar_length(variable->content) > 1) {
1181     WARN2
1182       ("You asked for the first value of the config element '%s', but there is %lu values\n",
1183        name, xbt_dynar_length(variable->content));
1184   } else if (xbt_dynar_length(variable->content) == 0) {
1185     return NULL;
1186   }
1187
1188   return xbt_dynar_get_as(variable->content, 0, char *);
1189 }
1190
1191 /** @brief Retrieve an peer value of a variable (get a warning if not uniq)
1192  *
1193  * \arg cfg the config set
1194  * \arg name the name of the variable
1195  * \arg peer the peer
1196  * \arg port the port number
1197  *
1198  * Returns the first value from the config set under the given name.
1199  * If there is more than one value, it will issue a warning. Consider using
1200  * xbt_cfg_get_dynar() instead.
1201  *
1202  * \warning the returned value is the actual content of the config set
1203  */
1204
1205 void xbt_cfg_get_peer(xbt_cfg_t cfg, const char *name, char **peer, int *port)
1206 {
1207   xbt_cfgelm_t variable;
1208   xbt_peer_t val;
1209
1210   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_peer);
1211
1212   if (xbt_dynar_length(variable->content) > 1) {
1213     WARN2
1214       ("You asked for the first value of the config element '%s', but there is %lu values\n",
1215        name, xbt_dynar_length(variable->content));
1216   }
1217
1218   val = xbt_dynar_get_as(variable->content, 0, xbt_peer_t);
1219   *peer = val->name;
1220   *port = val->port;
1221 }
1222
1223 /** @brief Retrieve the dynar of all the values stored in a variable
1224  *
1225  * \arg cfg where to search in
1226  * \arg name what to search for
1227  * \arg dynar result
1228  *
1229  * Get the data stored in the config set.
1230  *
1231  * \warning the returned value is the actual content of the config set
1232  */
1233 xbt_dynar_t xbt_cfg_get_dynar(xbt_cfg_t cfg, const char *name)
1234 {
1235   xbt_cfgelm_t variable = NULL;
1236   xbt_ex_t e;
1237
1238   TRY {
1239     variable = xbt_dict_get((xbt_dict_t) cfg, name);
1240   } CATCH(e) {
1241     if (e.category == not_found_error) {
1242       xbt_ex_free(e);
1243       THROW1(not_found_error, 0,
1244              "No registered variable %s in this config set", name);
1245     }
1246     RETHROW;
1247   }
1248
1249   return variable->content;
1250 }
1251
1252
1253 /** @brief Retrieve one of the integer value of a variable */
1254 int xbt_cfg_get_int_at(xbt_cfg_t cfg, const char *name, int pos)
1255 {
1256
1257   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_int);
1258   return xbt_dynar_get_as(variable->content, pos, int);
1259 }
1260
1261 /** @brief Retrieve one of the double value of a variable */
1262 double xbt_cfg_get_double_at(xbt_cfg_t cfg, const char *name, int pos)
1263 {
1264
1265   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_double);
1266   return xbt_dynar_get_as(variable->content, pos, double);
1267 }
1268
1269
1270 /** @brief Retrieve one of the string value of a variable */
1271 char *xbt_cfg_get_string_at(xbt_cfg_t cfg, const char *name, int pos)
1272 {
1273
1274   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_string);
1275   return xbt_dynar_get_as(variable->content, pos, char *);
1276 }
1277
1278 /** @brief Retrieve one of the peer value of a variable */
1279 void
1280 xbt_cfg_get_peer_at(xbt_cfg_t cfg, const char *name, int pos,
1281                     char **peer, int *port)
1282 {
1283
1284   xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_int);
1285   xbt_peer_t val = xbt_dynar_get_ptr(variable->content, pos);
1286
1287   *port = val->port;
1288   *peer = val->name;
1289 }
1290
1291
1292 #ifdef SIMGRID_TEST
1293 #include "xbt.h"
1294 #include "xbt/ex.h"
1295
1296 XBT_LOG_EXTERNAL_CATEGORY(xbt_cfg);
1297
1298 XBT_TEST_SUITE("config", "Configuration support");
1299
1300 static xbt_cfg_t make_set()
1301 {
1302   xbt_cfg_t set = NULL;
1303
1304   xbt_log_threshold_set(&_XBT_LOGV(xbt_cfg), xbt_log_priority_critical);
1305   xbt_cfg_register_str(&set, "speed:1_to_2_int");
1306   xbt_cfg_register_str(&set, "peername:1_to_1_string");
1307   xbt_cfg_register_str(&set, "user:1_to_10_string");
1308
1309   return set;
1310 }                               /* end_of_make_set */
1311
1312 XBT_TEST_UNIT("memuse", test_config_memuse, "Alloc and free a config set")
1313 {
1314   xbt_cfg_t set = make_set();
1315   xbt_test_add0("Alloc and free a config set");
1316   xbt_cfg_set_parse(set,
1317                     "peername:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
1318   xbt_cfg_free(&set);
1319   xbt_cfg_free(&set);
1320 }
1321
1322 XBT_TEST_UNIT("validation", test_config_validation, "Validation tests")
1323 {
1324   xbt_cfg_t set = set = make_set();
1325   xbt_ex_t e;
1326
1327   xbt_test_add0("Having too few elements for speed");
1328   xbt_cfg_set_parse(set,
1329                     "peername:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
1330   TRY {
1331     xbt_cfg_check(set);
1332   }
1333   CATCH(e) {
1334     if (e.category != mismatch_error ||
1335         strncmp(e.msg, "Config elem speed needs",
1336                 strlen("Config elem speed needs")))
1337       xbt_test_fail1("Got an exception. msg=%s", e.msg);
1338     xbt_ex_free(e);
1339   }
1340   xbt_cfg_free(&set);
1341   xbt_cfg_free(&set);
1342
1343
1344
1345   xbt_test_add0("Having too much values of 'speed'");
1346   set = make_set();
1347   xbt_cfg_set_parse(set, "peername:toto:42 user:alegrand");
1348   TRY {
1349     xbt_cfg_set_parse(set, "speed:42 speed:24 speed:34");
1350   }
1351   CATCH(e) {
1352     if (e.category != mismatch_error ||
1353         strncmp(e.msg, "Cannot add value 34 to the config elem speed",
1354                 strlen("Config elem speed needs")))
1355       xbt_test_fail1("Got an exception. msg=%s", e.msg);
1356     xbt_ex_free(e);
1357   }
1358   xbt_cfg_check(set);
1359   xbt_cfg_free(&set);
1360   xbt_cfg_free(&set);
1361
1362 }
1363
1364 XBT_TEST_UNIT("use", test_config_use, "Data retrieving tests")
1365 {
1366
1367   xbt_test_add0("Get a single value");
1368   {
1369     /* get_single_value */
1370     int ival;
1371     xbt_cfg_t myset = make_set();
1372
1373     xbt_cfg_set_parse(myset, "peername:toto:42 speed:42");
1374     ival = xbt_cfg_get_int(myset, "speed");
1375     if (ival != 42)
1376       xbt_test_fail1("Speed value = %d, I expected 42", ival);
1377     xbt_cfg_free(&myset);
1378   }
1379
1380   xbt_test_add0("Get multiple values");
1381   {
1382     /* get_multiple_value */
1383     xbt_dynar_t dyn;
1384     xbt_cfg_t myset = make_set();
1385
1386     xbt_cfg_set_parse(myset, "peername:veloce user:foo\nuser:bar\tuser:toto");
1387     xbt_cfg_set_parse(myset, "speed:42");
1388     xbt_cfg_check(myset);
1389     dyn = xbt_cfg_get_dynar(myset, "user");
1390
1391     if (xbt_dynar_length(dyn) != 3)
1392       xbt_test_fail1("Dynar length = %lu, I expected 3",
1393                      xbt_dynar_length(dyn));
1394
1395     if (strcmp(xbt_dynar_get_as(dyn, 0, char *), "foo"))
1396         xbt_test_fail1("Dynar[0] = %s, I expected foo",
1397                        xbt_dynar_get_as(dyn, 0, char *));
1398
1399     if (strcmp(xbt_dynar_get_as(dyn, 1, char *), "bar"))
1400         xbt_test_fail1("Dynar[1] = %s, I expected bar",
1401                        xbt_dynar_get_as(dyn, 1, char *));
1402
1403     if (strcmp(xbt_dynar_get_as(dyn, 2, char *), "toto"))
1404         xbt_test_fail1("Dynar[2] = %s, I expected toto",
1405                        xbt_dynar_get_as(dyn, 2, char *));
1406     xbt_cfg_free(&myset);
1407   }
1408
1409   xbt_test_add0("Access to a non-existant entry");
1410   {
1411     /* non-existant_entry */
1412     xbt_cfg_t myset = make_set();
1413     xbt_ex_t e;
1414
1415     TRY {
1416       xbt_cfg_set_parse(myset, "color:blue");
1417     } CATCH(e) {
1418       if (e.category != not_found_error)
1419         xbt_test_exception(e);
1420       xbt_ex_free(e);
1421     }
1422     xbt_cfg_free(&myset);
1423   }
1424 }
1425 #endif /* SIMGRID_TEST */