diff --git a/ChangeLog b/ChangeLog index 710ac4da..1426a50f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2018-12-23 Jay Berkenbilt + * When specifying @arg on the command line, if the file "arg" does + not exist, just treat this is a normal argument. This makes it + easier to deal with files whose names start with the @ character. + Fixes #265. + * Tweak completion so it works with zsh as well using bashcompinit. diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index 3d1967d8..1a45180c 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -1408,7 +1408,24 @@ ArgParser::handleArgFileArguments() new_argv.push_back(PointerHolder(true, QUtil::copy_string(argv[0]))); for (int i = 1; i < argc; ++i) { + char* argfile = 0; if ((strlen(argv[i]) > 1) && (argv[i][0] == '@')) + { + try + { + argfile = 1 + argv[i]; + if (strcmp(argfile, "-") != 0) + { + fclose(QUtil::safe_fopen(argfile, "rb")); + } + } + catch (std::runtime_error&) + { + // The file's not there; treating as regular option + argfile = 0; + } + } + if (argfile) { readArgsFromFile(1+argv[i]); } diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index 1f5009b9..8c976f6d 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -150,7 +150,7 @@ foreach my $c (@completion_tests) show_ntests(); # ---------- $td->notify("--- Argument Parsing ---"); -$n_tests += 3; +$n_tests += 4; $td->runtest("required argument", {$td->COMMAND => "qpdf --password minimal.pdf"}, @@ -167,6 +167,11 @@ $td->runtest("required argument with choices", {$td->REGEXP => "must be given as --decode-level=\\{.*all.*\\}", $td->EXIT_STATUS => 2}, $td->NORMALIZE_NEWLINES); +copy("minimal.pdf", '@file.pdf'); +$td->runtest("\@file exists and file doesn't", + {$td->COMMAND => "qpdf --check \@file.pdf"}, + {$td->FILE => "check-at-file.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); show_ntests(); # ---------- @@ -1100,6 +1105,7 @@ $td->notify("--- Overwrite self ---"); $n_tests += 1; copy("minimal.pdf", "a.pdf"); +# Also tests @- for reading args from stdin $td->runtest("don't overwrite self", {$td->COMMAND => "(echo a.pdf; echo a.pdf) | qpdf \@-"}, {$td->REGEXP => "input file and output file are the same.*", @@ -3384,5 +3390,5 @@ sub get_md5_checksum sub cleanup { system("rm -rf *.ps *.pnm ?.pdf ?.qdf *.enc* tif1 tif2 tiff-cache"); - system("rm -rf *split-out* ???-kfo.pdf *.tmpout"); + system("rm -rf *split-out* ???-kfo.pdf *.tmpout \@file.pdf"); } diff --git a/qpdf/qtest/qpdf/check-at-file.out b/qpdf/qtest/qpdf/check-at-file.out new file mode 100644 index 00000000..9d4f1618 --- /dev/null +++ b/qpdf/qtest/qpdf/check-at-file.out @@ -0,0 +1,6 @@ +checking @file.pdf +PDF Version: 1.3 +File is not encrypted +File is not linearized +No syntax or stream encoding errors found; the file may still contain +errors that qpdf cannot detect