Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use right test for error checking.
[simgrid.git] / src / xbt / config.c
index 64082db..2b352b1 100644 (file)
@@ -370,48 +370,37 @@ void xbt_cfg_help(xbt_cfg_t cfg)
       else
         printf("Arity: 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);
+    printf("Current value%s: ", (size <= 1 ? "" : "s"));
+
+    if (size != 1)
+      printf(size == 0 ? "n/a\n" : "{ ");
+    for (i = 0; i < size; i++) {
+      const char *sep = (size == 1 ? "\n" : (i < size - 1 ? ", " : " }\n"));
+
+      switch (variable->type) {
+      case xbt_cfgelm_int:
+        printf("%d%s", xbt_dynar_get_as(variable->content, i, int), sep);
+        break;
+
+      case xbt_cfgelm_double:
+        printf("%f%s", xbt_dynar_get_as(variable->content, i, double), sep);
+        break;
+
+      case xbt_cfgelm_string:
+        printf("'%s'%s", xbt_dynar_get_as(variable->content, i, char *), sep);
+        break;
+
+      case xbt_cfgelm_peer: {
+        xbt_peer_t hval = xbt_dynar_get_as(variable->content, i, xbt_peer_t);
+        printf("%s:%d%s", hval->name, hval->port, sep);
+        break;
       }
-      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);
+      default:
+        printf("Invalid type!!%s", sep);
       }
-      break;
-
-    default:
-      printf("Invalid type!!\n");
     }
-
   }
 
   xbt_dynar_free(&names);
@@ -695,7 +684,7 @@ void *xbt_cfg_set_as_string(xbt_cfg_t cfg, const char *key, const char *value) {
 
   case xbt_cfgelm_int:
     i = strtol(value, &ret, 0);
-    if (value == NULL) {
+    if (ret == value) {
       xbt_die("Value of option %s not valid. Should be an integer", key);
     }
 
@@ -704,7 +693,7 @@ void *xbt_cfg_set_as_string(xbt_cfg_t cfg, const char *key, const char *value) {
 
   case xbt_cfgelm_double:
     d = strtod(value, &ret);
-    if (value == NULL) {
+    if (ret == value) {
       xbt_die("Value of option %s not valid. Should be a double", key);
     }
 
@@ -721,7 +710,7 @@ void *xbt_cfg_set_as_string(xbt_cfg_t cfg, const char *key, const char *value) {
 
     *(val++) = '\0';
     i = strtol(val, &ret, 0);
-    if (val == NULL) {
+    if (ret == val) {
       xbt_die("Value of option %s not valid. Should be an peer (machine:port)", key);
     }