Annotation of hatari/doc/update-index.sh, revision 1.1

1.1     ! root        1: #!/bin/sh
        !             2: 
        !             3: # check arguments
        !             4: if [ -z "$1" ]; then
        !             5:        echo "usage: $0 <html file>"
        !             6:        echo
        !             7:        echo "Adds header anchors to the file and then outputs an corresponding index."
        !             8:        exit 1
        !             9: fi
        !            10: if [ \! -f "$1" ]; then
        !            11:        echo "ERROR: file '$1' not found"
        !            12:        exit 1
        !            13: fi
        !            14: doc=$1
        !            15: new=$doc.new
        !            16: tmp=$doc.tmp
        !            17: 
        !            18: # remove existing header anchors
        !            19: sed 's%<a name="[^"]*"></a><h%<h%' $doc > $tmp
        !            20: 
        !            21: # add an anchor before each of the headings
        !            22: # assumes valid, single line HTML headers without "'s
        !            23: sed 's%\(<[hH][0-9]>\)\([^<]*\)\(</[hH][0-9]>\)%<a name="\2"></a>\1\2\3%' $tmp > $new
        !            24: rm $tmp
        !            25: 
        !            26: # ask user whether he wants the new changes
        !            27: echo "Changes"
        !            28: echo "======="
        !            29: diff -u $doc $new
        !            30: while true; do
        !            31:        echo "Replace original (y/n)?"
        !            32:        read answer
        !            33:        
        !            34:        if [ "$answer" = 'y' ]; then
        !            35:                mv $new $doc
        !            36:                echo "replaced."
        !            37:                break
        !            38:        elif [ "$answer" = 'n' ]; then
        !            39:                rm $new
        !            40:                echo "undo."
        !            41:                break
        !            42:        fi
        !            43: done
        !            44: 
        !            45: # output index
        !            46: idx=$doc.idx
        !            47: echo "<ul>" > $idx
        !            48: grep '<a name="' $doc|sed 's%^.*<a name="\([^"]*\)".*$%  <li><a href="#\1">\1</a>%' >> $idx
        !            49: echo "</ul>" >> $idx
        !            50: 
        !            51: echo "---------------------------------------------------------"
        !            52: cat $idx
        !            53: echo "---------------------------------------------------------"
        !            54: echo "Above listed index for the '$doc' file is in file '$idx'."

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.