home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-15 | 8.3 KB | 399 lines | [TEXT/MPS ] |
- miniperl -Sx "{0}" {"Parameters"}
- Exit 0
-
- #!/usr/bin/perl
-
- $/ = "";
- $cutting = 1;
- $tcon = 0;
-
- $name = @ARGV ? $ARGV[0] : "something";
- $name =~ s/\..*//;
-
- while (<>) {
- if ($cutting) {
- next unless /^=/;
- $cutting = 0;
- }
- chomp;
-
- # Translate verbatim paragraph
-
- if (/^\s/) {
- @lines = split(/\n/);
- for (@lines) {
- 1 while s
- {^( [^\t]* ) \t ( \t* ) }
- { $1 . ' ' x (8 - (length($1)%8) + 8 * (length($2))) }ex;
- }
- $lines = @lines;
- &makespace;
- emit(join("\n", @lines) . "\n");
- &endpar;
- next;
- }
-
- if (!/^=item/) {
-
- # trofficate backslashes; must do it before what happens below
- s/\\/noremap('\\e')/ge;
-
- # first hide the escapes in case we need to
- # intuit something and get it wrong due to fmting
-
- s/([A-Z]<[^<>]*>)/noremap($1)/ge;
-
- # func() is a reference to a perl function
- s{
- \b
- (
- [:\w]+ \(\)
- )
- } {I<$1>}gx;
-
- # func(n) is a reference to a man page
- s{
- (\w+)
- (
- \(
- [^\s,\051]+
- \)
- )
- } {I<$1>($2)}gx;
-
- # convert simple variable references
- s/([\$\@%][\w:]+)/C<$1>/g;
-
- if (m{ (
- [\-\w]+
- \(
- [^\051]*?
- [\@\$,]
- [^\051]*?
- \)
- )
- }x && $` !~ /([LCI]<[^<>]*|-)$/ && !/^=\w/)
- {
- warn "``$1'' should be a [LCI]<$1> ref";
- }
-
- while (/(-[a-zA-Z])\b/g && $` !~ /[\w\-]$/) {
- warn "``$1'' should be [CB]<$1> ref";
- }
-
- # put it back so we get the <> processed again;
- clear_noremap(0); # 0 means leave the E's
-
- } else {
- # trofficate backslashes
- s/\\/noremap('\\e')/ge;
-
- }
-
- # need to hide E<> first; they're processed in clear_noremap
- s/(E<[^<>]+>)/noremap($1)/ge;
-
-
- $maxnest = 10;
- while ($maxnest-- && /[A-Z]</) {
-
- # can't do C font here
- s/([BI])<([^<>]*)>/$2/g;
-
- # files and filelike refs in italics
- s/F<([^<>]*)>/I<$1>/g;
-
- # no break -- usually we want C<> for this
- s/S<([^<>]*)>/nobreak($1)/eg;
-
- # LREF: a manpage(3f)
- s:L<([a-zA-Z][^\s\/]+)(\([^\)]+\))?>:the I<$1>$2 manpage:g;
-
- # LREF: an =item on another manpage
- s{
- L<
- ([^/]+)
- /
- (
- [:\w]+
- (\(\))?
- )
- >
- } {the C<$2> entry in the I<$1> manpage}gx;
-
- # LREF: an =item on this manpage
- s{
- ((?:
- L<
- /
- (
- [:\w]+
- (\(\))?
- )
- >
- (,?\s+(and\s+)?)?
- )+)
- } { internal_lrefs($1) }gex;
-
- # LREF: a =head2 (head1?), maybe on a manpage, maybe right here
- # the "func" can disambiguate
- s{
- L<
- (?:
- ([a-zA-Z]\S+?) /
- )?
- "?(.*?)"?
- >
- }{
- do {
- $1 # if no $1, assume it means on this page.
- ? "the section on I<$2> in the I<$1> manpage"
- : "the section on I<$2>"
- }
- }gex;
-
- s/Z<>/\\&/g;
-
- # comes last because not subject to reprocessing
- s/C<([^<>]*)>/noremap("${1}")/eg;
- }
-
- if (s/^=//) {
- $needspace = 0; # Assume this.
-
- s/\n/ /g;
-
- ($Cmd, $_) = split(' ', $_, 2);
-
- if (defined $_) {
- &escapes;
- }
-
- clear_noremap(1);
-
- if ($Cmd eq 'cut') {
- $cutting = 1;
- }
- elsif ($Cmd eq 'head1') {
- emit("\\str#\n");
- emit("\\keep\n") unless $keep++;
- emittoc("\\tcon $_\n\n");
- emit("\\style bold\n\\size 140\n$_\n\n");
- }
- elsif ($Cmd eq 'head2') {
- emit("\\keep\n") unless $keep++;
- emittoc("\\tcon $_\n\n");
- emit("\\style bold\n\\size 120\n$_\n");
- }
- elsif ($Cmd eq 'over') {
- push(@indent,$indent);
- $indent = $_ + 0;
- }
- elsif ($Cmd eq 'back') {
- $indent = pop(@indent);
- warn "Unmatched =back\n" unless defined $indent;
- $needspace = 1;
- }
- elsif ($Cmd eq 'item') {
- if (/\*.\s*(\S)/) {
- emit("• $1$'");
- } elsif (/\*/) {
- $bullet = "• ";
- } elsif (/\S/) {
- emit("$_");
- }
- }
- else {
- warn "Unrecognized directive: $Cmd\n";
- }
- } else {
- s/\n/ /g;
- &makespace;
- &escapes;
- clear_noremap(1);
- emit("$bullet$_\n");
- $bullet = "";
- &endpar;
- $needspace = 1;
- }
- }
-
- &eject;
-
- #########################################################################
-
- sub nobreak {
- my $string = shift;
- $string =~ s/ /\\ /g;
- $string;
- }
-
- sub escapes {
- }
-
-
- sub makespace {
- emit("\n");
- }
-
- sub noremap {
- local($thing_to_hide) = shift;
- $thing_to_hide =~ tr/\000-\177/\200-\377/;
- return $thing_to_hide;
- }
-
- sub init_noremap {
- if ( /[\200-\377]/ ) {
- warn "hit bit char in input stream";
- }
- }
-
- sub clear_noremap {
- my $ready_to_print = $_[0];
-
- tr/\200-\377/\000-\177/;
-
- s/\\ /\312/;
-
- # now for the E<>s, which have been hidden until now
- # otherwise the interative \w<> processing would have
- # been hosed by the E<gt>
- s {
- E<
- ( [A-Za-z]+ )
- >
- } {
- do {
- exists $HTML_Escapes{$1}
- ? do { $HTML_Escapes{$1} }
- : do {
- warn "Unknown escape: $& in $_";
- "E<$1>";
- }
- }
- }egx if $ready_to_print;
- }
-
- sub internal_lrefs {
- local($_) = shift;
-
- s{L</([^>]+)>}{$1}g;
- my(@items) = split( /(?:,?\s+(?:and\s+)?)/ );
- my $retstr = "the ";
- my $i;
- for ($i = 0; $i <= $#items; $i++) {
- $retstr .= "C<$items[$i]>";
- $retstr .= ", " if @items > 2 && $i != $#items;
- $retstr .= " and " if $i+2 == @items;
- }
-
- $retstr .= " entr" . ( @items > 1 ? "ies" : "y" )
- . " elsewhere in this document";
-
- return $retstr;
-
- }
-
- BEGIN {
- %HTML_Escapes = (
- 'amp' => '&', # ampersand
- 'lt' => '<', # left chevron, less-than
- 'gt' => '>', # right chevron, greater-than
- 'quot' => '"', # double quote
-
- "Aacute" => "A", # capital A, acute accent
- "aacute" => "á", # small a, acute accent
- "Acirc" => "A", # capital A, circumflex accent
- "acirc" => "â", # small a, circumflex accent
- "AElig" => "Æ", # capital AE diphthong (ligature)
- "aelig" => "æ", # small ae diphthong (ligature)
- "Agrave" => "A", # capital A, grave accent
- "agrave" => "à", # small a, grave accent
- "Aring" => "Å", # capital A, ring
- "aring" => 'å', # small a, ring
- "Atilde" => 'Ã', # capital A, tilde
- "atilde" => 'ã', # small a, tilde
- "Auml" => 'Ä', # capital A, dieresis or umlaut mark
- "auml" => 'ä', # small a, dieresis or umlaut mark
- "Ccedil" => 'Ç', # capital C, cedilla
- "ccedil" => 'ç', # small c, cedilla
- "Eacute" => "É", # capital E, acute accent
- "eacute" => "é", # small e, acute accent
- "Ecirc" => "E", # capital E, circumflex accent
- "ecirc" => "ê", # small e, circumflex accent
- "Egrave" => "E", # capital E, grave accent
- "egrave" => "è", # small e, grave accent
- "Euml" => "E", # capital E, dieresis or umlaut mark
- "euml" => "ë", # small e, dieresis or umlaut mark
- "Iacute" => "I", # capital I, acute accent
- "iacute" => "í", # small i, acute accent
- "Icirc" => "I", # capital I, circumflex accent
- "icirc" => "î", # small i, circumflex accent
- "Igrave" => "I", # capital I, grave accent
- "igrave" => "ì", # small i, grave accent
- "Iuml" => "I", # capital I, dieresis or umlaut mark
- "iuml" => "ï", # small i, dieresis or umlaut mark
- "Ntilde" => 'Ñ', # capital N, tilde
- "ntilde" => 'ñ', # small n, tilde
- "Oacute" => "O", # capital O, acute accent
- "oacute" => "ó", # small o, acute accent
- "Ocirc" => "O", # capital O, circumflex accent
- "ocirc" => "ô", # small o, circumflex accent
- "Ograve" => "O", # capital O, grave accent
- "ograve" => "ò", # small o, grave accent
- "Oslash" => "Ø", # capital O, slash
- "oslash" => "ø", # small o, slash
- "Otilde" => "Õ", # capital O, tilde
- "otilde" => "õ", # small o, tilde
- "Ouml" => "Ö", # capital O, dieresis or umlaut mark
- "ouml" => "ö", # small o, dieresis or umlaut mark
- "szlig" => 'ß', # small sharp s, German (sz ligature)
- "Uacute" => "U", # capital U, acute accent
- "uacute" => "ú", # small u, acute accent
- "Ucirc" => "U", # capital U, circumflex accent
- "ucirc" => "û", # small u, circumflex accent
- "Ugrave" => "U", # capital U, grave accent
- "ugrave" => "ù", # small u, grave accent
- "Uuml" => "Ü", # capital U, dieresis or umlaut mark
- "uuml" => "ü", # small u, dieresis or umlaut mark
- "Yacute" => "Y", # capital Y, acute accent
- "yacute" => "y", # small y, acute accent
- "yuml" => "ÿ", # small y, dieresis or umlaut mark
- );
- }
-
- sub emit {
- my($str) = @_;
-
- $body .= $str;
- }
-
- sub emittoc {
- my($str) = @_;
-
- $body .= $str;
- ++$ntoc;
- }
-
- sub eject {
- print <<END;
- \\only print
- \\style bold
- \\just center
- \\size 140
- Table of Contents
- \\only print
-
- \\itcon $ntoc
-
- \\page
- $body
- END
- }
-
- sub endpar {
- if ($keep) {
- emit("\\endkeep\n\n");
- $keep = 0;
- }
- }