summary refs log tree commit diff
path: root/doc/rfc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--doc/rfc/.gitignore2
-rw-r--r--doc/rfc/Makefile38
-rw-r--r--doc/rfc/rfc.160
-rw-r--r--doc/rfc/rfc.in41
-rw-r--r--doc/rfc/rfctags.pl21
5 files changed, 162 insertions, 0 deletions
diff --git a/doc/rfc/.gitignore b/doc/rfc/.gitignore
new file mode 100644
index 00000000..cc3245d4
--- /dev/null
+++ b/doc/rfc/.gitignore
@@ -0,0 +1,2 @@
+rfc
+rfctags
diff --git a/doc/rfc/Makefile b/doc/rfc/Makefile
new file mode 100644
index 00000000..3078dcd3
--- /dev/null
+++ b/doc/rfc/Makefile
@@ -0,0 +1,38 @@
+PREFIX ?= ~/.local
+MANDIR ?= ${PREFIX}/share/man
+
+MODULE = ftp.rfc-editor.org::rfcs
+RFCS = ${MODULE}/rfc-index.txt ${MODULE}/'rfc[1-9]*.txt' ${MODULE}/'rfc*.json'
+
+all: rfc rfctags
+
+.SUFFIXES: .in .pl
+
+.in:
+	sed 's|%%PREFIX%%|${PREFIX}|g' $< > $@
+	chmod a+x $@
+
+.pl:
+	cp -f $< $@
+	chmod a+x $@
+
+clean:
+	rm -f rfc rfctags
+
+install: rfc rfctags rfc.1
+	install -d ${PREFIX}/bin ${MANDIR}/man1
+	install rfc rfctags ${PREFIX}/bin
+	install -m 644 rfc.1 ${MANDIR}/man1
+	ln -fs rfc.1 ${MANDIR}/man1/rfctags.1
+
+sync:
+	install -d ${PREFIX}/share
+	rsync -ptz ${RFCS} ${PREFIX}/share/rfc
+
+compress:
+	find ${PREFIX}/share/rfc -name '*.txt' | xargs gzip -9f
+
+uninstall:
+	rm -f ${PREFIX}/bin/rfc ${PREFIX}/bin/rfctags
+	rm -f ${MANDIR}/man1/rfc.1 ${MANDIR}/man1/rfctags.1
+	rm -fr ${PREFIX}/share/rfc
diff --git a/doc/rfc/rfc.1 b/doc/rfc/rfc.1
new file mode 100644
index 00000000..da393e8b
--- /dev/null
+++ b/doc/rfc/rfc.1
@@ -0,0 +1,60 @@
+.Dd January  3, 2022
+.Dt RFC 1
+.Os
+.
+.Sh NAME
+.Nm rfc ,
+.Nm rfctags
+.Nd view IETF RFCs
+.
+.Sh SYNOPSIS
+.Nm rfc
+.Op Ar number
+.Nm rfc
+.Fl b Ar number
+.Nm rfctags
+.Op Ar
+.
+.Sh DESCRIPTION
+The
+.Nm rfc
+utility displays
+an IETF RFC by number,
+or the RFC index if no number is specified.
+The RFC is displayed in the
+.Ev PAGER
+with a tags file generated by
+.Nm rfctags .
+The
+.Fl b
+option outputs an
+.Xr mdoc 7
+bibliographic block.
+.
+.Pp
+The
+.Nm rfctags
+utility generates tags
+for RFC text file
+section numbers,
+section names
+and bracketed references.
+.
+.Sh ENVIRONMENT
+.Bl -tag -width Ds
+.It Ev PAGER
+The program used to display RFCs.
+It must accept the
+.Fl T
+flag for specifying
+the path of the tags file.
+The default is
+.Ev PAGER=less .
+.El
+.
+.Sh SEE ALSO
+.Xr ctags 1 ,
+.Xr less 1
+.
+.Sh AUTHORS
+.An June Bug Aq Mt june@causal.agency
diff --git a/doc/rfc/rfc.in b/doc/rfc/rfc.in
new file mode 100644
index 00000000..abeb293f
--- /dev/null
+++ b/doc/rfc/rfc.in
@@ -0,0 +1,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}"
diff --git a/doc/rfc/rfctags.pl b/doc/rfc/rfctags.pl
new file mode 100644
index 00000000..05173d00
--- /dev/null
+++ b/doc/rfc/rfctags.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use open ':encoding(ISO-8859-1)';
+
+($,, $\) = ("\t", "\n");
+while (<>) {
+	chomp;
+	# Section headings
+	if (/^([\d.]+|[A-Z][.])\s+([^\t]+)?/) {
+		print $1, $ARGV, $.;
+		print $2, $ARGV, $. if $2;
+		print $1, $ARGV, $. if $1 =~ /^([\d.]+)[.]$/;
+	}
+	# References
+	if (/^\s*(\[[\w-]+\])\s{2,}/) {
+		print $1, $ARGV, $.;
+		print "\\$1", $ARGV, $.; # vim ^] prepends \ to [
+	}
+	close ARGV if eof;
+}