Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/llfio.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spam@nowhere>2016-03-21 02:41:51 +0300
committerNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spam@nowhere>2016-03-21 02:41:51 +0300
commit758a934ab266ed660daa54b72e4606b78e374071 (patch)
tree6f2fe1c5d2b8331f9319549bc6f0c3390168eb6b /scripts
AFIO v2: Relocate all the AFIO v2 files in fs_probe into the root hierarchy. AFIO v2 is now the master branch!
Diffstat (limited to 'scripts')
-rw-r--r--scripts/AddTryItNow.py29
-rwxr-xr-xscripts/BuildTimes.py87
-rwxr-xr-xscripts/GenJenkinsMatrixDashboard.py96
-rwxr-xr-xscripts/JenkinsMatrixToDashboard.py83
-rwxr-xr-xscripts/SoakTest.py16
-rwxr-xr-xscripts/XMLTidy.py28
-rwxr-xr-xscripts/readme_to_html.sh8
-rw-r--r--scripts/travis_lldb.expect10
-rw-r--r--scripts/xhtml_to_docbook.xsl537
9 files changed, 894 insertions, 0 deletions
diff --git a/scripts/AddTryItNow.py b/scripts/AddTryItNow.py
new file mode 100644
index 00000000..1bd03f07
--- /dev/null
+++ b/scripts/AddTryItNow.py
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+
+import glob, os, sys
+
+if not os.path.exists("html/afio/try_it_now.html"):
+ sys.exit(0)
+with open("html/afio/try_it_now.html", "rb") as ih:
+ try_it_now=ih.read()
+
+def patch(i):
+ with open(i, "r+b") as ih:
+ t=ih.read();
+ it1=0
+ while 1:
+ it1=t.find('<div class="spirit-nav">', it1)
+ if it1==-1: break
+ it1=it1+24
+ t=t[:it1]+try_it_now+t[it1:]
+ ih.seek(0)
+ ih.truncate(0)
+ ih.write(t)
+
+patch("html/afio.html")
+for i in glob.glob("html/afio/*.html"):
+ patch(i)
+for i in glob.glob("html/afio/*/*.html"):
+ patch(i)
+for i in glob.glob("html/afio/*/*/*.html"):
+ patch(i)
diff --git a/scripts/BuildTimes.py b/scripts/BuildTimes.py
new file mode 100755
index 00000000..88f2b9ec
--- /dev/null
+++ b/scripts/BuildTimes.py
@@ -0,0 +1,87 @@
+#!/usr/bin/python3
+# Calculate boost.afio build times under various configs
+# (C) 2015 Niall Douglas
+# Created: 12th March 2015
+#[ [`--link-test --fast-build debug`][][[footnote ASIO has a link error without `link=static`]][fails]]
+#[ [`--link-test debug`][][][]]
+#[ [`--link-test --lto debug`][[]][][]]
+#[ [`--link-test pch=off debug`][][][]]
+#[[`--link-test --fast-build release`][][[footnote ASIO has a link error without `link=static`]][fails]]
+#[ [`--link-test release`][][][]]
+#[ [`--link-test --lto release`][][][]]
+
+import os, sys, subprocess, time, shutil, platform
+
+if len(sys.argv)<2:
+ print("Usage: "+sys.argv[0]+" <toolset>", file=sys.stderr)
+ sys.exit(1)
+if not os.path.exists("b2") and not os.path.exists("b2.exe"):
+ print("ERROR: Need to run me from boost root directory please", file=sys.stderr)
+print(os.getcwd())
+shutil.rmtree("bin.v2", True)
+
+onWindows="Windows" in platform.system()
+
+configs=[
+ ["--c++14 --link-test --fast-build debug", None],
+ ["--c++14 --link-test debug", None],
+ ["--c++14 --link-test --lto debug", None],
+ ["--c++14 --link-test pch=off debug", None],
+ ["--c++14 --link-test --fast-build release", None],
+ ["--c++14 --link-test release", None],
+ ["--c++14 --link-test --lto release", None],
+ ["standalone_singleabi", None],
+ ["standalone_multiabi", None]
+]
+for config in configs:
+ print("\n\nConfig: "+config[0])
+ if config[0]=="standalone_singleabi" or config[0]=="standalone_multiabi":
+ if onWindows:
+ test_all="test_all.exe"
+ tocall="alltests_msvc.bat" if "msvc" in sys.argv[1] else "alltests_gcc.bat"
+ else:
+ test_all="test_all"
+ tocall="alltests_gcc.sh"
+ if config[0]=="standalone_singleabi":
+ tocall="standalone_"+tocall
+ else:
+ tocall="multiabi_"+tocall
+ basedir=os.getcwd()
+ env=dict(os.environ)
+ if not onWindows:
+ tocall="./"+tocall
+ env['CXX']=sys.argv[1]
+ env['CXX']=env['CXX'].replace('gcc', 'g++')
+ env['CXX']=env['CXX'].replace('clang', 'clang++')
+ try:
+ os.chdir("libs/afio")
+ shutil.rmtree(test_all, True)
+ if subprocess.call(tocall, env=env, shell=True):
+ config[1]="FAILED"
+ continue
+ shutil.rmtree(test_all, True)
+ print("\n\nStarting benchmark ...")
+ begin=time.perf_counter()
+ subprocess.call(tocall, env=env, shell=True)
+ end=time.perf_counter()
+ finally:
+ os.chdir(basedir)
+ else:
+ shutil.rmtree("bin.v2/libs/afio", True)
+ if subprocess.call([os.path.abspath("b2"), "toolset="+sys.argv[1], "libs/afio/test", "-j", "8"]+config[0].split(" ")):
+ config[1]="FAILED"
+ continue
+ shutil.rmtree("bin.v2/libs/afio", True)
+ print("\n\nStarting benchmark ...")
+ begin=time.perf_counter()
+ subprocess.call([os.path.abspath("b2"), "toolset="+sys.argv[1], "libs/afio/test"]+config[0].split(" "))
+ end=time.perf_counter()
+ mins=int((end-begin)/60)
+ secs=int((end-begin)%60);
+ config[1]="%dm%ss" % (mins, secs)
+ print("Config %s took %dm%ss" % (config[0], mins, secs))
+
+print("\n\n")
+for config in configs:
+ print(config)
+ \ No newline at end of file
diff --git a/scripts/GenJenkinsMatrixDashboard.py b/scripts/GenJenkinsMatrixDashboard.py
new file mode 100755
index 00000000..5f87507b
--- /dev/null
+++ b/scripts/GenJenkinsMatrixDashboard.py
@@ -0,0 +1,96 @@
+#!/usr/bin/python3
+
+inputs=[
+ ((2, "Android 5.0", "clang 3.5", "libc++", "x86"), {"CPPSTD":["c++11"], "CXX":["g++-4.8"], "LINKTYPE":["standalone"], "label":"android-ndk"}),
+ ((0, "Android 5.0", "GCC 4.8", "libc++", "x86"), {"CPPSTD":["c++11"], "CXX":["g++-4.8"], "LINKTYPE":["standalone"], "label":"android-ndk"}),
+ ((1, "FreeBSD 10.1 on ZFS", "clang 3.4", "libc++", "x86"), {"CPPSTD":["c++11"], "CXX":["clang++-3.3"], "label":"freebsd10-clang3.3"}),
+
+ ((2, "Ubuntu Linux 12.04 LTS", "clang 3.3", "libstdc++ 4.8", "x86"), {"CPPSTD":["c++11"], "CXX":["clang++-3.3"], "label":"linux-gcc-clang"}),
+ ((0, "Ubuntu Linux 12.04 LTS", "clang 3.4", "libstdc++ 4.8", "x86"), {"CPPSTD":["c++11"], "CXX":["clang++-3.4"], "label":"linux-gcc-clang"}),
+
+ ((8, "Ubuntu Linux 14.04 LTS", "clang 3.5", "libstdc++ 4.9", "x64"), {"CPPSTD":["c++11"], "CXX":["clang++-3.5"], "label":"linux64-gcc-clang"}),
+ ((0, "Ubuntu Linux 14.04 LTS", "clang 3.5", "libstdc++ 4.9", "ARMv7"), {"CPPSTD":["c++11"], "CXX":["clang++-3.5"], "label":"arm-gcc-clang"}),
+ ((0, "Ubuntu Linux 14.04 LTS", "clang 3.6", "libstdc++ 4.9", "x64"), {"CXX":["clang++-3.6"], "label":"linux64-gcc-clang"}),
+ ((0, "Ubuntu Linux 14.04 LTS", "clang 3.7", "libstdc++ 4.9", "x64"), {"CXX":["clang++-3.7"], "label":"linux64-gcc-clang"}),
+ ((0, "Ubuntu Linux 14.04 LTS", "GCC 4.8", "libstdc++ 4.8", "x64"), {"CPPSTD":["c++11"], "CXX":["g++-4.8"], "label":"linux64-gcc-clang"}),
+ ((0, "Ubuntu Linux 14.04 LTS", "GCC 4.9", "libstdc++ 4.9", "x64"), {"CXX":["g++-4.9"], "label":"linux64-gcc-clang"}),
+ ((0, "Ubuntu Linux 14.04 LTS", "GCC 4.9", "libstdc++ 4.9", "ARMv7"), {"CXX":["g++-4.9"], "label":"arm-gcc-clang"}),
+ ((0, "Ubuntu Linux 14.04 LTS", "GCC 5.1", "libstdc++ 5.1", "x64"), {"CXX":["g++-5"], "label":"linux64-gcc-clang"}),
+
+ ((3, "Microsoft Windows 8.1", "Mingw-w64 GCC 4.8", "libstdc++ 4.8", "x64"), {"CPPSTD":["c++11"], "CXX":["mingw64"], "LINKTYPE":["static", "shared"], "label":"win8-msvc-mingw"}),
+ ((0, "Microsoft Windows 8.1", "Visual Studio 2015", "Dinkumware", "x64"), {"CPPSTD":["c++14"], "CXX":["msvc-14.0"], "label":"win8-msvc-mingw"}),
+]
+CPPSTDs=["c++11", "c++14"]
+CXXs=["g++-4.8", "g++-4.9", "g++-5"]
+LINKTYPEs=["static", "shared", "standalone"]
+
+print('''<p align="center">
+<a href="http://boostgsoc13.github.io/boost.afio/">Documentation can be found here</a>
+</p>
+<h3 align="center">
+Boost.AFIO Jenkins CI status:
+</h3>
+<p align="center">Unit test code coverage is: <a href='https://coveralls.io/r/BoostGSoC13/boost.afio'><img src='https://coveralls.io/repos/BoostGSoC13/boost.afio/badge.png' alt='Coverage Status' /></a></p>
+<p align="center">Appveyor: <a href='https://ci.appveyor.com/project/ned14/boost-afio'><img src='https://ci.appveyor.com/api/projects/status/f89cv89kj8c2nmvb/branch/master'/></a></p>
+
+<center>
+<table border="1" cellpadding="2">
+<tr><th>OS</th><th>Compiler</th><th>STL</th><th>CPU</th><th>Build</th><th>Unit tests</th></tr>
+
+<!-- static analysis clang -->
+<tr align="center"><td rowspan="2">Static analysis</td><td>clang 3.7 tidy + static analyser + GCC 4.8</td><td></td><td></td><td>
+<div><a href='https://ci.nedprod.com/job/Boost.AFIO%20Static%20Analysis%20clang/'><img src='https://ci.nedprod.com/buildStatus/icon?job=Boost.AFIO%20Static%20Analysis%20clang' /></a></div></td><td></td>
+</tr>
+
+<!-- static analysis MSVC -->
+<tr align="center"><td>VS2013</td><td></td><td></td><td>
+<div><a href='https://ci.nedprod.com/job/Boost.AFIO%20Static%20Analysis%20MSVC/'><img src='https://ci.nedprod.com/buildStatus/icon?job=Boost.AFIO%20Static%20Analysis%20MSVC' /></a></div></td><td></td>
+</tr>
+
+<!-- sanitiser -->
+<tr align="center"><td>Thread Sanitiser</td><td>clang 3.4</td><td>libstdc++ 4.9</td><td>x64</td><td></td><td>
+<div><a href='https://ci.nedprod.com/job/Boost.AFIO%20Sanitise%20Linux%20clang%203.4/'><img src='https://ci.nedprod.com/buildStatus/icon?job=Boost.AFIO%20Sanitise%20Linux%20clang%203.4' /></a></div></td>
+</tr>
+
+<!-- valgrind -->
+<tr align="center"><td>Valgrind</td><td>GCC 4.8</td><td>libstdc++ 4.8</td><td>x64</td><td></td><td>
+<div><a href='https://ci.nedprod.com/job/Boost.AFIO%20Valgrind%20Linux%20GCC%204.8/'><img src='https://ci.nedprod.com/buildStatus/icon?job=Boost.AFIO%20Valgrind%20Linux%20GCC%204.8' /></a></div></td>
+</tr>
+
+<!-- sep -->
+<tr></tr>
+
+<!-- os x -->
+<tr align="center"><td>Apple Mac OS X 10.9</td><td>clang 3.5</td><td>libc++</td><td>x64</td><td>
+<div><a href="https://travis-ci.org/BoostGSoC13/boost.afio"><img valign="middle" src="https://travis-ci.org/BoostGSoC13/boost.afio.png?branch=master"/></a></div></td><td>
+<div><a href="https://travis-ci.org/BoostGSoC13/boost.afio"><img valign="middle" src="https://travis-ci.org/BoostGSoC13/boost.afio.png?branch=master"/></a></div></td>
+</tr>
+''')
+
+# <a href='https://ci.nedprod.com/job/Boost.AFIO%20Build/CPPSTD=c++11,CXX=g++-4.8,LINKTYPE=static,label=android-ndk/'><img src='https://ci.nedprod.com/job/Boost.AFIO%20Build/CPPSTD=c++11,CXX=g++-4.8,LINKTYPE=static,label=android-ndk/badge/icon'></a>
+
+for line, items in inputs:
+ if line[0]==0:
+ line=("",)+line[2:]
+ else:
+ line=('<td rowspan="'+str(line[0])+'">'+line[1]+'</td>',)+line[2:]
+ print('<tr align="center">%s<td>%s</td><td>%s</td><td>%s</td><td>' % line)
+ label=items["label"]
+ cppstds=items["CPPSTD"] if "CPPSTD" in items else CPPSTDs
+ cxxs=items["CXX"] if "CXX" in items else CXXs
+ linktypes=items["LINKTYPE"] if "LINKTYPE" in items else LINKTYPEs
+ for cppstd in cppstds:
+ for cxx in cxxs:
+ for linktype in linktypes:
+ print(' <div><a href="https://ci.nedprod.com/job/Boost.AFIO%%20Build/CPPSTD=%s,CXX=%s,LINKTYPE=%s,label=%s/"><img src="https://ci.nedprod.com/job/Boost.AFIO%%20Build/CPPSTD=%s,CXX=%s,LINKTYPE=%s,label=%s/badge/icon" /></a></div>' % (cppstd, cxx, linktype, label, cppstd, cxx, linktype, label))
+ print('</td><td>')
+ for cppstd in cppstds:
+ for cxx in cxxs:
+ for linktype in linktypes:
+ print(' <div><a href="https://ci.nedprod.com/job/Boost.AFIO%%20Test/CPPSTD=%s,CXX=%s,LINKTYPE=%s,label=%s/"><img src="https://ci.nedprod.com/job/Boost.AFIO%%20Test/CPPSTD=%s,CXX=%s,LINKTYPE=%s,label=%s/badge/icon" /></a></div>' % (cppstd, cxx, linktype, label, cppstd, cxx, linktype, label))
+ print('</td></tr>')
+
+print('''</table>
+
+</center>
+''')
diff --git a/scripts/JenkinsMatrixToDashboard.py b/scripts/JenkinsMatrixToDashboard.py
new file mode 100755
index 00000000..7ba67b7d
--- /dev/null
+++ b/scripts/JenkinsMatrixToDashboard.py
@@ -0,0 +1,83 @@
+#!/usr/bin/python3
+
+import sys
+from urllib.request import urlopen
+from lxml import etree
+from lxml.html import parse
+
+if len(sys.argv)<3:
+ print(sys.argv[0], "<output html file> <url>")
+ sys.exit(1)
+outfile=sys.argv[1]
+url=sys.argv[2]
+
+p=parse(urlopen(url)).getroot()
+p.make_links_absolute(url)
+matrix=p.xpath("//table[@id='configuration-matrix']")
+matrixrows=matrix[0].xpath("tr")
+
+# First <tr> is compilers, and colspan on first td is number of horizontal qualifiers
+# Second <tr> first <td> is each build target, and rowspan is number of vertical qualifiers
+columntocompiler=[]
+for x in matrixrows[0]:
+ for n in range(0, int(x.get("colspan"))):
+ columntocompiler.append(x.text)
+matrixrows=matrixrows[1:]
+print(columntocompiler)
+
+# Essentially we column collapse the matrix into HTML. Quite straightforward.
+class Platform:
+ def __init__(self, name):
+ self.name=name
+ self.rows=[]
+
+platforms=[]
+rowspan=0
+for row in matrixrows:
+ cols=row.xpath("td")
+ outrow=""
+ count=0
+ for x in range(0, len(cols)):
+ if x==0 and rowspan==0:
+ rowspan=int(cols[x].get("rowspan"))
+ platform=Platform(cols[x].text)
+ platforms.append(platform)
+ count+=0.5
+ col=cols[x]
+ atags=col.xpath("div/a")
+ imgs=col.xpath("div/img")
+ if len(atags)==0 and len(imgs)==0:
+ col.set('valign', 'top')
+ outrow+=etree.tostring(col).decode('utf-8')
+ elif len(atags)!=0 and len(imgs)==0:
+ # Format: <div><a class="model-link inside" href="CPPSTD=c++11,CXX=clang++-3.5,LINKTYPE=shared,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="/static/5585b9ed/images/24x24/blue.png" tooltip="Success" /></a></div>
+ #col=col[:]
+ # Replace img src with something dynamic
+ # Form: https://ci.nedprod.com/job/Maidsafe%20CRUX/CPPSTD=c++11,CXX=g++-4.9,LINKTYPE=shared,label=arm-gcc-clang/badge/icon
+ joburl=atags[0].get("href")
+ imgs=atags[0].xpath("img")
+ del imgs[0].attrib["width"]
+ del imgs[0].attrib["height"]
+ imgs[0].set('src', joburl+"badge/icon")
+ imgs[0].set('align', "top")
+ # Insert target name just inside end of div
+ col.getchildren()[-1].getchildren()[-1].tail=" "+columntocompiler[len(columntocompiler)-(len(cols)-x)]
+ outrow+=etree.tostring(col).decode('utf-8')
+ count+=1
+ if count==0.5:
+ platform.rows.append(outrow[:outrow.find("</td>")+5])
+ elif count:
+ platform.rows.append(outrow)
+ else:
+ platform.rows.append("<td/>")
+ rowspan-=1
+
+with open(outfile, 'wt') as oh:
+ oh.write('<html><body><table id="configuration-matrix" width="100%" border="1">\n')
+ for platform in platforms:
+ for y in range(0, len(platform.rows)):
+ oh.write(' <tr>\n')
+ oh.write(' '+platform.rows[y]+'\n')
+ oh.write(' </tr>\n')
+ oh.write('</table></body></html>\n')
+
diff --git a/scripts/SoakTest.py b/scripts/SoakTest.py
new file mode 100755
index 00000000..30dddc5f
--- /dev/null
+++ b/scripts/SoakTest.py
@@ -0,0 +1,16 @@
+#!/usr/bin/python
+# Repeatedly runs a process until it crashes
+# (C) 2014 Niall Douglas
+# File created: Feb 2014
+
+import subprocess, sys
+
+if len(sys.argv)<2:
+ raise Exception("Need to specify a process to run!")
+
+n=1
+while True:
+ print("\n"+str(n)+": Running process "+sys.argv[1]+" ...")
+ subprocess.check_call(sys.argv[1])
+ n=n+1
+
diff --git a/scripts/XMLTidy.py b/scripts/XMLTidy.py
new file mode 100755
index 00000000..8ff1838a
--- /dev/null
+++ b/scripts/XMLTidy.py
@@ -0,0 +1,28 @@
+#!/usr/bin/python3
+# Tidy and repair malformed XML like that produced by CATCH under multithreaded use :)
+# (C) 2015 Niall Douglas http://www.nedprod.com/
+# Created: 22nd Feb 2015
+
+import sys, lxml.etree
+
+if len(sys.argv)<2:
+ print("Usage: "+sys.argv[0]+" <input> [<output>]", file=sys.stderr)
+ sys.exit(1)
+inputpath=sys.argv[1]
+if len(sys.argv)>2:
+ outputpath=sys.argv[2]
+else:
+ outputpath=None
+
+parser=lxml.etree.XMLParser(recover=True)
+tree=lxml.etree.parse(inputpath, parser)
+if parser.error_log:
+ print("Errors during XML parsing:", file=sys.stderr)
+ print(parser.error_log, file=sys.stderr)
+newxml=lxml.etree.tostring(tree.getroot())
+
+if outputpath is None:
+ print(newxml)
+else:
+ with open(outputpath, 'wb') as oh:
+ oh.write(newxml)
diff --git a/scripts/readme_to_html.sh b/scripts/readme_to_html.sh
new file mode 100755
index 00000000..b27ee45f
--- /dev/null
+++ b/scripts/readme_to_html.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+echo '<html xmlns="http://www.w3.org/1999/xhtml"><body>
+' > Readme.html
+cat Readme.md >> Readme.html
+echo '
+</body></html>
+' >> Readme.html
+xsltproc scripts/xhtml_to_docbook.xsl Readme.html > Readme.docbook
diff --git a/scripts/travis_lldb.expect b/scripts/travis_lldb.expect
new file mode 100644
index 00000000..d5466fad
--- /dev/null
+++ b/scripts/travis_lldb.expect
@@ -0,0 +1,10 @@
+spawn lldb ./test_all
+expect "*\nCurrent executable set to*"
+send "run\r"
+set timeout 120
+expect "*\r\nProcess * stopped\r\n*"
+send "bt\rthread list\rthread backtrace all\rquit\r"
+set timeout 10
+expect "*Quitting LLDB will kill one or more processes. Do you really want to proceed*"
+send "y\r"
+expect default
diff --git a/scripts/xhtml_to_docbook.xsl b/scripts/xhtml_to_docbook.xsl
new file mode 100644
index 00000000..4b7bdbca
--- /dev/null
+++ b/scripts/xhtml_to_docbook.xsl
@@ -0,0 +1,537 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:fo="http://www.w3.org/1999/XSL/Format"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns:saxon="http://icl.com/saxon"
+ exclude-result-prefixes="xsl fo html saxon">
+
+<xsl:output momit-xml-declaration="yes" method="xml" media-type="application/xhtml+xml"
+doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
+doctype-public="-//W3C//DTD XHTML 1.1//EN" encoding="UTF-8" indent="yes"/>
+<xsl:param name="filename"></xsl:param>
+<xsl:param name="prefix">wb</xsl:param>
+<xsl:param name="graphics_location"></xsl:param>
+
+<!-- Main block-level conversions -->
+<xsl:template match="html:html">
+ <xsl:apply-templates select="html:body"/>
+</xsl:template>
+
+<!-- This template converts each HTML file encountered into a DocBook
+ section. For a title, it selects the first h1 element -->
+<xsl:template match="html:body">
+ <section>
+ <xsl:if test="$filename != ''">
+ <xsl:attribute name="id">
+ <xsl:value-of select="$prefix"/>
+ <xsl:text>_</xsl:text>
+ <xsl:value-of select="translate($filename,' ()','__')"/>
+ </xsl:attribute>
+ </xsl:if>
+ <title>
+ <xsl:value-of select=".//html:h1[1]
+ |.//html:h2[1]
+ |.//html:h3[1]"/>
+ </title>
+ <xsl:apply-templates select="*"/>
+ </section>
+</xsl:template>
+
+<!-- This template matches on all HTML header items and makes them into
+ bridgeheads. It attempts to assign an ID to each bridgehead by looking
+ for a named anchor as a child of the header or as the immediate preceding
+ or following sibling -->
+<xsl:template match="html:h1
+ |html:h2
+ |html:h3
+ |html:h4
+ |html:h5
+ |html:h6">
+ <bridgehead>
+ <xsl:choose>
+ <xsl:when test="count(html:a/@name)">
+ <xsl:attribute name="id">
+ <xsl:value-of select="html:a/@name"/>
+ </xsl:attribute>
+ </xsl:when>
+ <xsl:when test="preceding-sibling::* = preceding-sibling::html:a[@name != '']">
+ <xsl:attribute name="id">
+ <xsl:value-of select="concat($prefix,preceding-sibling::html:a[1]/@name)"/>
+ </xsl:attribute>
+ </xsl:when>
+ <xsl:when test="following-sibling::* = following-sibling::html:a[@name != '']">
+ <xsl:attribute name="id">
+ <xsl:value-of select="concat($prefix,following-sibling::html:a[1]/@name)"/>
+ </xsl:attribute>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:apply-templates/>
+ </bridgehead>
+</xsl:template>
+
+<!-- These templates perform one-to-one conversions of HTML elements into
+ DocBook elements -->
+<xsl:template match="html:p|html:center|html:div">
+<!-- if the paragraph has no text (perhaps only a child <img>), don't
+ make it a para -->
+ <xsl:choose>
+ <xsl:when test="normalize-space(.) = ''">
+ <xsl:apply-templates/>
+ </xsl:when>
+ <xsl:otherwise>
+ <para>
+ <xsl:apply-templates/>
+ </para>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+<xsl:template match="html:pre">
+ <programlisting>
+ <xsl:apply-templates/>
+ </programlisting>
+</xsl:template>
+
+<!-- Hyperlinks -->
+<xsl:template match="html:a[contains(@href,'http://')]" priority="1.5">
+ <ulink>
+ <xsl:attribute name="url">
+ <xsl:value-of select="normalize-space(@href)"/>
+ </xsl:attribute>
+ <xsl:apply-templates/>
+ </ulink>
+</xsl:template>
+
+<xsl:template match="html:a[contains(@href,'https://')]" priority="1.5">
+ <ulink>
+ <xsl:attribute name="url">
+ <xsl:value-of select="normalize-space(@href)"/>
+ </xsl:attribute>
+ <xsl:apply-templates/>
+ </ulink>
+</xsl:template>
+
+<xsl:template match="html:a[contains(@href,'#')]" priority="0.6">
+ <xref>
+ <xsl:attribute name="linkend">
+ <xsl:call-template name="make_id">
+ <xsl:with-param name="string" select="substring-after(@href,'#')"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ </xref>
+</xsl:template>
+
+<xsl:template match="html:a[@href != '']">
+ <xref>
+ <xsl:attribute name="linkend">
+ <xsl:value-of select="$prefix"/>
+ <xsl:text>_</xsl:text>
+ <xsl:call-template name="make_id">
+ <xsl:with-param name="string" select="@href"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ </xref>
+</xsl:template>
+
+<!-- Need to come up with good template for converting filenames into ID's -->
+<xsl:template name="make_id">
+ <xsl:param name="string" select="''"/>
+ <xsl:variable name="fixedname">
+ <xsl:call-template name="get_filename">
+ <xsl:with-param name="path" select="translate($string,' \()','_/_')"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="contains($fixedname,'.htm')">
+ <xsl:value-of select="substring-before($fixedname,'.htm')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$fixedname"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="string.subst">
+ <xsl:param name="string" select="''"/>
+ <xsl:param name="substitute" select="''"/>
+ <xsl:param name="with" select="''"/>
+ <xsl:choose>
+ <xsl:when test="contains($string,$substitute)">
+ <xsl:variable name="pre" select="substring-before($string,$substitute)"/>
+ <xsl:variable name="post" select="substring-after($string,$substitute)"/>
+ <xsl:call-template name="string.subst">
+ <xsl:with-param name="string" select="concat($pre,$with,$post)"/>
+ <xsl:with-param name="substitute" select="$substitute"/>
+ <xsl:with-param name="with" select="$with"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$string"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- Images -->
+<!-- Images and image maps -->
+<xsl:template match="html:img">
+ <xsl:variable name="tag_name">
+ <xsl:choose>
+ <xsl:when test="boolean(parent::html:p) and
+ boolean(normalize-space(parent::html:p/text()))">
+ <xsl:text>inlinemediaobject</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>mediaobject</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:element name="{$tag_name}">
+ <imageobject>
+ <xsl:call-template name="process.image"/>
+ </imageobject>
+ </xsl:element>
+</xsl:template>
+
+<xsl:template name="process.image">
+ <imagedata>
+<xsl:attribute name="fileref">
+<!--
+ <xsl:call-template name="make_absolute">
+ <xsl:with-param name="filename" select="@src"/>
+ </xsl:call-template>
+ -->
+ <xsl:value-of select="@src"/>
+</xsl:attribute>
+<xsl:if test="@height != ''">
+ <xsl:attribute name="depth">
+ <xsl:value-of select="@height"/>
+ </xsl:attribute>
+</xsl:if>
+<xsl:if test="@width != ''">
+ <xsl:attribute name="width">
+ <xsl:value-of select="@width"/>
+ </xsl:attribute>
+</xsl:if>
+ </imagedata>
+</xsl:template>
+
+<xsl:template name="make_absolute">
+ <xsl:param name="filename"/>
+ <xsl:variable name="name_only">
+ <xsl:call-template name="get_filename">
+ <xsl:with-param name="path" select="$filename"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:value-of select="$graphics_location"/><xsl:value-of select="$name_only"/>
+</xsl:template>
+
+<xsl:template match="html:ul[count(*) = 0]">
+ <xsl:message>Matched</xsl:message>
+ <blockquote>
+ <xsl:apply-templates/>
+ </blockquote>
+</xsl:template>
+
+<xsl:template name="get_filename">
+ <xsl:param name="path"/>
+ <xsl:choose>
+ <xsl:when test="contains($path,'/')">
+ <xsl:call-template name="get_filename">
+ <xsl:with-param name="path" select="substring-after($path,'/')"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$path"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- LIST ELEMENTS -->
+<xsl:template match="html:ul">
+ <itemizedlist>
+ <xsl:apply-templates/>
+ </itemizedlist>
+</xsl:template>
+
+<xsl:template match="html:ol">
+ <orderedlist>
+ <xsl:apply-templates/>
+ </orderedlist>
+</xsl:template>
+
+<!-- This template makes a DocBook variablelist out of an HTML definition list -->
+<xsl:template match="html:dl">
+ <variablelist>
+ <xsl:for-each select="html:dt">
+ <varlistentry>
+ <term>
+ <xsl:apply-templates/>
+ </term>
+ <listitem>
+ <xsl:apply-templates select="following-sibling::html:dd[1]"/>
+ </listitem>
+ </varlistentry>
+ </xsl:for-each>
+ </variablelist>
+</xsl:template>
+
+<xsl:template match="html:dd">
+ <xsl:choose>
+ <xsl:when test="boolean(html:p)">
+ <xsl:apply-templates/>
+ </xsl:when>
+ <xsl:otherwise>
+ <para>
+ <xsl:apply-templates/>
+ </para>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="html:li">
+ <listitem>
+ <xsl:choose>
+ <xsl:when test="count(html:p) = 0">
+ <para>
+ <xsl:apply-templates/>
+ </para>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </listitem>
+</xsl:template>
+
+<xsl:template match="*">
+ <xsl:message>No template for <xsl:value-of select="name()"/>
+ </xsl:message>
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="@*">
+ <xsl:message>No template for <xsl:value-of select="name()"/>
+ </xsl:message>
+ <xsl:apply-templates/>
+</xsl:template>
+
+<!-- inline formatting -->
+<xsl:template match="html:b">
+ <emphasis role="bold">
+ <xsl:apply-templates/>
+ </emphasis>
+</xsl:template>
+<xsl:template match="html:i">
+ <emphasis>
+ <xsl:apply-templates/>
+ </emphasis>
+</xsl:template>
+<xsl:template match="html:u">
+ <citetitle>
+ <xsl:apply-templates/>
+ </citetitle>
+</xsl:template>
+
+<!-- Ignored elements -->
+<xsl:template match="html:hr"/>
+<xsl:template match="html:h1[1]|html:h2[1]|html:h3[1]" priority="1"/>
+<xsl:template match="html:br"/>
+<xsl:template match="html:p[normalize-space(.) = '' and count(*) = 0]"/>
+<xsl:template match="text()">
+ <xsl:choose>
+ <xsl:when test="normalize-space(.) = ''"></xsl:when>
+ <xsl:otherwise><xsl:copy/></xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- Workbench Hacks -->
+<xsl:template match="html:div[contains(@style,'margin-left: 2em')]">
+ <blockquote><para>
+ <xsl:apply-templates/></para>
+ </blockquote>
+</xsl:template>
+
+<xsl:template match="html:a[@href != ''
+ and not(boolean(ancestor::html:p|ancestor::html:li))]"
+ priority="1">
+ <para>
+ <xref>
+ <xsl:attribute name="linkend">
+ <xsl:value-of select="$prefix"/>
+ <xsl:text>_</xsl:text>
+ <xsl:call-template name="make_id">
+ <xsl:with-param name="string" select="@href"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ </xref>
+ </para>
+</xsl:template>
+
+<xsl:template match="html:a[contains(@href,'#')
+ and not(boolean(ancestor::html:p|ancestor::html:li))]"
+ priority="1.1">
+ <para>
+ <xref>
+ <xsl:attribute name="linkend">
+ <xsl:value-of select="$prefix"/>
+ <xsl:text>_</xsl:text>
+ <xsl:call-template name="make_id">
+ <xsl:with-param name="string" select="substring-after(@href,'#')"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ </xref>
+ </para>
+</xsl:template>
+
+<!-- Table conversion -->
+<xsl:template match="html:table">
+<!-- <xsl:variable name="column_count"
+ select="saxon:max(.//html:tr,saxon:expression('count(html:td)'))"/> -->
+ <xsl:variable name="column_count">
+ <xsl:call-template name="count_columns">
+ <xsl:with-param name="table" select="."/>
+ </xsl:call-template>
+ </xsl:variable>
+ <informaltable>
+ <tgroup>
+ <xsl:attribute name="cols">
+ <xsl:value-of select="$column_count"/>
+ </xsl:attribute>
+ <xsl:call-template name="generate-colspecs">
+ <xsl:with-param name="count" select="$column_count"/>
+ </xsl:call-template>
+ <thead>
+ <xsl:apply-templates select="html:tr[1]"/>
+ </thead>
+ <tbody>
+ <xsl:apply-templates select="html:tr[position() != 1]"/>
+ </tbody>
+ </tgroup>
+ </informaltable>
+</xsl:template>
+
+<xsl:template name="generate-colspecs">
+ <xsl:param name="count" select="0"/>
+ <xsl:param name="number" select="1"/>
+ <xsl:choose>
+ <xsl:when test="$count &lt; $number"/>
+ <xsl:otherwise>
+ <colspec>
+ <xsl:attribute name="colnum">
+ <xsl:value-of select="$number"/>
+ </xsl:attribute>
+ <xsl:attribute name="colname">
+ <xsl:value-of select="concat('col',$number)"/>
+ </xsl:attribute>
+ </colspec>
+ <xsl:call-template name="generate-colspecs">
+ <xsl:with-param name="count" select="$count"/>
+ <xsl:with-param name="number" select="$number + 1"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="html:tr">
+ <row>
+ <xsl:apply-templates/>
+ </row>
+</xsl:template>
+
+<xsl:template match="html:th|html:td">
+ <xsl:variable name="position" select="count(preceding-sibling::*) + 1"/>
+ <entry>
+ <xsl:if test="@colspan &gt; 1">
+ <xsl:attribute name="namest">
+ <xsl:value-of select="concat('col',$position)"/>
+ </xsl:attribute>
+ <xsl:attribute name="nameend">
+ <xsl:value-of select="concat('col',$position + number(@colspan) - 1)"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="@rowspan &gt; 1">
+ <xsl:attribute name="morerows">
+ <xsl:value-of select="number(@rowspan) - 1"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:apply-templates/>
+ </entry>
+</xsl:template>
+
+<xsl:template match="html:td_null">
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template name="count_columns">
+ <xsl:param name="table" select="."/>
+ <xsl:param name="row" select="$table/html:tr[1]"/>
+ <xsl:param name="max" select="0"/>
+ <xsl:choose>
+ <xsl:when test="local-name($table) != 'table'">
+ <xsl:message>Attempting to count columns on a non-table element</xsl:message>
+ </xsl:when>
+ <xsl:when test="local-name($row) != 'tr'">
+ <xsl:message>Row parameter is not a valid row</xsl:message>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- Count cells in the current row -->
+ <xsl:variable name="current_count">
+ <xsl:call-template name="count_cells">
+ <xsl:with-param name="cell" select="$row/html:td[1]|$row/html:th[1]"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <!-- Check for the maximum value of $current_count and $max -->
+ <xsl:variable name="new_max">
+ <xsl:choose>
+ <xsl:when test="$current_count &gt; $max">
+ <xsl:value-of select="number($current_count)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="number($max)"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <!-- If this is the last row, return $max, otherwise continue -->
+ <xsl:choose>
+ <xsl:when test="count($row/following-sibling::html:tr) = 0">
+ <xsl:value-of select="$new_max"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="count_columns">
+ <xsl:with-param name="table" select="$table"/>
+ <xsl:with-param name="row" select="$row/following-sibling::html:tr"/>
+ <xsl:with-param name="max" select="$new_max"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="count_cells">
+ <xsl:param name="cell"/>
+ <xsl:param name="count" select="0"/>
+ <xsl:variable name="new_count">
+ <xsl:choose>
+ <xsl:when test="$cell/@colspan &gt; 1">
+ <xsl:value-of select="number($cell/@colspan) + number($count)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="number('1') + number($count)"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="count($cell/following-sibling::*) &gt; 0">
+ <xsl:call-template name="count_cells">
+ <xsl:with-param name="cell"
+ select="$cell/following-sibling::*[1]"/>
+ <xsl:with-param name="count" select="$new_count"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$new_count"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
+