: ########################################################################## # Shellscript: authidx - create author index of refer(1) database # Version : $Revision: 1.1 $ # Author : Heiner Steven (heiner.steven@odn.de) # Date : 06/02/98 # Category : File Conversion, HTML # RCS-Id. : $Id: mkauthindex,v 1.1 1999/10/09 15:06:24 heiner Exp $ ########################################################################## # Description # # Valid fields (see addbib(1)): # %A Author's name # %B Book containing article reference # %C City (place of publication) # %D Date of publication # %E Editor of book containing article referenced # %F Footnote number or label (suppied by refer) # %G Government order number # %H Header commentary, printed before reference # %I Issuer (publisher) # %J Journal containing article # %K Keywords to use in locating reference # %L Label field used by -k option of refer # %M Bell Labs Memorandum (undefined) # %N Number within volume # %O Other commentary, printed at end of reference # %P Page number(s) # %Q Corporate or Foreign Author (unreversed) # %R Report, paper, or thesis (unpublished) # %S Seriess title # %T Title of article or book # %V Volume number # %X Abstract - used by roffbib, not by refer # %Y, Z Ignored by refer ########################################################################## PN=`basename "$0"` # Program name VER='1.1' Usage () { echo >&2 "$PN - create HTML author index of refer(1) database, Version $VER usage: $PN [database]" exit 1 } [ -z "$AWK" -a -x /bin/nawk ] && AWK=/bin/nawk : ${AWK:=awk} Books="${TMPDIR:=/tmp}/bk$$" trap 'rm -f "$Books" >/dev/null 2>&1' 0 trap "exit 2" 1 2 3 15 set -- `getopt hf: "$@"` HtmlFile= # Will be used for link targets Args= while [ $# -gt 0 ] do case "$1" in -f) HtmlFile="$2"; shift;; --) break;; # End of switches -h|-*) Usage;; *) break;; # First file name esac shift done shift # Remove terminating '--' from getopt [ -z "$HtmlFile" ] && echo >&2 "WARNING: no bibliography file specified for links" # # FIRST PASS: read "bib" file, convert it # # Output format: # booknumberauthortitle $AWK ' ($1 ~ /%[A-Z]$/) { Author = "" Comment = "" Year = "" Journal = "" Rating = "" City = "" Pages = "" Series = "" Title = "" Publisher = "" Vol = "" do { Rest = $0 if ( index (Rest, $1) > 0 ) Rest = substr (Rest, index (Rest, $1)+length ($1)+1) if ( $1 == "%A" ) { # Author if ( NF > 2 ) { # determine surname Surname = Append = "" # Find surname in lines like # "Prof. Dr. Guenther Drodowski et. al. (Hrsg.)" # and change to # "Drodowski, Prof. Dr. Guenter et.al (Hrsg.)" for ( i=NF; i>1; i-- ) { if ( !match ($i, "[\).]$") ) { Surname = $i break; } } A = Surname "," for ( i=2; i<=NF; i++ ) if ( $i != Surname ) A = A " " $i } else { # only surname A = $NF } Authors [A] = A if ( Author == "" ) { Author = A } else { Author = Author "; " A } } else if ( $1 == "%T" ) { Title = Rest ++bookno } else if ( $1 == "%I" ) { Publisher = Rest } else if ( $1 == "%C" ) { City = Rest } else if ( $1 == "%D" ) { Year = Rest } else if ( $1 == "%Y" ) { Rating = Rest } else if ( $1 == "%X" ) { Comment = Rest while ( getline && $0 != "" ) { Comment = Comment " " $0 } break # NOTE: EXIT OF LOOP } else if ( $1 == "%V" ) { if ( Rest ~ /^[0-9][0-9]*$/ ) Vol = "Vol. " Rest else Vol = Rest } else if ( $1 == "%S" ) { Series = Rest } else if ( $1 == "%J" ) { Journal = Rest } else if ( $1 == "%P" ) { Pages = Rest } else if ( $1 == "%O" ) { if ( Comment != "" ) Comment = Comment " " Comment = Comment Rest } else if ( $1 == "%K" || $1 == "%G" ) { # ignore } else { for ( i=2; i<=NF; i++ ) Comment = Comment " " $i } } while ( getline && $0 != "" ) for ( A in Authors ) { print bookno "\t" A "\t" Title delete Authors [A] } } ' "$@" | sort +1 > "$Books" # # SECOND PASS: create "quick jump table" # cat <<-!

[ ! $AWK -F' ' ' BEGIN { LowcaseTab = "abcdefghijklmnopqrstuvwxyz" UpcaseTab = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" firsttime = "true" } { bookno = $1 author = $2 title = $3 firstc = substr (author, 1, 1) if ( (pos = index (LowcaseTab, firstc)) ) { firstc = substr (UpcaseTab, pos, 1) } if ( Thumbs [firstc] == "" ) { line = "" firstc "" if ( firsttime == "true" ) { print line firsttime = "false" } else { print " | " line } Thumbs [firstc] = NR } } ' "$Books" cat <<-! ]

! # # THIRD PASS: create author/title table # $AWK -F' ' ' BEGIN { print "" } NF == 3 { bookno = $1 author = $2 title = $3 if ( (i = index (author, ",")) > 1 ) { surname = substr (author, 1, i-1) givenname = substr (author, i+1, length (author)) } else { surname = author givenname = "" } author = "" surname "," givenname if ( author != lastauthor ) { if ( lastauthor != "" ) { print "" print "" } lastauthor = author #print "" print "" print " " printf "%s", "
" "" author "" "
" author "" } # Note: it is uncommon for an anchor "" to include both # a HREF and a NAME (to be used as a target for a link) -- but # its perfectly valid. If a browser does not handle this right, # it should be changed. printf "%s", "" title "
" } END { print "" print "
" } ' "$Books"