Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement a --cfg-help flag to show existing configuration variables
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 26 Jun 2009 11:10:27 +0000 (11:10 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 26 Jun 2009 11:10:27 +0000 (11:10 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6366 48e7efb5-ca39-0410-a469-dd3cf9ba447f

ChangeLog
include/xbt/config.h
src/surf/surf_config.c
src/xbt/config.c

index dc7ecaf..24d1064 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@ SimGrid (3.4-svn) unstable; urgency=high
 
  OVERALL CHANGES:
   * Tested successfully on AIX
+  * Implement a --cfg-help to show existing configuration variables
 
  GRAS:
   * fix a bug on struct sizeof computation, which prevented the
index b250561..dde90d3 100644 (file)
@@ -176,6 +176,7 @@ XBT_PUBLIC(void) xbt_cfg_register(xbt_cfg_t cfg,
                                   xbt_cfg_cb_t cb_set, xbt_cfg_cb_t cb_rm);
 XBT_PUBLIC(void) xbt_cfg_unregister(xbt_cfg_t cfg, const char *name);
 XBT_PUBLIC(void) xbt_cfg_register_str(xbt_cfg_t cfg, const char *entry);
+XBT_PUBLIC(void) xbt_cfg_help(xbt_cfg_t cfg);
 XBT_PUBLIC(void) xbt_cfg_check(xbt_cfg_t cfg);
 XBT_PUBLIC(e_xbt_cfgelm_type_t) xbt_cfg_get_type(xbt_cfg_t cfg,
                                                  const char *name);
index 5c32d96..68ca07b 100644 (file)
@@ -66,14 +66,22 @@ static void surf_config_cmd_line(int *argc,char **argv)
        char *opt;
 
        for (i = 1; i < *argc; i++) {
+               int remove_it = 0;
                if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
                        opt = strchr(argv[i], '=');
                        opt++;
 
                        xbt_cfg_set_parse(_surf_cfg_set,opt);
                        DEBUG1("Did apply '%s' as config setting", opt);
-                       /*remove this from argv */
-
+                       remove_it = 1;
+               } else if (!strncmp(argv[i], "--cfg-help", strlen("--cfg-help")+1) ||
+                               !strncmp(argv[i], "--help", strlen("--help")+1)) {
+                       printf("Description of the configuration accepted by this simulator:\n");
+                       xbt_cfg_help(_surf_cfg_set);
+                       remove_it=1;
+                       exit(0);
+               }
+               if (remove_it) { /*remove this from argv */
                        for (j = i + 1; j < *argc; j++) {
                                argv[j - 1] = argv[j];
                        }
@@ -101,7 +109,7 @@ void surf_config_init(int *argc, char **argv) {
                        p+=sprintf(p,"%s%s",(i==0?"":", "),surf_workstation_model_description[i].name);
 
                xbt_cfg_register(_surf_cfg_set,
-                               "workstation_model", description,  xbt_cfgelm_string, 1, 1,
+                               "workstation_model", xbt_strdup(description),  xbt_cfgelm_string, 1, 1,
                                &_surf_cfg_cb__workstation_model, NULL);
 
                sprintf(description,"The model to use for the CPU. Possible values: ");
@@ -110,7 +118,7 @@ void surf_config_init(int *argc, char **argv) {
                for (i=0;surf_cpu_model_description[i].name;i++)
                        p+=sprintf(p,"%s%s",(i==0?"":", "),surf_cpu_model_description[i].name);
                xbt_cfg_register(_surf_cfg_set,
-                               "cpu_model", description, xbt_cfgelm_string, 1, 1,
+                               "cpu_model", xbt_strdup(description), xbt_cfgelm_string, 1, 1,
                                &_surf_cfg_cb__cpu_model, NULL);
 
                sprintf(description,"The model to use for the network. Possible values: ");
@@ -123,6 +131,8 @@ void surf_config_init(int *argc, char **argv) {
                                &_surf_cfg_cb__network_model, NULL);
 
                xbt_cfg_set_string(_surf_cfg_set, "workstation_model", "CLM03");
+               xbt_cfg_set_string(_surf_cfg_set, "cpu_model", "Cas01");
+               xbt_cfg_set_string(_surf_cfg_set, "network_model", "CM02");
 
                surf_config_cmd_line(argc,argv);
        }
index 72ad05e..10a9a97 100644 (file)
@@ -320,8 +320,65 @@ void xbt_cfg_register_str(xbt_cfg_t cfg, const char *entry)
   free(entrycpy);               /* strdup'ed by dict mechanism, but cannot be const */
 }
 
-/** @brief Check that each variable have the right amount of values */
+/** @brief Displays the declared options and their description */
+void xbt_cfg_help(xbt_cfg_t cfg) {
+       xbt_dict_cursor_t cursor;
+       xbt_cfgelm_t variable;
+       char *name;
+
+         int i;
+         int size;
+
+       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)
+                       printf("Arrity: min:%d to max:%d; ",variable->min,variable->max);
+               printf("Current value: ");
+               size = xbt_dynar_length(variable->content);
+
+           switch (variable->type) {
+                 int ival;
+                 char *sval;
+                 double dval;
+                 xbt_peer_t hval;
+
+           case xbt_cfgelm_int:
+             for (i = 0; i < size; i++) {
+               ival = xbt_dynar_get_as(variable->content, i, int);
+               printf("%s%d\n", (i==0?"":"              "),ival);
+             }
+             break;
+
+           case xbt_cfgelm_double:
+             for (i = 0; i < size; i++) {
+               dval = xbt_dynar_get_as(variable->content, i, double);
+               printf("%s%f\n", (i==0?"":"              "),dval);
+             }
+             break;
+
+           case xbt_cfgelm_string:
+             for (i = 0; i < size; i++) {
+               sval = xbt_dynar_get_as(variable->content, i, char *);
+               printf("%s'%s'\n", (i==0?"":"              "),sval);
+             }
+             break;
+
+           case xbt_cfgelm_peer:
+             for (i = 0; i < size; i++) {
+               hval = xbt_dynar_get_as(variable->content, i, xbt_peer_t);
+               printf("%s%s:%d\n", (i==0?"":"              "),hval->name, hval->port);
+             }
+             break;
+
+           default:
+             printf("Invalid type!!\n");
+           }
+
+       }
+}
 
+/** @brief Check that each variable have the right amount of values */
 void xbt_cfg_check(xbt_cfg_t cfg)
 {
   xbt_dict_cursor_t cursor;