From: Eric S. Raymond Date: Sat, 13 Sep 2003 20:19:21 +0000 (+0000) Subject: Better sorting for the report. X-Git-Tag: 1.6~38 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=0e0b580a6b5a3ced4d9291d3360b46888750ef0c;p=comparator.git Better sorting for the report. --- 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); }