Index: /trunk/gsdl/bin/script/gsConvert.pl
===================================================================
--- /trunk/gsdl/bin/script/gsConvert.pl	(revision 10281)
+++ /trunk/gsdl/bin/script/gsConvert.pl	(revision 10282)
@@ -63,4 +63,5 @@
 my $pdf_zoom;
 my $pdf_ignore_images;
+my $windows_scripting;
 
 sub print_usage
@@ -72,7 +73,8 @@
     print STDERR "  options:\n\t-type\tdoc|dot|pdf|ps|ppt|rtf|xls\t(input file type)\n";
     print STDERR "\t-errlog\t<filename>\t(append err messages)\n";
-    print STDERR "\t-output\thtml|text\n";
+    print STDERR "\t-output\tauto|html|text|pagedimg-jpg|pagedimg-gif|pagedimg-png\t(output file type)\n";
     print STDERR "\t-timeout\t<max cpu seconds>\t(ulimit on unix systems)\n";
     print STDERR "\t-use_strings\tuse strings to extract text if conversion fails\n";
+    print STDERR "\t-windows_scripting\tuse windows script when converting Microsoft Word and PPT via VB script\n";
     print STDERR "\t-pdf_complex\tuse complex output when converting PDF to HTML\n";
     print STDERR "\t-pdf_nohidden\tDon't attempt to extract hidden text from PDF files\n";
@@ -96,8 +98,9 @@
 			 'type/(doc|dot|pdf|ps|ppt|rtf|xls)/', \$input_type,
 			 '/errlog/.*/', \$faillogfile,
-			 'output/(html|text)/', \$output_type,
+			 'output/(auto|html|text|pagedimg).*/', \$output_type,
 			 'timeout/\d+/0',\$timeout,
-			 'verbose/\d+/0',   \$verbose,
+			 'verbose/\d+/0', \$verbose,
 			 'use_strings', \$use_strings,
+			 'windows_scripting',\$windows_scripting,
 			 'pdf_complex', \$pdf_complex,
 			 'pdf_ignore_images', \$pdf_ignore_images,
@@ -108,5 +111,6 @@
 	print_usage();
     }
-
+    
+  
     # Make sure the input file exists and can be opened for reading
     if (scalar(@ARGV!=1)) {
@@ -133,5 +137,4 @@
     my $stored_dir = cwd();
     chdir ($dirname) || die "Unable to change to directory $dirname";
-    
     # Select convert utility
     if (!defined $input_type) {
@@ -209,12 +212,25 @@
 
     my $success = 0;
+    if (!$output_type || ($output_type =~ /html/i)){
+	if ($windows_scripting) {
+	    print STDERR "***** Calling VB Script!\n";
+	    $success = &native_doc_to_html($input_filename, $output_filestem);
+	}
+	else {
+	    print STDERR "**** Calling wvWare\n";
+	    $success = &doc_to_html($input_filename, $output_filestem);	   
+	}
+	if ($success) {
+	   return "html";
+	}
+    }
 
     # Attempt specialised conversion to HTML
-    if (!$output_type || ($output_type =~ /html/i)) {
-	$success = &doc_to_html($input_filename, $output_filestem);
-	if ($success) {
-	    return "html";
-	}
-    }
+    #if (!$output_type || ($output_type =~ /html/i)) {
+#	$success = &doc_to_html($input_filename, $output_filestem);
+#	if ($success) {
+#	    return "html";
+#	}
+#    }
 
     return &convertAnything($input_filename, $output_filestem, $output_type);
@@ -313,7 +329,5 @@
 	}
     }
-
     return "fail";
-
 }
 
@@ -323,7 +337,38 @@
 
     my $success = 0;
-
-    # Attempt conversion to HTML
-    if (!$output_type || ($output_type =~ /html/i)) {
+    my $ppt_convert_type = "";
+    if (!$output_type || $windows_scripting ||($output_type !~ /html/i)){
+	if ($output_type =~ /gif/i) {
+	    $ppt_convert_type = "-g";
+	} elsif ($output_type =~ /jp?g/i){
+	    $ppt_convert_type = "-j";
+	} elsif ($output_type =~ /png/i){
+	    $ppt_convert_type = "-p";
+	}
+	my $vbScript = &util::filename_cat($ENV{'GSDLHOME'}, "bin",
+					   $ENV{'GSDLOS'}, "pptextract");
+	$vbScript = "pptextract" if ($ENV{'GSDLOS'} =~ /^windows$/i);
+			
+	$cmd = "";
+	#if ($timeout) {$cmd = "ulimit -t $timeout;";}
+	#$cmd .= "$vbScript \"$input_filename\" \"$output_filestem.html\"";
+	#$cmd .= "$vbScript $input_filename $output_filestem.html";
+	# if the converting directory has already existed
+	if (-d $output_filestem) {
+	    print STDERR "**The conversion directory has existed\n";
+	    return "item";
+	} else {
+	    $cmd .=  "$vbScript $ppt_convert_type $input_filename $output_filestem";
+	    $cmd .= " 2>\"$output_filestem.err\""
+		if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000);
+	    if (system($cmd) !=0) {
+		print STDERR "Powerpoint VB Scripting convert failed\n";
+	    } else {
+		return "item";
+	    }
+	}
+    } else {
+	# Attempt conversion to HTML
+	#if (!$output_type || ($output_type =~ /html/i)) {
 	# formulate the command
 	$cmd = "";
@@ -332,5 +377,4 @@
 	$cmd .= " 2>\"$output_filestem.err\""
 	    if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000);
