From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7e0af11f0ae4fd3e,start X-Google-Attributes: gid103376,public From: mw@ipx2.rz.uni-mannheim.de (Marc Wachowitz) Subject: Annotated Reference Manual: Text to HTML Date: 1997/11/02 Message-ID: <63i5pj$4mu$1@trumpet.uni-mannheim.de> X-Deja-AN: 287392490 Organization: --- Newsgroups: comp.lang.ada Date: 1997-11-02T00:00:00+00:00 List-Id: I've written a simple Perl script which transforms the text version of the Annotated Ada-95 Reference Manual into a set of html documents - though only links from/to a table of contents and the previous/next section/annex are created. The result isn't very beautiful, but sufficient for me to save lots of paper. Feel free to use it as you like (improvements are welcome, though I'm only interested if it works with lynx, a text-mode browser). The text version of the AARM is available as ftp://sw-eng.falls-church.va.us/public/AdaIC/standards/95lrm_rat/v6.0/aarm.txt -- Marc Wachowitz #! /usr/local/bin/perl -w # Expect Annotated Ada-95 Reference Manual on standard input use strict; use English; # file name conventions; prefix/suffix are not applied to $file_toc # (I prefer to put all files into directory 'AARM' - which must exist) my $file_toc = 'AARM/index.html'; my $file_prefix = 'AARM/'; my $file_suffix = '.html'; # html name conventions; prefix/suffix are not applied to $html_toc # (e.g. change '.html' to '.html.gz' and gzip all generated files later) my $html_toc = 'index.html'; my $html_prefix = ''; my $html_suffix = '.html'; # html document type my $doc = ''; # Annex titles for generated table of contents my %annex = ('A' => 'Predefined Language Environment', 'B' => 'Interface to Other Languages', 'C' => 'Systems Programming', 'D' => 'Real-Time Systems', 'E' => 'Distributed Systems', 'F' => 'Information Systems', 'G' => 'Numerics', 'H' => 'Safety and Security', 'J' => 'Obsolescent Features', 'K' => 'Language-Defined Attributes', 'L' => 'Language-Defined Pragmas', 'M' => 'Implementation-Defined Characteristics', 'N' => 'Glossary', 'P' => 'Syntax Summary'); my $prev_link; # undefined or reference to previous document my $counter = 0; # used to generate unique names my $pending_blank = 0; # are there any pending blank lines? sub chapter { # start new chapter, or close the last one my $name = shift; # logical name for this chapter my $title = shift; # title my $last = shift; # close last chapter? # mangle logical names (not necessary, but it's nice in the file system): $name =~ s/^([0-9])$/0$1/; $name =~ s/^([A-Z])$/$1_/; $name =~ s/^([0-9])\./0$1\./; $name =~ s/^([A-Z])\./$1_\./; $name =~ s/\.([0-9])\./\.0$1\./; $name =~ s/\.([0-9])$/\.0$1/; $name =~ s/^(..)\.(..)$/$1\.$2.00/; $name =~ s/^(..)$/$1\.00.00/; $counter++; $name = "$name._$counter"; # make $name unique, no matter what happened my $html_name = "$html_prefix$name$html_suffix"; if (defined($prev_link)) { # finish previous document if (! $last) { print OUT "\n[NEXT]\n"; } print OUT "\n"; close(OUT); } if (! $last) { # open this new document my $file_name = "$file_prefix$name$file_suffix"; open(OUT, "> $file_name") or die "cannot open output to '$file_name':\n$ERRNO\n"; $title =~ s/^s+//; $title =~ s/\s+$//; print OUT "$doc\n\n$title\n\n
\n";
    if (defined($prev_link)) {
      print OUT "[PREV]";
    }
    print OUT "[TOC]\n\n";
    print TOC "
  • $title\n"; } $prev_link = $html_name; $pending_blank = 0; } sub main { my $first_index = 1; open(TOC, "> $file_toc") or die "cannot open output to '$file_toc':\n$ERRNO\n"; print TOC "$doc\nAnnotated Ada-95 Reference Manual\n
      \n"; chapter('0', 'Preface', 0); while (defined(my $line = <>)) { $line =~ s/\s*$/\n/; $line =~ s/&/&/; $line =~ s//>/; if ($line =~ /^ *Section +([0-9]+)(:.*)$/) { print TOC "\n

      \n"; chapter($1, "$1$2", 0); } elsif ($line =~ /^ *Annex +([A-Z])$/) { print TOC "\n

      \n"; chapter($1, "$1: $annex{$1}\n", 0); } elsif ($line =~ /^Index$/ && $first_index) { print TOC "\n

      \n"; chapter('XX', $line, 0); $first_index = 0; } elsif ($line =~ /^Contents$/) { print TOC "\n

      \n"; chapter('ZZ', $line, 0); } elsif ($line =~ /^(([0-9]+|[A-Z])\.[0-9]+(\.[0-9]+)*) +[A-Z]/) { chapter($1, $line, 0); } if ($line =~ /^$/) { # compress multiple blank lines to just one $pending_blank = 1; } else { if ($pending_blank) { $pending_blank = 0; print OUT "\n"; } print OUT $line; } } print TOC "
    \n"; close(TOC); chapter('ZZ', '...', 1); # pseudo-chapter, to properly end the last one } main()