msc.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * $Id: msc.cpp,v 1.14 2001/03/19 19:27:40 root Exp $
00004  *
00005  * Copyright (C) 1997-2008 by Dimitri van Heesch.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and its
00008  * documentation under the terms of the GNU General Public License is hereby 
00009  * granted. No representations are made about the suitability of this software 
00010  * for any purpose. It is provided "as is" without express or implied warranty.
00011  * See the GNU General Public License for more details.
00012  *
00013  * Documents produced by Doxygen are derivative works derived from the
00014  * input used in their production; they are not affected by this license.
00015  *
00016  */
00017 
00018 #include "msc.h"
00019 #include "portable.h"
00020 #include "config.h"
00021 #include "message.h"
00022 #include "docparser.h"
00023 #include "doxygen.h"
00024 
00025 #include <qdir.h>
00026 
00027 static const int maxCmdLine = 40960;
00028 
00029 static bool convertMapFile(QTextStream &t,const char *mapName,const QCString relPath,
00030                            const QString &context)
00031 {
00032   QFile f(mapName);
00033   if (!f.open(IO_ReadOnly))
00034   {
00035     err("Error opening map file %s for inclusion in the docs!\n",mapName);
00036     return FALSE;
00037   }
00038   const int maxLineLen=1024;
00039   char buf[maxLineLen];
00040   char url[maxLineLen];
00041   char ref[maxLineLen];
00042   int x1,y1,x2,y2;
00043   while (!f.atEnd())
00044   {
00045     bool isRef = FALSE;
00046     int numBytes = f.readLine(buf,maxLineLen);
00047     buf[numBytes-1]='\0';
00048     //printf("ReadLine `%s'\n",buf);
00049     if (strncmp(buf,"rect",4)==0)
00050     {
00051       // obtain the url and the coordinates in the order used by graphviz-1.5
00052       sscanf(buf,"rect %s %d,%d %d,%d",url,&x1,&y1,&x2,&y2);
00053 
00054       if ( strcmp(url,"\\ref") == 0 )
00055       {
00056         isRef = TRUE;
00057         sscanf(buf,"rect %s %s %d,%d %d,%d",ref,url,&x1,&y1,&x2,&y2);
00058       }
00059 
00060       // sanity checks
00061       if (y2<y1) { int temp=y2; y2=y1; y1=temp; }
00062       if (x2<x1) { int temp=x2; x2=x1; x1=temp; }
00063 
00064       t << "<area href=\"";
00065 
00066       if ( isRef )
00067       {
00068         // handle doxygen \ref tag URL reference
00069         QCString *dest;
00070         DocRef *df = new DocRef( (DocNode*) 0, url, context );
00071         if (!df->ref().isEmpty())
00072         {
00073           if ((dest=Doxygen::tagDestinationDict[df->ref()])) t << *dest << "/";
00074         }
00075         if (!df->file().isEmpty()) t << relPath << df->file() << Doxygen::htmlFileExtension;
00076         if (!df->anchor().isEmpty()) t << "#" << df->anchor();
00077       }
00078       else
00079       {
00080         t << url;
00081       }
00082       t << "\" shape=\"rect\" coords=\""
00083         << x1 << "," << y1 << "," << x2 << "," << y2 << "\""
00084         << " alt=\"\">" << endl;
00085     }
00086   }
00087 
00088   return TRUE;
00089 }
00090 void writeMscGraphFromFile(const char *inFile,const char *outDir,
00091                            const char *outFile,MscOutputFormat format)
00092 {
00093   QCString absOutFile = outDir;
00094   absOutFile+=portable_pathSeparator();
00095   absOutFile+=outFile;
00096 
00097   // chdir to the output dir, so dot can find the font file.
00098   QCString oldDir = convertToQCString(QDir::currentDirPath());
00099   // go to the html output directory (i.e. path)
00100   QDir::setCurrent(outDir);
00101   //printf("Going to dir %s\n",QDir::currentDirPath().data());
00102   QCString mscExe = Config_getString("MSCGEN_PATH")+"mscgen"+portable_commandExtension();
00103   QCString mscArgs;
00104   QCString extension;
00105   if (format==MSC_BITMAP)
00106   {
00107     mscArgs+="-T png";
00108     extension=".png";
00109   }
00110   else if (format==MSC_EPS)
00111   {
00112     mscArgs+="-T eps";
00113     extension=".eps";
00114   }
00115   mscArgs+=" -i \"";
00116   mscArgs+=inFile;
00117   mscArgs+=".msc\" -o \"";
00118   mscArgs+=outFile;
00119   mscArgs+=extension+"\"";
00120   int exitCode;
00121   //printf("*** running: %s %s\n",mscExe.data(),mscArgs.data());
00122   if ((exitCode=portable_system(mscExe,mscArgs,FALSE))!=0)
00123   {
00124     goto error;
00125   }
00126   if ( (format==MSC_EPS) && (Config_getBool("USE_PDFLATEX")) )
00127   {
00128     QCString epstopdfArgs(maxCmdLine);
00129     epstopdfArgs.sprintf("\"%s.eps\" --outfile=\"%s.pdf\"",
00130                          outFile,outFile);
00131     if (portable_system("epstopdf",epstopdfArgs)!=0)
00132     {
00133       err("Error: Problems running epstopdf. Check your TeX installation!\n");
00134     }
00135   }
00136 
00137 error:
00138   QDir::setCurrent(oldDir);
00139 }
00140 
00141 QString getMscImageMapFromFile(const QString& inFile, const QString& outDir,
00142                                const QCString& relPath,const QString& context)
00143 {
00144   QString outFile = inFile + ".map";
00145 
00146   // chdir to the output dir, so dot can find the font file.
00147   QCString oldDir = convertToQCString(QDir::currentDirPath());
00148   // go to the html output directory (i.e. path)
00149   QDir::setCurrent(outDir);
00150   //printf("Going to dir %s\n",QDir::currentDirPath().data());
00151 
00152   QCString mscExe = Config_getString("MSCGEN_PATH")+"mscgen"+portable_commandExtension();
00153   QCString mscArgs = "-T ismap -i \"";
00154   mscArgs+=inFile + ".msc\" -o \"";
00155   mscArgs+=outFile + "\"";
00156 
00157   int exitCode;
00158   if ((exitCode=portable_system(mscExe,mscArgs,FALSE))!=0)
00159   {
00160     QDir::setCurrent(oldDir);
00161     return "";
00162   }
00163   
00164   QString result;
00165   QTextOStream tmpout(&result);
00166   convertMapFile(tmpout, outFile, relPath, context);
00167   QDir().remove(outFile);
00168 
00169   QDir::setCurrent(oldDir);
00170   return result;
00171 }
00172 
00173 



Generated on Mon Mar 31 10:58:41 2008 by  doxygen 1.5.1