: # mkcategories - make HTML table from command list, sorted by categories # # Author: Heiner Steven (heiner.steven@odn.de), 3/98 # Category: HTML : ${AWK:=awk} Categories=${TMPDIR:=/tmp}/mkcmd$$ Date=`date "+%d.%m.19%y"` trap 'rm -f "$Categories"' 0 trap "exit 2" 1 2 3 13 15 # 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|kategorie)[ ]*:[ ]*' "$@" | sed 's/[ ][ ]*/ /g' | sed 's/:#[ ]*[cC][aA][tT][eE][gG][oO][rR][yY][ ]*:[ ]*/ /' | sed 's/:#[ ]*[kK][aA][tT][eE][gG][oO][rR][iI][eE][ ]*:[ ]*/ /' | sort > "$Categories" || exit { # Format: "filename:# Shellscript: name - descriptive text" egrep '^# Shellscript:[ ]' "$@" | sed 's/[ ][ ]*/ /g' | sed 's/:# Shellscript:[ ]*/ /' # Format: "filename:# name - descriptive text" egrep '^#[ ][ ]*[a-z0-9][a-z0-9]* - ' "$@" | sed 's/[ ][ ]*/ /g' | sed 's/:\#[ ]*/ /' # Output format: # filenamedescriptive text } | sort | # 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 -f +1 | $AWK -F' ' ' BEGIN { Title = "Scripts sorted by category" } { filename = $1 description = $2 categories = $3 if ( filename ~ /\// ) { for ( i=length (filename); i>0; --i ) { if ( substr (filename, i, 1) == "/" ) break } if ( i > 0 ) { dirname = substr (filename, 0, 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 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. print "

" Title "

" # 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 "" for ( i=1; i<=ncat; i++ ) { category = categ [i] L = "" category "" if ( i < ncat ) L = L " | " print L } 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 "

" category "

" L = "

" L = L "Back

" print L print "

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

This table was generated" print "'"$Date"' using the script \"mkcategories\"

" print "" } '