This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[wwwdocs infrastructure] bin/preprocess refactoring
- From: Gerald Pfeifer <gerald at pfeifer dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 20 Aug 2007 00:08:32 +0200 (CEST)
- Subject: [wwwdocs infrastructure] bin/preprocess refactoring
This is something I had ment to do for ages, and had (nearly done) on
my disk for months. After using a slight variation of this for some
personal pages of mine for a while, I finally went ahead and committed
this change, update the copy on gcc.gnu.org and reran it there.
Looks good so far ;-), and in a minute I'll commit a change to our
main index.html and verify that goes well, too.
Gerald
Factor out handling of a single .html file into a new function
process_html_file(). Also consider lines with spaces only as blank
lines (if they appear at the beginning) and remove those as well as
single line comments. Construct the destination filename only once.
Index: bin/preprocess
===================================================================
RCS file: /cvs/gcc/wwwdocs/bin/preprocess,v
retrieving revision 1.44
diff -u -3 -p -r1.44 preprocess
--- bin/preprocess 17 Mar 2007 12:53:25 -0000 1.44
+++ bin/preprocess 19 Aug 2007 22:02:11 -0000
@@ -93,6 +93,56 @@ copy_if_different()
fi
}
+########
+# Procedure: Process a single HTML-based file.
+
+process_html_file()
+{
+ f=$1
+ fdest=$2
+
+ # Set environment variable PREPROCESS_FILE, which will then be
+ # accessible by MetaHTML.
+
+ PREPROCESS_FILE=$f
+ export PREPROCESS_FILE
+
+ # Prepend the MetaHTML style, set the MetaHTML include directory,
+ # and process the page; then remove leading blank lines and single
+ # line comments.
+
+ cat $STYLE > $TMPDIR/input
+ printf '<set-var MHTML::INCLUDE-PREFIX="%s">\n' `pwd` >> $TMPDIR/input
+ cat $f >> $TMPDIR/input
+ # Use sed to work around makeinfo 4.7 brokenness.
+ # Use sed to work around MetaHTML brokenness wrt. <DIV>.
+ ${MHC} $TMPDIR/input \
+ | sed -e 's/_002d/-/g' -e 's/_002a/*/g' \
+ | sed -e 's/<DIV/<div/g' \
+ | awk -- \
+ '/^( *)?$/ { if( ! body ) next } \
+ /^<!--.*-->$/ { if( ! body ) next } \
+ /.*/ { body=1; print $0 }' \
+ > $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.
+ if [ $? -ne 0 ]; then
+ echo " Problem processing $f; not updated!"
+ elif [ ! -f $fdest ]; then
+ echo " New file $fdest"
+ cp $TMPDIR/output $fdest
+ else
+ diff -I "$IGNORE_DIFF_MARKER" \
+ $TMPDIR/output $fdest >/dev/null
+ if [ $? -ne 0 ]; then
+ echo " Updating $fdest"
+ cp $TMPDIR/output $fdest
+ fi
+ fi
+}
+
+
process_file()
{
# Strip possibly leading "./".
@@ -124,44 +174,8 @@ process_file()
java/papers/*\.html)
copy_if_different $f $DESTTREE/$f
;;
-
*\.html)
- # Set environment variable PREPROCESS_FILE, which will then be
- # accessible by MetaHTML.
-
- PREPROCESS_FILE=$f
- export PREPROCESS_FILE
-
- # Prepend the MetaHTML style, set the MetaHTML include directory,
- # and process the page; then remove leading blank lines.
-
- cat $STYLE > $TMPDIR/input
- printf '<set-var MHTML::INCLUDE-PREFIX="%s">\n' `pwd` >> $TMPDIR/input
- cat $f >> $TMPDIR/input
- # Use sed to work around makeinfo 4.7 brokenness.
- # Use sed to work around MetaHTML brokenness wrt. <DIV>.
- ${MHC} $TMPDIR/input \
- | sed -e 's/_002d/-/g' -e 's/_002a/*/g' \
- | sed -e 's/<DIV/<div/g' \
- | awk -- \
- '/^$/ { if( ! body ) next } /.*/ { body=1; print $0; }' \
- > $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.
- if [ $? -ne 0 ]; then
- echo " Problem processing $f; not updated!"
- elif [ ! -f $DESTTREE/$f ]; then
- echo " New file $f"
- cp $TMPDIR/output $DESTTREE/$f
- else
- diff -I "$IGNORE_DIFF_MARKER" \
- $TMPDIR/output $DESTTREE/$f >/dev/null
- if [ $? -ne 0 ]; then
- echo " Updating $f"
- cp $TMPDIR/output $DESTTREE/$f
- fi
- fi
+ process_html_file $f $DESTTREE/$f
;;
*/ChangeLog|*\.gif|*/\.#*)
echo " Warning: $f ignored."