Doxygen
Loading...
Searching...
No Matches
dotrunner.cpp File Reference
#include "dotrunner.h"
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <gunzip.hh>
#include "config.h"
#include "dir.h"
#include "dot.h"
#include "doxygen.h"
#include "message.h"
#include "portable.h"
#include "threadpool.h"
#include "util.h"
Include dependency graph for dotrunner.cpp:

Go to the source code of this file.

Macros

#define MAX_LATEX_GRAPH_INCH   150
#define MAX_LATEX_GRAPH_SIZE   (MAX_LATEX_GRAPH_INCH * 72)
#define DBG(x)

Functions

static void checkPngResult (const DString &imgName)
static bool resetPDFSize (const int width, const int height, const DString &base)
static DString getBaseNameOfOutput (const DString &output)

Macro Definition Documentation

◆ DBG

#define DBG ( x)
Value:
do {} while(0)

Definition at line 74 of file dotrunner.cpp.

Referenced by reg::Ex::match(), reg::Ex::Private::matchAt(), and DotRunner::readBoundingBox().

◆ MAX_LATEX_GRAPH_INCH

#define MAX_LATEX_GRAPH_INCH   150

Definition at line 70 of file dotrunner.cpp.

Referenced by resetPDFSize().

◆ MAX_LATEX_GRAPH_SIZE

#define MAX_LATEX_GRAPH_SIZE   (MAX_LATEX_GRAPH_INCH * 72)

Definition at line 71 of file dotrunner.cpp.

Referenced by DotRunner::run().

Function Documentation

◆ checkPngResult()

void checkPngResult ( const DString & imgName)
static

Definition at line 80 of file dotrunner.cpp.

81{
82 FILE *f = Portable::fopen(imgName,"rb");
83 if (!f)
84 {
85 err("Could not read image '{}' generated by dot!\n",imgName);
86 return;
87 }
88
89 char data[4];
90 if (fread(data, 1, 4, f) != 4)
91 {
92 err("Could not read image '{}' generated by dot!\n",imgName);
93 fclose(f);
94 return;
95 }
96
97 if (!(data[1] == 'P' && data[2] == 'N' && data[3] == 'G'))
98 {
99 err("Image '{}' produced by dot is not a valid PNG!\n"
100 "You should either select a different format "
101 "(DOT_IMAGE_FORMAT in the config file) or install a more "
102 "recent version of graphviz (1.7+)\n", imgName);
103 }
104
105 fclose(f);
106}
#define err(fmt,...)
Definition message.h:127
FILE * fopen(const DString &fileName, const DString &mode)
Definition portable.cpp:365
int fclose(FILE *f)
Definition portable.cpp:385

References err, and Portable::fopen().

Referenced by DotRunner::run().

◆ getBaseNameOfOutput()

DString getBaseNameOfOutput ( const DString & output)
static

Definition at line 270 of file dotrunner.cpp.

271{
272 size_t index = output.rfind('.');
273 if (index==DString::npos) return output;
274 return output.left(index);
275}
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:244
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:178
DString left(size_t len) const
Definition dstring.h:306

References DString::left(), DString::npos, and DString::rfind().

Referenced by DotRunner::run().

◆ resetPDFSize()

bool resetPDFSize ( const int width,
const int height,
const DString & base )
static

Definition at line 108 of file dotrunner.cpp.

109{
110 DString tmpName = base+".tmp";
111 DString patchFile = base+".dot";
112 Dir thisDir;
113 if (!thisDir.rename(patchFile.str(),tmpName.str()))
114 {
115 err("Failed to rename file {} to {}!\n",patchFile,tmpName);
116 return false;
117 }
118 std::ifstream fi = Portable::openInputStream(tmpName);
119 std::ofstream t = Portable::openOutputStream(patchFile);
120 if (!fi.is_open())
121 {
122 err("problem opening file {} for patching!\n",tmpName);
123 thisDir.rename(tmpName.str(),patchFile.str());
124 return false;
125 }
126 if (!t.is_open())
127 {
128 err("problem opening file {} for patching!\n",patchFile);
129 thisDir.rename(tmpName.str(),patchFile.str());
130 return false;
131 }
132 std::string line;
133 while (getline(fi,line)) // foreach line
134 {
135 if (line.find("LATEX_PDF_SIZE") != std::string::npos)
136 {
137 double scale = (width > height ? width : height)/double(MAX_LATEX_GRAPH_INCH);
138 t << " size=\""<<width/scale << "," <<height/scale << "\";\n";
139 }
140 else
141 t << line << "\n";
142 }
143 fi.close();
144 t.close();
145 // remove temporary file
146 thisDir.remove(tmpName.str());
147 return true;
148}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
const std::string & str() const
Definition dstring.h:645
Class representing a directory in the file system.
Definition dir.h:73
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:320
bool rename(const std::string &orgName, const std::string &newName, bool acceptsAbsPath=true) const
Definition dir.cpp:327
#define MAX_LATEX_GRAPH_INCH
Definition dotrunner.cpp:70
std::ifstream openInputStream(const DString &name, bool binary=false, bool openAtEnd=false)
Definition portable.cpp:692
std::ofstream openOutputStream(const DString &name, bool append=false)
Definition portable.cpp:681

References err, MAX_LATEX_GRAPH_INCH, Portable::openInputStream(), Portable::openOutputStream(), Dir::remove(), Dir::rename(), and DString::str().

Referenced by DotRunner::run().