Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use the result of sprintf, instead of computing strlen again.
[simgrid.git] / src / simgrid / sg_config.c
index 11cf929..50b6136 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009-2010, 2012-2013. The SimGrid Team.
+/* Copyright (c) 2009-2010, 2012-2014. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -111,6 +111,27 @@ static void sg_config_cmd_line(int *argc, char **argv)
     sg_cfg_exit_early();
 }
 
+/* callback of the plugin variable */
+static void _sg_cfg_cb__plugin(const char *name, int pos)
+{
+  char *val;
+
+  XBT_VERB("PLUGIN");
+  xbt_assert(_sg_cfg_init_status < 2,
+              "Cannot load a plugin after the initialization");
+
+  val = xbt_cfg_get_string(_sg_cfg_set, name);
+
+  if (!strcmp(val, "help")) {
+    model_help("plugin", surf_plugin_description);
+    sg_cfg_exit_early();
+  }
+
+  /* New Module missing */
+  int plugin_id = find_model_description(surf_plugin_description, val);
+  surf_plugin_description[plugin_id].model_init_preparse();
+}
+
 /* callback of the workstation/model variable */
 static void _sg_cfg_cb__workstation_model(const char *name, int pos)
 {
@@ -435,10 +456,19 @@ void sg_config_init(int *argc, char **argv)
 
   /* Create the configuration support */
   if (_sg_cfg_init_status == 0) { /* Only create stuff if not already inited */
-    sprintf(description,
-            "The model to use for the CPU. Possible values: ");
-    p = description;
-    while (*(++p) != '\0');
+
+    /* Plugins configuration */
+    p = description + sprintf(description, "The plugins. Possible values: ");
+    for (i = 0; surf_plugin_description[i].name; i++)
+      p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
+                   surf_plugin_description[i].name);
+    sprintf(p,
+            ".\n       (use 'help' as a value to see the long description of each plugin)");
+    xbt_cfg_register(&_sg_cfg_set, "plugin", description,
+                     xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__plugin, NULL);
+
+    p = description + 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);
@@ -448,7 +478,9 @@ void sg_config_init(int *argc, char **argv)
                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__cpu_model, NULL);
     xbt_cfg_setdefault_string(_sg_cfg_set, "cpu/model", "Cas01");
 
-    while (*(++p) != '\0');
+    p = description +
+      sprintf(description,
+              "The optimization modes to use for the CPU. Possible values: ");
     for (i = 0; surf_optimization_mode_description[i].name; i++)
       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
                    surf_optimization_mode_description[i].name);
@@ -458,10 +490,9 @@ void sg_config_init(int *argc, char **argv)
                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__optimization_mode, NULL);
     xbt_cfg_setdefault_string(_sg_cfg_set, "cpu/optim", "Lazy");
 
-    sprintf(description,
-            "The model to use for the storage. Possible values: ");
-    p = description;
-    while (*(++p) != '\0');
+    p = description +
+      sprintf(description,
+              "The model to use for the storage. Possible values: ");
     for (i = 0; surf_storage_model_description[i].name; i++)
       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
                    surf_storage_model_description[i].name);
@@ -471,10 +502,9 @@ void sg_config_init(int *argc, char **argv)
                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__storage_mode, NULL);
     xbt_cfg_setdefault_string(_sg_cfg_set, "storage/model", "default");
 
-    sprintf(description,
-            "The model to use for the network. Possible values: ");
-    p = description;
-    while (*(++p) != '\0');
+    p = description +
+      sprintf(description,
+              "The model to use for the network. Possible values: ");
     for (i = 0; surf_network_model_description[i].name; i++)
       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
                    surf_network_model_description[i].name);
@@ -484,10 +514,9 @@ void sg_config_init(int *argc, char **argv)
                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__network_model, NULL);
     xbt_cfg_setdefault_string(_sg_cfg_set, "network/model", "LV08");
 
