diff options
Diffstat (limited to 'doc/rfc')
-rw-r--r-- | doc/rfc/Makefile | 30 | ||||
-rw-r--r-- | doc/rfc/rfc.1 | 9 | ||||
-rw-r--r-- | doc/rfc/rfc.in | 35 | ||||
-rw-r--r-- | doc/rfc/rfc.vim | 30 | ||||
-rw-r--r-- | doc/rfc/rfctags.pl | 30 |
5 files changed, 69 insertions, 65 deletions
diff --git a/doc/rfc/Makefile b/doc/rfc/Makefile index 445e1163..3078dcd3 100644 --- a/doc/rfc/Makefile +++ b/doc/rfc/Makefile @@ -1,11 +1,10 @@ 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' +MODULE = ftp.rfc-editor.org::rfcs +RFCS = ${MODULE}/rfc-index.txt ${MODULE}/'rfc[1-9]*.txt' ${MODULE}/'rfc*.json' -all: ${BINS} +all: rfc rfctags .SUFFIXES: .in .pl @@ -18,23 +17,22 @@ all: ${BINS} chmod a+x $@ clean: - rm -f ${BINS} + rm -f rfc rfctags -install: ${BINS} rfc.1 - install -d ${PREFIX}/bin ${MANDIR}/man1 ${PREFIX}/share - install ${BINS} ${PREFIX}/bin +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 -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 +compress: + find ${PREFIX}/share/rfc -name '*.txt' | xargs gzip -9f uninstall: - rm -f ${BINS:%=${PREFIX}/bin/%} ${BINS:%=${MANDIR}/man1/%.1} - rm -f ${PREFIX}/share/nvim/site/plugin/rfc.vim + 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 index ece5a901..da393e8b 100644 --- a/doc/rfc/rfc.1 +++ b/doc/rfc/rfc.1 @@ -1,4 +1,4 @@ -.Dd January 18, 2021 +.Dd January 3, 2022 .Dt RFC 1 .Os . @@ -10,6 +10,8 @@ .Sh SYNOPSIS .Nm rfc .Op Ar number +.Nm rfc +.Fl b Ar number .Nm rfctags .Op Ar . @@ -23,6 +25,11 @@ 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 diff --git a/doc/rfc/rfc.in b/doc/rfc/rfc.in index 958b09da..abeb293f 100644 --- a/doc/rfc/rfc.in +++ b/doc/rfc/rfc.in @@ -1,8 +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 -t rfc.XXXXXXXXXX) +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/rfc.vim b/doc/rfc/rfc.vim deleted file mode 100644 index 4649cdf5..00000000 --- a/doc/rfc/rfc.vim +++ /dev/null @@ -1,30 +0,0 @@ -if !exists('g:rfc_path') - let g:rfc_path = fnamemodify(exepath('rfc'), ':h:h') . '/share/rfc' -endif - -function! s:RFC(number) - if !empty(a:number) - let number = str2nr(matchstr(a:number, '\d\+'), 10) - else - let number = '-index' - endif - let path = expand(g:rfc_path . '/rfc' . number . '.txt') - if filereadable(path) - execute 'silent' 'noswapfile' 'view' path - else - echohl ErrorMsg | echo 'No such RFC' a:number | echohl None - endif -endfunction - -function! s:BufRead() - setlocal readonly - setlocal keywordprg=:RFC - setlocal iskeyword=a-z,A-Z,48-57,.,[,],-,_ - nmap <buffer> <silent> gO :call search('^Table of Contents', 'bcs')<CR> -endfunction - -command! -bar -nargs=? RFC call s:RFC(<q-args>) -augroup RFC - autocmd! - autocmd BufRead rfc*.txt call s:BufRead() -augroup END diff --git a/doc/rfc/rfctags.pl b/doc/rfc/rfctags.pl index 45e74f9a..05173d00 100644 --- a/doc/rfc/rfctags.pl +++ b/doc/rfc/rfctags.pl @@ -4,22 +4,18 @@ use warnings; use open ':encoding(ISO-8859-1)'; ($,, $\) = ("\t", "\n"); -for my $rfc (@ARGV) { - open my $handle, '<', $rfc or die "${rfc}: $!"; - while (<$handle>) { - chomp; - # Section headings - if (/^([\d.]+|[A-Z][.])\s+([^\t]+)?/) { - print $1, $rfc, $.; - print $2, $rfc, $. if $2; - print $1, $rfc, $. if $1 =~ /^([\d.]+)[.]$/; - } - # References - if (/^\s*(\[[\w-]+\])\s{2,}/) { - print $1, $rfc, $.; - print "\\$1", $rfc, $.; # vim ^] prepends \ to [ - } +while (<>) { + chomp; + # Section headings + if (/^([\d.]+|[A-Z][.])\s+([^\t]+)?/) { + print $1, $ARGV, $.; + print $2, $ARGV, $. if $2; + print $1, $ARGV, $. if $1 =~ /^([\d.]+)[.]$/; } - die "${rfc}: $!" if $!; - close $handle; + # References + if (/^\s*(\[[\w-]+\])\s{2,}/) { + print $1, $ARGV, $.; + print "\\$1", $ARGV, $.; # vim ^] prepends \ to [ + } + close ARGV if eof; } |