summary refs log tree commit diff
path: root/doc/rfc
diff options
context:
space:
mode:
Diffstat (limited to 'doc/rfc')
-rw-r--r--doc/rfc/.gitignore2
-rw-r--r--doc/rfc/Makefile38
-rw-r--r--doc/rfc/rfc.153
-rw-r--r--doc/rfc/rfc.in19
-rw-r--r--doc/rfc/rfctags.pl21
5 files changed, 133 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..31e238a0
--- /dev/null
+++ b/doc/rfc/Makefile
@@ -0,0 +1,38 @@
+PREFIX ?= ~/.local
+MANDIR ?= ${PREFIX}/share/man
+
+MODULE = ftp.rfc-editor.org::rfcs-text-only
+RFCS = ${MODULE}/rfc-index.txt ${MODULE}/'rfc[1-9]*.txt'
+
+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..ece5a901
--- /dev/null
+++ b/doc/rfc/rfc.1
@@ -0,0 +1,53 @@
+.Dd January 18, 2021
+.Dt RFC 1
+.Os
+.
+.Sh NAME
+.Nm rfc ,
+.Nm rfctags
+.Nd view IETF RFCs
+.
+.Sh SYNOPSIS
+.Nm rfc
+.Op 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 .
+.
+.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..16081c83
--- /dev/null
+++ b/doc/rfc/rfc.in
@@ -0,0 +1,19 @@
+#!/bin/sh
+set -eu
+
+mktemp='mktemp -t rfc'
+[ "$(uname)" = 'OpenBSD' ] && mktemp="${mktemp}.XXXXXXXXXX"
+
+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;
+}