aboutsummaryrefslogtreecommitdiffstats
path: root/bib-convert
diff options
context:
space:
mode:
Diffstat (limited to 'bib-convert')
-rwxr-xr-xbib-convert15
1 files changed, 9 insertions, 6 deletions
diff --git a/bib-convert b/bib-convert
index ef4c0b0..fc215b7 100755
--- a/bib-convert
+++ b/bib-convert
@@ -40,12 +40,15 @@ trap 'rm -f "$tmp"' EXIT INT TERM
cat "$@" > "$tmp"
if [ "$mode" = auto ]; then
- first=$(awk 'NF { sub(/^[ \t]+/, ""); print substr($0, 1, 1); exit }' "$tmp")
- case $first in
- @) mode=toref ;;
- %) mode=tobib ;;
- *) printf 'bib-convert: cannot detect input format\n' >&2; exit 1 ;;
- esac
+ # first line that is unambiguous wins: an @entry means bibtex, a
+ # %X field means refer (a bare "% comment" decides neither)
+ mode=$(awk '
+ /^[ \t]*@/ { print "toref"; exit }
+ /^%[A-Z] / { print "tobib"; exit }' "$tmp")
+ if [ -z "$mode" ]; then
+ printf 'bib-convert: cannot detect input format\n' >&2
+ exit 1
+ fi
fi
if [ "$mode" = toref ]; then