script to dynamically generate the hints list

Tushar Teredesai linux_from_scratch at yahoo.com
Mon Sep 15 10:11:02 PDT 2003


Jeroen Coumans wrote:

>#   That wasn't in the specs...
>#   ===========================
>#
># * I noticed information is missing from a few hints supposedly in the new
>#   format, so I added messages on stderr to report missing fields. I think
>#   that makes sense since they are mandatory, so their absence is a bug in
>#   the hint file. If you don't want them, comment out the echo line in the
>#   check_and_report function.
>
># set -x
>
># the simplest way to handle paths properly is to work in the hints/ directory.
>
># Script placed in the hints subdirectory
>#if [ -d hints ]
>#then
>#    cd hints
>#else
>#    echo "Error - no hints/ subdirectory" >> /dev/stderr
>#    exit 1
>#fi
>
>
># the file to which to write
>
>OUTPUTFILE="list.html"
>
>function output
>{
>    # echoes its argument to OUTPUTFILE
>
>    echo $1 >> $OUTPUTFILE
>}
>
>
>function htmlclean
>{
>    # replaces '<' and '>' with the corresponding entities so that they
>    # can appear in documents (useful for the authors' email addresses).
>
>    echo `echo $1 | sed -e 's/>/\>/' -e 's/</\</'`
>}
>
>function check_and_report
>{
>    # reports an error message if a field is empty
>    # (but continues processing as it is not a fatal error)
>
>    if [ -z "$1" ]
>    then
>        echo "hint "`basename $2 .txt`": missing "$3 >> /dev/stderr
>    fi
>}
>
># DATEDHINTS = list of all the files that contain a DATE
>#              in reverse chronological order.
>
>DATEDHINTS=`grep -H "DATE:" downloads/files/* | sort -fbi -r -k3 -t: | cut -f1 -d:`
>
>
># UNDATEDHINTS = list of all the files that do *not* contain a DATE.
>
>UNDATEDHINTS=`grep -LH "DATE:" downloads/files/*`
>
The undated hints can be dropped from the list,only display the DATED hints.

># initialise output file
>
>cat list-top.html > $OUTPUTFILE # The top of the list.
>
># write hints
>
>for HINT in $DATEDHINTS $UNDATEDHINTS
>do
>    DATE=`echo \`grep -h "DATE:" $HINT | cut -f2 -d:\``
>    SYNOPSIS=`echo \`grep -h "SYNOPSIS:" $HINT | cut -f2 -d:\``
>    AUTHORS=`echo \`grep "AUTHOR:" $HINT | \
>        cut -f2 -d: | sed 's/$/,/'\` | sed 's/,$//'`
>    LICENSE=`echo \`grep -h "LICENSE:" $HINT | cut -f2 -d:\``
>
>    check_and_report "$DATE" $HINT "date"
>    check_and_report "$SYNOPSIS" $HINT "synopsis"
>    check_and_report "$AUTHORS" $HINT "authors"
>    check_and_report "$LICENSE" $HINT "license"
>
>    # if the synopsis is missing we have to do something about it
>    # (otherwise there will be no usable link to it in the web page!)
>
>    if [ -z "$SYNOPSIS" ]
>    then
>        SYNOPSIS=`basename $HINT .txt`
>    fi
>
>    output "<li><h4><a href=\"$HINT\" title=\"$HINT\">$SYNOPSIS</a></h4>"
>    output "<dl>"
>    output "<dt>Author(s):</dt>"
>    output "<dd>`htmlclean "$AUTHORS"`</dd>"
>    output "<dt>Date Last Updated:</dt>"
>    output "<dd>$DATE</dd>"
>    output "<dt>License:</dt>"
>    output "<dd>$LICENSE</dd>"
>    output "</dl>"
>    output "</li>"
>done
>
>
># finalise output file
>
>cat list-bottom.html >> $OUTPUTFILE
>
>  
>

-- 
Tushar Teredesai
  mailto:tushar at linuxfromscratch.org
  http://linuxfromscratch.org/~tushar



__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com



More information about the website mailing list