#! perl
# @(#)adjust-html-file.pl,v 1.1 2004/01/22 05:57:50 leavens Exp

# Copyright (C) 2001 Iowa State University

# This file is part of typedscm

# typedscm is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# typedscm is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with typedscm; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

while (<>) {
    s/\r//g; # trim \r's, needed on cygwin
    if (/<H1><A NAME=[^>]+>.\. Grammar Summary<\/A><\/H1>/) {
	$in_summary = true;
    }
    s!`(http://[^'<]*)'!`<A HREF="$1">$1</A>'!g;
    s!`(ftp://[^'<]*)'!`<A HREF="$1">$1</A>'!g;
    s!^(  *)(http://[^ ]*)!$1<A HREF="$2">$2</A>!g;
    s!^(  *)(ftp://[^ ]*)!$1<A HREF="$2">$2</A>!g;
    s!@"a!\&\#228;!g;
    s!@"e!\&\#235;!g;
    s!@"e!\&\#239;!g;
    s!@"o!\&\#246;!g;
    s!@"u!\&\#252;!g;
    s!(<ADDRESS>by Gary T. Leavens and Curtis Clifton)</ADDRESS>!$1<br><br>Department of Computer Science, Iowa State University,<br>226 Atanasoff Hall, Ames, Iowa, 50011-1040 USA<br><br>Copyright (c) Gary T. Leavens and Curtis Clifton, 2001.</ADDRESS>!g;

     if ($in_summary) {
        s!^<VAR>([^<]*)</VAR> ::=!<A NAME="app-$1"><VAR>$1</VAR></A> ::=!g;
        s!([ {])<VAR>([^<]*)</VAR>!$1<A HREF="\#app-$2"><VAR>$2</VAR></A>!g;
     } else {
        s!^<VAR>([^<]*)</VAR> ::=!<A NAME="$1"><VAR>$1</VAR></A> ::=!g;
        s!([ {])<VAR>([^<]*)</VAR>!$1<A HREF="\#$2"><VAR>$2</VAR></A>!g;
     }

     print $_;
}
