@@ -33,11 +33,11 @@
#
# By Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at> 1999-12-29.
-MHC=${MHC-/usr/local/bin/mhc}
-
SOURCETREE=${SOURCETREE-/www/gcc/htdocs-preformatted}
DESTTREE=${DESTTREE-/www/gcc/htdocs}
+BINDIR=${SOURCETREE}/../bin
+
STYLE=$SOURCETREE/style.mhtml
IGNORE_DIFF_MARKER="IGNORE DIFF"
@@ -102,29 +102,26 @@ process_html_file()
fdest=$2
# Set environment variable PREPROCESS_FILE, which will then be
- # accessible by MetaHTML.
+ # accessible by bin/process-html-file.py.
PREPROCESS_FILE=$f
export PREPROCESS_FILE
- # Prepend the MetaHTML style, set the MetaHTML include directory,
+ # Prepend the MetaHTML include directory,
# and process the page.
-
- cat $STYLE > $TMPDIR/input
printf '<set-var MHTML::INCLUDE-PREFIX="%s">\n' `pwd` >> $TMPDIR/input
cat $f >> $TMPDIR/input
- if ! ${MHC} $TMPDIR/input > $TMPDIR/output.raw; then
- echo "${MHC} failed; aborting."
+ # Process the page.
+ if ! $BINDIR/process-html-file.py $TMPDIR/input > $TMPDIR/output.raw; then
+ echo "$BINDIR/process-html-file.py failed; aborting."
exit 1
fi
# Use sed to work around makeinfo 4.7 brokenness.
- # Use sed to work around MetaHTML brokenness wrt. <DIV>.
# Then remove leading blank lines and single line comments.
cat $TMPDIR/output.raw \
| sed -e 's/_002d/-/g' -e 's/_002a/*/g' \
- | sed -e 's/<DIV/<div/g' \
| awk -- \
'/^( *)?$/ { if( ! body ) next } \
/^<!--.*-->$/ { if( ! body ) next } \
@@ -132,7 +129,7 @@ process_html_file()
> $TMPDIR/output
# Copy the page only if it's new or there has been a change, and,
- # first of all, if there was no problem when running MetaHTML.
+ # first of all, if there was no problem when running process-html-file.py
if [ $? -ne 0 ]; then
echo " Problem processing $f; not updated!"
elif [ ! -f $fdest ]; then
@@ -221,11 +218,6 @@ shift `expr ${OPTIND} - 1`
## Various safety checks.
-if ! ${MHC} --version >/dev/null; then
- echo "Something does not look right with \"${MHC}\"; aborting."
- exit 1
-fi
-
if [ ! -d $SOURCETREE ]; then
echo "Source tree \"$SOURCETREE\" does not exist."
exit 1
new file mode 100755
@@ -0,0 +1,321 @@
+#!/usr/bin/python3
+#
+# Copyright (C) 2018 Free Software Foundation, Inc.
+#
+# Contributed by David Malcolm
+#
+# GCC is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 3, or (at your option) any later
+# version.
+#
+# GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+import datetime
+import os
+import re
+import sys
+import unittest
+
+NAVIGATION_FOOTER = """
+ </td> <!-- end of main frame -->
+
+ <td valign="top"> <!-- nav frame -->
+ <table class="nav" border="0" cellpadding="2" width="10em">
+
+ <tr><td><table class="navitem" width="100%">
+ <tr><td>About GCC</td></tr>
+ <tr><td>
+ <a href="<get-var BACKPATH>gccmission.html">Mission Statement</a><br />
+ <a href="<get-var BACKPATH>releases.html">Releases</a><br />
+ <a href="<get-var BACKPATH>snapshots.html">Snapshots</a><br />
+ <a href="<get-var BACKPATH>lists.html">Mailing lists</a><br />
+ <a href="https://gcc.gnu.org/onlinedocs/gcc/Contributors.html">Contributors</a><br />
+ <a href="<get-var BACKPATH>steering.html">Steering Committee</a><br />
+ <div align="center">
+ <a href="https://twitter.com/gnutools">
+ <img src="<get-var BACKPATH>twitter-bird-light-bgs.png"
+ height="42" width="42" align="middle" alt="@gnutools on Twitter"
+ />@gnutools</a>
+ </div>
+ <div align="center">
+ <a href="https://plus.google.com/108467477471815191158">
+ <img src="<get-var BACKPATH>gplus-32.png"
+ height="24" width="24" align="middle" alt="gnutools on Google+"
+ /> gnutools</a>
+ </div>
+ <div align="center">
+ <a href="https://my.fsf.org/civicrm/contribute/transact?reset=1&id=57">
+ <img src="<get-var BACKPATH>donate-110-23.png"
+ height="23" width="100" align="middle" alt="Donate to GNU Toolchain Fund"
+ /></a>
+ </div>
+ </td></tr>
+ </table></td></tr>
+
+ <tr><td><table class="navitem" width="100%">
+ <tr><td>Documentation</td></tr>
+ <tr><td>
+ <a href="https://gcc.gnu.org/install/">Installation</a><br />
+ · <a href="https://gcc.gnu.org/install/specific.html">Platforms</a><br />
+ <a href="<get-var BACKPATH>onlinedocs/">Manual</a><br />
+ <a href="<get-var BACKPATH>faq.html">FAQ</a><br />
+ <a href="https://gcc.gnu.org/wiki">Wiki</a><br />
+ <a href="<get-var BACKPATH>readings.html">Pointers</a>
+ </td></tr>
+ </table></td></tr>
+
+ <tr><td><table class="navitem" width="100%">
+ <tr><td>Download</td></tr>
+ <tr><td>
+ <a href="<get-var BACKPATH>mirrors.html">Mirrors</a><br />
+ <a href="https://gcc.gnu.org/install/binaries.html">Binaries</a>
+ </td></tr>
+ </table></td></tr>
+
+ <tr><td><table class="navitem" width="100%">
+ <tr><td>Sources</td></tr>
+ <tr><td>
+ <a href="<get-var BACKPATH>svn.html">SVN read access</a><br />
+ <a href="<get-var BACKPATH>svnwrite.html">SVN write access</a><br />
+ <a href="https://gcc.gnu.org/wiki/GitMirror">Git read access</a><br />
+ <a href="<get-var BACKPATH>rsync.html">Rsync</a><br />
+ </td></tr>
+ </table></td></tr>
+
+ <tr><td><table class="navitem" width="100%">
+ <tr><td>Development</td></tr>
+ <tr><td>
+ <a href="<get-var BACKPATH>develop.html">Development Plan</a><br />
+ · <a href="<get-var BACKPATH>develop.html#timeline">Timeline</a><br />
+ <a href="<get-var BACKPATH>contribute.html">Contributing</a><br />
+ <a href="<get-var BACKPATH>contributewhy.html">Why contribute?</a><br />
+ <a href="<get-var BACKPATH>projects/">Open projects</a><br />
+ <a href="<get-var BACKPATH>frontends.html">Front ends</a><br />
+ <a href="<get-var BACKPATH>backends.html">Back ends</a><br />
+ <a href="<get-var BACKPATH>extensions.html">Extensions</a><br />
+ <a href="<get-var BACKPATH>benchmarks/">Benchmarks</a><br />
+ <a href="http://toolchain.lug-owl.de/buildbot/">Build Robot</a><br />
+ <a href="<get-var BACKPATH>translation.html">Translations</a><br />
+ </td></tr>
+ </table></td></tr>
+
+ <tr><td><table class="navitem" width="100%">
+ <tr><td>Bugs</td></tr>
+ <tr><td>
+ <a href="<get-var BACKPATH>bugs/#known">Known bugs</a><br />
+ <a href="<get-var BACKPATH>bugs/">How to report</a><br />
+ <a href="https://gcc.gnu.org/bugzilla/">Bug tracker</a><br />
+ · <a href="<get-var BACKPATH>bugs/management.html">Management</a>
+ </td></tr>
+ </table></td></tr>
+
+ </table>
+ </td> <!-- end of nav frame -->
+
+ </tr>
+ </table>
+
+"""
+
+FOOTER = """
+<!-- ==================================================================== -->
+
+<div class="copyright">
+
+<address>For questions related to the use of GCC,
+please consult these web pages and the
+<a href="https://gcc.gnu.org/onlinedocs/">GCC manuals</a>. If that fails,
+the <a href="mailto:gcc-help@gcc.gnu.org">gcc-help@gcc.gnu.org</a>
+mailing list might help.
+Comments on these web pages and the development of GCC are welcome on our
+developer list at <a href="mailto:gcc@gcc.gnu.org">gcc@gcc.gnu.org</a>.
+All of <a href="https://gcc.gnu.org/lists.html">our lists</a>
+have public archives.
+</address>
+
+<p>Copyright (C)
+<a href="https://www.fsf.org">Free Software Foundation, Inc.</a>
+Verbatim copying and distribution of this entire article is
+permitted in any medium, provided this notice is preserved.</p>
+
+<p>These pages are
+<a href="https://gcc.gnu.org/about.html">maintained by the GCC team</a>.
+Last modified <date::format-time "YYYY-MM-DD"><!-- IGNORE DIFF
+--><a href="http://validator.w3.org/check/referer">.</a></p>
+
+</div>
+
+<!-- ==================================================================== -->
+
+"""
+
+def process(src_content, src_filename):
+ """
+ Given SRC_CONTENT, the input HTML page, return a string containing
+ the final HTML to be written out to be served.
+ """
+ xhtml = True
+ backpath = ''
+
+ # The "install/" pages are HTML, not XHTML.
+ if src_filename.startswith('install/'):
+ xhtml = False
+
+ # Strip out MetaHTML directives
+ include_prefix = None
+
+ m = re.match('<set-var MHTML::INCLUDE-PREFIX="(.*)">', src_content)
+ if m:
+ include_prefix = m.group(1)
+ src_content = src_content[:m.start()] + src_content[m.end():]
+
+ if '<set-var navigation>' in src_content:
+ navigation = True
+ src_content = src_content.replace('<set-var navigation>', '')
+ else:
+ navigation = False
+
+ if '<include searchbox.ihtml>' in src_content:
+ with open(os.path.join(include_prefix, 'searchbox.ihtml')) as f:
+ included_content = f.read()
+ src_content = src_content.replace('<include searchbox.ihtml>', included_content)
+
+ if xhtml:
+ dst_content = ('<?xml version="1.0" encoding="utf-8"?>\n'
+ ' <!DOCTYPE html\n'
+ ' PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n'
+ ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n'
+ ' \n\n\n \n' + ('\n' * 9))
+ else:
+ dst_content = (' <?xml version="1.0" encoding="utf-8"?>\n'
+ ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n'
+ ' \n' + ('\n' * 13))
+
+ for line in src_content.splitlines():
+ if xhtml:
+ # Redefine the <html> tag so that we can put XHTML attributes inside.
+ if line == '<html>':
+ dst_content += ' <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n \n'
+ continue
+ if line == '</html>':
+ dst_content += ' </html>\n \n '
+ continue
+
+ # Redefine the <head> tag so that we can add default <meta /> headers.
+ if line == '<head>':
+ if navigation:
+ dst_content += ' '
+ else:
+ dst_content += ' \n'
+ if xhtml:
+ dst_content += \
+ (' <head>\n'
+ ' \n'
+ ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n'
+ ' <link rel="shortcut icon" href="https://gcc.gnu.org/favicon.ico" />\n'
+ ' \n ')
+ else:
+ dst_content += \
+ (' <head>\n'
+ ' \n'
+ ' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n'
+ ' <link rel="shortcut icon" href="https://gcc.gnu.org/favicon.ico">\n'
+ ' <link rel="stylesheet" type="text/css" href="/gcc.css">\n')
+ continue
+ if line == '</head>':
+ dst_content += ' </head>\n \n'
+ continue
+
+ # Redefine the <title> tag to comply with the GNU style.
+ m = re.match('<title>(.*)</title>', line)
+ if m:
+ dst_content += ('<title>\n'
+ + m.group(1) + '\n'
+ + '- GNU Project - Free Software Foundation (FSF)</title>\n')
+ continue
+
+ # Stay faithful to what MetaHTML emitted:
+ if line == '<div>':
+ line = '<div >'
+
+ # Redefine the <body> tag, adding navigation and a standard footer.
+ if line == '<body>':
+ if navigation:
+ dst_content += \
+ ('<body>\n'
+ '\n'
+ ' <table border="0" cellspacing="0" cellpadding="2">\n'
+ ' <tr>\n'
+ '\n'
+ ' <td valign="top" width="99%"> <!-- main frame -->\n \n\n')
+ continue
+ else:
+ dst_content += '<body>\n\n\n\n'
+ continue
+ if line == '</body>':
+ if navigation:
+ dst_content += NAVIGATION_FOOTER.replace('<get-var BACKPATH>', backpath)
+ else:
+ dst_content += '\n\n'
+ if '<date::format-time "YYYY-MM-DD">' in FOOTER:
+ dst_content += FOOTER.replace('<date::format-time "YYYY-MM-DD">',
+ datetime.date.today().isoformat())
+
+ dst_content += line + '\n'
+
+
+ return dst_content
+
+class Tests(unittest.TestCase):
+ def test_xhtml_head(self):
+ dst_content = process('<head>\n</head>\n', 'not-in-install.html')
+ self.assertTrue(dst_content.startswith('<?xml version="1.0" encoding="utf-8"?>'))
+
+ def test_html_head(self):
+ dst_content = process('<head>\n</head>\n', 'install/foo.html')
+ self.assertTrue(dst_content.startswith(' <?xml version="1.0" encoding="utf-8"?>'))
+
+ def test_title(self):
+ dst_content = process('<title>Foo</title>\n', 'not-in-install.html')
+ self.assertIn('<title>\n'
+ 'Foo\n'
+ '- GNU Project - Free Software Foundation (FSF)</title>\n', dst_content)
+
+ self.assertTrue(dst_content.startswith('<?xml version="1.0" encoding="utf-8"?>'))
+
+ def test_footer(self):
+ dst_content = process('<body>\n</body>\n', 'not-in-install.html')
+ self.assertIn('<p>These pages are', dst_content)
+
+ def test_include(self):
+ dst_content = process('<set-var MHTML::INCLUDE-PREFIX="../htdocs">\n<include searchbox.ihtml>\n',
+ 'not-in-install.html')
+ self.assertNotIn('<include', dst_content)
+ self.assertIn('search.cgi', dst_content)
+
+ def test_navigation(self):
+ dst_content = process('<set-var navigation>\n<body>\n</body>\n', 'not-in-install.html')
+ self.assertIn('<!-- main frame -->', dst_content)
+ self.assertIn('<!-- end of nav frame -->', dst_content)
+
+def main():
+ # Expect either "--unittest", or an input filename
+ if sys.argv[1] == '--unittest':
+ sys.argv = [sys.argv[0]] + sys.argv[2:]
+ unittest.main()
+ return
+ src_filename = sys.argv[1]
+ with open(src_filename) as infile:
+ src_content = infile.read()
+ dst_content = process(src_content, src_filename)
+ print(dst_content)
+
+main()
deleted file mode 100644
@@ -1,223 +0,0 @@
-;;; Set a couple of site-wide defaults, some of which we'll override in the
-;;; following.
-
-<set-var XHTML>
-<set-var BACKPATH>
-
-;;; The "install/" pages are HTML, not XHTML.
-
-<if <match <get-var env::PREPROCESS_FILE> "install/.*">
- <unset-var XHTML>
->
-
-;;; Note that the <?xml...> line really needs to start in the first column.
-
-<if <var-exists XHTML>
- <group
-<?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE html
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- >
- <group
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- >
->
-
-;;; Redefine the <html> tag so that we can put XHTML attributes inside.
-
-<if <var-exists XHTML>
- <group <define-container html>
- <verbatim>
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- </verbatim>
- %body
- <verbatim>
- </html>
- </verbatim>
- </define-container> >
->
-
-;;; Redefine the <head> tag so that we can add default <meta /> headers.
-
-<define-container head>
- <verbatim>
- <head>
- </verbatim>
- <if <var-exists XHTML>
- <group
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <link rel="shortcut icon" href="https://gcc.gnu.org/favicon.ico" />
- >
- <group
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <link rel="shortcut icon" href="https://gcc.gnu.org/favicon.ico">
- <link rel="stylesheet" type="text/css" href="/gcc.css">
- >
- >
- %body
- <verbatim>
- </head>
- </verbatim>
-</define-container>
-
-;;; Redefine the <title> tag to comply with the GNU style.
-
-<define-container title>
-<verbatim><title></verbatim>
-%body
-<verbatim>- GNU Project - Free Software Foundation (FSF)</title></verbatim>
-</define-container>
-
-;;; Redefine the <body> tag, adding navigation and a standard footer.
-
-<define-container body>
-<verbatim><body></verbatim>
-
-<if <var-exists navigation>
- <group
- <table border="0" cellspacing="0" cellpadding="2">
- <tr>
-
- <td valign="top" width="99%"> <!-- main frame -->
- >
->
-
-%body
-
-<if <var-exists navigation>
- <group
- </td> <!-- end of main frame -->
-
- <td valign="top"> <!-- nav frame -->
- <table class="nav" border="0" cellpadding="2" width="10em">
-
- <tr><td><table class="navitem" width="100%">
- <tr><td>About GCC</td></tr>
- <tr><td>
- <a href="<get-var BACKPATH>gccmission.html">Mission Statement</a><br />
- <a href="<get-var BACKPATH>releases.html">Releases</a><br />
- <a href="<get-var BACKPATH>snapshots.html">Snapshots</a><br />
- <a href="<get-var BACKPATH>lists.html">Mailing lists</a><br />
- <a href="https://gcc.gnu.org/onlinedocs/gcc/Contributors.html">Contributors</a><br />
- <a href="<get-var BACKPATH>steering.html">Steering Committee</a><br />
- <div align="center">
- <a href="https://twitter.com/gnutools">
- <img src="<get-var BACKPATH>twitter-bird-light-bgs.png"
- height="42" width="42" align="middle" alt="@gnutools on Twitter"
- />@gnutools</a>
- </div>
- <div align="center">
- <a href="https://plus.google.com/108467477471815191158">
- <img src="<get-var BACKPATH>gplus-32.png"
- height="24" width="24" align="middle" alt="gnutools on Google+"
- /> gnutools</a>
- </div>
- <div align="center">
- <a href="https://my.fsf.org/civicrm/contribute/transact?reset=1&id=57">
- <img src="<get-var BACKPATH>donate-110-23.png"
- height="23" width="100" align="middle" alt="Donate to GNU Toolchain Fund"
- /></a>
- </div>
- </td></tr>
- </table></td></tr>
-
- <tr><td><table class="navitem" width="100%">
- <tr><td>Documentation</td></tr>
- <tr><td>
- <a href="https://gcc.gnu.org/install/">Installation</a><br />
- · <a href="https://gcc.gnu.org/install/specific.html">Platforms</a><br />
- <a href="<get-var BACKPATH>onlinedocs/">Manual</a><br />
- <a href="<get-var BACKPATH>faq.html">FAQ</a><br />
- <a href="https://gcc.gnu.org/wiki">Wiki</a><br />
- <a href="<get-var BACKPATH>readings.html">Pointers</a>
- </td></tr>
- </table></td></tr>
-
- <tr><td><table class="navitem" width="100%">
- <tr><td>Download</td></tr>
- <tr><td>
- <a href="<get-var BACKPATH>mirrors.html">Mirrors</a><br />
- <a href="https://gcc.gnu.org/install/binaries.html">Binaries</a>
- </td></tr>
- </table></td></tr>
-
- <tr><td><table class="navitem" width="100%">
- <tr><td>Sources</td></tr>
- <tr><td>
- <a href="<get-var BACKPATH>svn.html">SVN read access</a><br />
- <a href="<get-var BACKPATH>svnwrite.html">SVN write access</a><br />
- <a href="https://gcc.gnu.org/wiki/GitMirror">Git read access</a><br />
- <a href="<get-var BACKPATH>rsync.html">Rsync</a><br />
- </td></tr>
- </table></td></tr>
-
- <tr><td><table class="navitem" width="100%">
- <tr><td>Development</td></tr>
- <tr><td>
- <a href="<get-var BACKPATH>develop.html">Development Plan</a><br />
- · <a href="<get-var BACKPATH>develop.html#timeline">Timeline</a><br />
- <a href="<get-var BACKPATH>contribute.html">Contributing</a><br />
- <a href="<get-var BACKPATH>contributewhy.html">Why contribute?</a><br />
- <a href="<get-var BACKPATH>projects/">Open projects</a><br />
- <a href="<get-var BACKPATH>frontends.html">Front ends</a><br />
- <a href="<get-var BACKPATH>backends.html">Back ends</a><br />
- <a href="<get-var BACKPATH>extensions.html">Extensions</a><br />
- <a href="<get-var BACKPATH>benchmarks/">Benchmarks</a><br />
- <a href="http://toolchain.lug-owl.de/buildbot/">Build Robot</a><br />
- <a href="<get-var BACKPATH>translation.html">Translations</a><br />
- </td></tr>
- </table></td></tr>
-
- <tr><td><table class="navitem" width="100%">
- <tr><td>Bugs</td></tr>
- <tr><td>
- <a href="<get-var BACKPATH>bugs/#known">Known bugs</a><br />
- <a href="<get-var BACKPATH>bugs/">How to report</a><br />
- <a href="https://gcc.gnu.org/bugzilla/">Bug tracker</a><br />
- · <a href="<get-var BACKPATH>bugs/management.html">Management</a>
- </td></tr>
- </table></td></tr>
-
- </table>
- </td> <!-- end of nav frame -->
-
- </tr>
- </table>
- >
->
-
-<!-- ==================================================================== -->
-
-<div class="copyright">
-
-<address>For questions related to the use of GCC,
-please consult these web pages and the
-<a href="https://gcc.gnu.org/onlinedocs/">GCC manuals</a>. If that fails,
-the <a href="mailto:gcc-help@gcc.gnu.org">gcc-help@gcc.gnu.org</a>
-mailing list might help.
-Comments on these web pages and the development of GCC are welcome on our
-developer list at <a href="mailto:gcc@gcc.gnu.org">gcc@gcc.gnu.org</a>.
-All of <a href="https://gcc.gnu.org/lists.html">our lists</a>
-have public archives.
-</address>
-
-<p>Copyright (C)
-<a href="https://www.fsf.org">Free Software Foundation, Inc.</a>
-Verbatim copying and distribution of this entire article is
-permitted in any medium, provided this notice is preserved.</p>
-
-<p>These pages are
-<a href="https://gcc.gnu.org/about.html">maintained by the GCC team</a>.
-Last modified <date::format-time "YYYY-MM-DD"><!-- IGNORE DIFF
---><a href="http://validator.w3.org/check/referer">.</a></p>
-
-</div>
-
-<!-- ==================================================================== -->
-
-<verbatim>
-</body>
-</verbatim>
-</define-container>