1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# 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 ""
}
# render a field value as plain text: strip braces, collapse whitespace
function bib_clean(v) {
gsub(/[{}]/, "", v)
gsub(/[ \t\r\n]+/, " ", v)
return bib_trim(v)
}
# print a blank line between output records (nothing before the first)
function bib_sep() {
if (BIB_OUT_N++)
print ""
}
|