From cd581388f3d013c501e3cefbaf3e81cf93d46fcb Mon Sep 17 00:00:00 2001
From: Dimitri van Heesch <doxygen@gmail.com>
Date: Sun, 19 Apr 2020 14:21:18 +0200
Subject: [PATCH] issue #7706: Md5 hash does not match for two different runs
 (part 2)

---
 src/dotfilepatcher.cpp | 41 +++++++++++++++++++++--------------------
 src/dotgraph.cpp       | 12 +-----------
 2 files changed, 22 insertions(+), 31 deletions(-)

diff --git a/src/dotfilepatcher.cpp b/src/dotfilepatcher.cpp
index e386af9..20ce4c1 100644
--- a/src/dotfilepatcher.cpp
+++ b/src/dotfilepatcher.cpp
@@ -132,7 +132,7 @@ static QCString replaceRef(const QCString &buf,const QCString relPath,
   //bool isXLink=FALSE;
   int len = 6;
   int indexS = buf.find("href=\""), indexE;
-  bool setTarget = FALSE;
+  bool targetAlreadySet = buf.find("target=")!=-1;
   if (indexS>5 && buf.find("xlink:href=\"")!=-1) // XLink href (for SVG)
   {
     indexS-=6;
@@ -152,9 +152,9 @@ static QCString replaceRef(const QCString &buf,const QCString relPath,
         // fake ref node to resolve the url
         DocRef *df = new DocRef( (DocNode*) 0, link.mid(5), context );
         result+=externalRef(relPath,df->ref(),TRUE);
-        if (!df->file().isEmpty())  
+        if (!df->file().isEmpty())
           result += df->file().data() + Doxygen::htmlFileExtension;
-        if (!df->anchor().isEmpty()) 
+        if (!df->anchor().isEmpty())
           result += "#" + df->anchor();
         delete df;
         result += "\"";
@@ -174,7 +174,6 @@ static QCString replaceRef(const QCString &buf,const QCString relPath,
         if (!ref.isEmpty())
         {
           result = externalLinkTarget(true);
-          if (result != "") setTarget = TRUE;
         }
         result+= href+"=\"";
         result+=externalRef(relPath,ref,TRUE);
@@ -185,12 +184,14 @@ static QCString replaceRef(const QCString &buf,const QCString relPath,
         result = href+"=\"" + link + "\"";
       }
     }
-    if (!target.isEmpty() && !setTarget)
+    if (!target.isEmpty() && !targetAlreadySet)
     {
       result+=" target=\""+target+"\"";
     }
     QCString leftPart = buf.left(indexS);
     QCString rightPart = buf.mid(indexE+1);
+    //printf("replaceRef(\n'%s'\n)->\n'%s+%s+%s'\n",
+    //    buf.data(),leftPart.data(),result.data(),rightPart.data());
     return leftPart + result + rightPart;
   }
   else
@@ -215,7 +216,7 @@ bool DotFilePatcher::convertMapFile(FTextStream &t,const char *mapName,
                     const QCString &context)
 {
   QFile f(mapName);
-  if (!f.open(IO_ReadOnly)) 
+  if (!f.open(IO_ReadOnly))
   {
     err("problems opening map file %s for inclusion in the docs!\n"
       "If you installed Graphviz/dot after a previous failing run, \n"
@@ -250,7 +251,7 @@ bool DotFilePatcher::convertMapFile(FTextStream &t,const char *mapName,
   return TRUE;
 }
 
-DotFilePatcher::DotFilePatcher(const char *patchFile) 
+DotFilePatcher::DotFilePatcher(const char *patchFile)
   : m_patchFile(patchFile)
 {
   m_maps.setAutoDelete(TRUE);
@@ -346,7 +347,7 @@ bool DotFilePatcher::run() const
   }
   QFile fi(tmpName);
   QFile fo(patchFile);
-  if (!fi.open(IO_ReadOnly)) 
+  if (!fi.open(IO_ReadOnly))
   {
     err("problem opening file %s for patching!\n",tmpName.data());
     QDir::current().rename(tmpName,patchFile);
@@ -380,7 +381,7 @@ bool DotFilePatcher::run() const
     ASSERT(numBytes<maxLineLen);
     if (isSVGFile)
     {
-      if (interactiveSVG_local) 
+      if (interactiveSVG_local)
       {
         if (line.find("<svg")!=-1 && !replacedHeader)
         {
@@ -412,7 +413,7 @@ bool DotFilePatcher::run() const
           replacedHeader=TRUE;
         }
       }
-      if (!insideHeader || !foundSize) // copy SVG and replace refs, 
+      if (!insideHeader || !foundSize) // copy SVG and replace refs,
                                        // unless we are inside the header of the SVG.
                                        // Then we replace it with another header.
       {
@@ -602,18 +603,18 @@ bool DotFilePatcher::writeSVGFigureLink(FTextStream &out,const QCString &relPath
     if (height<=60) height=300; else height+=300; // add some extra space for zooming
     if (height>600) height=600; // clip to maximum height of 600 pixels
     out << "<div class=\"zoom\">";
-    //out << "<object type=\"image/svg+xml\" data=\"" 
-    //out << "<embed type=\"image/svg+xml\" src=\"" 
-    out << "<iframe scrolling=\"no\" frameborder=\"0\" src=\"" 
+    //out << "<object type=\"image/svg+xml\" data=\""
+    //out << "<embed type=\"image/svg+xml\" src=\""
+    out << "<iframe scrolling=\"no\" frameborder=\"0\" src=\""
         << relPath << baseName << ".svg\" width=\"100%\" height=\"" << height << "\">";
   }
   else
   {
-    //out << "<object type=\"image/svg+xml\" data=\"" 
-    //out << "<embed type=\"image/svg+xml\" src=\"" 
-    out << "<iframe scrolling=\"no\" frameborder=\"0\" src=\"" 
-        << relPath << baseName << ".svg\" width=\"" 
-        << ((width*96+48)/72) << "\" height=\"" 
+    //out << "<object type=\"image/svg+xml\" data=\""
+    //out << "<embed type=\"image/svg+xml\" src=\""
+    out << "<iframe scrolling=\"no\" frameborder=\"0\" src=\""
+        << relPath << baseName << ".svg\" width=\""
+        << ((width*96+48)/72) << "\" height=\""
         << ((height*96+48)/72) << "\">";
   }
   writeSVGNotSupported(out);
@@ -650,7 +651,7 @@ bool DotFilePatcher::writeVecGfxFigure(FTextStream &out,const QCString &baseName
   }
   //printf("Got PDF/EPS size %d,%d\n",width,height);
   int maxWidth  = 350;  /* approx. page width in points, excl. margins */
-  int maxHeight = 550;  /* approx. page height in points, excl. margins */ 
+  int maxHeight = 550;  /* approx. page height in points, excl. margins */
   out << "\\nopagebreak\n"
          "\\begin{figure}[H]\n"
          "\\begin{center}\n"
diff --git a/src/dotgraph.cpp b/src/dotgraph.cpp
index e622dd4..c0cc4fd 100644
--- a/src/dotgraph.cpp
+++ b/src/dotgraph.cpp
@@ -74,15 +74,6 @@ static bool checkDeliverables(const QCString &file1,
   return file1Ok && file2Ok;
 }
 
-static void removeDotGraph(const QCString &dotName)
-{
-  if (Config_getBool(DOT_CLEANUP))
-  {
-    QDir d;
-    d.remove(dotName);
-  }
-}
-
 static bool insertMapFile(FTextStream &out,const QCString &mapFile,
                           const QCString &relPath,const QCString &mapLabel)
 {
@@ -108,7 +99,7 @@ static bool insertMapFile(FTextStream &out,const QCString &mapFile,
 QCString DotGraph::imgName() const
 {
   return m_baseName + ((m_graphFormat == GOF_BITMAP) ?
-                      ("." + getDotImageExtension()) : (Config_getBool(USE_PDFLATEX) ? ".pdf" : ".eps")); 
+                      ("." + getDotImageExtension()) : (Config_getBool(USE_PDFLATEX) ? ".pdf" : ".eps"));
 }
 
 QCString DotGraph::writeGraph(
@@ -166,7 +157,6 @@ bool DotGraph::prepareDotFile()
      )
   {
     // all needed files are there
-    removeDotGraph(absDotName());
     return FALSE;
   }
 
-- 
1.8.3.1

