1 /******************************************************************************
5 * Copyright (C) 1997-2015 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"
26 #include "ftextstream.h"
30 static const int maxCmdLine = 40960;
32 static bool convertMapFile(FTextStream &t,const char *mapName,const QCString relPath,
33 const QCString &context)
36 if (!f.open(IO_ReadOnly))
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",mapName);
43 const int maxLineLen=1024;
51 int numBytes = f.readLine(buf,maxLineLen);
53 //printf("ReadLine `%s'\n",buf);
54 if (qstrncmp(buf,"rect",4)==0)
56 // obtain the url and the coordinates in the order used by graphviz-1.5
57 sscanf(buf,"rect %s %d,%d %d,%d",url,&x1,&y1,&x2,&y2);
59 if (qstrcmp(url,"\\ref")==0 || qstrcmp(url,"@ref")==0)
62 sscanf(buf,"rect %s %s %d,%d %d,%d",ref,url,&x1,&y1,&x2,&y2);
66 if (y2<y1) { int temp=y2; y2=y1; y1=temp; }
67 if (x2<x1) { int temp=x2; x2=x1; x1=temp; }
73 // handle doxygen \ref tag URL reference
74 DocRef *df = new DocRef( (DocNode*) 0, url, context );
75 t << externalRef(relPath,df->ref(),TRUE);
76 if (!df->file().isEmpty()) t << df->file() << Doxygen::htmlFileExtension;
77 if (!df->anchor().isEmpty()) t << "#" << df->anchor();
84 t << "\" shape=\"rect\" coords=\""
85 << x1 << "," << y1 << "," << x2 << "," << y2 << "\""
86 << " alt=\"\"/>" << endl;
93 void writeMscGraphFromFile(const char *inFile,const char *outDir,
94 const char *outFile,MscOutputFormat format)
96 QCString absOutFile = outDir;
97 absOutFile+=portable_pathSeparator();
100 // chdir to the output dir, so dot can find the font file.
101 QCString oldDir = QDir::currentDirPath().utf8();
102 // go to the html output directory (i.e. path)
103 QDir::setCurrent(outDir);
104 //printf("Going to dir %s\n",QDir::currentDirPath().data());
105 QCString mscExe = Config_getString(MSCGEN_PATH)+"mscgen"+portable_commandExtension();
107 QCString imgName = outFile;
123 goto error; // I am not very fond of goto statements, but when in Rome...
129 mscArgs+=imgName+"\"";
131 // printf("*** running: %s %s outDir:%s %s\n",mscExe.data(),mscArgs.data(),outDir,outFile);
132 portable_sysTimerStart();
133 if ((exitCode=portable_system(mscExe,mscArgs,FALSE))!=0)
135 portable_sysTimerStop();
138 portable_sysTimerStop();
139 if ( (format==MSC_EPS) && (Config_getBool(USE_PDFLATEX)) )
141 QCString epstopdfArgs(maxCmdLine);
142 epstopdfArgs.sprintf("\"%s.eps\" --outfile=\"%s.pdf\"",
144 portable_sysTimerStart();
145 if (portable_system("epstopdf",epstopdfArgs)!=0)
147 err("Problems running epstopdf. Check your TeX installation!\n");
149 portable_sysTimerStop();
152 Doxygen::indexList->addImageFile(imgName);
155 QDir::setCurrent(oldDir);
158 QCString getMscImageMapFromFile(const QCString& inFile, const QCString& outDir,
159 const QCString& relPath,const QCString& context)
161 QCString outFile = inFile + ".map";
164 //printf("*** running:getMscImageMapFromFile \n");
165 // chdir to the output dir, so dot can find the font file.
166 QCString oldDir = QDir::currentDirPath().utf8();
167 // go to the html output directory (i.e. path)
168 QDir::setCurrent(outDir);
169 //printf("Going to dir %s\n",QDir::currentDirPath().data());
171 QCString mscExe = Config_getString(MSCGEN_PATH)+"mscgen"+portable_commandExtension();
172 QCString mscArgs = "-T ismap -i \"";
175 mscArgs+=outFile + "\"";
178 portable_sysTimerStart();
179 if ((exitCode=portable_system(mscExe,mscArgs,FALSE))!=0)
181 portable_sysTimerStop();
182 QDir::setCurrent(oldDir);
185 portable_sysTimerStop();
188 FTextStream tmpout(&result);
189 convertMapFile(tmpout, outFile, relPath, context);
190 QDir().remove(outFile);
192 QDir::setCurrent(oldDir);
193 return result.data();
196 void writeMscImageMapFromFile(FTextStream &t,const QCString &inFile,
197 const QCString &outDir,
198 const QCString &relPath,
199 const QCString &baseName,
200 const QCString &context,
201 MscOutputFormat format
204 QCString mapName = baseName+".map";
205 t << "<img src=\"" << relPath << baseName << ".";
220 QCString imap = getMscImageMapFromFile(inFile,outDir,relPath,context);
224 << baseName << "\" border=\"0\" usemap=\"#" << mapName << "\"/>" << endl;
225 t << "<map name=\"" << mapName << "\" id=\"" << mapName << "\">" << imap << "</map>" << endl;
229 t << "\" alt=\"" << baseName << "\" border=\"0\"/>" << endl;