-    sprintf(description,
-            "The optimization modes to use for the network. Possible values: ");
-    p = description;
-    while (*(++p) != '\0');
+    p = description +
+      sprintf(description,
+              "The optimization modes to use for the network. Possible values: ");
     for (i = 0; surf_optimization_mode_description[i].name; i++)
       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
                    surf_optimization_mode_description[i].name);
@@ -497,10 +526,9 @@ void sg_config_init(int *argc, char **argv)
                      xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__optimization_mode, NULL);
     xbt_cfg_setdefault_string(_sg_cfg_set, "network/optim", "Lazy");
 
-    sprintf(description,
-            "The model to use for the workstation. Possible values: ");
-    p = description;
-    while (*(++p) != '\0');
+    p = description +
+      sprintf(description,
+              "The model to use for the workstation. Possible values: ");
     for (i = 0; surf_workstation_model_description[i].name; i++)
       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
                    surf_workstation_model_description[i].name);
@@ -619,18 +647,19 @@ void sg_config_init(int *argc, char **argv)
     xbt_cfg_setdefault_boolean(_sg_cfg_set, "verbose-exit", "yes");
 
     /* context factory */
-    sprintf(description,
-            "Context factory to use in SIMIX. Possible values: thread");
+    p = description +
+      sprintf(description,
+              "Context factory to use in SIMIX. Possible values: thread");
     const char *dflt_ctx_fact = "thread";
 #ifdef CONTEXT_UCONTEXT
     dflt_ctx_fact = "ucontext";
-    strcat(strcat(description, ", "), dflt_ctx_fact);
+    p += sprintf(p, ", %s", dflt_ctx_fact);
 #endif
 #ifdef HAVE_RAWCTX
     dflt_ctx_fact = "raw";
-    strcat(strcat(description, ", "), dflt_ctx_fact);
+    p += sprintf(p, ", %s", dflt_ctx_fact);
 #endif
-    strcat(description, ".");
+    sprintf(p, ".");
     xbt_cfg_register(&_sg_cfg_set, "contexts/factory", description,
                      xbt_cfgelm_string, 1, 1, _sg_cfg_cb_context_factory, NULL);
     xbt_cfg_setdefault_string(_sg_cfg_set, "contexts/factory", dflt_ctx_fact);
@@ -915,32 +944,37 @@ void surf_config_models_setup()
 
 }
 
+int sg_cfg_is_default_value(const char *name)
+{
+  return xbt_cfg_is_default_value(_sg_cfg_set, name);
+}
+
 int sg_cfg_get_int(const char* name)
 {
-  return xbt_cfg_get_int(_sg_cfg_set,name);
+  return xbt_cfg_get_int(_sg_cfg_set, name);
 }
 
 double sg_cfg_get_double(const char* name)
 {
-  return xbt_cfg_get_double(_sg_cfg_set,name);
+  return xbt_cfg_get_double(_sg_cfg_set, name);
 }
 
 char* sg_cfg_get_string(const char* name)
 {
-  return xbt_cfg_get_string(_sg_cfg_set,name);
+  return xbt_cfg_get_string(_sg_cfg_set, name);
 }
 
 int sg_cfg_get_boolean(const char* name)
 {
-  return xbt_cfg_get_boolean(_sg_cfg_set,name);
+  return xbt_cfg_get_boolean(_sg_cfg_set, name);
 }
 
 void sg_cfg_get_peer(const char *name, char **peer, int *port)
 {
-  xbt_cfg_get_peer(_sg_cfg_set,name, peer, port);
+  xbt_cfg_get_peer(_sg_cfg_set, name, peer, port);
 }
 
 xbt_dynar_t sg_cfg_get_dynar(const char* name)
 {
-  return xbt_cfg_get_dynar(_sg_cfg_set,name);
+  return xbt_cfg_get_dynar(_sg_cfg_set, name);
 }