Index: /gsdl/trunk/bin/script/gsConvert.pl
===================================================================
--- /gsdl/trunk/bin/script/gsConvert.pl	(revision 16434)
+++ /gsdl/trunk/bin/script/gsConvert.pl	(revision 16435)
@@ -215,5 +215,5 @@
 
     my $success = 0;
-    if (!$output_type || ($output_type =~ /html/i)){
+    if (!$output_type || ($output_type =~ m/html/i)){
 	if ($windows_scripting) {
 	    $success = &native_doc_to_html($input_filename, $output_filestem);
@@ -238,5 +238,5 @@
 
     # Attempt specialised conversion to HTML
-    if (!$output_type || ($output_type =~ /html/i)) {
+    if (!$output_type || ($output_type =~ m/html/i)) {
 
 	if ($windows_scripting) {
@@ -266,5 +266,5 @@
   
     # Attempt simple conversion to HTML
-    if (!$output_type || ($output_type =~ /html/i)) {
+    if (!$output_type || ($output_type =~ m/html/i)) {
 	$success = &any_to_html($input_filename, $output_filestem);
 	if ($success) {
@@ -274,5 +274,5 @@
 
     # Convert to text
-    if (!$output_type || ($output_type =~ /text/i)) {
+    if (!$output_type || ($output_type =~ m/text/i)) {
 	$success = &any_to_text($input_filename, $output_filestem);
 	if ($success) {
@@ -293,5 +293,5 @@
     $output_type =~ s/.*\-(.*)/$1/i;
     # Attempt coversion to Image
-    if ($output_type =~ /jp?g|gif|png/i) {
+    if ($output_type =~ m/jp?g|gif|png/i) {
 	$success = &pdf_to_img($dirname, $input_filename, $output_filestem, $output_type);
 	if ($success){
@@ -301,5 +301,5 @@
 
     # Attempt conversion to HTML
-    if (!$output_type || ($output_type =~ /html/i)) {
+    if (!$output_type || ($output_type =~ m/html/i)) {
 	$success = &pdf_to_html($dirname, $input_filename, $output_filestem);
 	if ($success) {
@@ -309,5 +309,5 @@
 
     # Attempt conversion to TEXT
-    if (!$output_type || ($output_type =~ /text/i)) {
+    if (!$output_type || ($output_type =~ m/text/i)) {
 	$success = &pdf_to_text($dirname, $input_filename, $output_filestem);
 	if ($success) {
@@ -329,5 +329,5 @@
     $output_type =~ s/.*\-(.*)/$1/i;
     # Attempt coversion to Image
-    if ($output_type =~ /jp?g|gif|png/i) {
+    if ($output_type =~ m/jp?g|gif|png/i) {
 	$success = &ps_to_img($dirname, $input_filename, $output_filestem, $output_type);
 	if ($success){
@@ -337,5 +337,5 @@
 
     # Attempt conversion to TEXT
-    if (!$output_type || ($output_type =~ /text/i)) {
+    if (!$output_type || ($output_type =~ m/text/i)) {
 	$success = &ps_to_text($input_filename, $output_filestem);
 	if ($success) {
@@ -352,16 +352,16 @@
 
     my $ppt_convert_type = "";
-    #if (!$output_type || $windows_scripting ||($output_type !~ /html/i) ||($output_type !~ /text/i)){
-    if ($windows_scripting && ($output_type !~ /html/i) && ($output_type !~ /text/i)){
-	if ($output_type =~ /gif/i) {
+    #if (!$output_type || $windows_scripting || ($output_type !~ m/html/i) || ($output_type !~ m/text/i)){
+    if ($windows_scripting && ($output_type !~ m/html/i) && ($output_type !~ m/text/i)){
+	if ($output_type =~ m/gif/i) {
 	    $ppt_convert_type = "-g";
-	} elsif ($output_type =~ /jp?g/i){
+	} elsif ($output_type =~ m/jp?g/i){
 	    $ppt_convert_type = "-j";
-	} elsif ($output_type =~ /png/i){
+	} elsif ($output_type =~ m/png/i){
 	    $ppt_convert_type = "-p";
 	}
 	my $vbScript = &util::filename_cat($ENV{'GSDLHOME'}, "bin",
 					   $ENV{'GSDLOS'}, "pptextract");
-	$vbScript = "pptextract" if ($ENV{'GSDLOS'} =~ /^windows$/i);
+	$vbScript = "pptextract" if ($ENV{'GSDLOS'} =~ m/^windows$/i);
 			
 	$cmd = "";
@@ -374,5 +374,5 @@
 	    $cmd .=  "$vbScript $ppt_convert_type \"$input_filename\" \"$output_filestem\"";
 	    $cmd .= " 2>\"$output_filestem.err\""
-		if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000);
+		if ($ENV{'GSDLOS'} !~ m/^windows$/i || $is_winnt_2000);
 	    if (system($cmd) !=0) {
 		print STDERR "Powerpoint VB Scripting convert failed\n";
@@ -381,7 +381,7 @@
 	    }
 	}
-    } elsif (!$output_type || ($output_type =~ /html/i)) {
+    } elsif (!$output_type || ($output_type =~ m/html/i)) {
 	# Attempt conversion to HTML
-	#if (!$output_type || ($output_type =~ /html/i)) {
+	#if (!$output_type || ($output_type =~ m/html/i)) {
 	# formulate the command
 	$cmd = "";
@@ -389,5 +389,5 @@
 	$cmd .= " \"$input_filename\" \"$output_filestem.html\"";
 	$cmd .= " 2>\"$output_filestem.err\""
-	    if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000);
+	    if ($ENV{'GSDLOS'} !~ m/^windows$/i || $is_winnt_2000);
 
 	# execute the command
@@ -416,5 +416,5 @@
 
     # Attempt conversion to HTML
-    if (!$output_type || ($output_type =~ /html/i)) {
+    if (!$output_type || ($output_type =~ m/html/i)) {
 	# formulate the command
 	$cmd = "";
@@ -422,5 +422,5 @@
 	$cmd .= " \"$input_filename\" \"$output_filestem.html\"";
 	$cmd .= " 2>\"$output_filestem.err\""
-	    if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000);
+	    if ($ENV{'GSDLOS'} !~ m/^windows$/i || $is_winnt_2000);
 	
 	
@@ -463,5 +463,5 @@
 	if ($first) {
 	    # check to see if this is an rtf file
-	    if ($line =~ /^\{\\rtf/) {
+	    if ($line =~ m/^\{\\rtf/) {
 		close(CHK);
 		return "rtf";
@@ -471,5 +471,5 @@
 	
 	# is this is a word 6/7/8 document?
-	if ($line =~ /Word\.Document\.([678])/) {
+	if ($line =~ m/Word\.Document\.([678])/) {
 	    close(CHK);
 	    return "word$1";
@@ -500,5 +500,5 @@
     # with quoting when GSDLHOME might contain spaces) but assume
     # that the PATH is set up correctly
-    $wvWare = "wvWare" if ($ENV{'GSDLOS'} =~ /^windows$/i);
+    $wvWare = "wvWare" if ($ENV{'GSDLOS'} =~ m/^windows$/i);
 
     my $wv_conf = &util::filename_cat($ENV{'GSDLHOME'}, "etc", 
@@ -573,5 +573,5 @@
     # redirecting STDERR is a bad idea on windows 95/98
     $cmd .= " 2> \"$output_filestem.err\""
-	if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000);
+	if ($ENV{'GSDLOS'} !~ m/^windows$/i || $is_winnt_2000);
     # execute the command
     $!=0;
@@ -588,5 +588,5 @@
 	    my $line;
 	    while ($line=<ERRFILE>) {
-		if ($line =~ /\w/) {
+		if ($line =~ m/\w/) {
 		    print STDERR "$line";
 		    print FAILLOG "$line" if ($write_to_fail_log);
@@ -609,16 +609,15 @@
 	$line = <TMP>;
 	close(TMP);
-	if ($line && $line =~ /DOCTYPE HTML/) {
+	if ($line && $line =~ m/DOCTYPE HTML/) {
 	    &util::rm("$output_filestem.err") if -e "$output_filestem.err";    
 
 	    # Inserted this code to remove the images directory if it was still empty after 
 	    # the html was generated (in case there were no images in the word document)
-	    if(&is_dir_empty($assoc_dir)) {
+	    if (&util::is_dir_empty($assoc_dir)) {
 		#print STDERR "***gsConvert.pl: Image dir $assoc_dir is empty, removing***\n";
 		&util::rm_r($assoc_dir);
 	    } else { # there was an image folder (it was generated)
 		# Therefore, the html file generated contains absolute links to the images
-		# If the folder contains images
-		# Replace them with relative links instead, so it can be moved elsewhere
+		# Replace them with relative links instead, so the folder can be moved elsewhere
 		&make_links_to_assocdir_relative($toppath, $docname, "$output_filestem.html", $assoc_dir, $docname."_files");	
 	    }
@@ -640,20 +639,4 @@
     
     return 0;
-}
-
-
-# A method to check if a directory is empty (note that an empty directory still has non-zero size!!!) 
-# Code is from http://episteme.arstechnica.com/eve/forums/a/tpc/f/6330927813/m/436007700831
-sub is_dir_empty
-{
-    my ($path) = @_;
-    opendir DIR, $path;
-    while(my $entry = readdir DIR) {
-        next if($entry =~ /^\.\.?$/);
-        closedir DIR;
-        return 0;
-    }
-    closedir DIR;
-    return 1;
 }
 
@@ -699,7 +682,8 @@
     # we can't just replace $assoc_dir_path with $assoc_dir
     # $assoc_dir_path represents a regular expression that needs to be replaced
-    # if it contains ., -, [ or ] -- which all have special meaning in Perl regular expressions --
-    # we need to escape these first
+    # if it contains ., -, [, ], or Windows style backslashes in paths  -- which all have special
+    # meaning in Perl regular expressions -- we need to escape these first
     my $safe_reg_expression = $assoc_dir_path;
+    $safe_reg_expression =~ s/\\/\\\\/g;
     $safe_reg_expression =~ s/\./\\./g;
     $safe_reg_expression =~ s/\-/\\-/g;
@@ -722,8 +706,8 @@
                #$html_contents =~ s/$safe_reg_expression/$assoc_dirname/gs; # this works, used as fall-back
     # now replace any %20 chars in filenames of href or src attributes to use literal space ' '. Calls a function for this
-    $html_contents =~ s/(<(a|img).*?(href|src)=(\"|\')?)(.*)(.*?(\"|\')?.*?>)/&percent_twenty_to_space($1, $5, $6)/sge;
-   
-    #print STDERR "assoc_dirname: ****$assoc_dirname***\n";
-    #print STDERR "safe_reg_expression: ****$safe_reg_expression***\n";
+    $html_contents =~ s/(<(a|img).*?(href|src)=(\"|\')?)(.*)(.*?(\"|\')?.*?>)/&post_process_assocfile_urls($1, $5, $6)/sge;
+
+    print STDERR "****assoc_dirname: $assoc_dirname***\n";
+    print STDERR "****safe_reg_expression: $safe_reg_expression***\n";
    
     # delete the original file and recreate it
@@ -736,4 +720,5 @@
 	return 0;
     }
+
     # write out the updated contents and close the file
     print FOUT $html_contents;
@@ -742,10 +727,13 @@
 }
 
-# Utility routine to convert all %20 introduced by wvWare in link pathnames into space again
-sub percent_twenty_to_space
+# Utility routine to make sure HTML plugin gets img src/href link pathnames that contain 
+# url slashes (/) instead of windows-style backwards slashes, and to convert all %20 
+# introduced in link pathnames by wvWare into space again 
+sub post_process_assocfile_urls
 {
     my ($pre, $text, $post) = @_;
 
     $text =~ s/%20/ /g;
+    $text =~ s/\\/\//g;
 
     return "$pre$text$post";
@@ -759,5 +747,5 @@
 				       $ENV{'GSDLOS'}, "word2html");
 
-    $vbScript = "word2html" if ($ENV{'GSDLOS'} =~ /^windows$/i);
+    $vbScript = "word2html" if ($ENV{'GSDLOS'} =~ m/^windows$/i);
     if (-e "$output_filestem.html") {
 	print STDERR "*** The conversion file has existed\n";
@@ -773,5 +761,5 @@
     # redirecting STDERR
     $cmd .= " 2> \"$output_filestem.err\""
-	if ($ENV {'GSDLOS'} !~ /^windows$/i || $is_winnt_2000);
+	if ($ENV {'GSDLOS'} !~ m/^windows$/i || $is_winnt_2000);
     
     # execute the command
@@ -789,5 +777,5 @@
 	    my $line;
 	    while ($line=<ERRFILE>) {
-		if ($line =~ /\w/) {
+		if ($line =~ m/\w/) {
 		    print STDERR "$line";
 		    print FAILLOG "$line" if ($write_to_fail_log);
@@ -809,5 +797,5 @@
 	$line = <TMP>;
 	close(TMP);
-	if ($line && $line =~ /html/) {
+	if ($line && $line =~ m/html/) {
 	    &util::rm("$output_filestem.err") if -e "$output_filestem.err";
 	    return 1;
@@ -843,5 +831,5 @@
 
     $cmd .= " 2>\"$output_filestem.err\""
-        if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000);
+        if ($ENV{'GSDLOS'} !~ m/^windows$/i || $is_winnt_2000);
 
 
@@ -865,10 +853,10 @@
 
 	    if ($past_header == 0) {
-		if ($line =~ /<body>/) {$past_header=1;}
+		if ($line =~ m/<body>/) {$past_header=1;}
 		next;
 	    }
 
 	    $line =~ s/<[^>]+>//g;
-	    if ($line =~ /\w/ && $past_header) {  # we found some content...
+	    if ($line =~ m/\w/ && $past_header) {  # we found some content...
 		$was_successful=1;
 		last;
@@ -898,5 +886,5 @@
 
 	    # print out header info from src html.
-	    while (defined($_ = <HTMLSRC>) && $_ =~ /\w/) {
+	    while (defined($_ = <HTMLSRC>) && $_ =~ m/\w/) {
 		print HTML "$_";
 	    }
@@ -962,5 +950,5 @@
     $cmd .= " \"$input_filename\" \"$output_filestem\"";
     
-    if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000) {
+    if ($ENV{'GSDLOS'} !~ m/^windows$/i || $is_winnt_2000) {
 	$cmd .= " > \"$output_filestem.out\" 2> \"$output_filestem.err\"";
     } else {
@@ -1029,5 +1017,5 @@
     $output_type =~ s/.*\_(.*)/$1/i;
      $cmd .= "perl -S pdftoimg.pl -convert_to $output_type \"$input_filename\" \"$output_filestem\"";
-    if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000) {
+    if ($ENV{'GSDLOS'} !~ m/^windows$/i || $is_winnt_2000) {
 	$cmd .= " > \"$output_filestem.out\" 2> \"$output_filestem.err\"";
     } else {
@@ -1086,5 +1074,5 @@
     my $cmd = "pdftotext \"$input_filename\" \"$output_filestem.text\"";
 
-    if ($ENV{'GSDLOS'} !~ /^windows$/i) {
+    if ($ENV{'GSDLOS'} !~ m/^windows$/i) {
 	$cmd .= " > \"$output_filestem.out\" 2> \"$output_filestem.err\"";
     } else {
@@ -1105,5 +1093,5 @@
 	my $seen_text=0;
 	while (($seen_text==0) && ($line=<EXTR_TEXT>)) {
-	    if ($line=~ /\w/) {$seen_text=1;}
+	    if ($line=~ m/\w/) {$seen_text=1;}
 	}
 	close EXTR_TEXT;
@@ -1157,5 +1145,5 @@
     # if we're on windows we'll fall straight through without attempting
     # to use gs
-    if ($ENV{'GSDLOS'} =~ /^windows$/i) {
+    if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
 	$error = "Windows does not support gs";
 
@@ -1181,5 +1169,5 @@
 	    # possible for the actual text to start with this, but....
 	    open PSOUT, "$output_filestem.text";
-	    if (<PSOUT> =~ /^Error: (.*)/) {
+	    if (<PSOUT> =~ m/^Error: (.*)/) {
 		$error="interpreter error - \"$1\"";
 	    }
@@ -1223,5 +1211,5 @@
 
 	# Make sure this is a ps file...
-	if ($text !~ /^%!/) {
+	if ($text !~ m/^%!/) {
 	    print STDERR "Bad postscript header: not '%!'\n";
 	    if ($faillogfile ne "" && defined(open(FAILLOG, ">>$faillogfile")))
@@ -1334,5 +1322,5 @@
     $output_type =~ s/.*\_(.*)/$1/i;
     $cmd .= "perl -S pstoimg.pl -convert_to $output_type \"$input_filename\" \"$output_filestem\"";
-    if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000) {
+    if ($ENV{'GSDLOS'} !~ m/^windows$/i || $is_winnt_2000) {
 	$cmd .= " > \"$output_filestem.out\" 2> \"$output_filestem.err\"";
     } else {
@@ -1406,5 +1394,5 @@
 	$line =~ s/</&lt;/g;
 	$line =~ s/>/&gt;/g;
-	if ($line =~ /^\s*$/) {
+	if ($line =~ m/^\s*$/) {
 	    print HTML "<p>";
 	} else {
@@ -1447,5 +1435,5 @@
 	# delete any string less than 10 characters long
 	$line =~ s/^.{0,9}$/\n/mg;
-	while ($line =~ /^.{1,9}$/m) {
+	while ($line =~ m/^.{1,9}$/m) {
 	    $line =~ s/^.{0,9}$/\n/mg;
 	    $line =~ s/\n+/\n/sg;
@@ -1457,5 +1445,5 @@
 
 	# output whatever is left
-	if ($line =~ /[^\n ]/) {
+	if ($line =~ m/[^\n ]/) {
 	    print OUT $line;
 	    ++$output_line_count;
