: ########################################################################## # Shellscript: mkscripttab - make HTML table from command list # Author : Heiner Steven (heiner.steven@odn.de) # Date : 05.03.1998 # Category : HTML # $Id: mkscripttab,v 1.7 2009-01-04 15:13:22 heiner Exp $ ########################################################################## # Description # ########################################################################## : ${AWK:=awk} PN=`basename "$0"` # Program name VER=`echo '$Revision: 1.7 $' | cut -d' ' -f2` PATH=$PATH:../../bin export PATH Usage () { echo >&2 "$PN - make HTML table from command list, $VER usage: $PN [file ...]" exit 1 } Msg () { for MsgLine do echo "$PN: $MsgLine" >&2 done } Fatal () { Msg "$@"; exit 1; } #set -- `getopt h "$@"` while [ $# -gt 0 ] do case "$1" in --) shift; break;; -h) Usage;; -*) Usage;; *) break;; # First file name esac shift done # Ignore all commands ending in ".txt" Args= while [ $# -gt 0 ] do if [ -d "$1" ] then : # Ignore directory else case "$1" in *.txt) ;; # Ignore *) Args="$Args $1";; esac fi shift done set -- $Args NewFiles=${TMPDIR:=/tmp}/mkcmd$$.new trap 'rm -f "$NewFiles"' 0 trap "exit 2" 1 2 3 13 15 # Create a list of new files lsrecent -d `fdate +"%Y-%m-01" -1 month` "$@" > "$NewFiles" { # Format: "filename:# Shellscript: name - descriptive text" egrep '^# (Shellscript|Title[ ]*):[ ]' "$@" | sed -e 's/[ ][ ]*/ /g' \ -e 's/:# Shellscript:[ ]*/ /' \ -e 's/:# Title[ ]:[ ]*/ /' # Format: "filename:# name - descriptive text" egrep '^#[ ][ ]*[a-z0-9][a-z0-9]* - ' "$@" | sed 's/[ ][ ]*/ /g' | sed 's/:\#[ ]*/ /' } | $AWK -F" " '!L[$1]++' | # Sort by file name, ignoring case sort -f -k2 | { $AWK ' BEGIN { ChangeText ["new"] = "${NEWTAG}" ChangeText ["update"] = "${UPDATETAG}" # Input example: # test.sh update 2000-02-02 1.2 # testing new 2000-02-02 1.2 NewFiles = "'"$NewFiles"'" while ( getline < NewFiles ) { isNewFile [$1] = $2 } close (NewFiles) # Lower/upper case table LTab = "abcdefghijklmnopqrstuvwxyz" UTab = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" print "

" print "[" print "" for ( i=1; i<=length (UTab); i++ ) { c = substr (UTab, i, 1) L = "" c "" if ( i < length (UTab) ) L = L " | " print L } print "" print "]" print "

\n" } { # Process each file only once if ( filenames [$1] != "" ) next; filenames [$1] = $1 filename = $1 "" viewname = filename ".txt" cmdname = $2 "" descr = "" changetext = ChangeText [isNewFile [filename]] for ( i=4; i<=NF; i++ ) { if ( i > 4 ) descr = descr " " descr = descr "" $i } if ( filename ~ /\// ) { for ( i=length (filename); i>0; --i ) { if ( substr (filename, i, 1) == "/" ) break } if ( i > 0 ) { dirname = substr (filename, 1, i-1) "/" basename = substr (filename, i+1, length (filename) - i) } else { dirname = "" basename = filename } } if ( basename "" != cmdname && length (basename) >= length (cmdname) ) { print "WARNING: file " filename " is called " cmdname | "cat >&2" } if ( cmdname != "" ) { firstc = substr (cmdname, 1, 1) i = index (LTab, firstc "") if ( i > 0 ) firstc = substr (UTab, i, 1) if ( index (tabsprinted, firstc) <= 0 ) { #TabAnchor = " " TabAnchor = "Tab_" firstc tabsprinted = tabsprinted "" firstc } else { TabAnchor = "" } } # We should take "basename" instead of "cmdname", but # with DOS the name would be truncated to 8 characters fileurl = dirname "" cmdname if ( filename == "" ) filename = " " if ( viewname == "" ) viewname = " " if ( cmdname == "" ) cmdname = " " if ( descr == "" ) descr = " " print "" #print " " L = " " print L print " " print " " print "" } END { print "
" TabAnchor "" cmdname "" L = L changetext if ( TabAnchor != "" ) { L = L "" cmdname } else { L = L "" cmdname } L = L " D " descr "
" print "

This table was generated ${DATE} using the script \"'"$PN"'\"

" } ' }