aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--include/qpdf/FileInputSource.hh4
-rw-r--r--libqpdf/ClosedFileInputSource.cc4
-rw-r--r--libqpdf/FileInputSource.cc13
-rw-r--r--libqpdf/QPDF.cc6
-rw-r--r--libqpdf/QPDFJob.cc4
-rw-r--r--libtests/closed_file_input_source.cc3
-rw-r--r--qpdf/test_tokenizer.cc3
8 files changed, 28 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 27b1d679..53e1e8d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2022-05-04 Jay Berkenbilt <ejb@ql.org>
+ * FileInputSource has new constructors that eliminate the need to
+ call setFilename or setFile in most cases.
+
* Enhance JSON by adding a write method that takes a Pipeline* and
depth, and add several helper methods to make it easier to write
large amounts of JSON incrementally without having to have the
diff --git a/include/qpdf/FileInputSource.hh b/include/qpdf/FileInputSource.hh
index 1b4f5d6a..f1e7edf4 100644
--- a/include/qpdf/FileInputSource.hh
+++ b/include/qpdf/FileInputSource.hh
@@ -30,6 +30,10 @@ class QPDF_DLL_CLASS FileInputSource: public InputSource
QPDF_DLL
FileInputSource();
QPDF_DLL
+ FileInputSource(char const* filename);
+ QPDF_DLL
+ FileInputSource(char const* description, FILE* filep, bool close_file);
+ QPDF_DLL
void setFilename(char const* filename);
QPDF_DLL
void setFile(char const* description, FILE* filep, bool close_file);
diff --git a/libqpdf/ClosedFileInputSource.cc b/libqpdf/ClosedFileInputSource.cc
index 7c4e5dbe..7d49bf70 100644
--- a/libqpdf/ClosedFileInputSource.cc
+++ b/libqpdf/ClosedFileInputSource.cc
@@ -24,8 +24,8 @@ void
ClosedFileInputSource::before()
{
if (0 == this->m->fis.get()) {
- this->m->fis = std::make_shared<FileInputSource>();
- this->m->fis->setFilename(this->m->filename.c_str());
+ this->m->fis =
+ std::make_shared<FileInputSource>(this->m->filename.c_str());
this->m->fis->seek(this->m->offset, SEEK_SET);
this->m->fis->setLastOffset(this->last_offset);
}
diff --git a/libqpdf/FileInputSource.cc b/libqpdf/FileInputSource.cc
index 9b467821..08b35056 100644
--- a/libqpdf/FileInputSource.cc
+++ b/libqpdf/FileInputSource.cc
@@ -23,6 +23,19 @@ FileInputSource::FileInputSource() :
{
}
+FileInputSource::FileInputSource(char const* filename) :
+ m(new Members(false))
+{
+ setFilename(filename);
+}
+
+FileInputSource::FileInputSource(
+ char const* description, FILE* filep, bool close_file) :
+ m(new Members(false))
+{
+ setFile(description, filep, close_file);
+}
+
void
FileInputSource::setFilename(char const* filename)
{
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index aa99942c..8b8dd59e 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -270,8 +270,7 @@ QPDF::~QPDF()
void
QPDF::processFile(char const* filename, char const* password)
{
- FileInputSource* fi = new FileInputSource();
- fi->setFilename(filename);
+ FileInputSource* fi = new FileInputSource(filename);
processInputSource(std::shared_ptr<InputSource>(fi), password);
}
@@ -279,8 +278,7 @@ void
QPDF::processFile(
char const* description, FILE* filep, bool close_file, char const* password)
{
- FileInputSource* fi = new FileInputSource();
- fi->setFile(description, filep, close_file);
+ FileInputSource* fi = new FileInputSource(description, filep, close_file);
processInputSource(std::shared_ptr<InputSource>(fi), password);
}
diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc
index ca56b8d5..63312f27 100644
--- a/libqpdf/QPDFJob.cc
+++ b/libqpdf/QPDFJob.cc
@@ -2445,9 +2445,9 @@ QPDFJob::handlePageSpecs(
cis->stayOpen(true);
} else {
QTC::TC("qpdf", "QPDFJob keep files open y");
- FileInputSource* fis = new FileInputSource();
+ FileInputSource* fis =
+ new FileInputSource(page_spec.filename.c_str());
is = std::shared_ptr<InputSource>(fis);
- fis->setFilename(page_spec.filename.c_str());
}
std::shared_ptr<QPDF> qpdf_ph =
processInputSource(is, password, true);
diff --git a/libtests/closed_file_input_source.cc b/libtests/closed_file_input_source.cc
index ff5354fb..e4c8ed36 100644
--- a/libtests/closed_file_input_source.cc
+++ b/libtests/closed_file_input_source.cc
@@ -73,8 +73,7 @@ main()
do_tests(&cf2);
cf2.stayOpen(false);
std::cout << "testing with FileInputSource\n";
- FileInputSource f;
- f.setFilename("input");
+ FileInputSource f("input");
do_tests(&f);
std::cout << "all assertions passed" << std::endl;
return 0;
diff --git a/qpdf/test_tokenizer.cc b/qpdf/test_tokenizer.cc
index f1155a28..2b18eb77 100644
--- a/qpdf/test_tokenizer.cc
+++ b/qpdf/test_tokenizer.cc
@@ -191,8 +191,7 @@ process(char const* filename, bool include_ignorable, size_t max_len)
std::shared_ptr<InputSource> is;
// Tokenize file, skipping streams
- FileInputSource* fis = new FileInputSource();
- fis->setFilename(filename);
+ FileInputSource* fis = new FileInputSource(filename);
is = std::shared_ptr<InputSource>(fis);
dump_tokens(is, "FILE", max_len, include_ignorable, true, false);