diff options
Diffstat (limited to 'libqpdf/FileInputSource.cc')
-rw-r--r-- | libqpdf/FileInputSource.cc | 70 |
1 files changed, 29 insertions, 41 deletions
diff --git a/libqpdf/FileInputSource.cc b/libqpdf/FileInputSource.cc index b64df811..26ce20e6 100644 --- a/libqpdf/FileInputSource.cc +++ b/libqpdf/FileInputSource.cc @@ -1,9 +1,9 @@ #include <qpdf/FileInputSource.hh> -#include <string.h> -#include <qpdf/QUtil.hh> #include <qpdf/QPDFExc.hh> +#include <qpdf/QUtil.hh> #include <algorithm> +#include <string.h> FileInputSource::Members::Members(bool close_file) : close_file(close_file), @@ -13,8 +13,7 @@ FileInputSource::Members::Members(bool close_file) : FileInputSource::Members::~Members() { - if (this->file && this->close_file) - { + if (this->file && this->close_file) { fclose(this->file); } } @@ -33,8 +32,7 @@ FileInputSource::setFilename(char const* filename) } void -FileInputSource::setFile( - char const* description, FILE* filep, bool close_file) +FileInputSource::setFile(char const* description, FILE* filep, bool close_file) { this->m = PointerHolder<Members>(new Members(close_file)); this->m->filename = description; @@ -52,35 +50,26 @@ FileInputSource::findAndSkipNextEOL() qpdf_offset_t result = 0; bool done = false; char buf[10240]; - while (! done) - { + while (!done) { qpdf_offset_t cur_offset = QUtil::tell(this->m->file); size_t len = this->read(buf, sizeof(buf)); - if (len == 0) - { + if (len == 0) { done = true; result = this->tell(); - } - else - { + } else { char* p1 = static_cast<char*>(memchr(buf, '\r', len)); char* p2 = static_cast<char*>(memchr(buf, '\n', len)); char* p = (p1 && p2) ? std::min(p1, p2) : p1 ? p1 : p2; - if (p) - { + if (p) { result = cur_offset + (p - buf); // We found \r or \n. Keep reading until we get past // \r and \n characters. this->seek(result + 1, SEEK_SET); char ch; - while (! done) - { - if (this->read(&ch, 1) == 0) - { + while (!done) { + if (this->read(&ch, 1) == 0) { done = true; - } - else if (! ((ch == '\r') || (ch == '\n'))) - { + } else if (!((ch == '\r') || (ch == '\n'))) { this->unreadCh(ch); done = true; } @@ -106,11 +95,11 @@ FileInputSource::tell() void FileInputSource::seek(qpdf_offset_t offset, int whence) { - QUtil::os_wrapper(std::string("seek to ") + - this->m->filename + ", offset " + - QUtil::int_to_string(offset) + " (" + - QUtil::int_to_string(whence) + ")", - QUtil::seek(this->m->file, offset, whence)); + QUtil::os_wrapper( + std::string("seek to ") + this->m->filename + ", offset " + + QUtil::int_to_string(offset) + " (" + QUtil::int_to_string(whence) + + ")", + QUtil::seek(this->m->file, offset, whence)); } void @@ -124,18 +113,16 @@ FileInputSource::read(char* buffer, size_t length) { this->last_offset = this->tell(); size_t len = fread(buffer, 1, length, this->m->file); - if (len == 0) - { - if (ferror(this->m->file)) - { - throw QPDFExc(qpdf_e_system, - this->m->filename, "", - this->last_offset, - std::string("read ") + - QUtil::uint_to_string(length) + " bytes"); - } - else if (length > 0) - { + if (len == 0) { + if (ferror(this->m->file)) { + throw QPDFExc( + qpdf_e_system, + this->m->filename, + "", + this->last_offset, + std::string("read ") + QUtil::uint_to_string(length) + + " bytes"); + } else if (length > 0) { this->seek(0, SEEK_END); this->last_offset = this->tell(); } @@ -146,6 +133,7 @@ FileInputSource::read(char* buffer, size_t length) void FileInputSource::unreadCh(char ch) { - QUtil::os_wrapper(this->m->filename + ": unread character", - ungetc(static_cast<unsigned char>(ch), this->m->file)); + QUtil::os_wrapper( + this->m->filename + ": unread character", + ungetc(static_cast<unsigned char>(ch), this->m->file)); } |