# -*- Perl -*- # # $Id: rfcgen,v 1.10 2001/11/14 21:51:32 sra Exp $ # # Automate some processing for I-D documents. # Read our magic control goop out of NROFF comments at the head of the file. while (<>) { push @lines, $_; chomp; # last if (/^\.\\""*\s*%%\s*make_header\s*$/i); last unless (/^\.\\""*/); next unless (/^\.\\""*\s*%%\s*(\w+)\s*::=\s*(.*\S)\s*$/); my $key = $1; my $val = $2; if ($key eq 'draft_name') { $draft_name = $val; next; } if ($key eq 'draft_number') { $draft_number = $val, next; } if ($key eq 'author_foot') { $author_foot = $val, next; } if ($key eq 'author') { push @authors, $val; next; } warn "unrecognized key \"$key\""; } # Allow draft number to come from RCS/CVS major revision number. $draft_number = sprintf("%02d", $1 - 1) if ($draft_number =~ /\044Revision: (\d+)(\.\d+)+ \044/); # Check our magic control goop. die "Missing draft_name" unless (defined ($draft_name)); die "Missing draft_number" unless (defined ($draft_number)); die "Missing author_foot" unless (defined ($author_foot)); die "Missing author" unless (@authors); die "Malformatted draft_number" unless ($draft_number =~ /^[0-9][0-9]$/); # Filenames we're going to generate. $nroff_filename = $draft_name . '-' . $draft_number . '.ms'; $text_filename = $draft_name . '-' . $draft_number . '.txt'; # Calculate the date values we need for the header. { my @months = qw(January February March April May June July August September October November December); my $now = time; my ($pub_month, $pub_year) = (localtime ($now))[4..5]; my ($exp_day, $exp_month, $exp_year) = (localtime ($now + 187 *24*60*60))[3..5]; $publication = $months[$pub_month] . " " . ($pub_year + 1900); $expiration = $exp_day . " " . $months[$exp_month] . " " . ($exp_year + 1900); } # Generate the NROFF output file. die "Couldn't open $nroff_filename: $!" unless (open(NROFF_FILE, '>' . $nroff_filename)); select(NROFF_FILE); $line = pop @lines; print @lines; print <); close(NROFF_FILE); # Run nroff on the file we just generated, and post-process its output die "Couldn't open $text_filename: $!" unless (open(TEXT_FILE, ">" . $text_filename)); die "Couldn't run nroff: $!" unless (open(NROFF, "nroff -ms " . $nroff_filename . "|")); select(TEXT_FILE); while () { next if ($skip && /^[ \t]*\n/); $skip = 0, print "\f\n" if ($skip); print; $skip = 1 if (/\[Page [0-9]*\]$/); } close(NROFF); close(TEXT_FILE); # Candidate RCS keywords for automatic frobbing, one of these days: # # $Source: /usr/cvsroot/ietf/rfcgen/rfcgen,v $ # $Date: 2001/11/14 21:51:32 $ # $RCSfile: rfcgen,v $ # $Revision: 1.10 $ # One way we could guess the author's name.... # # $_ = ((getpwuid $<)[6]); s/(\w)\w* /$1. /g;