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 c57b33c..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
@@ -457,24 +457,18 @@ 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 */
 
-       /* Plugins configuration */
-
-       sprintf(description,
-               "The plugins. Possible values: ");
-             p = description;
-       while (*(++p) != '\0');
-       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);
-
-    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);
@@ -484,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);
@@ -494,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);
@@ -507,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);
@@ -520,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);
@@ -533,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);
@@ -655,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);
@@ -951,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);
 }