summary refs log tree commit diff
path: root/rfc/rfctags.pl
blob: 5833e17aac638030fd4e0e85bacaa4bdca730e47 (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
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;
		}
		# References
		if (/^\s*(\[[\w-]+\])\s{2,}/) {
			print $1, $rfc, $.;
			print "\\$1", $rfc, $.; # vim ^] prepends \ to [
		}
	}
	die "${rfc}: $!" if $!;
	close $handle;
}