#!/usr/bin/perl
#
# This script file has been customized for Unix/Linux
#
# This perl script modifies a Visio generated htm file
#  for the FIU-SCS Course syllabi html custom format
#
#  Usage: perl modifyHtml.pl [input_htm_filename]
#
# Author: Prabakar 4/3/08 (revised on 2/22/19)
#

use strict;

my $filename = "png_1.htm";
# print "Usage: perl $0 [input_htm_filename]\n";
if ($#ARGV >= 0) { # in Perl, argcnt is zero for one argument
    $filename = $ARGV[0];
}

my @line = `cat $filename`;
open( FILEOUT, ">$filename" ) || die "cannot open output $filename: $!";

# strings for replacements
my $hrefpath = "http://www4.cis.fiu.edu/courses/Syllabi/";

for (my $idx = 0; $idx <= $#line; $idx++) {
  $line[$idx] =~ s/\s+$//; # strip trailing whitespace
  if (($line[$idx] =~ /^\s+<area/i ) && ($line[$idx] =~ / onfocus/i)) {
    $line[$idx] =~ s/\xe2\x80\xa8/ /g; # replaces special UTF characters with a blank
    $line[$idx] =~ s/ onfocus.*$/>/;
    $line[$idx] =~ s/\&.*number=/_/;
    $line[$idx] =~ s/ HREF=".*prefix=/ HREF="$hrefpath/;
    $line[$idx] =~ s/" target=/.pdf" target=/;
  }
  print FILEOUT @line[$idx]."\n";
}
close(FILEOUT);

exit(0);
