aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bib-canon.awk
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bib-canon.awk')
-rw-r--r--lib/bib-canon.awk28
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 ""
+}