Autogenerate search.php from the html templates
g0dil [Tue, 24 Apr 2007 12:45:53 +0000 (12:45 +0000)]
autogenerate list of search indices
replace @TOPDIR@ in html templates with relative path to project root

git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@231 270642c3-0616-0410-b53a-bc976706d245

SConstruct
doclib/SConscript [new file with mode: 0644]
doclib/doxy-header-overview.html
doclib/doxy-header.html
doclib/html-munge.xsl
doclib/search.php [deleted file]
doclib/search_functions.php
senfscons/Doxygen.py
senfscons/SENFSCons.py

index 807596a..5ce43a2 100644 (file)
@@ -38,12 +38,10 @@ SENFSCons.StandardTargets(env)
 SENFSCons.GlobalTargets(env)
 SENFSCons.Doxygen(env)
 
-#, extra_sources = [
-#    'Examples/Sniffer/Sniffer.cc',
-#])
 SENFSCons.DoxyXRef(env,
                    HTML_HEADER = '#/doclib/doxy-header-overview.html',
                    HTML_FOOTER = '#/doclib/doxy-footer.html')
+SENFSCons.DoxySearch(env)
 
 # Create Doxyfile.local if not cleaning and the file does not exist
 # otherwise doxygen will barf on this non-existent file
diff --git a/doclib/SConscript b/doclib/SConscript
new file mode 100644 (file)
index 0000000..0d93b93
--- /dev/null
@@ -0,0 +1,19 @@
+# -*- python -*-
+
+Import('env')
+import SENFSCons
+
+###########################################################################
+
+# This is not nice .. really ...
+env.Alias(
+    'all_docs',
+    env.Command('search.php',
+                [ 'doxy-header-overview.html', 'doxy-footer.html', 'html-munge.xsl' ], 
+                [ "sed -e 's/\\$$title/Search results/g' -e 's/\\$$projectname/Overview/g' ${SOURCES[0]} > ${TARGET}.tmp",
+                  'echo "PHPSEARCH" >> ${TARGET}.tmp',
+                  'cat ${SOURCES[1]} >> ${TARGET}.tmp',
+                  'xsltproc --nonet --html --stringparam topdir .. -o - ${SOURCES[2]} ${TARGET}.tmp 2>/dev/null'
+                  + '| sed -e "s/PHPSEARCH/<?php include \'search_functions.php\'; ?><?php search(); ?>/" > $TARGET',
+                  'rm -f ${TARGET}.tmp' ]))
+
index 195b602..28f3fa3 100644 (file)
@@ -2,8 +2,8 @@
 <html>
 <head>
 <title>$title</title>
