Index: /home/cheetah/dev/doxygen/src/util.cpp
===================================================================
--- /home/cheetah/dev/doxygen/src/util.cpp	(revision 755)
+++ /home/cheetah/dev/doxygen/src/util.cpp	(working copy)
@@ -4598,9 +4598,75 @@
   //printf("substitute(%s,%s,%s)->%s\n",s,src,dst,result.data());
   return result;
 }
+//----------------------------------------------------------------------
+// Clear a text block from begin to end markers

+QCString clearBlock(const char *s,const char *begin,const char *end)
+{
+  if (s==0 || begin==0 || end==0) return s;
+  const char *p, *q;
+  int beginLen = strlen(begin);
+  int endLen = strlen(end);
+  int resLen = 0;
+  for(p=s; (q=strstr(p,begin))!=0; p=q+endLen)
+  {
+    resLen+=q-p;
+    p=q+beginLen;
+    if((q=strstr(p,end))==0)
+    {
+      resLen+=beginLen;
+      break;
+    }
+  }
+  resLen+=strlen(p);
+
+  QCString result(resLen+1);
+  char *r;
+  for (r=result.data(), p=s; (q=strstr(p,begin))!=0; p=q+endLen)
+  {
+    int l = (int)(q-p);
+    memcpy(r,p,l);
+    r+=l;
+    p=q+beginLen;
+    if((q=strstr(p,end))==0)
+    {
+      memcpy(r,begin,beginLen);
+      r+=beginLen;
+      break;
+    }
+  }
+  strcpy(r,p);
+  printf("clearblock(%s,%s,%s)->%s\n",s,begin,end,result.data());
+  return result;
+}
 //----------------------------------------------------------------------

