diff options
| author | Douglas B. Rumbaugh <doug@douglasrumbaugh.com> | 2026-06-06 12:02:41 -0400 |
|---|---|---|
| committer | Douglas B. Rumbaugh <doug@douglasrumbaugh.com> | 2026-06-06 12:02:41 -0400 |
| commit | eabf1f6d74dac497ce31e3e2f441cfa25e9f74f2 (patch) | |
| tree | 626d64c3574cfbc7cc38eae6d142ef22b21cf59b /lib/bib-canon.awk | |
| parent | 8351a1da3f56cde9939b934bc5533a95aff1c95e (diff) | |
| download | bibutils-eabf1f6d74dac497ce31e3e2f441cfa25e9f74f2.tar.gz | |
Initial implementation (only a few years later!)
This is pure Claude. I'd written out the plan for
this suite of scripts eons ago, but never found the
time to actual do it. Remembered it this morning,
pointed Claude at the README, and had something
that appears to work in minutes.
caveat emptor: the design is mine, but the code is
purely LLM generated at this point.
Diffstat (limited to 'lib/bib-canon.awk')
| -rw-r--r-- | lib/bib-canon.awk | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/bib-canon.awk b/lib/bib-canon.awk new file mode 100644 index 0000000..d11e9cb --- /dev/null +++ b/lib/bib-canon.awk @@ -0,0 +1,28 @@ +# bib-canon.awk - canonical output helpers for bibutils +# +# Requires bib-parse.awk. Provides bib_emit() to print the current +# entry in canonical form, and bib_get() to look up a field value. + +# print the current entry canonically: lowercase type and field names, +# 2-space indent, brace-delimited values with whitespace collapsed +function bib_emit(type, key, j, v) { + printf "@%s{%s,\n", type, key + for (j = 1; j <= BIB_N; j++) { + v = BIB_VAL[j] + if (BIB_KIND[j] == "s") { + gsub(/[ \t\r\n]+/, " ", v) + v = bib_trim(v) + printf " %s = {%s},\n", BIB_NAME[j], v + } else + printf " %s = %s,\n", BIB_NAME[j], v + } + print "}" +} + +# value of field `name` (lowercase) in the current entry, "" if absent +function bib_get(name, j) { + for (j = 1; j <= BIB_N; j++) + if (BIB_NAME[j] == name) + return BIB_VAL[j] + return "" +} |