]> granicus.if.org Git - strace/blobdiff - count.c
tests: fix format warnings on x32
[strace] / count.c
diff --git a/count.c b/count.c
index 3adde7a3623eb0fb511000ff693aaf26319cc82e..a1cdf8235ee34d3db1ab300698f9b353e5af337e 100644 (file)
--- a/count.c
+++ b/count.c
@@ -86,22 +86,48 @@ count_cmp(const void *a, const void *b)
        return (m < n) ? 1 : (m > n) ? -1 : 0;
 }
 
+static int
+error_cmp(const void *a, const void *b)
+{
+       const unsigned int *a_int = a;
+       const unsigned int *b_int = b;
+       unsigned int m = counts[*a_int].errors;
+       unsigned int n = counts[*b_int].errors;
+
+       return (m < n) ? 1 : (m > n) ? -1 : 0;
+}
+
 static int (*sortfun)(const void *, const void *);
 
 void
 set_sortby(const char *sortby)
 {
-       if (strcmp(sortby, "time") == 0)
-               sortfun = time_cmp;
-       else if (strcmp(sortby, "calls") == 0)
-               sortfun = count_cmp;
-       else if (strcmp(sortby, "name") == 0)
-               sortfun = syscall_cmp;
-       else if (strcmp(sortby, "nothing") == 0)
-               sortfun = NULL;
-       else {
-               error_msg_and_help("invalid sortby: '%s'", sortby);
+       static const struct {
+               int (*fn)(const void *, const void *);
+               const char *name;
+       } sort_fns[] = {
+               { time_cmp,     "time" },
+               { time_cmp,     "time_total" },
+               { time_cmp,     "total_time" },
+               { count_cmp,    "calls" },
+               { count_cmp,    "count" },
+               { error_cmp,    "error" },
+               { error_cmp,    "errors" },
+               { syscall_cmp,  "name" },
+               { syscall_cmp,  "syscall" },
+               { syscall_cmp,  "syscall_name" },
+               { NULL,         "none" },
+               { NULL,         "nothing" },
+       };
+
+       for (size_t i = 0; i < ARRAY_SIZE(sort_fns); ++i) {
+               if (!strcmp(sort_fns[i].name, sortby)) {
+                       sortfun = sort_fns[i].fn;
+                       return;
+               }
        }
+
+       error_msg_and_help("invalid sortby: '%s'", sortby);
 }
 
 int