X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=finddup.git;a=blobdiff_plain;f=finddup.c;h=150279166903355e63d76c9f95a4e2a115aedb66;hp=20673723dbec75ae20ede7ad3240fcbe015938e2;hb=5d880a48149f85f6d5ac7942a696248eac0b8acc;hpb=e41b7a6614371af4f9ac5e988a6b468d1d1a0e60 diff --git a/finddup.c b/finddup.c index 2067372..1502791 100644 --- a/finddup.c +++ b/finddup.c @@ -112,7 +112,7 @@ struct file_with_size { size_t size; ino_t inode; struct file_with_size *next; - int group_id; + int group_id, dir_id; }; void file_list_delete(struct file_with_size *head) { @@ -237,6 +237,7 @@ struct file_with_size *scan_directory(struct file_with_size *tail, tmp->size = sb.st_size; tmp->inode = sb.st_ino; tmp->group_id = -1; + tmp->dir_id = -1; tail = tmp; } } @@ -276,7 +277,13 @@ int compare_nodes(const void *x1, const void *x2) { } else if((*f1)->group_id > (*f2)->group_id) { return 1; } else { - return 0; + if((*f1)->dir_id < (*f2)->dir_id) { + return -1; + } else if((*f1)->dir_id > (*f2)->dir_id) { + return 1; + } else { + return 0; + } } } @@ -317,6 +324,9 @@ void print_result(struct file_with_size *list1, struct file_with_size *list2) { qsort(nodes, nb, sizeof(struct file_with_size *), compare_nodes); for(n = 0; n < nb; n++) { + if(!show_groups && n > 0 && nodes[n]->group_id != nodes[n-1]->group_id) { + printf("\n"); + } print_file(nodes[n]); } @@ -406,11 +416,13 @@ void start(const char *dirname1, const char *dirname2) { node1->group_id = node2->group_id; } else { node1->group_id = k; + node1->dir_id = 1; k++; } } if(node2->group_id < 0) { node2->group_id = node1->group_id; + node2->dir_id = 2; } } } @@ -456,7 +468,7 @@ int main(int argc, char **argv) { setlocale (LC_ALL, ""); while (1) { - c = getopt(argc, argv, "hrcgd0p"); + c = getopt(argc, argv, "hircgd0p"); if (c == -1) break;