1 /******************************************************************************
3 * $Id: msc.cpp,v 1.14 2001/03/19 19:27:40 root Exp $
5 * Copyright (C) 1997-2012 by Dimitri van Heesch.
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.
13 * Documents produced by Doxygen are derivative works derived from the
14 * input used in their production; they are not affected by this license.
22 #include "docparser.h"
27 static const int maxCmdLine = 40960;
29 static bool convertMapFile(QTextStream &t,const char *mapName,const QCString relPath,
30 const QCString &context)
33 if (!f.open(IO_ReadOnly))
35 err("error: failed to open map file %s for inclusion in the docs!\n"
36 "If you installed Graphviz/dot after a previous failing run, \n"
37 "try deleting the output directory and rerun doxygen.\n",mapName);
40 const int maxLineLen=1024;
48 int numBytes = f.readLine(buf,maxLineLen);
50 //printf("ReadLine `%s'\n",buf);
51 if (strncmp(buf,"rect",4)==0)
53 // obtain the url and the coordinates in the order used by graphviz-1.5
54 sscanf(buf,"rect %s %d,%d %d,%d",url,&x1,&y1,&x2,&y2);
56 if ( strcmp(url,"\\ref") == 0 )
59 sscanf(buf,"rect %s %s %d,%d %d,%d",ref,url,&x1,&y1,&x2,&y2);
63 if (y2<y1) { int temp=y2; y2=y1; y1=temp; }
64 if (x2<x1) { int temp=x2; x2=x1; x1=temp; }
70 // handle doxygen \ref tag URL reference
71 DocRef *df = new DocRef( (DocNode*) 0, url, context );
72 t << externalRef(relPath,df->ref(),TRUE);
73 if (!df->file().isEmpty()) t << df->file() << Doxygen::htmlFileExtension;
74 if (!df->anchor().isEmpty()) t << "#" << df->anchor();
80 t << "\" shape=\"rect\" coords=\""
81 << x1 << "," << y1 << "," << x2 << "," << y2 << "\""
82 << " alt=\"\"/>" << endl;
89 void writeMscGraphFromFile(const char *inFile,const char *outDir,
90 const char *outFile,MscOutputFormat format)
92 QCString absOutFile = outDir;
93 absOutFile+=portable_pathSeparator();
96 // chdir to the output dir, so dot can find the font file.
97 QCString oldDir = convertToQCString(QDir::currentDirPath());
98 // go to the html output directory (i.e. path)
99 QDir::setCurrent(outDir);
100 //printf("Going to dir %s\n",QDir::currentDirPath().data());
101 QCString mscExe = Config_getString("MSCGEN_PATH")+"mscgen"+portable_commandExtension();
104 if (format==MSC_BITMAP)
109 else if (format==MSC_EPS)
119 mscArgs+=extension+"\"";
121 // printf("*** running: %s %s outDir:%s %s\n",mscExe.data(),mscArgs.data(),outDir,outFile);
122 portable_sysTimerStart();
123 if ((exitCode=portable_system(mscExe,mscArgs,FALSE))!=0)
125 portable_sysTimerStop();
128 portable_sysTimerStop();
129 if ( (format==MSC_EPS) && (Config_getBool("USE_PDFLATEX")) )
131 QCString epstopdfArgs(maxCmdLine);
132 epstopdfArgs.sprintf("\"%s.eps\" --outfile=\"%s.pdf\"",
134 portable_sysTimerStart();
135 if (portable_system("epstopdf",epstopdfArgs)!=0)
137 err("error: Problems running epstopdf. Check your TeX installation!\n");
139 portable_sysTimerStop();
143 QDir::setCurrent(oldDir);
146 QCString getMscImageMapFromFile(const QCString& inFile, const QCString& outDir,
147 const QCString& relPath,const QCString& context)
149 QCString outFile = inFile + ".map";
152 //printf("*** running:getMscImageMapFromFile \n");
153 // chdir to the output dir, so dot can find the font file.
154 QCString oldDir = convertToQCString(QDir::currentDirPath());
155 // go to the html output directory (i.e. path)
156 QDir::setCurrent(outDir);
157 //printf("Going to dir %s\n",QDir::currentDirPath().data());
159 QCString mscExe = Config_getString("MSCGEN_PATH")+"mscgen"+portable_commandExtension();
160 QCString mscArgs = "-T ismap -i \"";
162 QFileInfo fi(inFile);
164 mscArgs+=outFile + "\"";
167 portable_sysTimerStart();
168 if ((exitCode=portable_system(mscExe,mscArgs,FALSE))!=0)
170 portable_sysTimerStop();
171 QDir::setCurrent(oldDir);
174 portable_sysTimerStop();
177 QTextOStream tmpout(&result);
178 convertMapFile(tmpout, outFile, relPath, context);
179 QDir().remove(outFile);
181 QDir::setCurrent(oldDir);
182 return result.data();
185 void writeMscImageMapFromFile(FTextStream &t,const QCString &inFile,
186 const QCString &outDir,
187 const QCString &relPath,
188 const QCString &baseName,
189 const QCString &context)
191 QCString mapName = baseName+".map";
192 QCString mapFile = inFile+".map";
193 t << "<img src=\"" << relPath << baseName << ".png\" alt=\""
194 << baseName << "\" border=\"0\" usemap=\"#" << mapName << "\"/>" << endl;
195 QCString imap = getMscImageMapFromFile(inFile,outDir,relPath,context);
196 t << "<map name=\"" << mapName << "\" id=\"" << mapName << "\">" << imap << "</map>" << endl;