#!/bin/ksh93 # # listbib # # List the contents of all given BibTeX files (bibliographic data bases, # extension .bib). # Prerequisites: # LaTeX 2e, <1999/06/01> will work (earlier ones might) # bibtex 0.99b # package listbib, version 2.0 or later VERSION="VK 1.2.4, 28 Aug 2000" typeset -r FPROG=${.sh.file} typeset -r PROG=${FPROG##*/} SDIR=${FPROG%/*} # The root of the filenames generated by latex etc. #OUTFILE="listbib-$$" # numbers are awkward #OUTFILE="listbib" # not good! OUTFILE="listedbibs" IDSTRING="% ${PROG} ${VERSION}" [[ ${ uname -s; } == 'SunOS' ]] && GREP='/usr/xpg4/bin/grep' || GREP='grep' function showUsage { [[ -z $1 ]] && X='--man' || X='-?' getopts -a ${PROG} "${ print ${USAGE} ; }" OPT $X } function cleanup { (( DELTMP || PSONLY || SIGNAL )) && \ rm -f ./"${OUTFILE}."{aux,bbl,blg,log,tex} (( PSONLY || SIGNAL )) && rm -f "${OUTFILE}.dvi" (( SIGNAL )) && rm -f "${OUTFILE}.ps" } # check if existing .tex is not a listbib one function check_tex_is_ours { typeset OUT="$1" [[ -f ${OUT}.tex ]] || return 0 ${GREP} -q -F "${IDSTRING}" "${OUT}.tex" && return 0 # is ours print -u2 "File '${OUT}.tex' already exists." return 2 } function create_latexfile { typeset OUT="$1" if [[ ${OUT} == 'listbib' ]]; then print -u2 "Refusing to create temp file 'listbib.tex'." \ 'This file already exists and would cause an infinite loop.' return 3 fi typeset BIBS= typeset -n BASENAMES=$2 # i.e. w/o trailing '.' and '.bib' for X in "${BASENAMES[@]}" ; do BIBS+=",$X" done cat >"${OUT}.tex"</dev/null /dev/null /dev/null 2>&1 } function doMain { [[ -z $1 ]] && showUsage 1 && return 1 typeset LISTBIBS= while [[ -n $1 ]]; do X="${1%.}" LISTBIBS+=( "${X%.bib}" ) shift done # if same, ps file basename == last arg (( SAME )) && OUTFILEPS="${X%.bib}" || OUTFILEPS="${OUTFILE}" print "${PROG} ${VERSION}" print "Listing bibliographies: ${LISTBIBS[@]}" check_tex_is_ours "${OUTFILE}" || return $? create_latexfile "${OUTFILE}" LISTBIBS || return $? make_dvi "${OUTFILE}" || return $? run_dvips "${OUTFILE}" "${OUTFILEPS}" } USAGE='[-?'"${VERSION}"' ] [-copyright?Copyright 2000 Volker Kuhlmann ] [-copyright?Copyright (c) 2015 Jens Elkner (ksh93 port).] [-license?GNU General Public License (GPL) Version 2] [+NAME?'"${PROG}"' - list the contents of BibTeX files] [+DESCRIPTION?'"${PROG}"' lists the contents of all given BibTeX files (i.e. bibliographic data bases with the file extension \b.bib\b).] [h:help?Print this help and exit.] [F:functions?Print a list of all functions available.] [T:trace]:[fnList?A comma separated list of functions of this script to trace (convinience for troubleshooting).] [+?] [o:output]:[name?Use the given \aname\a as basename for the \b.dvi\b and \b.ps\b files to generate. Default: '"${OUTFILE}"'] [O:same?Use the basename of the last \afile\a operand as basename for the \b.dvi\b and \b.ps\b files to generate.] [p:ps?Generate PostScript as well as DVI.] [d:deltmp?Delete all TeX generated but .dvi files.] [P:psonly?Generate PostScript, only (delete all generated but .ps files).] [+EXAMPLES] [+?List contents of mystrings.bib and mybib.bib, generating '"${OUTFILE}.dvi"']{ [+?listbib -d mystrings.bib mybib.bib] } [+?As before, but only generate '"${OUTFILE}"'.ps]{ [+?listbib -P mystrings.bib mybib.bib] } [+?Generate mybib.ps instead]{ [+?listbib -P -O mystrings.bib mybib.bib] } \n\n\afile\a[\b.bib\b] ... ' X="${ print ${USAGE} ; }" integer SAME=0 PS=0 DELTMP=0 PSONLY=0 SIGNAL=1 while getopts "${X}" OPT ; do case ${OPT} in T) if [[ ${OPTARG} == 'ALL' ]]; then typeset -ft ${ typeset +f ; } else typeset -ft ${OPTARG//,/ } fi ;; F) typeset +f && exit 0 ;; h) showUsage ; exit 0 ;; o) OUTFILE="${OPTARG}" ;; O) SAME=1 ;; p) PS=1 ;; d) DELTMP=1 ;; P) PSONLY=1 ;; *) showUsage 1 ; exit 1 ;; esac done X=$((OPTIND-1)) shift $X && OPTIND=1 unset X trap cleanup EXIT doMain "$@" SIGNAL=0 # let cleanup know, that everything is fine