From b56c273d8198ae6cee69bbc9fe5a6a61da4074e4 Mon Sep 17 00:00:00 2001 From: "Douglas B. Rumbaugh" Date: Sat, 6 Jun 2026 12:26:27 -0400 Subject: Code cleanup --- bib-convert | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'bib-convert') 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 -- cgit v1.2.3