+ struct file_with_size *node1, *node2;
+ struct stat sb1, sb2;
+ int not_in, found, same_dir;
+
+ 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);
+
+ fprintf(stderr, "Scanning %s ... ", dirname1);
+ list1 = scan_directory(0, dirname1);
+ if(same_dir) {
+ list2 = list1;
+ } else {
+ fprintf(stderr, "%s ... ", dirname2);
+ list2 = scan_directory(0, dirname2);
+ }
+ fprintf(stderr, "done.\n");
+
+ if(not_in) {
+ for(node1 = list1; node1; node1 = node1->next) {
+ 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 {
+ int k = 0;
+
+ for(node1 = list1; node1; node1 = node1->next) {
+ for(node2 = list2; node2; node2 = node2->next) {
+ if(node1->inode != node2->inode && same_files(node1, node2)) {
+ if(node1->id < 0) {
+ if(node2->id >= 0) {
+ node1->id = node2->id;
+ } else {
+ node1->id = k;
+ k++;
+ }
+ print_file(node1);
+ }
+ if(node2->id < 0) {
+ node2->id = node1->id;
+ if(show_hits) {
+ print_file(node2);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ 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, " -r show the real file paths\n");
+ fprintf(out, "\n");
+ fprintf(out, "Report bugs and comments to <francois@fleuret.org>\n");