summary refs log tree commit diff
path: root/rfc/rfctags.pl
blob: 01324a0d5838e846ed85ac4ca71a127ffdd286f9 (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
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}";
	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 [
		}
	}
	die "${rfc}: $!" if $!;
	close $handle;
}