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
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);
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];
}
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: ");
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: ");
&_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);
}
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;