summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2011-12-04 23:56:44 +0000
committerKarl Berry <karl@freefriends.org>2011-12-04 23:56:44 +0000
commitaabe08f93039c34eb07eb15099cd9185955bd62b (patch)
tree3359dc06dca4c39bdc73fb30fc86c6182f9b4073 /Master/texmf-dist/scripts
parentf5c6e997af999daa5341de5f267a93415634c6df (diff)
bibexport
git-svn-id: svn://tug.org/texlive/trunk@24749 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
-rwxr-xr-xMaster/texmf-dist/scripts/bibexport/bibexport.sh168
1 files changed, 91 insertions, 77 deletions
diff --git a/Master/texmf-dist/scripts/bibexport/bibexport.sh b/Master/texmf-dist/scripts/bibexport/bibexport.sh
index 657e713c006..f946a68b539 100755
--- a/Master/texmf-dist/scripts/bibexport/bibexport.sh
+++ b/Master/texmf-dist/scripts/bibexport/bibexport.sh
@@ -7,7 +7,7 @@
##
## bibexport.dtx (with options: `script')
##
-## (c) 2011/11/19 Nicolas Markey <markey at lsv dot ens-cachan dot fr>
+## (c) 2011/11/28 Nicolas Markey <markey at lsv dot ens-cachan dot fr>
##
## This work may be distributed and/or modified under the conditions of
## the LaTeX Project Public License, either version 1.3 of this license
@@ -38,10 +38,22 @@
## Grave accent \` Left brace \{ Vertical bar \|
## Right brace \} Tilde \~}
##
+function checkversion()
+{
+ kpsewhich expcites.bst > /dev/null ||
+ echo "-----------
+--Warning-- file expcites.bst not found.
+-----------"
+ grep -q $VDATE `kpsewhich expkeys.bst` ||
+ echo "-----------
+--Warning-- the version of the .bst files does not match with that of this
+script.
+-----------"
+}
function usage()
{
echo "bibexport: a tool to extract BibTeX entries out of .bib files.
-usage: $0 [-h|v|n|c|a|d|s|t] [-b|e|es|ec|o|r file] file...
+usage: `basename $0` [-h|v|n|c|a|d|s|t] [-b|e|es|ec|o|r file] file...
Basic options:
--------------
@@ -59,12 +71,12 @@ Advanced options:
-e bib, --extra bib extra .bib file to be used (crossrefs and strings)
-es bib, --extras bib extra .bib file to be used (for strings)
-ec bib, --extrac bib extra .bib file to be used (for crossrefs)
- -s, --no-preamble don't write a preamble at beginning of output
+ -p, --preamble write a preamble at beginning of output
-r bib, --replace bib replace .bib file(s) in the .aux file
-d, --debug create intermediate files but don't run BibTeX";
exit 0;
}
-function opttolate()
+function opttoolate()
{
if [ ${TOOLATE} -ne 0 ]; then
echo "No option is allowed after the input files";
@@ -72,9 +84,9 @@ if [ ${TOOLATE} -ne 0 ]; then
fi
}
## Version number
-VERSION="3.00";
+VERSION="3.01";
## Release date
-VDATE="2011/11/19";
+VDATE="2011/11/28";
# ALL is a flag set to 1 when '-a' is given
ALL="0";
@@ -96,7 +108,7 @@ BST="export";
# TERSE will be set to '-terse' if '-t' is given
TERSE="";
# BANNER is used to turn on or off the preamble informations in the output
-BANNER="true";
+BANNER="false";
# CREF is the number of citations of crossrefs from which the crossref'd entry
# must be included.
CREF="0";
@@ -112,17 +124,18 @@ ARGS=$@;
if [ $# -eq 0 ]; then
usage;
fi
+checkversion;
while [ $# != 0 ]; do
case $1 in
-a|--all)
- ## - export all entries in the input file(s)
- ## - the input files are BibTeX files
- opttolate;
- EXT=""; SPACE="";
+ ## - export all entries in the input file(s)
+ ## - the input files are BibTeX files
+ opttoolate;
+ EXT=""; SPACE=""; ALL=1;
shift ;;
-b|--bst)
- ## - specifies the .bst file to use (default to 'export.bst')
- opttolate;
+ ## - specifies the .bst file to use (default to 'export.bst')
+ opttoolate;
if [ "`dirname $2`" = "." ]; then
DOLLARTWO="`basename $2 .bst`";
else
@@ -131,18 +144,18 @@ while [ $# != 0 ]; do
BST="${DOLLARTWO}";
shift 2;;
-d|--debug)
- ## - debug mode: we create files but do not run bibtex
- ## - instead, we print what we would have done...
+ ## - debug mode: we create files but do not run bibtex
+ ## - instead, we print what we would have done...
opttoolate;
- DEBUG="echo";
- shift ;;
+ DEBUG="echo";
+ shift ;;
-e|--extra)
- ## - extra input files (containing crossrefs or strings)
- ## - they will be included twice: once before the main file(s)
- ## (for @string's), once after (for crossrefs). We fool BibTeX
- ## by naming the first one 'file.bib' and the second one
- ## 'file.bib.bib', to avoid complains.
- opttolate;
+ ## - extra input files (containing crossrefs or strings)
+ ## - they will be included twice: once before the main file(s)
+ ## (for @string's), once after (for crossrefs). We fool BibTeX
+ ## by naming the first one 'file.bib' and the second one
+ ## 'file.bib.bib', to avoid complains.
+ opttoolate;
if [ "`dirname $2`" = "." ]; then
DOLLARTWO="`basename $2 .bib`";
else
@@ -152,10 +165,10 @@ while [ $# != 0 ]; do
EXTRABIB="${EXTRABIB},${DOLLARTWO}.bib";
shift 2;;
-es|--extras)
- ## - extra input files (containing strings)
- ## - will be included *before* the main files (hence not suitable
- ## for crossrefs)
- opttolate;
+ ## - extra input files (containing strings)
+ ## - will be included *before* the main files (hence not suitable
+ ## for crossrefs)
+ opttoolate;
if [ "`dirname $2`" = "." ]; then
DOLLARTWO="`basename $2 .bib`";
else
@@ -164,10 +177,10 @@ while [ $# != 0 ]; do
EXTRA="${EXTRA}${DOLLARTWO},";
shift 2;;
-ec|--extrac)
- ## - extra input files (containing crossrefs)
- ## - will be included only *after* the main files (hence not
- ## suitable for @string's)
- opttolate;
+ ## - extra input files (containing crossrefs)
+ ## - will be included only *after* the main files (hence not
+ ## suitable for @string's)
+ opttoolate;
if [ "`dirname $2`" = "." ]; then
DOLLARTWO="`basename $2 .bib`";
else
@@ -176,9 +189,9 @@ while [ $# != 0 ]; do
EXTRABIB="${EXTRABIB},${DOLLARTWO}.bib";
shift 2;;
-o|--output-file)
- ## - name of the output file
- ## - we force it to end with '.bib'
- opttolate;
+ ## - name of the output file
+ ## - we force it to end with '.bib'
+ opttoolate;
if [ "`dirname $2`" = "." ]; then
DOLLARTWO="`basename $2 .bib`";
else
@@ -187,24 +200,24 @@ while [ $# != 0 ]; do
OUTPUT="${DOLLARTWO}.bib";
shift 2 ;;
-c|--crossref|--crossrefs|--with-crossref|--with-crossrefs)
- ## - whether or not to preserve 'crossref' keys.
- ## - by default, they are removed, but crossref'd entries are
- ## included.
- ## - crossrefs are *always* expanded anyway.
- opttolate;
+ ## - whether or not to preserve 'crossref' keys.
+ ## - by default, they are removed, but crossref'd entries are
+ ## included.
+ ## - crossrefs are *always* expanded anyway.
+ opttoolate;
CREF="1" ;
shift ;;
-n|--no-crossref|--without-crossref|--no-crossrefs|--without-crossrefs)
- ## - to remove crossref'd entries (hence remove 'crossref' keys).
- opttolate;
+ ## - to remove crossref'd entries (hence remove 'crossref' keys).
+ opttoolate;
CREF="20000" ;
shift ;;
-r|--replace)
- ## - to replace the file(s) given in \bibdata in the .aux file with
- ## (a) new one(s).
- opttolate;
- REPLACEBIB="1";
- if [ "`dirname $2`" = "." ]; then
+ ## - to replace the file(s) given in \bibdata in the .aux file with
+ ## (a) new one(s).
+ opttoolate;
+ REPLACEBIB="1";
+ if [ "`dirname $2`" = "." ]; then
DOLLARTWO="`basename $2 .bib`";
else
DOLLARTWO="`dirname $2`/`basename $2 .bib`";
@@ -213,8 +226,8 @@ while [ $# != 0 ]; do
shift 2;;
-v|--version)
echo "This is bibexport v${VERSION} (released ${VDATE})"; exit 0;;
- -s|--no-preamble|--without-preamble)
- NOBANNER="false";
+ -p|--preamble|--with-preamble)
+ BANNER="true";
shift ;;
-t|--terse|--silent)
TERSE=" -terse ";
@@ -222,9 +235,9 @@ while [ $# != 0 ]; do
-*)
usage;;
*)
- ## - list of input files
- ## - we ensure that no extra option is given later...
- TOOLATE="1";
+ ## - list of input files
+ ## - we ensure that no extra option is given later...
+ TOOLATE="1";
if [ "`dirname $1`" = "." ]; then
DOLLARONE="`basename $1 ${EXT}`";
else
@@ -233,8 +246,8 @@ while [ $# != 0 ]; do
FILE="${FILE}${SPACE}${DOLLARONE}${EXT}";
if [ ${ALL} -eq 1 ]; then
SPACE=",";
- else
-SPACE=" ";
+ else
+ SPACE=" ";
fi;
shift;;
esac
@@ -252,15 +265,16 @@ if [ -z "${EXT}" ]; then ## we export all entries
\bibstyle{${BST}}
EOF
else ## we have extra files (e.g. for crossrefs) but want all entries from ${FILE}
- ## we first extract the keys to be used:
+ ## we first extract the keys to be used:
cat > ${TMPFILE}.aux <<EOF
\citation{*}
\bibdata{${FILE}}
\bibstyle{expkeys}
EOF
- bibtex -min-crossrefs=${CREF} -terse ${TMPFILE};
+ ## This run may generate errors. We redirect the output:
+ bibtex -min-crossrefs=${CREF} -terse ${TMPFILE} >/dev/null 2>&1;
mv -f ${TMPFILE}.bbl ${TMPFILE}.aux;
-## and then prepare the .aux file for exporting:
+ ## and then prepare the .aux file for exporting:
cat >> ${TMPFILE}.aux <<EOF
\bibdata{${EXTRA}${FILE}${EXTRABIB}}
\bibstyle{${BST}}
@@ -277,7 +291,7 @@ fi
if [ -z "$DEBUG" ]; then
bibtex -min-crossrefs=${CREF} ${TERSE} ${TMPFILE};
if [ -e ${FINALFILE} ]; then
-mv ${FINALFILE} ${FINALFILE}-save-`date "+%Y.%m.%d:%H.%M.%S"`
+ mv ${FINALFILE} ${FINALFILE}-save-`date "+%Y.%m.%d:%H.%M.%S"`
fi
echo "" > ${FINALFILE}
else
@@ -286,35 +300,35 @@ fi
if [ ! "${BANNER}" = "false" ]; then
## list of cited entries
if [ -z "$DEBUG" ]; then
-sed -i -e "s/\\\bibstyle{.*}/\\\bibstyle{expcites}/" ${TMPFILE}.aux
-mv ${TMPFILE}.aux ${TMPFILE}-cites.aux
-bibtex -terse -min-crossrefs=${CREF} ${TMPFILE}-cites
-echo -ne "@comment{generated using bibexport:\n" >> ${FINALFILE};
-echo -ne " creation date:\t`date +\"%c\"`\n" >> ${FINALFILE};
-echo -ne " command:\t\t$0 ${ARGS}\n" >> ${FINALFILE};
-if [ -z "${EXT}" ]; then
- echo -ne " source files:\t\t${FILETAB}\t\t\t${EXTRABIBTAB}\n" >> ${FINALFILE}; \
-fi
-cat ${TMPFILE}-cites.bbl >> ${FINALFILE};
-echo -ne " bibexport-version:\tv${VERSION} (${VDATE})\n" >> ${FINALFILE};
-echo -ne " bibexport-maintainer:\tmarkey(at)lsv.ens-cachan.fr\n" >> ${FINALFILE};
-sed -i -e "s/}/)/g" ${FINALFILE};
-echo -n -e "}\n\n\n" >> ${FINALFILE};
-rm -f ${TMPFILE}-cites.bbl ${TMPFILE}-cites.aux ${TMPFILE}-cites.blg
+ sed -i -e "s/\\\bibstyle{.*}/\\\bibstyle{expcites}/" ${TMPFILE}.aux
+ mv ${TMPFILE}.aux ${TMPFILE}-cites.aux
+ bibtex -terse -min-crossrefs=${CREF} ${TMPFILE}-cites
+ echo -ne "@comment{generated using bibexport:\n" >> ${FINALFILE};
+ echo -ne " creation date:\t`date +\"%c\"`\n" >> ${FINALFILE};
+ echo -ne " command:\t\t`basename $0` ${ARGS}\n" >> ${FINALFILE};
+ if [ -z "${EXT}" ]; then
+ echo -ne " source files:\t\t${FILETAB}\t\t\t${EXTRABIBTAB}\n" >> ${FINALFILE}; \
+ fi
+ cat ${TMPFILE}-cites.bbl >> ${FINALFILE};
+ echo -ne " bibexport-version:\tv${VERSION} (${VDATE})\n" >> ${FINALFILE};
+ echo -ne " bibexport-maintainer:\tmarkey(at)lsv.ens-cachan.fr\n" >> ${FINALFILE};
+ sed -i -e "s/}/)/g" ${FINALFILE};
+ echo -n -e "}\n\n\n" >> ${FINALFILE};
+ rm -f ${TMPFILE}-cites.bbl ${TMPFILE}-cites.aux ${TMPFILE}-cites.blg
fi
fi
if [ ${CREF} -ne 1 ]; then
if [ -z "$DEBUG" ]; then
-egrep -iv '^ *crossref *= *[^,]+,?$' \
- ${TMPFILE}.bbl >> ${FINALFILE};
+ egrep -iv '^ *crossref *= *[^,]+,?$' \
+ ${TMPFILE}.bbl >> ${FINALFILE};
else
-echo "egrep -iv '^ *crossref *= *[^,]+,?$' ${TMPFILE}.bbl >> ${FINALFILE};"
+ echo "egrep -iv '^ *crossref *= *[^,]+,?$' ${TMPFILE}.bbl >> ${FINALFILE};"
fi
else
if [ -z "$DEBUG" ]; then
-cat ${TMPFILE}.bbl >> ${FINALFILE};
+ cat ${TMPFILE}.bbl >> ${FINALFILE};
else
-echo "cat ${TMPFILE}.bbl >> ${FINALFILE};"
+ echo "cat ${TMPFILE}.bbl >> ${FINALFILE};"
fi
fi
if [ -z "$DEBUG" ]; then