+QCString selectBlock(const QCString& s,const QCString &name,bool which)
+{
+  const QCString begin = "<!--BEGIN " + name + "-->";
+  const QCString end = "<!--END " + name + "-->";
+  const QCString nobegin = "<!--BEGIN NO" + name + "-->";
+  const QCString noend = "<!--END NO" + name + "-->";
+
+  QCString result = s;
+  if (which)
+  {
+    result = substitute(result, begin, "");
+    result = substitute(result, end, "");
+    result = clearBlock(result, nobegin, noend);
+  }
+  else
+  {
+    result = substitute(result, nobegin, "");
+    result = substitute(result, noend, "");
+    result = clearBlock(result, begin, end);
+  }
+
+  return result;
+}
+
+//----------------------------------------------------------------------
+
 struct FindFileCacheElem
 {
   FindFileCacheElem(FileDef *fd,bool ambig) : fileDef(fd), isAmbig(ambig) {}
@@ -4721,6 +4787,61 @@

 QCString substituteKeywords(const QCString &s,const char *title,const QCString &relPath)
 {
+  // Build CSS/Javascript tags depending on treeview, search engine settings
+  QCString treeViewCss = "";
+  QCString treeViewJs = "";
+  QCString searchCss = "";
+  QCString searchJs = "";
+  QCString mathJaxJs = "";
+  static bool treeView = Config_getBool("GENERATE_TREEVIEW");
+  static bool searchEngine = Config_getBool("SEARCHENGINE");
+  static bool serverBasedSearch = Config_getBool("SERVER_BASED_SEARCH");
+  static bool mathJax = Config_getBool("USE_MATHJAX");
+
+  if (treeView)
+  {
+    treeViewCss = "<link href=\"$relpath$navtree.css\" rel=\"stylesheet\" type=\"text/css\"/>";
+    treeViewJs = "<script type=\"text/javascript\" src=\"$relpath$jquery.js\"></script>\n"
+                 "<script type=\"text/javascript\" src=\"$relpath$resize.js\"></script>\n"
+                 "<script type=\"text/javascript\" src=\"$relpath$navtree.js\"></script>\n"
+                 "<script type=\"text/javascript\">\n"
+                 "  $(document).ready(initResizable);\n"
+                 "</script>";
+  }
+
+  if (searchEngine)
+  {
+    searchCss = "<link href=\"$relpath$search/search.css\" rel=\"stylesheet\" type=\"text/css\"/>";
+    if (!Config_getBool("GENERATE_TREEVIEW"))
+    {
+      searchJs = "<script type=\"text/javascript\" src=\"$relpath$jquery.js\"></script>\n";
+    }
+    searchJs = searchJs + "<script type=\"text/javascript\" src=\"$relpath$search/search.js\"></script>\n";
+
+    if (!serverBasedSearch) {
+      searchJs = searchJs + "<script type=\"text/javascript\">\n"
+                            "  $(document).ready(function() { searchBox.OnSelectItem(0); });\n"
+                            "</script>";
+    }
+    else {
+      searchJs = searchJs + "<script type=\"text/javascript\">\n"
+                            "  $(document).ready(function() {\n"
+                            "    if ($('.searchresults').length > 0) { searchBox.DOMSearchField().focus(); }\n"
+                            "  });\n"
+                            "</script>";
+    }
+  }
+
+  if (mathJax)
+  {
+    mathJaxJs = "<script src=\"$relpath$MathJax.js\">\n"
+                "  MathJax.Hub.Config({\n"
+                "    extensions: [\"tex2jax.js\"],\n"
+                "    jax: [\"input/TeX\",\"output/HTML-CSS\"],\n"
+                "});\n"
+                "</script>\n";
+  }
+
   QCString result = s.copy();
   if (title) result = substitute(result,"$title",title);
   result = substitute(result,"$datetime",dateToString(TRUE));
@@ -4731,7 +4852,14 @@
   result = substitute(result,"$projectnumber",Config_getString("PROJECT_NUMBER"));
   result = substitute(result,"$projectbrief",Config_getString("PROJECT_BRIEF"));
   result = substitute(result,"$projectlogo",Config_getString("PROJECT_LOGO"));
+  result = substitute(result,"$treeviewcss", treeViewCss);
+  result = substitute(result,"$treeviewjs", treeViewJs);
+  result = substitute(result,"$searchcss", searchCss);
+  result = substitute(result,"$searchjs", searchJs);
+  result = substitute(result,"$mathjaxjs", mathJaxJs);
   result = substitute(result,"$relpath$",relPath);
+  result = selectBlock(result, "TREEVIEW", treeView);
+  result = selectBlock(result, "SEARCH", searchEngine);
   return result;
 }



Index: /home/cheetah/dev/doxygen/src/util.h
===================================================================
--- /home/cheetah/dev/doxygen/src/util.h    (revision 755)
+++ /home/cheetah/dev/doxygen/src/util.h    (working copy)
@@ -178,6 +178,10 @@

 QCString substitute(const char *s,const char *src,const char *dst);

+QCString clearBlock(const char *s,const char *begin,const char *end);
+
+QCString selectBlock(const QCString& s,const QCString &name,bool which);
+
 QCString resolveDefines(const char *n);

 ClassDef *getClass(const char *key);


Index: /home/cheetah/dev/doxygen/src/htmlgen.cpp
===================================================================
--- /home/cheetah/dev/doxygen/src/htmlgen.cpp	(revision 755)
+++ /home/cheetah/dev/doxygen/src/htmlgen.cpp	(working copy)
@@ -58,7 +58,17 @@
 #include "search_css.h"
 ;

+static const char search_jquery_script1[]=
+#include "jquery_js.h"
+;
+static const char search_jquery_script2[]=
+#include "sizzle_js.h"
+;
+static const char search_jquery_script3[]=
+#include "jquery_ui_js.h"
+;

+
 static QCString g_header;
 static QCString g_footer;

@@ -2803,6 +2806,17 @@
   {
      err("Failed to open file '%s' for writing...\n",scriptName.data());
   }
+
+    // generate jquery.js, if not done by Treeview
+  if (!generateTreeView)
+  {
+    QFile f(Config_getString("HTML_OUTPUT")+"/jquery.js");
+    if (f.open(IO_WriteOnly))
+    {
+      FTextStream t(&f);
+      t << search_jquery_script1 << search_jquery_script2 << search_jquery_script3;
+    }
+  }
 }

 #if 0

