#!/usr/local/bin/perl -w # ==================================================================== # Copyright (c) 1999, MeepZor Consulting. # All rights reserved. # # The use and distribution of this code or document is # governed by version 1.0.1 of the MeepZor Consulting Public # Licence (MCPL), which may be found on the Internet at # . # # # $Id: ietf-paginate,v 1.5 1999/12/12 18:44:22 coar Exp $ # # # A script to massage ASCII text into RFC or Internet-Draft format. # It inserts formfeeds, page headers, and page footers according to # RFC 2223. It will *not* adjust page numbers in a table of contents. # # Assumptions: # o the first header is correct; formatting begins at the first footer # o The author's name, category, and date will fit into 72 characters, with # whitespace filler # # STDIN is the input file # Results are emitted to STDOUT # # Options: # -a "author(s)" # -c "category" (only for RFCs): {"Standards Track", "Best Current Practice", # "Informational", "Experimental"} # -d "date" ("month, year" for RFC, "day month, year" for I-D) # -t type (RFC or draft) # -T "title" use Getopt::Std; @categories = ( "INTERNET-DRAFT", "Standards Track", "Best Current Practice", "Informational", "Experimental" ); $categories = join("|", @categories); $opt_a = $opt_c = $opt_d = $opt_t = $opt_T = ""; &getopts("a:c:d:t:T:"); @errors = (); $Type = uc($opt_t); if (! $Type) { $Type = "DRAFT"; print STDERR "Assuming '-t DRAFT'\n"; } if ($Type !~ /RFC|DRAFT/) { push(@errors, "-t must specify either RFC or DRAFT"); } if ($Type eq "DRAFT") { $Category = "INTERNET-DRAFT"; } else { $Category = $opt_c; } if ($Category !~ /$categories/) { my($errmsg); $errmsg = "-c must specify one of the following:\n"; $errmsg .= "\t" . join("\n\t", @categories); push(@errors, $errmsg); } $Author = $opt_a; if (! $Author) { push(@errors, "-a must specify an author"); } $Date = $opt_d; if (! $Date) { my($tmp) = ($Type eq "DRAFT") ? "n expiration" : " release"; push(@errors, "-d must specify a$tmp date"); } $Title = $opt_T; if (! $Title) { push(@errors, "-T must specify a document title"); } if ($#errors >= 0) { print STDERR "$0: ", join("\n$0: ", @errors), "\n"; exit 1; } $Page = 1; $Line = 0; while () { $Line++; if (($Line == 3) && ($Page != 1)){ print &Header(); } print $_; if ($Line == 56) { print &Footer(); $Line = 2; } } if ($Line != 2) { print "\n" x (56 - $Line), &Footer(); } exit 0; sub Header { local($fDate, $lwsp1, $lwsp2, $fHeader); $fDate = $Date; if ($Type eq "DRAFT") { $fDate = "Expires: " . $fDate; } $lwsp1 = 36 - int(length($Title) / 2); $lwsp2 = 72 - (length($fDate) + length($Title) + $lwsp1); $fHeader = (" " x $lwsp1) . $Title . (" " x $lwsp2) . $fDate; return $fHeader . "\n\n"; } sub Footer { local ($lwsp1, $lwsp2, $page, $fFooter); $lwsp1 = 36 - length($Author) - int(length($Category) / 2); $page = "[Page $Page]"; $Page++; $lwsp2 = 72 - (length($page) + $lwsp1 + length($Author) + length($Category)); $fFooter = $Author . (" " x $lwsp1) . $Category . (" " x $lwsp2) . $page; return "\n$fFooter\n\f\n"; }