]> granicus.if.org Git - curl/commitdiff
curl: display --version features sorted alphabetically
authorDaniel Stenberg <daniel@haxx.se>
Mon, 25 Feb 2019 11:25:15 +0000 (12:25 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 27 Feb 2019 07:14:07 +0000 (08:14 +0100)
Closes #3611

src/tool_help.c

index aeffd3dea58f77179a68263e0edd28a0344bf4c8..414e00b212815ec44aba24fd23aea34c54250392 100644 (file)
@@ -540,6 +540,21 @@ void tool_help(void)
   }
 }
 
+static int
+featcomp(const void *p1, const void *p2)
+{
+  /* The arguments to this function are "pointers to pointers to char", but
+     the comparison arguments are "pointers to char", hence the following cast
+     plus dereference */
+#ifdef HAVE_STRCASECMP
+  return strcasecmp(* (char * const *) p1, * (char * const *) p2);
+#elif defined(HAVE_STRCMPI)
+  return strcmpi(* (char * const *) p1, * (char * const *) p2);
+#else
+  return strcmp(* (char * const *) p1, * (char * const *) p2);
+#endif
+}
+
 void tool_version_info(void)
 {
   const char *const *proto;
@@ -559,15 +574,20 @@ void tool_version_info(void)
     puts(""); /* newline */
   }
   if(curlinfo->features) {
+    char *featp[ sizeof(feats) / sizeof(feats[0]) + 1];
+    size_t numfeat = 0;
     unsigned int i;
-    printf("Features: ");
+    printf("Features:");
     for(i = 0; i < sizeof(feats)/sizeof(feats[0]); i++) {
       if(curlinfo->features & feats[i].bitmask)
-        printf("%s ", feats[i].name);
+        featp[numfeat++] = (char *)feats[i].name;
     }
 #ifdef USE_METALINK
-    printf("Metalink ");
+    featp[numfeat++] = (char *)"Metalink";
 #endif
+    qsort(&featp[0], numfeat, sizeof(char *), featcomp);
+    for(i = 0; i< numfeat; i++)
+      printf(" %s", featp[i]);
     puts(""); /* newline */
   }
 }