summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-src/src
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src')
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.cpp2
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/FileSystem.cpp4
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/FontCache.cpp6
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/FontMap.cpp2
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/GFGlyphTracer.cpp4
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.cpp2
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/MetafontWrapper.cpp8
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.cpp2
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.cpp72
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.hpp26
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/StreamReader.cpp6
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/utility.cpp4
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/version.hpp2
13 files changed, 86 insertions, 54 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.cpp
index 511b6b04c1a..d9af5936bc5 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/DVIToSVGActions.cpp
@@ -280,7 +280,7 @@ BoundingBox& DVIToSVGActions::bbox(const string& name, bool reset) {
* a rotating dash. */
void DVIToSVGActions::progress (const char *id) {
if (PROGRESSBAR_DELAY < 1000) {
- static double time=0;
+ static double time=System::time();
// slow down updating the progress indicator to prevent flickering
if (System::time() - time > 0.1) {
progress(0, 0, id);
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/FileSystem.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/FileSystem.cpp
index 4804b56f404..744de1920ff 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/FileSystem.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/FileSystem.cpp
@@ -98,8 +98,8 @@ bool FileSystem::remove (const string &fname) {
* @param[in] remove_src remove file 'src' if true
* @return true on success */
bool FileSystem::copy (const string &src, const string &dest, bool remove_src) {
- ifstream ifs(src.c_str(), ios::in|ios::binary);
- ofstream ofs(dest.c_str(), ios::out|ios::binary);
+ ifstream ifs(src, ios::in|ios::binary);
+ ofstream ofs(dest, ios::out|ios::binary);
if (ifs && ofs) {
ofs << ifs.rdbuf();
if (!ifs.fail() && !ofs.fail() && remove_src) {
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/FontCache.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/FontCache.cpp
index f14a4ca8bd0..c233408960c 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/FontCache.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/FontCache.cpp
@@ -81,7 +81,7 @@ bool FontCache::write (const string &fontname, const string &dir) const {
string dirstr = dir.empty() ? FileSystem::getcwd() : dir;
ostringstream oss;
oss << dirstr << '/' << fontname << ".fgd";
- ofstream ofs(oss.str().c_str(), ios::binary);
+ ofstream ofs(oss.str(), ios::binary);
return write(fontname, ofs);
}
return false;
@@ -177,7 +177,7 @@ bool FontCache::read (const string &fontname, const string &dir) {
string dirstr = dir.empty() ? FileSystem::getcwd() : dir;
ostringstream oss;
oss << dirstr << '/' << fontname << ".fgd";
- ifstream ifs(oss.str().c_str(), ios::binary);
+ ifstream ifs(oss.str(), ios::binary);
return read(fontname, ifs);
}
@@ -265,7 +265,7 @@ bool FontCache::fontinfo (const string &dirname, vector<FontInfo> &infos, vector
if (fname[0] == 'f' && fname.length() > 5 && fname.substr(fname.length()-4) == ".fgd") {
FontInfo info;
string path = dirname+"/"+(fname.substr(1));
- ifstream ifs(path.c_str(), ios::binary);
+ ifstream ifs(path, ios::binary);
if (fontinfo(ifs, info))
infos.emplace_back(move(info));
else
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/FontMap.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/FontMap.cpp
index b8293a14361..85bb428b7c5 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/FontMap.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/FontMap.cpp
@@ -47,7 +47,7 @@ FontMap& FontMap::instance() {
* @param[in] mode selects how to integrate the map file entries into the global map tree
* @return true if file could be opened */
bool FontMap::read (const string &fname, FontMap::Mode mode) {
- ifstream ifs(fname.c_str());
+ ifstream ifs(fname);
if (!ifs)
return false;
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/GFGlyphTracer.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/GFGlyphTracer.cpp
index 425bc6494aa..dbbcc419a14 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/GFGlyphTracer.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/GFGlyphTracer.cpp
@@ -34,7 +34,7 @@ GFGlyphTracer::GFGlyphTracer (string &fname, double upp, Callback *cb)
{
if (_callback)
_callback->setFont(fname);
- _ifs.open(fname.c_str(), ios::binary);
+ _ifs.open(fname, ios::binary);
}
@@ -44,7 +44,7 @@ void GFGlyphTracer::reset (string &fname, double upp) {
if (_ifs.is_open())
_ifs.close();
unitsPerPoint(upp);
- _ifs.open(fname.c_str(), ios::binary);
+ _ifs.open(fname, ios::binary);
}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.cpp
index 27285fbb7c2..72c134d5a4e 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/ImageToSVG.cpp
@@ -93,7 +93,7 @@ string ImageToSVG::getSVGFilename (unsigned pageno) const {
void ImageToSVG::progress (const char *id) {
- static double time=0;
+ static double time=System::time();
static bool draw=false; // show progress indicator?
static size_t count=0;
count++;
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/MetafontWrapper.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/MetafontWrapper.cpp
index 295237d1d91..6b0b1a498d4 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/MetafontWrapper.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/MetafontWrapper.cpp
@@ -106,8 +106,8 @@ bool MetafontWrapper::call (const string &mode, double mag) {
* @param[in] mag magnification factor
* @return true on success */
bool MetafontWrapper::make (const string &mode, double mag) {
- ifstream tfm((_dir+_fontname+".tfm").c_str());
- ifstream gf((_dir+_fontname+".gf").c_str());
+ ifstream tfm(_dir+_fontname+".tfm");
+ ifstream gf(_dir+_fontname+".gf");
if (gf && tfm) // @@ distinguish between gf and tfm
return true;
return call(mode, mag);
@@ -115,7 +115,7 @@ bool MetafontWrapper::make (const string &mode, double mag) {
bool MetafontWrapper::success () const {
- ifstream tfm((_dir+_fontname+".tfm").c_str());
- ifstream gf((_dir+_fontname+".gf").c_str());
+ ifstream tfm(_dir+_fontname+".tfm");
+ ifstream gf(_dir+_fontname+".gf");
return tfm && gf;
}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.cpp
index f6aa64fc144..eb09cc0b8a3 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/PsSpecialHandler.cpp
@@ -243,7 +243,7 @@ bool PsSpecialHandler::process (const string &prefix, istream &is, SpecialAction
StreamInputReader in(is);
if (in.check(" plotfile ")) { // ps: plotfile fname
string fname = in.getString();
- ifstream ifs(fname.c_str());
+ ifstream ifs(fname);
if (ifs)
_psi.execute(ifs);
else
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.cpp
index 96efb50a875..d1622fb66f5 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.cpp
@@ -50,58 +50,74 @@ static int fdclose (int fd) {return close(fd);}
#endif
-SourceInput::~SourceInput () {
- // remove temporary file created for reading from stdin
- if (!_tmpfilepath.empty())
- FileSystem::remove(_tmpfilepath);
-}
-
-
-/** Creates a temporary file in the configured tmp folder.
- * @param[out] path path of the created file
- * @return file descriptor (>= 0 on success) */
-static int create_tmp_file (string &path) {
- path = FileSystem::tmpdir();
+/** Creates a new temporary file in the configured tmp folder.
+ * If the object already holds an opened temporary file, it's closed
+ * and removed before creating the new one.
+ * @return true on success */
+bool TemporaryFile::create () {
+ if (opened())
+ close();
+ _path = FileSystem::tmpdir();
#ifndef _WIN32
- path += "stdinXXXXXX";
- int fd = mkstemp(&path[0]);
+ _path += "stdinXXXXXX";
+ _fd = mkstemp(&_path[0]);
#else
- int fd = -1;
char fname[MAX_PATH];
- std::replace(path.begin(), path.end(), '/', '\\');
- if (GetTempFileName(path.c_str(), "stdin", 0, fname)) {
- fd = _open(fname, _O_CREAT | _O_WRONLY | _O_BINARY, _S_IWRITE);
- path = fname;
+ std::replace(_path.begin(), _path.end(), '/', '\\');
+ if (GetTempFileName(_path.c_str(), "stdin", 0, fname)) {
+ _fd = _open(fname, _O_CREAT | _O_WRONLY | _O_BINARY, _S_IWRITE);
+ _path = fname;
}
#endif
- return fd;
+ return opened();
+}
+
+
+/** Writes a sequence of characters to the file.
+ * @param[in] buf buffer containing the characters to write
+ * @param[in] len number of characters to write
+ * @return true on success */
+bool TemporaryFile::write (const char *buf, size_t len) {
+ return opened() && fdwrite(_fd, buf, len) >= 0;
}
+/** Closes and removes the temporary file.
+ * @return true on success */
+bool TemporaryFile::close () {
+ bool ok = true;
+ if (opened()) {
+ ok = (fdclose(_fd) >= 0);
+ FileSystem::remove(_path);
+ _fd = -1;
+ _path.clear();
+ }
+ return ok;
+}
+
+////////////////////////////////////////////////////////////////
+
istream& SourceInput::getInputStream (bool showMessages) {
if (!_ifs.is_open()) {
if (!_fname.empty())
_ifs.open(_fname, ios::binary);
else {
- int fd = create_tmp_file(_tmpfilepath);
- if (fd < 0)
- throw MessageException("can't create temporary file for writing");
#ifdef _WIN32
if (_setmode(_fileno(stdin), _O_BINARY) == -1)
throw MessageException("can't open stdin in binary mode");
#endif
+ if (!_tmpfile.create())
+ throw MessageException("can't create temporary file for writing");
if (showMessages)
Message::mstream() << "reading from " << getMessageFileName() << '\n';
char buf[1024];
while (cin) {
cin.read(buf, 1024);
size_t count = cin.gcount();
- if (fdwrite(fd, buf, count) < 0)
+ if (!_tmpfile.write(buf, count))
throw MessageException("failed to write data to temporary file");
}
- if (fdclose(fd) < 0)
- throw MessageException("failed to close temporary file");
- _ifs.open(_tmpfilepath, ios::binary);
+ _ifs.open(_tmpfile.path(), ios::binary);
}
}
return _ifs;
@@ -119,5 +135,5 @@ string SourceInput::getMessageFileName () const {
string SourceInput::getFilePath () const {
- return _tmpfilepath.empty() ? _fname : _tmpfilepath;
+ return _tmpfile.path().empty() ? _fname : _tmpfile.path();
}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.hpp
index 95f496a60a2..be596d8b557 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/SourceInput.hpp
@@ -18,16 +18,32 @@
** along with this program; if not, see <http://www.gnu.org/licenses/>. **
*************************************************************************/
-#ifndef DVIINPUT_HPP
-#define DVIINPUT_HPP
+#ifndef SOURCEINPUT_HPP
+#define SOURCEINPUT_HPP
#include <fstream>
#include <string>
+
+/** Helper class to handle temporary files. */
+class TemporaryFile {
+ public:
+ ~TemporaryFile () {close();}
+ bool create ();
+ bool opened () const {return _fd >= 0;}
+ bool write (const char *buf, size_t len);
+ bool close ();
+ const std::string& path () const {return _path;}
+
+ private:
+ int _fd = -1; ///< file descriptor assigned to the temporary file
+ std::string _path; ///< path to temporary file
+};
+
+
class SourceInput {
public:
SourceInput (const std::string &fname) : _fname(fname) {}
- ~SourceInput ();
std::istream& getInputStream (bool showMessages=false);
std::string getFileName () const;
std::string getMessageFileName () const;
@@ -35,8 +51,8 @@ class SourceInput {
private:
const std::string &_fname; ///< name of file to read from
- std::string _tmpfilepath; ///< path of temporary file used when reading from stdin
+ TemporaryFile _tmpfile; ///< temporary file used when reading from stdin
std::ifstream _ifs;
};
-#endif \ No newline at end of file
+#endif
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/StreamReader.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/StreamReader.cpp
index 3e4fa2adcc5..61e1c2ff1b9 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/StreamReader.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/StreamReader.cpp
@@ -99,7 +99,7 @@ string StreamReader::readString () {
* @return the string read */
string StreamReader::readString (CRC32 &crc32, bool finalZero) {
string ret = readString();
- crc32.update((const uint8_t*)ret.c_str(), ret.length());
+ crc32.update(reinterpret_cast<const uint8_t*>(ret.data()), ret.length());
if (finalZero)
crc32.update(0, 1);
return ret;
@@ -114,7 +114,7 @@ string StreamReader::readString (int length) {
throw StreamReaderException("no stream assigned");
length = max(0, length);
string str(length, '\0');
- _is->read(&str[0], length); // reads 'length' bytes and appends \0
+ _is->read(&str[0], length); // read 'length' bytes and append '\0'
return str;
}
@@ -125,7 +125,7 @@ string StreamReader::readString (int length) {
* @return the string read */
string StreamReader::readString (int length, CRC32 &crc32) {
string ret = readString(length);
- crc32.update(ret.c_str());
+ crc32.update(reinterpret_cast<const uint8_t*>(ret.data()), length);
return ret;
}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/utility.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/utility.cpp
index 9517a6a1013..92fa6f3c65c 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/utility.cpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/utility.cpp
@@ -124,7 +124,7 @@ int util::ilog10 (int n) {
/** Returns the contents of a file.
* @param[in] fname name/path of the file */
string util::read_file_contents (const string &fname) {
- ifstream ifs(fname.c_str(), ios::binary);
+ ifstream ifs(fname, ios::binary);
return string(istreambuf_iterator<char>(ifs.rdbuf()), istreambuf_iterator<char>());
}
@@ -134,6 +134,6 @@ string util::read_file_contents (const string &fname) {
* @param[in] start iterator pointing to the begin of the byte sequence
* @param[in] end iterator pointing to the first byte after the byte sequence to write */
void util::write_file_contents (const string &fname, string::iterator start, string::iterator end) {
- ofstream ofs(fname.c_str(), ios::binary);
+ ofstream ofs(fname, ios::binary);
copy(start, end, ostream_iterator<char>(ofs));
}
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/version.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/version.hpp
index bbcd4cf0dbb..ef46850c80e 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/version.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/version.hpp
@@ -22,7 +22,7 @@
#define VERSION_HPP
constexpr const char *PROGRAM_NAME = "dvisvgm";
-constexpr const char *PROGRAM_VERSION = "2.4";
+constexpr const char *PROGRAM_VERSION = "2.4.1";
#endif