: # mkcategtab - make HTML table from command list, grouped by categories # # Author: Heiner Steven (heiner.steven@odn.de), 1/00 # Category: HTML # # Thanks to Jean-Pierre Pilote for pointing out a off-by-one bug, causing # the program to use wrong directory names for generated URL. # # $Id: mkcategtab,v 1.9 2014/09/08 18:46:26 heiner Exp $ PN=`basename "$0"` PATH=$PATH:../../bin export PATH : ${AWK:=awk} # 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 Categories=${TMPDIR:=/tmp}/mkcmd$$ NewFiles=$TMPDIR/mkcmd$$.new trap 'rm -f "$Categories" "$NewFiles"' 0 trap "exit 2" 1 2 3 13 15 # Create a list of new files lastmonth=`fdate +"%Y-%m-01" -1 month` lsrecent -d $lastmonth "$@" > "$NewFiles" # Search all "Category:" header lines, and write them to a file. # All lines *must* be sorted in dictionary order for "join" to work. # File format: # filenamecategory text egrep -i '^#[ ]+(category|categories|kategorie|kategorien)[. ]*:[ ]*' "$@" | awk -F: '!L[$1]++' | sed -e 's/[ ][ ]*/ /g' \ -e 's/:#[ ]*[cC][aA][tT][eE][gG][oO][rR][yY][. ]*:[ ]*/ /' \ -e 's/:#[ ]*[cC][aA][tT][eE][gG][oO][rR][iI][eE][sS][. ]*:[ ]*/ /' \ -e 's/:#[ ]*[kK][aA][tT][eE][gG][oO][rR][iI][eE][. ]*:[ ]*/ /' \ -e 's/:#[ ]*[kK][aA][tT][eE][gG][oO][rR][iI][eE][nN][. ]*:[ ]*/ /' | sort -k1,1 > "$Categories" || exit { # 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/:\#[ ]*/ /' # Output format: # filenamedescriptive text } | awk -F" " '!L[$1]++' | # each file can appear only once sort -f -k1,1 | # Input must be sorted on the first field for join to work join -t ' ' - $Categories | # Output format (sorted by command name, case ignored): # filenamename - descriptive textcategory sort -k2 | $AWK -F' ' ' BEGIN { ChangeText ["new"] = "${NEWTAG}" ChangeText ["update"] = "${UPDATETAG}" NewFiles = "'"$NewFiles"'" # Input example: # test.sh update 2000-02-02 1.2 # testing new 2000-02-02 1.2 while ( getline < NewFiles ) { IsNewFile [$1] = $2 } close (NewFiles) } { filename = $1 description = $2 categories = $3 haschanged = ChangeText [IsNewFile [filename]] 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 } } # The description has the format # name - descriptive text [...] n = split (description, d, "[ ]") cmdname = "" for ( i=1; i<=n; i++ ) { if ( d [i] == "-" ) { ++i; break } if ( i>1 ) cmdname = cmdname " " cmdname = cmdname "" d [i] } descr = "" for ( j=i; j<=n; j++ ) { if ( j > i ) descr = descr " " descr = descr d [j] } if ( basename "" != cmdname && length (basename) >= length (cmdname) ) { print "WARNING: file " filename " is called " cmdname | "cat >&2" } # We should take "basename" instead of "cmdname", but # with DOS the name would be truncated to 8 characters fileurl = dirname "" cmdname if ( fileurl == "" ) fileurl = " " if ( descr == "" ) descr = " " url [cmdname] = fileurl ChangeNote [cmdname] = haschanged descriptions [cmdname] = descr # "category" may contain more than one category, # separated by ";" or "," n = split (categories, c, "[,;]") for ( i=1; i<=n; i++ ) { category = c [i] if ( category == "" ) continue # Remove leading and trailing whitespace gsub (/^[ ]*/, "", category) gsub (/[ ]*$/, "", category) # Substitute blanks with "non breaking spaces" gsub (/[ ][ ]*/, "\\ ", category) if ( cmds [category] != "" ) cmds [category] = cmds [category] " " cmds [category] = cmds [category] "" cmdname } } END { # Now write the HTML output. # We will take care to write the tables in a way # that older browsers may display the result, too. # Copy all category texts to the vector categ[]. This # way we can sort the vectory on the category name. ncat = 0 for ( category in cmds ) { categ [++ncat] = category } # Sort categories in categ[] using "Insertion Sort" for ( i=1; i<=ncat; i++ ) { smallest = i; for ( j=i+1; j<=ncat; j++ ) { if ( categ [j] < categ [smallest] ) smallest = j; # find position of smallest element } tmp = categ [i] categ [i] = categ [smallest] categ [smallest] = tmp } # At first print a list of links to directly jump to a category print "
" print "[ " for ( i=1; i<=ncat; i++ ) { category = categ [i] L = "" category "" if ( i < ncat ) L = L " | " print L } print " ]" print "
\n" # Now write all categories, using a table for the # commands contained within. for ( i=1; i<=ncat; i++ ) { category = categ [i] n = split (cmds [category], c, "[ ]") # c[1..n] contains the command names print "

${SSH}${SFIXEDFONT}" category "${EFIXEDFONT}${ESH}

" #L = "" #L = L "Top" #print L print "" for ( j=1; j<=n; j++ ) { cmd = c [j] viewurl = url [cmd] ".txt" L = " " L = L " " L = L " " print L } print "
" L = L ChangeNote [cmd] L = L "" cmd " D " descriptions [cmd] # Special handling: terminate line for older browsers L = L "
\n" } print "

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

" } '