Doxygen
msc.cpp
浏览该文件的文档.
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2021 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby
7  * granted. No representations are made about the suitability of this software
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  */
15 
16 #include <sstream>
17 
18 #include "msc.h"
19 #include "portable.h"
20 #include "config.h"
21 #include "message.h"
22 #include "docparser.h"
23 #include "doxygen.h"
24 #include "index.h"
25 #include "util.h"
26 #include "mscgen_api.h"
27 #include "dir.h"
28 #include "textstream.h"
29 
30 static const int maxCmdLine = 40960;
31 
32 static bool convertMapFile(TextStream &t,const QCString &mapName,const QCString &relPath,
33  const QCString &context)
34 {
35  std::ifstream f(mapName.str(),std::ifstream::in);
36  if (!f.is_open())
37  {
38  err("failed to open map file %s for inclusion in the docs!\n"
39  "If you installed Graphviz/dot after a previous failing run, \n"
40  "try deleting the output directory and rerun doxygen.\n",qPrint(mapName));
41  return false;
42  }
43  const int maxLineLen=1024;
44  char url[maxLineLen];
45  char ref[maxLineLen];
46  int x1,y1,x2,y2;
47  std::string line;
48  while (getline(f,line))
49  {
50  bool isRef = false;
51  //printf("ReadLine '%s'\n",line.c_str());
52  if (qstrncmp(line.c_str(),"rect",4)==0)
53  {
54  // obtain the url and the coordinates in the order used by graphviz-1.5
55  sscanf(line.c_str(),"rect %s %d,%d %d,%d",url,&x1,&y1,&x2,&y2);
56 
57  if (qstrcmp(url,"\\ref")==0 || qstrcmp(url,"@ref")==0)
58  {
59  isRef = true;
60  sscanf(line.c_str(),"rect %s %s %d,%d %d,%d",ref,url,&x1,&y1,&x2,&y2);
61  }
62 
63  // sanity checks
64  if (y2<y1) { int temp=y2; y2=y1; y1=temp; }
65  if (x2<x1) { int temp=x2; x2=x1; x1=temp; }
66 
67  t << "<area href=\"";
68 
69  if ( isRef )
70  {
71  // handle doxygen \ref tag URL reference
72 
73  std::unique_ptr<IDocParser> parser { createDocParser() };
74  std::unique_ptr<DocRef> df { createRef( *parser.get(), url, context ) };
75  t << externalRef(relPath,df->ref(),TRUE);
76  if (!df->file().isEmpty()) t << addHtmlExtensionIfMissing(df->file());
77  if (!df->anchor().isEmpty()) t << "#" << df->anchor();
78  }
79  else
80  {
81  t << url;
82  }
83  t << "\" shape=\"rect\" coords=\""
84  << x1 << "," << y1 << "," << x2 << "," << y2 << "\""
85  << " alt=\"\"/>\n";
86  }
87  }
88 
89  return true;
90 }
91 
92 void writeMscGraphFromFile(const QCString &inFile,const QCString &outDir,
93  const QCString &outFile,MscOutputFormat format,
94  const QCString &srcFile,int srcLine
95  )
96 {
97  QCString absOutFile = outDir;
98  absOutFile+=Portable::pathSeparator();
99  absOutFile+=outFile;
100 
101  mscgen_format_t msc_format;
102  QCString imgName = absOutFile;
103  switch (format)
104  {
105  case MSC_BITMAP:
106  msc_format = mscgen_format_png;
107  imgName+=".png";
108  break;
109  case MSC_EPS:
110  msc_format = mscgen_format_eps;
111  imgName+=".eps";
112  break;
113  case MSC_SVG:
114  msc_format = mscgen_format_svg;
115  imgName+=".svg";
116  break;
117  default:
118  return;
119  }
120  int code;
121  if ((code=mscgen_generate(inFile.data(),imgName.data(),msc_format))!=0)
122  {
123  err_full(srcFile,srcLine,"Problems generating msc output (error=%s). Look for typos in you msc file %s\n",
124  mscgen_error2str(code),qPrint(inFile));
125  return;
126  }
127 
128  if ( (format==MSC_EPS) && (Config_getBool(USE_PDFLATEX)) )
129  {
130  QCString epstopdfArgs(maxCmdLine);
131  epstopdfArgs.sprintf("\"%s.eps\" --outfile=\"%s.pdf\"",
132  qPrint(absOutFile),qPrint(absOutFile));
134  if (Portable::system("epstopdf",epstopdfArgs)!=0)
135  {
136  err_full(srcFile,srcLine,"Problems running epstopdf when processing '%s.eps'. Check your TeX installation!\n",
137  qPrint(absOutFile));
138  }
140  }
141 
143 
144 }
145 
146 static QCString getMscImageMapFromFile(const QCString& inFile, const QCString& outDir,
147  const QCString& relPath,const QCString& context,
148  bool writeSVGMap,const QCString &srcFile,int srcLine)
149 {
150  QCString outFile = inFile + ".map";
151 
152  int code;
153  if ((code=mscgen_generate(inFile.data(),outFile.data(),
154  writeSVGMap ? mscgen_format_svgmap : mscgen_format_pngmap))!=0)
155  {
156  err_full(srcFile,srcLine,"Problems generating msc output (error=%s). Look for typos in you msc file %s\n",
157  mscgen_error2str(code),qPrint(inFile));
158  return "";
159  }
160 
161  TextStream t;
162  convertMapFile(t, outFile, relPath, context);
163 
164  Dir().remove(outFile.str());
165 
166  return t.str();
167 }
168 
170  const QCString &outDir,
171  const QCString &relPath,
172  const QCString &baseName,
173  const QCString &context,
174  MscOutputFormat format,
175  const QCString &srcFile,
176  int srcLine
177  )
178 {
179  QCString mapName = baseName+".map";
180  t << "<img src=\"" << relPath << baseName << ".";
181  switch (format)
182  {
183  case MSC_BITMAP:
184  t << "png";
185  break;
186  case MSC_EPS:
187  t << "eps";
188  break;
189  case MSC_SVG:
190  t << "svg";
191  break;
192  default:
193  t << "unknown";
194  }
195  QCString imap = getMscImageMapFromFile(inFile,outDir,relPath,context,format==MSC_SVG,srcFile,srcLine);
196  if (!imap.isEmpty())
197  {
198  t << "\" alt=\""
199  << baseName << "\" border=\"0\" usemap=\"#" << mapName << "\"/>\n";
200  t << "<map name=\"" << mapName << "\" id=\"" << mapName << "\">" << imap << "</map>\n";
201  }
202  else
203  {
204  t << "\" alt=\"" << baseName << "\" border=\"0\"/>\n";
205  }
206 }
207 
Portable::pathSeparator
QCString pathSeparator()
Definition: portable.cpp:347
writeMscImageMapFromFile
void writeMscImageMapFromFile(TextStream &t, const QCString &inFile, const QCString &outDir, const QCString &relPath, const QCString &baseName, const QCString &context, MscOutputFormat format, const QCString &srcFile, int srcLine)
Definition: msc.cpp:169
Dir::remove
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition: dir.cpp:256
Dir
Class representing a directory in the file system
Definition: dir.h:68
QCString::isEmpty
bool isEmpty() const
Returns TRUE iff the string is empty
Definition: qcstring.h:144
index.h
Doxygen::indexList
static IndexList * indexList
Definition: doxygen.h:114
MSC_BITMAP
@ MSC_BITMAP
Definition: msc.h:22
msc.h
QCString::str
std::string str() const
Definition: qcstring.h:442
getMscImageMapFromFile
static QCString getMscImageMapFromFile(const QCString &inFile, const QCString &outDir, const QCString &relPath, const QCString &context, bool writeSVGMap, const QCString &srcFile, int srcLine)
Definition: msc.cpp:146
MSC_EPS
@ MSC_EPS
Definition: msc.h:22
MscOutputFormat
MscOutputFormat
Definition: msc.h:22
maxCmdLine
static const int maxCmdLine
Definition: msc.cpp:30
textstream.h
err
void err(const char *fmt,...)
Definition: message.cpp:203
TextStream
Text streaming class that buffers data.
Definition: textstream.h:33
convertMapFile
static bool convertMapFile(TextStream &t, const QCString &mapName, const QCString &relPath, const QCString &context)
Definition: msc.cpp:32
qstrncmp
int qstrncmp(const char *str1, const char *str2, size_t len)
Definition: qcstring.h:91
addHtmlExtensionIfMissing
QCString addHtmlExtensionIfMissing(const QCString &fName)
Definition: util.cpp:5275
message.h
Portable::sysTimerStart
void sysTimerStart()
Definition: portable.cpp:470
IndexList::addImageFile
void addImageFile(const QCString &name)
Definition: index.h:105
doxygen.h
docparser.h
TRUE
#define TRUE
Definition: qcstring.h:36
Portable::system
int system(const QCString &command, const QCString &args, bool commandHasConsole=true)
Definition: portable.cpp:42
MSC_SVG
@ MSC_SVG
Definition: msc.h:22
TextStream::str
std::string str() const
Return the contents of the buffer as a std::string object
Definition: textstream.h:208
writeMscGraphFromFile
void writeMscGraphFromFile(const QCString &inFile, const QCString &outDir, const QCString &outFile, MscOutputFormat format, const QCString &srcFile, int srcLine)
Definition: msc.cpp:92
createRef
DocRef * createRef(IDocParser &parserIntf, const QCString &target, const QCString &context)
Definition: docparser.cpp:7675
Config_getBool
#define Config_getBool(name)
Definition: config.h:33
qPrint
const char * qPrint(const char *s)
Definition: qcstring.h:589
config.h
err_full
void err_full(const QCString &file, int line, const char *fmt,...)
Definition: message.cpp:212
Portable::sysTimerStop
void sysTimerStop()
Definition: portable.cpp:475
QCString::data
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string
Definition: qcstring.h:153
qstrcmp
int qstrcmp(const char *str1, const char *str2)
Definition: qcstring.h:82
portable.h
Portable versions of functions that are platform dependent.
externalRef
QCString externalRef(const QCString &relPath, const QCString &ref, bool href)
Definition: util.cpp:6334
dir.h
util.h
A bunch of utility functions.
QCString::sprintf
QCString & sprintf(const char *format,...)
Definition: qcstring.cpp:24
createDocParser
std::unique_ptr< IDocParser > createDocParser()
Definition: docparser.cpp:179
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108