Logo AND Algorithmique Numérique Distribuée

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