msc.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  *
4  *
5  * Copyright (C) 1997-2015 by Dimitri van Heesch.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation under the terms of the GNU General Public License is hereby
9  * granted. No representations are made about the suitability of this software
10  * for any purpose. It is provided "as is" without express or implied warranty.
11  * See the GNU General Public License for more details.
12  *
13  * Documents produced by Doxygen are derivative works derived from the
14  * input used in their production; they are not affected by this license.
15  *
16  */
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 "util.h"
25 #include "ftextstream.h"
26 
27 #include <qdir.h>
28 
29 static const int maxCmdLine = 40960;
30 
31 static bool convertMapFile(FTextStream &t,const char *mapName,const QCString relPath,
32  const QCString &context)
33 {
34  QFile f(mapName);
35  if (!f.open(IO_ReadOnly))
36  {
37  err("failed to open map file %s for inclusion in the docs!\n"
38  "If you installed Graphviz/dot after a previous failing run, \n"
39  "try deleting the output directory and rerun doxygen.\n",mapName);
40  return FALSE;
41  }
42  const int maxLineLen=1024;
43  char buf[maxLineLen];
44  char url[maxLineLen];
45  char ref[maxLineLen];
46  int x1,y1,x2,y2;
47  while (!f.atEnd())
48  {
49  bool isRef = FALSE;
50  int numBytes = f.readLine(buf,maxLineLen);
51  buf[numBytes-1]='\0';
52  //printf("ReadLine `%s'\n",buf);
53  if (qstrncmp(buf,"rect",4)==0)
54  {
55  // obtain the url and the coordinates in the order used by graphviz-1.5
56  sscanf(buf,"rect %s %d,%d %d,%d",url,&x1,&y1,&x2,&y2);
57 
58  if (qstrcmp(url,"\\ref")==0 || qstrcmp(url,"@ref")==0)
59  {
60  isRef = TRUE;
61  sscanf(buf,"rect %s %s %d,%d %d,%d",ref,url,&x1,&y1,&x2,&y2);
62  }
63 
64  // sanity checks
65  if (y2<y1) { int temp=y2; y2=y1; y1=temp; }
66  if (x2<x1) { int temp=x2; x2=x1; x1=temp; }
67 
68  t << "<area href=\"";
69 
70  if ( isRef )
71  {
72  // handle doxygen \ref tag URL reference
73  DocRef *df = new DocRef( (DocNode*) 0, url, context );
74  t << externalRef(relPath,df->ref(),TRUE);
75  if (!df->file().isEmpty()) t << df->file() << Doxygen::htmlFileExtension;
76  if (!df->anchor().isEmpty()) t << "#" << df->anchor();
77  delete df;
78  }
79  else
80  {
81  t << url;
82  }
83  t << "\" shape=\"rect\" coords=\""
84  << x1 << "," << y1 << "," << x2 << "," << y2 << "\""
85  << " alt=\"\"/>" << endl;
86  }
87  }
88 
89  return TRUE;
90 }
91 
92 void writeMscGraphFromFile(const char *inFile,const char *outDir,
93  const char *outFile,MscOutputFormat format)
94 {
95  QCString absOutFile = outDir;
96  absOutFile+=portable_pathSeparator();
97  absOutFile+=outFile;
98 
99  // chdir to the output dir, so dot can find the font file.
100  QCString oldDir = QDir::currentDirPath().utf8();
101  // go to the html output directory (i.e. path)
102  QDir::setCurrent(outDir);
103  //printf("Going to dir %s\n",QDir::currentDirPath().data());
104  QCString mscExe = Config_getString("MSCGEN_PATH")+"mscgen"+portable_commandExtension();
105  QCString mscArgs;
106  QCString extension;
107  switch (format)
108  {
109  case MSC_BITMAP:
110  mscArgs+="-T png";
111  extension=".png";
112  break;
113  case MSC_EPS:
114  mscArgs+="-T eps";
115  extension=".eps";
116  break;
117  case MSC_SVG:
118  mscArgs+="-T svg";
119  extension=".svg";
120  break;
121  default:
122  goto error; // I am not very fond of goto statements, but when in Rome...
123  }
124  mscArgs+=" -i \"";
125  mscArgs+=inFile;
126 
127  mscArgs+="\" -o \"";
128  mscArgs+=outFile;
129  mscArgs+=extension+"\"";
130  int exitCode;
131 // printf("*** running: %s %s outDir:%s %s\n",mscExe.data(),mscArgs.data(),outDir,outFile);
133  if ((exitCode=portable_system(mscExe,mscArgs,FALSE))!=0)
134  {
136  goto error;
137  }
139  if ( (format==MSC_EPS) && (Config_getBool("USE_PDFLATEX")) )
140  {
141  QCString epstopdfArgs(maxCmdLine);
142  epstopdfArgs.sprintf("\"%s.eps\" --outfile=\"%s.pdf\"",
143  outFile,outFile);
145  if (portable_system("epstopdf",epstopdfArgs)!=0)
146  {
147  err("Problems running epstopdf. Check your TeX installation!\n");
148  }
150  }
151 
152 error:
153  QDir::setCurrent(oldDir);
154 }
155 
157  const QCString& relPath,const QCString& context)
158 {
159  QCString outFile = inFile + ".map";
160 
161 
162  //printf("*** running:getMscImageMapFromFile \n");
163  // chdir to the output dir, so dot can find the font file.
164  QCString oldDir = QDir::currentDirPath().utf8();
165  // go to the html output directory (i.e. path)
166  QDir::setCurrent(outDir);
167  //printf("Going to dir %s\n",QDir::currentDirPath().data());
168 
169  QCString mscExe = Config_getString("MSCGEN_PATH")+"mscgen"+portable_commandExtension();
170  QCString mscArgs = "-T ismap -i \"";
171  mscArgs+=inFile;
172  mscArgs+="\" -o \"";
173  mscArgs+=outFile + "\"";
174 
175  int exitCode;
177  if ((exitCode=portable_system(mscExe,mscArgs,FALSE))!=0)
178  {
180  QDir::setCurrent(oldDir);
181  return "";
182  }
184 
186  FTextStream tmpout(&result);
187  convertMapFile(tmpout, outFile, relPath, context);
188  QDir().remove(outFile);
189 
190  QDir::setCurrent(oldDir);
191  return result.data();
192 }
193 
195  const QCString &outDir,
196  const QCString &relPath,
197  const QCString &baseName,
198  const QCString &context,
200  )
201 {
202  QCString mapName = baseName+".map";
203  t << "<img src=\"" << relPath << baseName << ".";
204  switch (format)
205  {
206  case MSC_BITMAP:
207  t << "png";
208  break;
209  case MSC_EPS:
210  t << "eps";
211  break;
212  case MSC_SVG:
213  t << "svg";
214  break;
215  default:
216  t << "unknown";
217  }
218  t << "\" alt=\""
219  << baseName << "\" border=\"0\" usemap=\"#" << mapName << "\"/>" << endl;
220  QCString imap = getMscImageMapFromFile(inFile,outDir,relPath,context);
221  t << "<map name=\"" << mapName << "\" id=\"" << mapName << "\">" << imap << "</map>" << endl;
222 }
223 
Traverses directory structures and contents in a platform-independent way.
Definition: qdir.h:52
Q_EXPORT int qstrncmp(const char *str1, const char *str2, uint len)
Definition: qcstring.h:101
void portable_sysTimerStop()
Definition: portable.cpp:415
QCString anchor() const
Definition: docparser.h:830
QCString getMscImageMapFromFile(const QCString &inFile, const QCString &outDir, const QCString &relPath, const QCString &context)
Definition: msc.cpp:156
char * data() const
Definition: qgstring.h:42
void writeMscGraphFromFile(const char *inFile, const char *outDir, const char *outFile, MscOutputFormat format)
Definition: msc.cpp:92
static QCString result
bool isEmpty() const
Definition: qcstring.h:189
virtual bool remove(const QString &fileName, bool acceptAbsPath=TRUE)
Definition: qdir.cpp:915
static QCString htmlFileExtension
Definition: doxygen.h:130
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
Definition: qstring.cpp:11496
const bool FALSE
Definition: qglobal.h:370
error
Definition: include.cc:26
int readLine(char *data, uint maxlen)
Definition: qfile.cpp:268
TFile * outFile
Definition: makeDST.cxx:36
Simplified and optimized version of QTextStream.
Definition: ftextstream.h:11
QCString file() const
Definition: docparser.h:827
static bool convertMapFile(FTextStream &t, const char *mapName, const QCString relPath, const QCString &context)
Definition: msc.cpp:31
static const int maxCmdLine
Definition: msc.cpp:29
void portable_sysTimerStart()
Definition: portable.cpp:410
#define IO_ReadOnly
Definition: qiodevice.h:61
QCString ref() const
Definition: docparser.h:829
bool open(int)
Definition: qfile_unix.cpp:134
static QString currentDirPath()
Definition: qdir_unix.cpp:141
A bunch of utility functions.
Definition: msc.h:24
#define Config_getString(val)
Definition: config.cpp:660
Definition: msc.h:24
#define Config_getBool(val)
Definition: config.cpp:664
MscOutputFormat
Definition: msc.h:24
void err(const char *fmt,...)
Definition: message.cpp:226
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
QCString & sprintf(const char *format,...)
Definition: qcstring.cpp:27
TFile * inFile
Definition: makeDST.cxx:36
const char * portable_commandExtension()
Definition: portable.cpp:382
static QCString baseName
Definition: scanner.cpp:10890
char portable_pathSeparator()
Definition: portable.cpp:355
Q_EXPORT int qstrcmp(const char *str1, const char *str2)
Definition: qcstring.h:95
QCString utf8() const
Definition: qstring.cpp:14507
const bool TRUE
Definition: qglobal.h:371
bool atEnd() const
Definition: qfile.cpp:239
Portable versions of functions that are platform dependent.
static bool setCurrent(const QString &path)
Definition: qdir_unix.cpp:134
Definition: msc.h:24
QTextStream & endl(QTextStream &s)
QCString externalRef(const QCString &relPath, const QCString &ref, bool href)
Definition: util.cpp:7856
void writeMscImageMapFromFile(FTextStream &t, const QCString &inFile, const QCString &outDir, const QCString &relPath, const QCString &baseName, const QCString &context, MscOutputFormat format)
Definition: msc.cpp:194
int portable_system(const char *command, const char *args, bool commandHasConsole)
Definition: portable.cpp:33