-<link href="doxygen.css" rel="stylesheet" type="text/css">
-<link href="../../doclib/senf.css" rel="stylesheet" type="text/css">
+<link href="@TOPDIR@/doc/html/doxygen.css" rel="stylesheet" type="text/css">
+<link href="@TOPDIR@/doclib/senf.css" rel="stylesheet" type="text/css">
 <style type="text/css">
 div.tabs ul li.$projectname a { background-color: #EDE497; }
 </style>
@@ -12,7 +12,7 @@ div.tabs ul li.$projectname a { background-color: #EDE497; }
 
 <div id="head">
   <div id="search">
-    <form action="../../doclib/search.php" method="get">
+    <form action="@TOPDIR@/doclib/search.php" method="get">
       Search: <input type="text" name="query" size="20" accesskey="s"/> 
     </form>
   </div>
@@ -24,21 +24,22 @@ div.tabs ul li.$projectname a { background-color: #EDE497; }
   <div id="content2">
     <div class="tabs menu">
       <ul>
-        <li class="Overview"><a href="../../doc/html/index.html">Overview</a></li>
-        <li class="libSocket"><a href="../../Socket/doc/html/index.html">libSocket</a></li>
-        <li class="libPackets"><a href="../../Packets/doc/html/index.html">libPackets</a></li>
-        <li class="libScheduler"><a href="../../Scheduler/doc/html/index.html">libScheduler</a></li>
-        <li class="libUtils"><a href="../../Utils/doc/html/index.html">libUtils</a></li>
-        <li class="Examples"><a href="../../Examples/doc/html/index.html">Examples</a></li>
-        <li class="SENFSCons"><a href="../../senfscons/doc/html/index.html">SENFSCons</a></li>
+        <li class="Overview"><a href="@TOPDIR@/doc/html/index.html">Overview</a></li>
+        <li class="libSocket"><a href="@TOPDIR@/Socket/doc/html/index.html">libSocket</a></li>
+        <li class="libPackets"><a href="@TOPDIR@/Packets/doc/html/index.html">libPackets</a></li>
+        <li class="libScheduler"><a href="@TOPDIR@/Scheduler/doc/html/index.html">libScheduler</a></li>
+       <li class="libPPI"><a href="@TOPDIR@/PPI/doc/html/index.html">libPPI</a></li>
+        <li class="libUtils"><a href="@TOPDIR@/Utils/doc/html/index.html">libUtils</a></li>
+        <li class="Examples"><a href="@TOPDIR@/Examples/doc/html/index.html">Examples</a></li>
+        <li class="SENFSCons"><a href="@TOPDIR@/senfscons/doc/html/index.html">SENFSCons</a></li>
       </ul>
     </div>
 
     <div class="tabs">
       <ul>
         <li><a href="xref.html">Open Issues</a></li>
-        <li><a href="http://svn.berlios.de/wsvn/senf/?op=log&rev=0&sc=0&isdir=1">SVN ChangeLog</a></li>
-        <li><a href="http://developer.berlios.de/projects/senf">SENF @ BerliOS</a></li>
-        <li><a href="http://openfacts.berlios.de/index-en.phtml?title=SENF+Network+Framework">Wiki</a></li>
+        <li><a class="ext" href="http://svn.berlios.de/wsvn/senf/?op=log&rev=0&sc=0&isdir=1">SVN ChangeLog</a></li>
+        <li><a class="ext" href="http://developer.berlios.de/projects/senf">SENF @ BerliOS</a></li>
+        <li><a class="ext" href="http://openfacts.berlios.de/index-en.phtml?title=SENF+Network+Framework">Wiki</a></li>
       </ul>
     </div>
\ No newline at end of file
index f05fb45..9981f18 100644 (file)
@@ -2,8 +2,8 @@
 <html>
 <head>
 <title>$title</title>
-<link href="doxygen.css" rel="stylesheet" type="text/css">
-<link href="../../../doclib/senf.css" rel="stylesheet" type="text/css">
+<link href="@TOPDIR@/doc/html/doxygen.css" rel="stylesheet" type="text/css">
+<link href="@TOPDIR@/doclib/senf.css" rel="stylesheet" type="text/css">
 <style type="text/css">
 div.tabs ul li.$projectname a { background-color: #EDE497; }
 </style>
@@ -12,7 +12,7 @@ div.tabs ul li.$projectname a { background-color: #EDE497; }
 
 <div id="head">
   <div id="search">
-    <form action="../../../doclib/search.php" method="get">
+    <form action="@TOPDIR@/doclib/search.php" method="get">
       Search: <input type="text" name="query" size="20" accesskey="s"/> 
     </form>
   </div>
@@ -24,12 +24,13 @@ div.tabs ul li.$projectname a { background-color: #EDE497; }
   <div id="content2">
     <div class="tabs menu">
       <ul>
-        <li class="Overview"><a href="../../../doc/html/index.html">Overview</a></li>
-        <li class="libSocket"><a href="../../../Socket/doc/html/index.html">libSocket</a></li>
-        <li class="libPackets"><a href="../../../Packets/doc/html/index.html">libPackets</a></li>
-        <li class="libScheduler"><a href="../../../Scheduler/doc/html/index.html">libScheduler</a></li>
-        <li class="libUtils"><a href="../../../Utils/doc/html/index.html">libUtils</a></li>
-        <li class="Examples"><a href="../../../Examples/doc/html/index.html">Examples</a></li>
-        <li class="SENFSCons"><a href="../../../senfscons/doc/html/index.html">SENFSCons</a></li>
+        <li class="Overview"><a href="@TOPDIR@/doc/html/index.html">Overview</a></li>
+        <li class="libSocket"><a href="@TOPDIR@/Socket/doc/html/index.html">libSocket</a></li>
+        <li class="libPackets"><a href="@TOPDIR@/Packets/doc/html/index.html">libPackets</a></li>
+        <li class="libScheduler"><a href="@TOPDIR@/Scheduler/doc/html/index.html">libScheduler</a></li>
+       <li class="libPPI"><a href="@TOPDIR@/PPI/doc/html/index.html">libPPI</a></li>
+        <li class="libUtils"><a href="@TOPDIR@/Utils/doc/html/index.html">libUtils</a></li>
+        <li class="Examples"><a href="@TOPDIR@/Examples/doc/html/index.html">Examples</a></li>
+        <li class="SENFSCons"><a href="@TOPDIR@/senfscons/doc/html/index.html">SENFSCons</a></li>
       </ul>
     </div>
index e1cc7d6..d025ef6 100644 (file)
@@ -6,23 +6,49 @@
     encoding="html" \r
     doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"\r
     doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>\r
+\r
+  <xsl:param name="topdir" select="''"/>\r
   \r
   <xsl:template match="*">\r
     <xsl:copy>\r
-      <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>\r
+      <xsl:call-template name="copy-attributes"/>\r
       <xsl:apply-templates/>\r
     </xsl:copy>\r
   </xsl:template>\r
   \r
+  <xsl:template name="copy-attributes">\r
+    <xsl:for-each select="@*">\r
+      <xsl:attribute name="{name(current())}">\r
+        <xsl:choose>\r
+          <xsl:when test="contains(current(),'@TOPDIR@')">\r
+            <xsl:value-of select="substring-before(current(),'@TOPDIR@')"/>\r
+            <xsl:value-of select="$topdir"/>\r
+            <xsl:value-of select="substring-after(current(),'@TOPDIR@')"/>\r
+          </xsl:when>\r
+          <xsl:otherwise>\r
+            <xsl:value-of select="current()"/>\r
+          </xsl:otherwise>\r
+        </xsl:choose>\r
+      </xsl:attribute>\r
+    </xsl:for-each>\r
+  </xsl:template>\r
+  \r
   <xsl:template match="li[form]"> \r
   </xsl:template>\r
   \r
+  <!-- Replace @TOPDIR@ with  relative top directory path -->\r
+  <xsl:template match="@*[contains(current(),'@TOPDIR@')]">\r
+    <xsl:value-of select="substring-before(current(),'@TOPDIR')"/>\r
+    <xsl:value-of select="$topdir"/>\r
+    <xsl:value-of select="substring-after(current(),'@TOPDIR')"/>\r
+  </xsl:template>\r
+  \r
   <!-- Add 'class' attribute to some special paragraphs/lists -->\r
   \r
   <xsl:template name="add-class">\r
     <xsl:param name="class"/>\r
     <xsl:copy>\r
-      <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>\r
+      <xsl:call-template name="copy-attributes"/>\r
       <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>\r
       <xsl:apply-templates/>\r
     </xsl:copy>\r
diff --git a/doclib/search.php b/doclib/search.php
deleted file mode 100644 (file)
index f5842fe..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-<title>Search</title>
-<link href="../doc/html/doxygen.css" rel="stylesheet" type="text/css">
-<link href="senf.css" rel="stylesheet" type="text/css">
-<?php include 'search_functions.php'; ?>
-</head>
-<body>
-
-<div id="head">
-  <div id="search">
-    <form action="search.php" method="get">
-    Search: <?php inputfield(); ?>
-    </form>
-  </div>
-  <h1>SENF Extensible Network Framework</h1>
-  <h2>Search Results</h2>
-</div>
-
-<div id="content1">
-  <div id="content2">
-    <div class="tabs menu">
-      <ul>
-        <li class="Overview"><a href="../doc/html/index.html">Overview</a></li>
-        <li class="libSocket"><a href="../Socket/doc/html/index.html">libSocket</a></li>
-        <li class="libPackets"><a href="../Packets/doc/html/index.html">libPackets</a></li>
-        <li class="libScheduler"><a href="../Scheduler/doc/html/index.html">libScheduler</a></li>
-        <li class="libUtils"><a href="../Utils/doc/html/index.html">libUtils</a></li>
-        <li class="Examples"><a href="../Examples/doc/html/index.html">Examples</a></li>
-        <li class="SENFSCons"><a href="../senfscons/doc/html/index.html">SENFSCons</a></li>
-      </ul>
-    </div>
-
-    <div class="tabs">
-      <ul>
-        <li><a href="xref.html">Open Issues</a></li>
-        <li><a href="http://svn.berlios.de/wsvn/senf/?op=log&rev=0&sc=0&isdir=1">SVN ChangeLog</a></li>
-        <li><a href="http://developer.berlios.de/projects/senf">SENF @ BerliOS</a></li>
-        <li><a href="http://openfacts.berlios.de/index-en.phtml?title=SENF+Network+Framework">Wiki</a></li>
-      </ul>
-    </div>
-  
-    <!-- Generated by Doxygen 1.4.7 -->
-    <div class="tabs">
-      <ul>
-        <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
-        <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
-      <hr style="width:0px;border:none;clear:both;margin:0;padding:0" />
-    </div>
-
-    <?php search(); ?>
-
-    <hr style="width:0px;border:none;clear:both;margin:0;padding:0" />
-  </div>
-</div>
-<div id="footer">
-  <span>
-    <a href="mailto:senf-dev@lists.berlios.de">Contact: senf-dev@lists.berlios.de</a> |
-    Copyright &copy; 2006 Fraunhofer Gesellschaft, SatCom, Stefan Bund
-  </span>
-</div>
-
-</body></html>
index 0431d0c..e3205be 100644 (file)
@@ -1,3 +1,4 @@
+<?php include '../doc/html/search_paths.php'; ?>
 <?php
 
 function search_results()
@@ -313,14 +314,7 @@ function search()
     die("Error: PHP version 4.1.0 or above required!");
   }
 
-  $paths = array(
-       "../doc/html/", 
-    "../Socket/doc/html/",
-    "../Examples/doc/html/",
-    "../Packets/doc/html/",
-    "../Utils/doc/html/",
-    "../Scheduler/doc/html/",
-  );
+  $paths = paths();
   $files = array();
   $j=0;
   for ($i=0; $i<sizeof($paths); $i++) {
index 562d568..3b52795 100644 (file)
@@ -255,17 +255,22 @@ def DoxyEmitter(source, target, env):
       out_dir = '.'
 
    # add our output locations
+   html_dir = None
    for (k, v) in output_formats.iteritems():
       if data.get("GENERATE_" + k, v[0]).upper() == "YES":
          dir = env.Dir( os.path.join(source[0].dir.abspath, out_dir, data.get(k + "_OUTPUT", v[1])) )
+         if k == "HTML" : html_dir = dir
          dir.sources = source
          node = env.File( os.path.join(dir.abspath, k.lower()+".stamp" ) )
          targets.append(node)
          if env.GetOption('clean'): targets.append(dir)
 
-   if data.has_key("GENERATE_TAGFILE"):
+   if data.has_key("GENERATE_TAGFILE") and html_dir:
       targets.append(env.File( os.path.join(source[0].dir.abspath, data["GENERATE_TAGFILE"]) ))
 
+   if data.get("SEARCHENGINE","NO").upper() == "YES":
+      targets.append(env.File( os.path.join(html_dir.abspath, "search.idx") ))
+
    # don't clobber targets
    for node in targets:
       env.Precious(node)
index e365e85..623bbc7 100644 (file)
@@ -364,6 +364,7 @@ def Doxygen(env, doxyfile = "Doxyfile", extra_sources = []):
         if isinstance(doc,SCons.Node.FS.Dir): continue
         if doc.name == 'xml.stamp' : xmlnode = doc
         if doc.name == 'html.stamp' : htmlnode = doc
+        if doc.name == 'search.idx' : continue
         if os.path.splitext(doc.name)[1] == '.stamp' : continue # ignore other file stamps
         # otherwise it must be the tag file
         tagnode = doc
@@ -379,18 +380,21 @@ def Doxygen(env, doxyfile = "Doxyfile", extra_sources = []):
 
     if htmlnode and env.get('DOXY_HTML_XSL'):
         xslfile = env.File(env['DOXY_HTML_XSL'])
+        reltopdir = '../' * len(htmlnode.dir.abspath[len(env.Dir('#').abspath)+1:].split('/'))
+        if reltopdir : reltopdir = reltopdir[:-1]
+        else         : reltopdir = '.'
         env.AddPostAction(
             docs,
             SCons.Action.Action(("for html in %s/*.html; do " +
                         "    echo $$html;" +
                         "    sed -e 's/id=\"current\"/class=\"current\"/' $${html}" +
                         "        | tidy -ascii -q --show-warnings no --fix-uri no" +
-                        "        | xsltproc --nonet --html -o $${html}.new %s - 2>&1" +
+                        "        | xsltproc --nonet --html --stringparam topdir %s -o $${html}.new %s - 2>&1" +
                         "        | grep '^-'" +
                         "        | grep -v 'ID .* already defined';" +
                         "    mv $${html}.new $${html}; " +
                         "done")
-                       % (htmlnode.dir.abspath, xslfile.abspath)))
+                       % (htmlnode.dir.abspath, reltopdir, xslfile.abspath)))
         for doc in docs:
             env.Depends(doc,xslfile)
 
@@ -460,6 +464,21 @@ def DoxyXRef(env, docs=None,
     env.Alias('all_docs',xref)
     return xref
 
+
+def DoxySearch(env, docs=None):
+    if docs is None:
+        docs = env.Alias('all_docs')[0].sources
+    indices = [ doc for doc in docs if doc.name == "search.idx" ]
+    commands = [ "echo '<?php function paths() { return array(' >$TARGET" ]
+    root = env.Dir('#').abspath
+    commands.extend([ "echo '\"..%s/\",' >>$TARGET" % index.dir.abspath[len(root):]
+                      for index in indices  ])
+    commands.append("echo '); } ?>' >>$TARGET" )
+    target = env.Command("doc/html/search_paths.php", indices, commands)
+    env.Alias('all_docs', target)
+    return target
+
+
 ## \brief Build library
 #
 # This target helper will build the given library. The library will be