Orb/Doxygen/src/msc.cpp
changeset 3 d8fccb2cd802
parent 0 42188c7ea2d9
child 4 468f4c8d3d5b
equal deleted inserted replaced
2:932c358ece3e 3:d8fccb2cd802
       
     1 /******************************************************************************
       
     2  *
       
     3  * 
       
     4  *
       
     5  * Copyright (C) 1997-2008 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 
       
    25 #include <qdir.h>
       
    26 
       
    27 static const int maxCmdLine = 40960;
       
    28 
       
    29 static bool convertMapFile(QTextStream &t,const char *mapName,const QCString relPath,
       
    30                            const QString &context)
       
    31 {
       
    32   QFile f(mapName);
       
    33   if (!f.open(IO_ReadOnly))
       
    34   {
       
    35     err("Error opening 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);
       
    38     return FALSE;
       
    39   }
       
    40   const int maxLineLen=1024;
       
    41   char buf[maxLineLen];
       
    42   char url[maxLineLen];
       
    43   char ref[maxLineLen];
       
    44   int x1,y1,x2,y2;
       
    45   while (!f.atEnd())
       
    46   {
       
    47     bool isRef = FALSE;
       
    48     int numBytes = f.readLine(buf,maxLineLen);
       
    49     buf[numBytes-1]='\0';
       
    50     //printf("ReadLine `%s'\n",buf);
       
    51     if (strncmp(buf,"rect",4)==0)
       
    52     {
       
    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);
       
    55 
       
    56       if ( strcmp(url,"\\ref") == 0 )
       
    57       {
       
    58         isRef = TRUE;
       
    59         sscanf(buf,"rect %s %s %d,%d %d,%d",ref,url,&x1,&y1,&x2,&y2);
       
    60       }
       
    61 
       
    62       // sanity checks
       
    63       if (y2<y1) { int temp=y2; y2=y1; y1=temp; }
       
    64       if (x2<x1) { int temp=x2; x2=x1; x1=temp; }
       
    65 
       
    66       t << "<area href=\"";
       
    67 
       
    68       if ( isRef )
       
    69       {
       
    70         // handle doxygen \ref tag URL reference
       
    71         QCString *dest;
       
    72         DocRef *df = new DocRef( (DocNode*) 0, url, context );
       
    73         if (!df->ref().isEmpty())
       
    74         {
       
    75           if ((dest=Doxygen::tagDestinationDict[df->ref()])) t << *dest << "/";
       
    76         }
       
    77         if (!df->file().isEmpty()) t << relPath << df->file() << Doxygen::htmlFileExtension;
       
    78         if (!df->anchor().isEmpty()) t << "#" << df->anchor();
       
    79       }
       
    80       else
       
    81       {
       
    82         t << url;
       
    83       }
       
    84       t << "\" shape=\"rect\" coords=\""
       
    85         << x1 << "," << y1 << "," << x2 << "," << y2 << "\""
       
    86         << " alt=\"\"/>" << endl;
       
    87     }
       
    88   }
       
    89 
       
    90   return TRUE;
       
    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 = convertToQCString(QDir::currentDirPath());
       
   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   if (format==MSC_BITMAP)
       
   108   {
       
   109     mscArgs+="-T png";
       
   110     extension=".png";
       
   111   }
       
   112   else if (format==MSC_EPS)
       
   113   {
       
   114     mscArgs+="-T eps";
       
   115     extension=".eps";
       
   116   }
       
   117   mscArgs+=" -i \"";
       
   118   mscArgs+=inFile;
       
   119   mscArgs+=".msc\" -o \"";
       
   120   mscArgs+=outFile;
       
   121   mscArgs+=extension+"\"";
       
   122   int exitCode;
       
   123   //printf("*** running: %s %s\n",mscExe.data(),mscArgs.data());
       
   124   if ((exitCode=portable_system(mscExe,mscArgs,FALSE))!=0)
       
   125   {
       
   126     goto error;
       
   127   }
       
   128   if ( (format==MSC_EPS) && (Config_getBool("USE_PDFLATEX")) )
       
   129   {
       
   130     QCString epstopdfArgs(maxCmdLine);
       
   131     epstopdfArgs.sprintf("\"%s.eps\" --outfile=\"%s.pdf\"",
       
   132                          outFile,outFile);
       
   133     if (portable_system("epstopdf",epstopdfArgs)!=0)
       
   134     {
       
   135       err("Error: Problems running epstopdf. Check your TeX installation!\n");
       
   136     }
       
   137   }
       
   138 
       
   139 error:
       
   140   QDir::setCurrent(oldDir);
       
   141 }
       
   142 
       
   143 QString getMscImageMapFromFile(const QString& inFile, const QString& outDir,
       
   144                                const QCString& relPath,const QString& context)
       
   145 {
       
   146   QString outFile = inFile + ".map";
       
   147 
       
   148   // chdir to the output dir, so dot can find the font file.
       
   149   QCString oldDir = convertToQCString(QDir::currentDirPath());
       
   150   // go to the html output directory (i.e. path)
       
   151   QDir::setCurrent(outDir);
       
   152   //printf("Going to dir %s\n",QDir::currentDirPath().data());
       
   153 
       
   154   QCString mscExe = Config_getString("MSCGEN_PATH")+"mscgen"+portable_commandExtension();
       
   155   QCString mscArgs = "-T ismap -i \"";
       
   156   mscArgs+=inFile + ".msc\" -o \"";
       
   157   mscArgs+=outFile + "\"";
       
   158 
       
   159   int exitCode;
       
   160   if ((exitCode=portable_system(mscExe,mscArgs,FALSE))!=0)
       
   161   {
       
   162     QDir::setCurrent(oldDir);
       
   163     return "";
       
   164   }
       
   165   
       
   166   QString result;
       
   167   QTextOStream tmpout(&result);
       
   168   convertMapFile(tmpout, outFile, relPath, context);
       
   169   QDir().remove(outFile);
       
   170 
       
   171   QDir::setCurrent(oldDir);
       
   172   return result;
       
   173 }
       
   174 
       
   175