From: mw@ipx2.rz.uni-mannheim.de (Marc Wachowitz)
Subject: Annotated Reference Manual: Text to HTML
Date: 1997/11/02
Date: 1997-11-02T00:00:00+00:00 [thread overview]
Message-ID: <63i5pj$4mu$1@trumpet.uni-mannheim.de> (raw)
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 <mw@ipx2.rz.uni-mannheim.de>
#! /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 = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">';
# 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<a href=\"$html_name\">[NEXT]</a>\n";
}
print OUT "</pre>\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<title>\n$title\n</title>\n<pre>\n";
if (defined($prev_link)) {
print OUT "<a href=\"$prev_link\">[PREV]</a>";
}
print OUT "<a href=\"$html_toc#$name\">[TOC]</a>\n\n";
print TOC "<li><a name=\"$name\" href=\"$html_name\">$title</a>\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\n<title>Annotated Ada-95 Reference Manual</title>\n<ul>\n";
chapter('0', 'Preface', 0);
while (defined(my $line = <>)) {
$line =~ s/\s*$/\n/;
$line =~ s/&/&/;
$line =~ s/</</;
$line =~ s/>/>/;
if ($line =~ /^ *Section +([0-9]+)(:.*)$/) {
print TOC "\n</ul><p><ul>\n";
chapter($1, "$1$2", 0);
} elsif ($line =~ /^ *Annex +([A-Z])$/) {
print TOC "\n</ul><p><ul>\n";
chapter($1, "$1: $annex{$1}\n", 0);
} elsif ($line =~ /^Index$/ && $first_index) {
print TOC "\n</ul><p><ul>\n";
chapter('XX', $line, 0);
$first_index = 0;
} elsif ($line =~ /^Contents$/) {
print TOC "\n</ul><p><ul>\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 "</ul>\n";
close(TOC);
chapter('ZZ', '...', 1); # pseudo-chapter, to properly end the last one
}
main()
next reply other threads:[~1997-11-02 0:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-11-02 0:00 Marc Wachowitz [this message]
1997-11-03 0:00 ` Annotated Reference Manual: Text to HTML Stephen Leake
1997-11-03 0:00 ` Simon Wright
1997-11-06 0:00 ` Chris Morgan
1997-11-03 0:00 ` Jon S Anthony
-- strict thread matches above, loose matches on Subject: below --
1997-11-03 0:00 Marc Wachowitz
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox