summary refs log tree commit diff
path: root/rfc/rfctags.pl
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-18 22:59:41 -0500
committerJune McEnroe <june@causal.agency>2020-12-18 22:59:41 -0500
commit95ae2be15891eae0b62a83d1adcc8380548c9290 (patch)
tree7ccbe7678ea106d18c378bcf362f7799fd2118d3 /rfc/rfctags.pl
parentFix bibsort name sorting for middle names, trailing titles (diff)
downloadsrc-95ae2be15891eae0b62a83d1adcc8380548c9290.tar.gz
src-95ae2be15891eae0b62a83d1adcc8380548c9290.zip
Add scripts to download, compress and tag IETF RFCs
Diffstat (limited to 'rfc/rfctags.pl')
-rw-r--r--rfc/rfctags.pl26
1 files changed, 26 insertions, 0 deletions
diff --git a/rfc/rfctags.pl b/rfc/rfctags.pl
new file mode 100644
index 00000000..cd3ba288
--- /dev/null
+++ b/rfc/rfctags.pl
@@ -0,0 +1,26 @@
+use strict;
+use warnings;
+use open ':encoding(ISO-8859-1)';
+
+use IO::Uncompress::Gunzip qw($GunzipError);
+
+($,, $\) = ("\t", "\n");
+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, $.;
+		}
+		# References
+		if (/^\s*(\[[\w-]+\])\s{2,}/) {
+			print $1, $rfc, $.;
+			print "\\$1", $rfc, $.; # vim ^] prepends \ to [
+		}
+	}
+	die "${rfc}: $!" if $!;
+	close $handle;
+}