diff options
| author | Douglas B. Rumbaugh <doug@douglasrumbaugh.com> | 2026-06-06 12:26:27 -0400 |
|---|---|---|
| committer | Douglas B. Rumbaugh <doug@douglasrumbaugh.com> | 2026-06-06 12:26:27 -0400 |
| commit | b56c273d8198ae6cee69bbc9fe5a6a61da4074e4 (patch) | |
| tree | f75b89299fe2783354ba0ab7e3ace088fa60245a /bib-convert | |
| parent | 4aec9800fca665713b0eba19f10af927b483332e (diff) | |
| download | bibutils-b56c273d8198ae6cee69bbc9fe5a6a61da4074e4.tar.gz | |
Code cleanup
Diffstat (limited to 'bib-convert')
| -rwxr-xr-x | bib-convert | 15 |
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 |