From: Urban Wallasch Date: Mon, 7 Jun 2021 14:29:34 +0000 (+0200) Subject: * Added '-i' option to include text in output. X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=a004d5ac183ab7647c1941c7b70d0a39b1965244;p=imgdupe.git * Added '-i' option to include text in output. * Improved error reporting for '-I' and '-m' options. --- diff --git a/README.md b/README.md index 4b5315d..079b174 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,8 @@ OPTIONS: -t n similarity threshold in bits (0..256) or percent; default: 256 -b float blur factor; add -r when changed between runs; default: 2.5 -r re-scan files already in database - -I file use file contents as lead-in for output + -i text add text as lead-in to output + -I file add file contents as lead-in to output -T n number of scan threads (default: 4) -h display this help text and exit ``` @@ -64,11 +65,13 @@ OPTIONS: * `-r` initiates a full re-scan, even for files already present in the database. - * `-I` allows to include a custom lead-in in the output, which is in + * `-i` include text as a custom lead-in in the output, which is in particular useful to replace the default dummy versions of the `VIEW()` and `END()` functions which are used by `imgdupe` to structure its output. + * `-I` same as `-i`, but add the contents of the specified file. + * `-T` allows to set the number of hashing threads to use; for optimal performance this should be equal to the number of (physical) processor cores. diff --git a/main.c b/main.c index 426a253..e2f8eaf 100644 --- a/main.c +++ b/main.c @@ -148,7 +148,8 @@ static void usage(char *pname, int ec) { " -t n similarity threshold in bits (0..256) or percent; default: 256\n" " -b float blur factor; add -r when changed between runs; default: 2.5\n" " -r re-scan files already in database\n" - " -I file use file contents as lead-in for output\n" + " -i text add text as lead-in to output\n" + " -I file add file contents as lead-in to output\n" " -T n number of scan threads (default: 4)\n" " -h display this help text and exit\n" ); @@ -167,7 +168,7 @@ int main(int argc, char *argv[]) { "END(){ echo 'Done'; }\n\n"; db = db_init(); - while ( ( c = getopt( argc, argv, "+:b:d:hI:f:m:prt:T:" ) ) != -1 ) { + while ( ( c = getopt( argc, argv, "+:b:d:hi:I:f:m:prt:T:x" ) ) != -1 ) { switch (c) { case 'b': n = atoi(optarg); @@ -180,18 +181,37 @@ int main(int argc, char *argv[]) { case 'h': usage(argv[0], EXIT_SUCCESS); break; + case 'i': + n = printf("%s\n", optarg); + dprintf("written %d bytes lead-in (-i)\n", n); + lead_in = ""; + break; case 'I': n = cat_file(optarg); - lead_in = ""; - dprintf("written %d bytes lead-in (%s)\n", n, optarg); + if ( n >= 0 ) { + lead_in = ""; + dprintf("written %d bytes lead-in (%s)\n", n, optarg); + } + else { + eprintf("ERROR: '%s': %s\n", optarg, strerror(errno)); + ++err; + } break; case 'f': cfg.db_outfile = optarg; - /* fall through */ + dprintf("loading '%s'\n", optarg); + n = db_read(db, optarg); + dprintf("read %d entries\n", n > 0 ? n : 0); + break; case 'm': dprintf("loading '%s'\n", optarg); n = db_read(db, optarg); - dprintf("loaded %d entries\n", n>0?n:0); + if ( n >= 0 ) + dprintf("read %d entries\n", n); + else { + eprintf("ERROR: '%s': %s\n", optarg, strerror(errno)); + ++err; + } break; case 'p': cfg.db_prune = 1;