summaryrefslogtreecommitdiffstats
path: root/src/dotrunner.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotrunner.cpp')
-rw-r--r--src/dotrunner.cpp112
1 files changed, 51 insertions, 61 deletions
diff --git a/src/dotrunner.cpp b/src/dotrunner.cpp
index a1bbc52..f9f077d 100644
--- a/src/dotrunner.cpp
+++ b/src/dotrunner.cpp
@@ -16,14 +16,12 @@
#include <cassert>
#include "dotrunner.h"
-
-#include "qstring.h"
#include "util.h"
#include "portable.h"
#include "dot.h"
#include "message.h"
-#include "ftextstream.h"
#include "config.h"
+#include "dir.h"
// the graphicx LaTeX has a limitation of maximum size of 16384
// To be on the save side we take it a little bit smaller i.e. 150 inch * 72 dpi
@@ -35,7 +33,7 @@
// since dot silently reproduces the input file when it does not
// support the PNG format, we need to check the result.
-static void checkPngResult(const char *imgName)
+static void checkPngResult(const QCString &imgName)
{
FILE *f = Portable::fopen(imgName,"rb");
if (f)
@@ -48,73 +46,65 @@ static void checkPngResult(const char *imgName)
err("Image '%s' produced by dot is not a valid PNG!\n"
"You should either select a different format "
"(DOT_IMAGE_FORMAT in the config file) or install a more "
- "recent version of graphviz (1.7+)\n",imgName
+ "recent version of graphviz (1.7+)\n",qPrint(imgName)
);
}
}
else
{
- err("Could not read image '%s' generated by dot!\n",imgName);
+ err("Could not read image '%s' generated by dot!\n",qPrint(imgName));
}
fclose(f);
}
else
{
- err("Could not open image '%s' generated by dot!\n",imgName);
+ err("Could not open image '%s' generated by dot!\n",qPrint(imgName));
}
}
-static bool resetPDFSize(const int width,const int height, const char *base)
+static bool resetPDFSize(const int width,const int height, const QCString &base)
{
- QCString tmpName = QCString(base)+".tmp";
- QCString patchFile = QCString(base)+".dot";
- if (!QDir::current().rename(patchFile,tmpName))
+ std::string tmpName = base.str()+".tmp";
+ std::string patchFile = base.str()+".dot";
+ Dir thisDir;
+ if (!thisDir.rename(patchFile,tmpName))
{
- err("Failed to rename file %s to %s!\n",patchFile.data(),tmpName.data());
+ err("Failed to rename file %s to %s!\n",qPrint(patchFile),qPrint(tmpName));
return FALSE;
}
- QFile fi(tmpName);
- QFile fo(patchFile);
- if (!fi.open(IO_ReadOnly))
+ std::ifstream fi(tmpName,std::ifstream::in);
+ std::ofstream t(patchFile,std::ofstream::out | std::ofstream::binary);
+ if (!fi.is_open())
{
- err("problem opening file %s for patching!\n",tmpName.data());
- QDir::current().rename(tmpName,patchFile);
+ err("problem opening file %s for patching!\n",qPrint(tmpName));
+ thisDir.rename(tmpName,patchFile);
return FALSE;
}
- if (!fo.open(IO_WriteOnly))
+ if (!t.is_open())
{
- err("problem opening file %s for patching!\n",patchFile.data());
- QDir::current().rename(tmpName,patchFile);
- fi.close();
+ err("problem opening file %s for patching!\n",qPrint(patchFile));
+ thisDir.rename(tmpName,patchFile);
return FALSE;
}
- FTextStream t(&fo);
- const int maxLineLen=100*1024;
- while (!fi.atEnd()) // foreach line
+ std::string line;
+ while (getline(fi,line)) // foreach line
{
- QCString line(maxLineLen);
- int numBytes = fi.readLine(line.rawData(),maxLineLen);
- if (numBytes<=0)
- {
- break;
- }
- line.resize(numBytes+1);
- if (line.find("LATEX_PDF_SIZE") != -1)
+ if (line.find("LATEX_PDF_SIZE") != std::string::npos)
{
double scale = (width > height ? width : height)/double(MAX_LATEX_GRAPH_INCH);
- t << " size=\""<<width/scale << "," <<height/scale <<"\";\n";
+ t << " size=\""<<width/scale << "," <<height/scale << "\";\n";
}
else
- t << line;
+ t << line << "\n";
}
fi.close();
- fo.close();
+ t.close();
// remove temporary file
- QDir::current().remove(tmpName);
+ thisDir.remove(tmpName);
return TRUE;
}
-bool DotRunner::readBoundingBox(const char *fileName,int *width,int *height,bool isEps)
+bool DotRunner::readBoundingBox(const QCString &fileName,int *width,int *height,bool isEps)
{
const char *bb = isEps ? "%%PageBoundingBox:" : "/MediaBox [";
int bblen = (int)strlen(bb);
@@ -141,23 +131,23 @@ bool DotRunner::readBoundingBox(const char *fileName,int *width,int *height,bool
return TRUE;
}
}
- err("Failed to extract bounding box from generated diagram file %s\n",fileName);
+ err("Failed to extract bounding box from generated diagram file %s\n",qPrint(fileName));
fclose(f);
return FALSE;
}
//---------------------------------------------------------------------------------
-DotRunner::DotRunner(const std::string& absDotName, const std::string& md5Hash)
- : m_file(absDotName.data())
- , m_md5Hash(md5Hash.data())
+DotRunner::DotRunner(const QCString& absDotName, const QCString& md5Hash)
+ : m_file(absDotName)
+ , m_md5Hash(md5Hash)
, m_dotExe(Config_getString(DOT_PATH)+"dot")
, m_cleanUp(Config_getBool(DOT_CLEANUP))
{
}
-void DotRunner::addJob(const char *format, const char *output)
+void DotRunner::addJob(const QCString &format, const QCString &output)
{
for (auto& s: m_jobs)
@@ -167,8 +157,8 @@ void DotRunner::addJob(const char *format, const char *output)
// we have this job already
return;
}
- auto args = std::string ("-T") + format + " -o \"" + output + "\"";
- m_jobs.emplace_back(format, output, args);
+ auto args = QCString("-T") + format + " -o \"" + output + "\"";
+ m_jobs.emplace_back(format.str(), output, args);
}
QCString getBaseNameOfOutput(const QCString &output)
@@ -187,20 +177,20 @@ bool DotRunner::run()
// create output
if (Config_getBool(DOT_MULTI_TARGETS))
{
- dotArgs=QCString("\"")+m_file.data()+"\"";
+ dotArgs=QCString("\"")+m_file+"\"";
for (auto& s: m_jobs)
{
dotArgs+=' ';
- dotArgs+=s.args.data();
+ dotArgs+=s.args;
}
- if ((exitCode=Portable::system(m_dotExe.data(),dotArgs,FALSE))!=0) goto error;
+ if ((exitCode=Portable::system(m_dotExe,dotArgs,FALSE))!=0) goto error;
}
else
{
for (auto& s : m_jobs)
{
- dotArgs=QCString("\"")+m_file.data()+"\" "+s.args.data();
- if ((exitCode=Portable::system(m_dotExe.data(),dotArgs,FALSE))!=0) goto error;
+ dotArgs=QCString("\"")+m_file+"\" "+s.args;
+ if ((exitCode=Portable::system(m_dotExe,dotArgs,FALSE))!=0) goto error;
}
}
@@ -208,35 +198,35 @@ bool DotRunner::run()
// As there should be only one pdf file be generated, we don't need code for regenerating multiple pdf files in one call
for (auto& s : m_jobs)
{
- if (s.format.compare(0, 3, "pdf") == 0)
+ if (s.format.left(3)=="pdf")
{
int width=0,height=0;
- if (!readBoundingBox(s.output.data(),&width,&height,FALSE)) goto error;
+ if (!readBoundingBox(s.output,&width,&height,FALSE)) goto error;
if ((width > MAX_LATEX_GRAPH_SIZE) || (height > MAX_LATEX_GRAPH_SIZE))
{
- if (!resetPDFSize(width,height,getBaseNameOfOutput(s.output.data()))) goto error;
- dotArgs=QCString("\"")+m_file.data()+"\" "+s.args.data();
- if ((exitCode=Portable::system(m_dotExe.data(),dotArgs,FALSE))!=0) goto error;
+ if (!resetPDFSize(width,height,getBaseNameOfOutput(s.output))) goto error;
+ dotArgs=QCString("\"")+m_file+"\" "+s.args;
+ if ((exitCode=Portable::system(m_dotExe,dotArgs,FALSE))!=0) goto error;
}
}
- if (s.format.compare(0, 3, "png") == 0)
+ if (s.format.left(3)=="png")
{
- checkPngResult(s.output.data());
+ checkPngResult(s.output);
}
}
// remove .dot files
if (m_cleanUp)
{
- //printf("removing dot file %s\n",m_file.data());
- Portable::unlink(m_file.data());
+ //printf("removing dot file %s\n",qPrint(m_file));
+ Portable::unlink(m_file);
}
// create checksum file
- if (!m_md5Hash.empty())
+ if (!m_md5Hash.isEmpty())
{
- QCString md5Name = getBaseNameOfOutput(m_file.data()) + ".md5";
+ QCString md5Name = getBaseNameOfOutput(m_file) + ".md5";
FILE *f = Portable::fopen(md5Name,"w");
if (f)
{
@@ -247,7 +237,7 @@ bool DotRunner::run()
return TRUE;
error:
err("Problems running dot: exit code=%d, command='%s', arguments='%s'\n",
- exitCode,m_dotExe.data(),dotArgs.data());
+ exitCode,qPrint(m_dotExe),qPrint(dotArgs));
return FALSE;
}