#!/usr/bin/perl
###############################################################
# include latex2html output v0.1
# written in 1998/99 by Cyrille Artho, published under the GPL

my @files = <*.html>;
if ($ARGV[0] == '-imgbug') { $imgbug = 1; }

if (scalar @files > 101) { # more than 99 node files + index + toc
  die "Too many html files - try 'split -n' in latex2.html.\n";
} elsif (scalar @files == 0) {
  die "Could not find any .html files, sorry.\n";
}

foreach $file (@files) {
  open (FILE, $file) or die "Could not open $file: $!\n";
  @lines = <FILE>;
  close FILE;
  unlink ($file) or die "Could not delete $file: $!\n";
  $file =~ s/node(.)\.html/node0$1.html/i;
  open (FILE, ">$file") or die "Could not open $file for writing: $!\n";
  foreach (@lines) { 
    s/node(.)\.html/node0$1.html/ig;   # do all replacements
    if ($imgbug) {
      s/ WIDTH="\d+" HEIGHT="\d+"//i;  # remove (wrong) size attributes
      if (/SRC="img\d+\.gif"/i) { s/(\d+)(?=\.gif)/$1+1/ie; }
    }
    print FILE $_;
  }
  close FILE;
}

if ($imgbug) {
  @files = <*.old>;
  foreach $file (@files) {
    unlink $file;
  }
}