-	
 	
 	# execute the command
@@ -388,11 +432,8 @@
 
 
-
-
 # Find the real type of a .doc file
 #
 # We seem to have a lot of files with a .doc extension that are .rtf 
 # files or Word 5 files.  This function attempts to tell the difference.
-
 sub find_docfile_type {
     ($input_filename) = @_;
@@ -428,5 +469,4 @@
 
 
-
 # Specific type-to-type conversions
 #
@@ -438,5 +478,4 @@
 
 # Attempt to convert a word document to html with the wv program
-
 sub doc_to_html {
     ($input_filename, $output_filestem) = @_;
@@ -461,5 +500,5 @@
     $cmd .= " 2> \"$output_filestem.err\""
 	if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000);
-
+    
     # execute the command
     $!=0;
@@ -518,4 +557,77 @@
 }
 
+# Attempt to convert a word document to html with the word2html scripting program
+sub native_doc_to_html {
+    ($input_filename, $output_filestem) = @_;
+
+    my $vbScript = &util::filename_cat($ENV{'GSDLHOME'}, "bin",
+				       $ENV{'GSDLOS'}, "word2html");
+
+    $vbScript = "word2html" if ($ENV{'GSDLOS'} =~ /^windows$/i);
+
+    my $cmd = "";
+    if ($timeout) {$cmd = "ulimit -t $timeout;";}
+    #$cmd .= "$vbScript \"$input_filename\" \"$output_filestem.html\"";
+    $cmd .=  "$vbScript $input_filename $output_filestem.html";
+    
+    # redirecting STDERR
+    $cmd .= " 2> \"$output_filestem.err\""
+	if ($ENV {'GSDLOS'} !~ /^windows$/i || $is_winnt_2000);
+    
+    # execute the command
+    $!=0;
+    if (system($cmd)!=0)
+    {
+	print STDERR "Error executing word2Html converter:$!\n";
+	if (-s "$output_filestem.err") {
+	    open (ERRFILE, "<$output_filestem.err");
+	    
+	    my $write_to_fail_log=0;
+	    if ($faillogfile ne "" && defined(open(FAILLOG,">>$faillogfile")))
+	    {$write_to_fail_log=1;}
+
+	    my $line;
+	    while ($line=<ERRFILE>) {
+		if ($line =~ /\w/) {
+		    print STDERR "$line";
+		    print FAILLOG "$line" if ($write_to_fail_log);
+		}
+		if ($line !~ m/startup error/) {next;}
+		print STDERR " (given an invalid .DOC file?)\n";
+		print FAILLOG " (given an invalid .DOC file?)\n"
+		if ($write_to_fail_log);
+		
+	    } # while ERRFILE
+	    close FAILLOG if ($write_to_fail_log);
+	}
+	return 0; # we can try any_to_text
+    }
+
+    # Was the conversion successful?
+    if (-s "$output_filestem.html") {
+	open(TMP, "$output_filestem.html");
+	$line = <TMP>;
+	close(TMP);
+	if ($line && $line =~ /html/) {
+	    &util::rm("$output_filestem.err") if -e "$output_filestem.err";
+	    return 1;
+	}
+    }
+	
+    # If here, an error of some sort occurred
+    &util::rm("$output_filestem.html") if -e "$output_filestem.html";
+    if (-e "$output_filestem.err") {
+	if ($faillogfile ne "" && defined(open(FAILLOG,">>$faillogfile"))) {
+	    open (ERRLOG,"$output_filestem.err");
+	    while (<ERRLOG>) {print FAILLOG $_;}
+	    close FAILLOG;
+	    close ERRLOG;
+	}
+	&util::rm("$output_filestem.err");
+    }
+    return 0;
+}
+
+
 
 # Attempt to convert an RTF document to html with rtftohtml
@@ -528,4 +640,5 @@
     if ($timeout) {$cmd = "ulimit -t $timeout;";}
     $cmd .= "rtftohtml";
+    #$cmd .= "rtf-converter";
 
     $cmd .= " -o \"$output_filestem.html\" \"$input_filename\"";
@@ -621,4 +734,5 @@
 	{
 	    print FAILLOG "Error - rtftohtml - couldn't extract text\n";
+	    #print FAILLOG "Error - rtf-converter - couldn't extract text\n";
 	    print FAILLOG " (rtf file might be too recent):\n";
 	    open (ERRLOG, "$output_filestem.err");
@@ -687,9 +801,9 @@
 		close FAILLOG;
 	    }	
-    &util::rm("$output_filestem.err");
+	    &util::rm("$output_filestem.err");
 	}
 	return 0;
     }
-
+    
     &util::rm("$output_filestem.err") if (-e "$output_filestem.err");
     &util::rm("$output_filestem.out") if (-e "$output_filestem.out");
@@ -785,5 +899,4 @@
 	$cmd .= " 2> $output_filestem.err";
 	$!=0;
-
 	my $retcode=system($cmd);
 	$retcode = $? >> 8;  # see man perlfunc - system for this...
