summary refs log tree commit diff
diff options
context:
space:
mode:
authorC. McEnroe <june@causal.agency>2021-01-18 16:56:05 -0500
committerC. McEnroe <june@causal.agency>2021-01-18 16:56:05 -0500
commit3ad036b9a04811da71977fac5dc7ab6971f622bc (patch)
treecf8d976262922ce59df5b2053c385a64e86c9e10
parentPublish "reusing tags" (diff)
downloadsrc-3ad036b9a04811da71977fac5dc7ab6971f622bc.tar.gz
src-3ad036b9a04811da71977fac5dc7ab6971f622bc.zip
Don't compress RFCs, add rfc(1) command
-rw-r--r--doc/rfc/.gitignore5
-rw-r--r--doc/rfc/Makefile39
-rw-r--r--doc/rfc/rfc.153
-rw-r--r--doc/rfc/rfc.in8
-rw-r--r--doc/rfc/rfc.vim6
-rw-r--r--doc/rfc/rfctags.pl9
6 files changed, 98 insertions, 22 deletions
diff --git a/doc/rfc/.gitignore b/doc/rfc/.gitignore
index 808cd63..cc3245d 100644
--- a/doc/rfc/.gitignore
+++ b/doc/rfc/.gitignore
@@ -1,3 +1,2 @@
-*.txt
-*.txt.gz
-tags
+rfc
+rfctags
diff --git a/doc/rfc/Makefile b/doc/rfc/Makefile
index 87462a6..445e116 100644
--- a/doc/rfc/Makefile
+++ b/doc/rfc/Makefile
@@ -1,21 +1,40 @@
 PREFIX ?= ~/.local
+MANDIR ?= ${PREFIX}/share/man
 
+BINS = rfc rfctags
 MODULE = ftp.rfc-editor.org::rfcs-text-only
+RFCS = ${MODULE}/rfc-index.txt ${MODULE}/'rfc[1-9]*.txt'
 
-tags: rfctags.pl rfc-index.txt.gz
-	perl rfctags.pl | sort -f > $@
+all: ${BINS}
 
-rfc-index.txt.gz:
-	rsync -ptz ${MODULE}/rfc-index.txt ${MODULE}/'rfc[1-9]*.txt' .
-	gzip -9f *.txt
+.SUFFIXES: .in .pl
+
+.in:
+	sed 's|%%PREFIX%%|${PREFIX}|g' $< > $@
+	chmod a+x $@
+
+.pl:
+	cp -f $< $@
+	chmod a+x $@
 
 clean:
-	rm -f tags *.txt *.txt.gz
+	rm -f ${BINS}
+
+install: ${BINS} rfc.1
+	install -d ${PREFIX}/bin ${MANDIR}/man1 ${PREFIX}/share
+	install ${BINS} ${PREFIX}/bin
+	install -m 644 rfc.1 ${MANDIR}/man1
+	ln -fs rfc.1 ${MANDIR}/man1/rfctags.1
+	rsync -ptz ${RFCS} ${PREFIX}/share/rfc
 
-install: tags rfc.vim
-	install -d ${PREFIX}/share/rfc ${PREFIX}/share/nvim/site/plugin
-	ln -f tags *.txt.gz ${PREFIX}/share/rfc
+install-nvim: install rfc.vim
+	install -d ${PREFIX}/share/nvim/site/plugin
 	install -m 644 rfc.vim ${PREFIX}/share/nvim/site/plugin
+	(cd ${PREFIX}/share/rfc \
+		&& printf '!_TAG_FILE_SORTED\t2\ttags\n' \
+		&& ${PREFIX}/bin/rfctags *.txt) | sort -f > ${PREFIX}/share/rfc/tags
 
 uninstall:
-	rm -fr ${PREFIX}/share/rfc ${PREFIX}/share/nvim/site/plugin/rfc.vim
+	rm -f ${BINS:%=${PREFIX}/bin/%} ${BINS:%=${MANDIR}/man1/%.1}
+	rm -f ${PREFIX}/share/nvim/site/plugin/rfc.vim
+	rm -fr ${PREFIX}/share/rfc
diff --git a/doc/rfc/rfc.1 b/doc/rfc/rfc.1
new file mode 100644
index 0000000..ece5a90
--- /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 0000000..adf297e
--- /dev/null
+++ b/doc/rfc/rfc.in
@@ -0,0 +1,8 @@
+#!/bin/sh
+set -eu
+
+rfc=%%PREFIX%%/share/rfc/"rfc${1:--index}.txt"
+tags=$(mktemp -t rfc)
+trap 'rm "${tags}"' EXIT
+%%PREFIX%%/bin/rfctags "${rfc}" >"${tags}"
+${PAGER:-less} -T "${tags}" "${rfc}"
diff --git a/doc/rfc/rfc.vim b/doc/rfc/rfc.vim
index 2455d8a..4649cdf 100644
--- a/doc/rfc/rfc.vim
+++ b/doc/rfc/rfc.vim
@@ -1,5 +1,5 @@
 if !exists('g:rfc_path')
-	let g:rfc_path = expand('<sfile>:h:h:h:h') . '/rfc'
+	let g:rfc_path = fnamemodify(exepath('rfc'), ':h:h') . '/share/rfc'
 endif
 
 function! s:RFC(number)
@@ -8,7 +8,7 @@ function! s:RFC(number)
 	else
 		let number = '-index'
 	endif
-	let path = expand(g:rfc_path . '/rfc' . number . '.txt.gz')
+	let path = expand(g:rfc_path . '/rfc' . number . '.txt')
 	if filereadable(path)
 		execute 'silent' 'noswapfile' 'view' path
 	else
@@ -26,5 +26,5 @@ endfunction
 command! -bar -nargs=? RFC call s:RFC(<q-args>)
 augroup RFC
 	autocmd!
-	autocmd BufRead rfc*.txt.gz call s:BufRead()
+	autocmd BufRead rfc*.txt call s:BufRead()
 augroup END
diff --git a/doc/rfc/rfctags.pl b/doc/rfc/rfctags.pl
index 01324a0..45e74f9 100644
--- a/doc/rfc/rfctags.pl
+++ b/doc/rfc/rfctags.pl
@@ -1,14 +1,11 @@
+#!/usr/bin/env perl
 use strict;
 use warnings;
 use open ':encoding(ISO-8859-1)';
 
-use IO::Uncompress::Gunzip qw($GunzipError);
-
 ($,, $\) = ("\t", "\n");
-print '!_TAG_FILE_SORTED', 2, $0; # Promise to pipe this through sort -f
-for my $rfc (<*.txt.gz>) {
-	my $handle = new IO::Uncompress::Gunzip $rfc
-		or die "${rfc}: ${GunzipError}";
+for my $rfc (@ARGV) {
+	open my $handle, '<', $rfc or die "${rfc}: $!";
 	while (<$handle>) {
 		chomp;
 		# Section headings