From efbf2ac15b2739e4a24faec602c902f5737c408a Mon Sep 17 00:00:00 2001 From: agiersch Date: Thu, 27 Jan 2011 10:51:52 +0000 Subject: [PATCH] Display the config options, sorted by their names. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9512 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/xbt/config.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/xbt/config.c b/src/xbt/config.c index 456f47daed..cd6cfbc63a 100644 --- a/src/xbt/config.c +++ b/src/xbt/config.c @@ -337,17 +337,30 @@ void xbt_cfg_register_str(xbt_cfg_t * cfg, const char *entry) free(entrycpy); /* strdup'ed by dict mechanism, but cannot be const */ } +static int strcmp_voidp(const void *pa, const void *pb) +{ + return strcmp(*(const char **)pa, *(const char **)pb); +} + /** @brief Displays the declared options and their description */ void xbt_cfg_help(xbt_cfg_t cfg) { - xbt_dict_cursor_t cursor; + xbt_dict_cursor_t dict_cursor; + unsigned int dynar_cursor; xbt_cfgelm_t variable; char *name; + xbt_dynar_t names = xbt_dynar_new(sizeof(char *), NULL); - int i; - int size; + xbt_dict_foreach((xbt_dict_t )cfg, dict_cursor, name, variable) { + xbt_dynar_push(names, &name); + } + xbt_dynar_sort(names, strcmp_voidp); + + xbt_dynar_foreach(names, dynar_cursor, name) { + int i; + int size; + variable = xbt_dict_get((xbt_dict_t )cfg, name); - xbt_dict_foreach((xbt_dict_t) cfg, cursor, name, variable) { printf(" %s: %s\n", name, variable->desc); printf(" Type: %s; ", xbt_cfgelm_type_name[variable->type]); if (variable->min != 1 || variable->max != 1) { @@ -399,6 +412,8 @@ void xbt_cfg_help(xbt_cfg_t cfg) } } + + xbt_dynar_free(&names); } /** @brief Check that each variable have the right amount of values */ -- 2.20.1