summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-09-24 18:59:55 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-09-24 18:59:55 +0200
commit50e27cf3d83a17efe7d6ee7515d00716593a2a51 (patch)
treec9368533dbc81910c9e6215d7d5841c580fcdad1
parent734931d84fd54f65fd8b2658829191ce101b10bb (diff)
downloadponymap-50e27cf3d83a17efe7d6ee7515d00716593a2a51.tar.gz
ponymap-50e27cf3d83a17efe7d6ee7515d00716593a2a51.tar.xz
ponymap-50e27cf3d83a17efe7d6ee7515d00716593a2a51.zip
Order the results by port
-rw-r--r--ponymap.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/ponymap.c b/ponymap.c
index 303654a..5fc486a 100644
--- a/ponymap.c
+++ b/ponymap.c
@@ -1405,12 +1405,14 @@ target_dump_terminal (struct target *self, struct target_dump_data *data)
}
static int
-unit_cmp_by_group (const void *ax, const void *bx)
+unit_cmp_by_order (const void *ax, const void *bx)
{
const struct unit **ay = (void *) ax, **by = (void *) bx;
const struct unit *a = *ay, *b = *by;
int x = strcmp (a->service->name, b->service->name);
- return x ? x : strcmp (a->transport->name, b->transport->name);
+ if (!x) x = strcmp (a->transport->name, b->transport->name);
+ if (!x) x = (int) a->port - (int) b->port;
+ return x;
}
static void
@@ -1431,7 +1433,7 @@ target_dump_results (struct target *self)
sorted[--len] = iter;
// Sort them by service name so that they can be grouped
- qsort (sorted, N_ELEMENTS (sorted), sizeof *sorted, unit_cmp_by_group);
+ qsort (sorted, N_ELEMENTS (sorted), sizeof *sorted, unit_cmp_by_order);
if (ctx->json_results)
target_dump_json (self, &data);