+static int
+cmp_users_by_hosts(const void *va, const void *vb)
+{
+ const struct out_user *a = va;
+ const struct out_user *b = vb;
+ return strcmp(a->host->name, b->host->name);
+}
+
+static int
+cmp_users_by_names(const void *va, const void *vb)
+{
+ const struct out_user *a = va;
+ const struct out_user *b = vb;
+ return strcmp(a->user->name, b->user->name);
+}
+
+static void
+sort_users(int by_hosts)
+{
+ qsort(user_array, num_users, sizeof(user_array[0]),
+ (by_hosts ? cmp_users_by_hosts : cmp_users_by_names));
+}
+
+static int
+cmp_hosts(const void *va, const void *vb)
+{
+ const struct out_host * const *a = va;
+ const struct out_host * const *b = vb;
+ return strcmp((*a)->name, (*b)->name);
+}
+
+static void
+sort_hosts(void)
+{
+ qsort(host_array, num_hosts, sizeof(host_array[0]), cmp_hosts);
+}
+