+ struct file_with_size *node1, *node2;
+ struct stat sb1, sb2;
+ int not_in, found, same_dir;
+ int k, p, pp, l1, n;
+
+ if(strncmp(dirname2, "not:", 4) == 0) {
+ not_in = 1;
+ dirname2 += 4;
+ } else {
+ not_in = 0;
+ }
+
+ if(lstat(dirname1, &sb1) != 0) {
+ fprintf(stderr, "Can not stat \"%s\": %s\n", dirname1, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ if(lstat(dirname2, &sb2) != 0) {
+ fprintf(stderr, "Can not stat \"%s\": %s\n", dirname2, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ same_dir = (sb1.st_ino == sb2.st_ino);
+
+ if(show_progress) {
+ fprintf(stderr, "Scanning %s ... ", dirname1);
+ }
+
+ list1 = scan_directory(0, dirname1);
+
+ if(same_dir) {
+ list2 = list1;
+ } else {
+ if(show_progress) {
+ fprintf(stderr, "%s ... ", dirname2);
+ }
+ list2 = scan_directory(0, dirname2);
+ }
+
+ if(show_progress) {
+ fprintf(stderr, "done.\n");
+ }
+
+ k = 0;
+ pp = -1;
+ n = 0;
+ l1 = file_list_length(list1);
+
+ if(not_in) {
+ for(node1 = list1; node1; node1 = node1->next) {
+ if(show_progress) {
+ p = (100 * n)/l1;
+ if(p > pp) {
+ fprintf(stderr, "%d%%\n", p);
+ pp = p;
+ }
+ n++;
+ }
+
+ found = 0;
+
+ for(node2 = list2; !found && node2; node2 = node2->next) {
+ if(node1->inode != node2->inode && same_files(node1, node2)) {
+ found = 1;
+ }
+ }
+
+ if(!found) {
+ if(show_realpaths) {
+ printf("%s\n", realpath(node1->filename, 0));
+ } else {
+ printf("%s\n", node1->filename);
+ }
+ }
+ }
+
+ } else {
+ for(node1 = list1; node1; node1 = node1->next) {
+ if(show_progress) {
+ p = (100 * n)/l1;
+ if(p > pp) {
+ fprintf(stderr, "%d%%\n", p);
+ pp = p;
+ }
+ n++;
+ }
+
+ for(node2 = list2; node2; node2 = node2->next) {
+ if(node1->inode != node2->inode && same_files(node1, node2)) {
+ if(node1->group_id < 0) {
+ if(node2->group_id >= 0) {
+ node1->group_id = node2->group_id;
+ } else {
+ node1->group_id = k;
+ k++;
+ }
+ }
+ if(node2->group_id < 0) {
+ node2->group_id = node1->group_id;
+ }
+ }
+ }
+ }
+ }
+
+ print_result(list1, list2);
+
+ file_list_delete(list1);
+ if(!same_dir) {
+ file_list_delete(list2);
+ }
+}
+
+void print_help(FILE *out) {
+ fprintf(out, "Usage: finddup [OPTION]... DIR1 [[not:]DIR2]\n");
+ fprintf(out, "Version %s (%s)\n", VERSION_NUMBER, UNAME);
+ fprintf(out, "Without DIR2, lists duplicated files found in DIR1. With DIR2, lists files common to both directories. With the not: prefix, lists files found in DIR1 which do not exist in DIR2.\n");
+ fprintf(out, "\n");
+ fprintf(out, " -h show this help\n");
+ fprintf(out, " -d ignore dot files and directories\n");
+ fprintf(out, " -c do not show which files in DIR2 corresponds to those in DIR1\n");
+ fprintf(out, " -g do not show the file groups\n");
+ fprintf(out, " -p show progress\n");
+ fprintf(out, " -r show the real file paths\n");
+ fprintf(out, "\n");
+ fprintf(out, "Report bugs and comments to <francois@fleuret.org>\n");