#!/usr/bin/perl -w use strict; # Convert 1id-index.txt from IETF Internet-Drafts repository # (ftp://ftp.ietf.org/internet-drafts/1id-index.txt and on mirrors) # into an infobot factpack. The index changes all the time, so this # has to be run often. # Unfortunately, the index file is usually a mess with extra blank # lines, bad formatting, etc. Most formatting errors will show up like this: # no draft name at ../1id-index2fact line 43, <> line 5370. # You may ignore the warnings or manually fix the file after the secretariat. # Written by Stanislav Shalunov, 2001-11, http://www.internet2.edu/~shalunov/ my ($wg, $par); {local $/= ""; <>; <>;} # Skip first two paragraphs (boilerplate). print "# Generated from 1id-index.txt with 1id-index2fact.\n", "# 1id-index2fact is a simple Perl program by Stanislav Shalunov.\n", "# See http://www.internet2.edu/~shalunov/1id-index2fact/\n"; while (<>) { # Unfortunately, the IETF secretariat puts spaces on some blank # lines, so setting $/ to "" won't enable us to read # paragraph-by-paragraph. We have to do this ugliness... next unless $par or $_; $par .= $_; unless (/^\s*$/) { $_ = <>; redo unless eof(); } $_ = $par; undef $par; # At this point, it's as if there was nothing above this line in the # loop body with $/ == "\n\s*\n" (modulo trailing space, which we # will remove anyway). If only $/ *were* a regexp... my @lines = split /\n/; #print "DEBUG: $lines[0]: ", scalar @lines, " lines\n"; if ($lines[1] and $lines[1] =~ /^----*$/) { # WG name in underlined $wg = $lines[0]; # with dashes. } else { # It's a draft name. s/\s+/ /g; # Make one line, remove extra whitespace. s/^\s+//; s/\s+$//; # Remove leading/trailing whitespace. unless (m/^(.*) <(draft-.*\.txt)/) { warn "no draft name"; next; } print "$2 => $1 $wg\n"; my $draft = $2; $draft =~ /^(.*)(\d\d)\.txt$/; my ($base, $version) = ($1, $2); for (my $i = 0; $i < $version; $i++) { printf "%s%02u.txt => obsolete. See %s.\n", $base, $i, $draft; } } }