: ########################################################################## # Shellscript: bib2txt - format refer(1) database as text # Version : 0.5 (beta) # Author : Heiner Steven (heiner.steven@odn.de) # Date : 03/30/94 # Category : File Conversion # SCCS-Id. : $Id: bib2txt,v 1.1.1.1 1999/06/15 19:29:05 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 Series title # %T Title of article or book # %V Volume number # %X Abstract - used by roffbib, not by refer # %Y, Z Ignored by refer # # Notes # Uses non-standard program "umbruch" to fold long lines. ########################################################################## # Changes # 04/19/94 stv Handling of %V, %O (0.2) # 08/10/94 stv Ignore %K fields (0.3) # 11/03/94 stv Name preceedes christian name (0.4) # 11/09/94 stv Author "Gnuelpf Corp." -> "Gnuelpf, Corp." # 12/12/94 stv Handle multi line abstracts (%X) correctly (0.5) ########################################################################## PN=`basename $0` # Program name VER='0.5 (beta)' Usage () { echo "$PN - Convert refer(1) database to text, Version $VER usage: $PN [-o offset] [-w width] [database]" >&2 exit 1 } [ -z "$AWK" -a -x /bin/nawk ] && AWK=/bin/nawk : ${AWK:=awk} set -- `getopt 'o:w:e:h' "$@"` Args= while [ $# -gt 0 ] do case "$1" in -o|-w|-e) Args="$Args $1 $2"; shift;; --) break;; # End of switches -h|-*) Usage;; *) break;; # First file name esac shift done shift # Remove terminating '--' from getopt : ${Args:='-o8'} $AWK ' ($1 ~ /%[A-Z]$/) { Autor = "" Bem = "" Jahr = "" Journal = "" Kennung = "" Orte = "" Pages = "" Serie = "" Titel = "" Verlag = "" 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 if ( Autor == "" ) Autor = A else Autor = Autor "; " A } else if ( $1 == "%T" ) { Titel = Rest } else if ( $1 == "%I" ) { Verlag = Rest } else if ( $1 == "%C" ) { Orte = Rest } else if ( $1 == "%D" ) { Jahr = Rest } else if ( $1 == "%Y" ) { Kennung = Rest } else if ( $1 == "%X" ) { Bem = Rest while ( getline && $0 != "" ) { Bem = Bem " " $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" ) { Serie = Rest } else if ( $1 == "%J" ) { Journal = Rest } else if ( $1 == "%P" ) { Pages = Rest } else if ( $1 == "%O" ) { if ( Bem != "" ) Bem = Bem " " Bem = Bem Rest } else if ( $1 == "%K" || $1 == "%G" ) { # ignore } else { for ( i=2; i<=NF; i++ ) Bem = Bem " " $i } } while ( getline && $0 != "" ) if ( Kennung != "" ) printf "%s ", Kennung printf "%s: %s. \n\t", Autor, Titel if ( Vol != "" || Serie != "" ) { Z = "" if ( Serie != "" ) Z = Z Serie if ( Vol != "" ) { if ( Serie != "" ) Z = Z " " Z = Z Vol } printf "%s. ", Z } if ( Verlag != "" ) printf "%s; ", Verlag if ( Orte != "" ) printf "%s ", Orte if ( Jahr != "" ) printf "%s. ", Jahr print "" # Zeile beenden print "" # Leerzeile if ( Bem != "" ) { print " " Bem print "" } } ' "$@" | eval umbruch $Args