Doxygen
Loading...
Searching...
No Matches
dotrunner.cpp File Reference
#include <cassert>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <numeric>
#include <random>
#include "threadpool.h"
#include <gunzip.hh>
#include "dotrunner.h"
#include "util.h"
#include "portable.h"
#include "dot.h"
#include "message.h"
#include "config.h"
#include "dir.h"
#include "doxygen.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 QCString &imgName)
static bool resetPDFSize (const int width, const int height, const QCString &base)
static QCString getBaseNameOfOutput (const QCString &output)

Macro Definition Documentation

◆ DBG

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

Definition at line 70 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 66 of file dotrunner.cpp.

Referenced by resetPDFSize().

◆ MAX_LATEX_GRAPH_SIZE

#define MAX_LATEX_GRAPH_SIZE   (MAX_LATEX_GRAPH_INCH * 72)

Definition at line 67 of file dotrunner.cpp.

Referenced by DotRunner::run().

Function Documentation

◆ checkPngResult()

void checkPngResult ( const QCString & imgName)
static

Definition at line 76 of file dotrunner.cpp.

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

References err, and Portable::fopen().

Referenced by DotRunner::run().

◆ getBaseNameOfOutput()

QCString getBaseNameOfOutput ( const QCString & output)
static

Definition at line 266 of file dotrunner.cpp.

267{
268 int index = output.findRev('.');
269 if (index < 0) return output;
270 return output.left(index);
271}
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition qcstring.cpp:96
QCString left(size_t len) const
Definition qcstring.h:229

References QCString::findRev(), and QCString::left().

Referenced by DotRunner::run().

◆ resetPDFSize()

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

Definition at line 104 of file dotrunner.cpp.

105{
106 QCString tmpName = base+".tmp";
107 QCString patchFile = base+".dot";
108 Dir thisDir;
109 if (!thisDir.rename(patchFile.str(),tmpName.str()))
110 {
111 err("Failed to rename file {} to {}!\n",patchFile,tmpName);
112 return FALSE;
113 }
114 std::ifstream fi = Portable::openInputStream(tmpName);
115 std::ofstream t = Portable::openOutputStream(patchFile);
116 if (!fi.is_open())
117 {
118 err("problem opening file {} for patching!\n",tmpName);
119 thisDir.rename(tmpName.str(),patchFile.str());
120 return FALSE;
121 }
122 if (!t.is_open())
123 {
124 err("problem opening file {} for patching!\n",patchFile);
125 thisDir.rename(tmpName.str(),patchFile.str());
126 return FALSE;
127 }
128 std::string line;
129 while (getline(fi,line)) // foreach line
130 {
131 if (line.find("LATEX_PDF_SIZE") != std::string::npos)
132 {
133 double scale = (width > height ? width : height)/double(MAX_LATEX_GRAPH_INCH);
134 t << " size=\""<<width/scale << "," <<height/scale << "\";\n";
135 }
136 else
137 t << line << "\n";
138 }
139 fi.close();
140 t.close();
141 // remove temporary file
142 thisDir.remove(tmpName.str());
143 return TRUE;
144}
Class representing a directory in the file system.
Definition dir.h:75
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:314
bool rename(const std::string &orgName, const std::string &newName, bool acceptsAbsPath=true) const
Definition dir.cpp:321
This is an alternative implementation of QCString.
Definition qcstring.h:101
const std::string & str() const
Definition qcstring.h:552
#define MAX_LATEX_GRAPH_INCH
Definition dotrunner.cpp:66
std::ifstream openInputStream(const QCString &name, bool binary=false, bool openAtEnd=false)
Definition portable.cpp:659
std::ofstream openOutputStream(const QCString &name, bool append=false)
Definition portable.cpp:648
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34

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

Referenced by DotRunner::run().