Browse Source

* add '-d' option

master
Alex 'AdUser' Z 8 years ago
parent
commit
f72fd9992c
  1. 19
      src/main.c

19
src/main.c

@ -47,6 +47,7 @@ usage(int exitcode) {
fprintf(stderr, fprintf(stderr,
"Usage: simdb-fdupes [path]\n" "Usage: simdb-fdupes [path]\n"
" -h This help\n" " -h This help\n"
" -d <int> Max difference in images (in percents: 0-50)\n"
" -v Verbose messages\n" " -v Verbose messages\n"
); );
exit(exitcode); exit(exitcode);
@ -143,7 +144,7 @@ make_samples(filelist_t *list, simdb_t *simdb) {
} }
static group_t * static group_t *
make_groups(filelist_t *list, simdb_t *simdb) { make_groups(filelist_t *list, simdb_t *simdb, int maxdiff) {
simdb_search_t search; simdb_search_t search;
group_t *groups = NULL, *group, **map = NULL; group_t *groups = NULL, *group, **map = NULL;
int pct = 0, inum, gnum = 1; /* next group number */ int pct = 0, inum, gnum = 1; /* next group number */
@ -157,6 +158,8 @@ make_groups(filelist_t *list, simdb_t *simdb) {
} }
simdb_search_init(&search); simdb_search_init(&search);
search.d_ratio = maxdiff / (float) 100;
search.d_bitmap = maxdiff / (float) 100;
for (int num = 1; num < list->size; num++) { for (int num = 1; num < list->size; num++) {
if (!filelist_get(flist, num)) if (!filelist_get(flist, num))
continue; /* file was not sampled */ continue; /* file was not sampled */
@ -233,17 +236,20 @@ int main(int argc, char **argv) {
group_t *groups = NULL; group_t *groups = NULL;
char tempdb[] = "/tmp/simdb-XXXXXX"; char tempdb[] = "/tmp/simdb-XXXXXX";
char path[PATH_MAX] = ""; char path[PATH_MAX] = "";
int opt = -1, ret = 0; int opt = -1, ret = 0, maxdiff = 7;
if (argc <= 1) if (argc <= 1)
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
while ((opt = getopt(argc, argv, "hv")) != -1) { while ((opt = getopt(argc, argv, "hd:v")) != -1) {
switch (opt) { switch (opt) {
case 'v': case 'v':
if (msglevel < debug) if (msglevel < debug)
msglevel++; msglevel++;
break; break;
case 'd':
maxdiff = atoi(optarg);
break;
case 'h': case 'h':
usage(EXIT_SUCCESS); usage(EXIT_SUCCESS);
break; break;
@ -259,6 +265,11 @@ int main(int argc, char **argv) {
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
} }
if (maxdiff < 0 || maxdiff > 50) {
fprintf(stderr, "! '-d' option should be in range [0, 50]\n");
return EXIT_FAILURE;
}
/* resolve root path */ /* resolve root path */
if (realpath(root, path) == NULL) { if (realpath(root, path) == NULL) {
perror("Can't resolve given path"); perror("Can't resolve given path");
@ -304,7 +315,7 @@ int main(int argc, char **argv) {
make_samples(flist, simdb); make_samples(flist, simdb);
groups = make_groups(flist, simdb); groups = make_groups(flist, simdb, maxdiff);
if (groups) { if (groups) {
log_msg(verbose, "* found image groups:\n"); log_msg(verbose, "* found image groups:\n");

Loading…
Cancel
Save