From 0e0b580a6b5a3ced4d9291d3360b46888750ef0c Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sat, 13 Sep 2003 20:19:21 +0000 Subject: [PATCH] Better sorting for the report. --- report.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/report.c b/report.c index 72b0591..1bbfad7 100644 --- a/report.c +++ b/report.c @@ -273,12 +273,25 @@ static int sortmatch(const void *a, const void *b) { struct sorthash_t *s = ((struct match_t *)a)->matches; struct sorthash_t *t = ((struct match_t *)b)->matches; + int i; - int cmp = strcmp(s->file->name, t->file->name); - if (cmp) - return(cmp); - else - return(s->hash.start - t->hash.start); + /* first sort by file */ + for (i = 0; i < ((struct match_t *)a)->nmatches; i++) + { + int cmp = strcmp(s[i].file->name, t[i].file->name); + + if (cmp) + return(cmp); + } + + /* then sort by start line number */ + for (i = 0; i < ((struct match_t *)a)->nmatches; i++) + { + int cmp = s->hash.start - t->hash.start; + + if (cmp) + return(cmp); + } return(0); } -- 2.43.0