aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bib2ref.awk
blob: 137c6ad650c9c4ccc4bd0d47b733b90a1072628a (plain)
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
42
43
44
45
46
47
# bib2ref.awk - convert bibtex entries to refer records
#
# Requires bib-parse.awk and bib-canon.awk.

function bib_pass(raw) { }

function r_field(tag, v) {
  v = bib_clean(v)
  if (v != "")
    printf "%%%s %s\n", tag, v
}

function r_names(tag, v,    n, parts, i) {
  n = split(bib_clean(v), parts, / +[Aa][Nn][Dd] +/)
  for (i = 1; i <= n; i++)
    if (parts[i] != "")
      printf "%%%s %s\n", tag, parts[i]
}

function bib_entry(type, key,    d, p, m) {
  bib_sep()
  r_names("A", bib_get("author"))
  r_names("E", bib_get("editor"))
  r_field("T", bib_get("title"))
  r_field("J", bib_get("journal"))
  r_field("B", bib_get("booktitle"))
  d = bib_get("year")
  m = bib_get("month")
  if (m != "")
    d = (d != "") ? m " " d : m
  r_field("D", d)
  r_field("V", bib_get("volume"))
  r_field("N", bib_get("number"))
  p = bib_get("pages")
  gsub(/--/, "-", p)
  r_field("P", p)
  if (bib_get("publisher") != "")
    r_field("I", bib_get("publisher"))
  else if (bib_get("institution") != "")
    r_field("I", bib_get("institution"))
  else if (bib_get("school") != "")
    r_field("I", bib_get("school"))
  r_field("C", bib_get("address"))
  r_field("K", bib_get("keywords"))
  r_field("X", bib_get("abstract"))
  r_field("O", bib_get("note"))
}