summary refs log tree commit diff
path: root/doc/rfc/rfc.in
blob: abeb293ff640f3bc55eb13a8d404760e4a363389 (plain) (blame)
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
#!/bin/sh
set -eu

mktemp='mktemp -t rfc'
[ "$(uname)" = 'OpenBSD' ] && mktemp="${mktemp}.XXXXXXXXXX"

bib=
while getopts 'b:' opt; do
	case $opt in
		(b) bib=$OPTARG;;
		(?) exit 1;;
	esac
done
shift $((OPTIND - 1))

if test -n "${bib}"; then
	exec jq -r '
		".Rs",
		(.authors[] | ".%A \(.)"),
		".%T \(.title | ltrimstr(" "))",
		".%I IETF",
		".%R \(.doc_id)",
		".%U https://tools.ietf.org/html/\(.doc_id | ascii_downcase)",
		".%D \(.pub_date)",
		".Re"
	' %%PREFIX%%/share/rfc/"rfc${bib}.json"
fi

rfc=%%PREFIX%%/share/rfc/"rfc${1:--index}.txt"
tags=$($mktemp)
trap 'rm "${tags}"' EXIT

if test -f "${rfc}.gz"; then
	txt=$($mktemp)
	trap 'rm "${txt}" "${tags}"' EXIT
	gunzip -c "${rfc}.gz" >"${txt}"
	rfc=$txt
fi

%%PREFIX%%/bin/rfctags "${rfc}" >"${tags}"
${PAGER:-less} -T "${tags}" "${rfc}"