Commit e4905983d2751b4b0f7ae535cdffee2be7fbf36f
1 parent
e5edfc78
QPDFJob: convert outfilename to shared pointer
Showing
3 changed files
with
21 additions
and
20 deletions
include/qpdf/QPDFJob.hh
libqpdf/QPDFJob.cc
| ... | ... | @@ -414,7 +414,6 @@ QPDFJob::QPDFJob() : |
| 414 | 414 | replace_input(false), |
| 415 | 415 | check_is_encrypted(false), |
| 416 | 416 | check_requires_password(false), |
| 417 | - outfilename(0), | |
| 418 | 417 | m(new Members()) |
| 419 | 418 | { |
| 420 | 419 | } |
| ... | ... | @@ -3257,7 +3256,8 @@ QPDFJob::setWriterOptions(QPDF& pdf, QPDFWriter& w) |
| 3257 | 3256 | { |
| 3258 | 3257 | w.registerProgressReporter( |
| 3259 | 3258 | new ProgressReporter( |
| 3260 | - *(this->m->cout), this->m->message_prefix, o.outfilename)); | |
| 3259 | + *(this->m->cout), this->m->message_prefix, | |
| 3260 | + o.outfilename.get())); | |
| 3261 | 3261 | } |
| 3262 | 3262 | } |
| 3263 | 3263 | |
| ... | ... | @@ -3268,27 +3268,27 @@ QPDFJob::doSplitPages(QPDF& pdf, bool& warnings) |
| 3268 | 3268 | // Generate output file pattern |
| 3269 | 3269 | std::string before; |
| 3270 | 3270 | std::string after; |
| 3271 | - size_t len = strlen(o.outfilename); | |
| 3272 | - char* num_spot = strstr(const_cast<char*>(o.outfilename), "%d"); | |
| 3271 | + size_t len = strlen(o.outfilename.get()); | |
| 3272 | + char* num_spot = strstr(const_cast<char*>(o.outfilename.get()), "%d"); | |
| 3273 | 3273 | if (num_spot != 0) |
| 3274 | 3274 | { |
| 3275 | 3275 | QTC::TC("qpdf", "qpdf split-pages %d"); |
| 3276 | - before = std::string(o.outfilename, | |
| 3277 | - QIntC::to_size(num_spot - o.outfilename)); | |
| 3276 | + before = std::string(o.outfilename.get(), | |
| 3277 | + QIntC::to_size(num_spot - o.outfilename.get())); | |
| 3278 | 3278 | after = num_spot + 2; |
| 3279 | 3279 | } |
| 3280 | 3280 | else if ((len >= 4) && |
| 3281 | 3281 | (QUtil::str_compare_nocase( |
| 3282 | - o.outfilename + len - 4, ".pdf") == 0)) | |
| 3282 | + o.outfilename.get() + len - 4, ".pdf") == 0)) | |
| 3283 | 3283 | { |
| 3284 | 3284 | QTC::TC("qpdf", "qpdf split-pages .pdf"); |
| 3285 | - before = std::string(o.outfilename, len - 4) + "-"; | |
| 3286 | - after = o.outfilename + len - 4; | |
| 3285 | + before = std::string(o.outfilename.get(), len - 4) + "-"; | |
| 3286 | + after = o.outfilename.get() + len - 4; | |
| 3287 | 3287 | } |
| 3288 | 3288 | else |
| 3289 | 3289 | { |
| 3290 | 3290 | QTC::TC("qpdf", "qpdf split-pages other"); |
| 3291 | - before = std::string(o.outfilename) + "-"; | |
| 3291 | + before = std::string(o.outfilename.get()) + "-"; | |
| 3292 | 3292 | } |
| 3293 | 3293 | |
| 3294 | 3294 | if (shouldRemoveUnreferencedResources(pdf)) |
| ... | ... | @@ -3385,24 +3385,25 @@ void |
| 3385 | 3385 | QPDFJob::writeOutfile(QPDF& pdf) |
| 3386 | 3386 | { |
| 3387 | 3387 | QPDFJob& o = *this; // QXXXQ |
| 3388 | - std::string temp_out; | |
| 3388 | + std::shared_ptr<char> temp_out; | |
| 3389 | 3389 | if (o.replace_input) |
| 3390 | 3390 | { |
| 3391 | 3391 | // Append but don't prepend to the path to generate a |
| 3392 | 3392 | // temporary name. This saves us from having to split the path |
| 3393 | 3393 | // by directory and non-directory. |
| 3394 | - temp_out = std::string(o.infilename.get()) + ".~qpdf-temp#"; | |
| 3394 | + temp_out = QUtil::make_shared_cstr( | |
| 3395 | + std::string(o.infilename.get()) + ".~qpdf-temp#"); | |
| 3395 | 3396 | // o.outfilename will be restored to 0 before temp_out |
| 3396 | 3397 | // goes out of scope. |
| 3397 | - o.outfilename = temp_out.c_str(); | |
| 3398 | + o.outfilename = temp_out; | |
| 3398 | 3399 | } |
| 3399 | - else if (strcmp(o.outfilename, "-") == 0) | |
| 3400 | + else if (strcmp(o.outfilename.get(), "-") == 0) | |
| 3400 | 3401 | { |
| 3401 | 3402 | o.outfilename = 0; |
| 3402 | 3403 | } |
| 3403 | 3404 | { |
| 3404 | 3405 | // Private scope so QPDFWriter will close the output file |
| 3405 | - QPDFWriter w(pdf, o.outfilename); | |
| 3406 | + QPDFWriter w(pdf, o.outfilename.get()); | |
| 3406 | 3407 | setWriterOptions(pdf, w); |
| 3407 | 3408 | w.write(); |
| 3408 | 3409 | } |
| ... | ... | @@ -3427,7 +3428,7 @@ QPDFJob::writeOutfile(QPDF& pdf) |
| 3427 | 3428 | backup.append(1, '#'); |
| 3428 | 3429 | } |
| 3429 | 3430 | QUtil::rename_file(o.infilename.get(), backup.c_str()); |
| 3430 | - QUtil::rename_file(temp_out.c_str(), o.infilename.get()); | |
| 3431 | + QUtil::rename_file(temp_out.get(), o.infilename.get()); | |
| 3431 | 3432 | if (warnings) |
| 3432 | 3433 | { |
| 3433 | 3434 | *(this->m->cerr) | ... | ... |
libqpdf/QPDFJob_argv.cc
| ... | ... | @@ -72,7 +72,7 @@ ArgParser::argPositional(char* arg) |
| 72 | 72 | } |
| 73 | 73 | else if (o.outfilename == 0) |
| 74 | 74 | { |
| 75 | - o.outfilename = arg; | |
| 75 | + o.outfilename = QUtil::make_shared_cstr(arg); | |
| 76 | 76 | } |
| 77 | 77 | else |
| 78 | 78 | { |
| ... | ... | @@ -1494,7 +1494,7 @@ ArgParser::doFinalChecks() |
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 1496 | 1496 | if (o.require_outfile && o.outfilename && |
| 1497 | - (strcmp(o.outfilename, "-") == 0)) | |
| 1497 | + (strcmp(o.outfilename.get(), "-") == 0)) | |
| 1498 | 1498 | { |
| 1499 | 1499 | if (o.split_pages) |
| 1500 | 1500 | { |
| ... | ... | @@ -1514,7 +1514,7 @@ ArgParser::doFinalChecks() |
| 1514 | 1514 | } |
| 1515 | 1515 | |
| 1516 | 1516 | if ((! o.split_pages) && |
| 1517 | - QUtil::same_file(o.infilename.get(), o.outfilename)) | |
| 1517 | + QUtil::same_file(o.infilename.get(), o.outfilename.get())) | |
| 1518 | 1518 | { |
| 1519 | 1519 | QTC::TC("qpdf", "qpdf same file error"); |
| 1520 | 1520 | usage("input file and output file are the same;" | ... | ... |