Index: /main/trunk/greenstone2/perllib/util.pm
===================================================================
--- /main/trunk/greenstone2/perllib/util.pm	(revision 32846)
+++ /main/trunk/greenstone2/perllib/util.pm	(revision 32847)
@@ -51,24 +51,24 @@
 # removes files (but not directories)
 sub rm {
-  warnings::warnif("deprecated", "util::rm() is deprecated, using FileUtils::removeFiles() instead");
-  return &FileUtils::removeFiles(@_);
+    warnings::warnif("deprecated", "util::rm() is deprecated, using FileUtils::removeFiles() instead");
+    return &FileUtils::removeFiles(@_);
 }
 
 # recursive removal
 sub filtered_rm_r {
-  warnings::warnif("deprecated", "util::filtered_rm_r() is deprecated, using FileUtils::removeFilesFiltered() instead");
-  return &FileUtils::removeFilesFiltered(@_);
+    warnings::warnif("deprecated", "util::filtered_rm_r() is deprecated, using FileUtils::removeFilesFiltered() instead");
+    return &FileUtils::removeFilesFiltered(@_);
 }
 
 # recursive removal
 sub rm_r {
-  warnings::warnif("deprecated", "util::rm_r() is deprecated, using FileUtils::removeFilesRecursive() instead");
-  return &FileUtils::removeFilesRecursive(@_);
+    warnings::warnif("deprecated", "util::rm_r() is deprecated, using FileUtils::removeFilesRecursive() instead");
+    return &FileUtils::removeFilesRecursive(@_);
 }
 
 # moves a file or a group of files
 sub mv {
-  warnings::warnif("deprecated", "util::mv() is deprecated, using FileUtils::moveFiles() instead");
-  return &FileUtils::moveFiles(@_);
+    warnings::warnif("deprecated", "util::mv() is deprecated, using FileUtils::moveFiles() instead");
+    return &FileUtils::moveFiles(@_);
 }
 
@@ -78,12 +78,12 @@
 # but other files and folders in the target will continue to exist
 sub mv_dir_contents {
-  warnings::warnif("deprecated", "util::mv_dir_contents() is deprecated, using FileUtils::moveDirectoryContents() instead");
-  return &FileUtils::moveDirectoryContents(@_);
+    warnings::warnif("deprecated", "util::mv_dir_contents() is deprecated, using FileUtils::moveDirectoryContents() instead");
+    return &FileUtils::moveDirectoryContents(@_);
 }
 
 # copies a file or a group of files
 sub cp {
-  warnings::warnif("deprecated", "util::cp() is deprecated, using FileUtils::copyFiles() instead");
-  return &FileUtils::copyFiles(@_);
+    warnings::warnif("deprecated", "util::cp() is deprecated, using FileUtils::copyFiles() instead");
+    return &FileUtils::copyFiles(@_);
 }
 
@@ -93,6 +93,6 @@
 # another use cp instead
 sub cp_r {
-  warnings::warnif("deprecated", "util::cp_r() is deprecated, using FileUtils::copyFilesrecursive() instead");
-  return &FileUtils::copyFilesRecursive(@_);
+    warnings::warnif("deprecated", "util::cp_r() is deprecated, using FileUtils::copyFilesrecursive() instead");
+    return &FileUtils::copyFilesRecursive(@_);
 }
 
@@ -102,17 +102,17 @@
 # another use cp instead
 sub cp_r_nosvn {
-  warnings::warnif("deprecated", "util::cp_r_nosvn() is deprecated, using FileUtils::copyFilesRecursiveNoSVN() instead");
-  return &FileUtils::copyFilesRecursiveNoSVN(@_);
+    warnings::warnif("deprecated", "util::cp_r_nosvn() is deprecated, using FileUtils::copyFilesRecursiveNoSVN() instead");
+    return &FileUtils::copyFilesRecursiveNoSVN(@_);
 }
 
 # copies a directory and its contents, excluding subdirectories, into a new directory
 sub cp_r_toplevel {
-  warnings::warnif("deprecated", "util::cp_r_toplevel() is deprecated, using FileUtils::recursiveCopyTopLevel() instead");
-  return &FileUtils::recursiveCopyTopLevel(@_);
+    warnings::warnif("deprecated", "util::cp_r_toplevel() is deprecated, using FileUtils::recursiveCopyTopLevel() instead");
+    return &FileUtils::recursiveCopyTopLevel(@_);
 }
 
 sub mk_dir {
-  warnings::warnif("deprecated", "util::mk_dir() is deprecated, using FileUtils::makeDirectory() instead");
-  return &FileUtils::makeDirectory(@_);
+    warnings::warnif("deprecated", "util::mk_dir() is deprecated, using FileUtils::makeDirectory() instead");
+    return &FileUtils::makeDirectory(@_);
 }
 
@@ -121,18 +121,18 @@
 # slightly faster (surprisingly) - Stefan.
 sub mk_all_dir {
-  warnings::warnif("deprecated", "util::mk_all_dir() is deprecated, using FileUtils::makeAllDirectories() instead");
-  return &FileUtils::makeAllDirectories(@_);
+    warnings::warnif("deprecated", "util::mk_all_dir() is deprecated, using FileUtils::makeAllDirectories() instead");
+    return &FileUtils::makeAllDirectories(@_);
 }
 
 # make hard link to file if supported by OS, otherwise copy the file
 sub hard_link {
-  warnings::warnif("deprecated", "util::hard_link() is deprecated, using FileUtils::hardLink() instead");
-  return &FileUtils::hardLink(@_);
+    warnings::warnif("deprecated", "util::hard_link() is deprecated, using FileUtils::hardLink() instead");
+    return &FileUtils::hardLink(@_);
 }
 
 # make soft link to file if supported by OS, otherwise copy file
 sub soft_link {
-  warnings::warnif("deprecated", "util::soft_link() is deprecated, using FileUtils::softLink() instead");
-  return &FileUtils::softLink(@_);
+    warnings::warnif("deprecated", "util::soft_link() is deprecated, using FileUtils::softLink() instead");
+    return &FileUtils::softLink(@_);
 }
 
@@ -167,52 +167,52 @@
 sub raw_filename_to_unicode
 {
-	my ($directory, $raw_file, $filename_encoding ) = @_;
-		
-	my $unicode_filename = $raw_file;
-	if (($ENV{'GSDLOS'} =~ m/^windows$/i) && ($^O ne "cygwin")) {
-	    # Try turning a short version to the long version
-	    # If there are "funny" characters in the file name, that can't be represented in the ANSI code, then we will have a short weird version, eg E74~1.txt
-	    $unicode_filename = &util::get_dirsep_tail(&util::upgrade_if_dos_filename(&FileUtils::filenameConcatenate($directory, $raw_file), 0));
+    my ($directory, $raw_file, $filename_encoding ) = @_;
+    
+    my $unicode_filename = $raw_file;
+    if (($ENV{'GSDLOS'} =~ m/^windows$/i) && ($^O ne "cygwin")) {
+	# Try turning a short version to the long version
+	# If there are "funny" characters in the file name, that can't be represented in the ANSI code, then we will have a short weird version, eg E74~1.txt
+	$unicode_filename = &util::get_dirsep_tail(&util::upgrade_if_dos_filename(&FileUtils::filenameConcatenate($directory, $raw_file), 0));
+	
+	
+	if ($unicode_filename eq $raw_file) {
+	    # This means the original filename *was* able to be encoded in the local ANSI file encoding (eg windows_1252), so now we turn it back to perl's unicode
 	    
-	    
-	    if ($unicode_filename eq $raw_file) {
-		# This means the original filename *was* able to be encoded in the local ANSI file encoding (eg windows_1252), so now we turn it back to perl's unicode
-		
-		$unicode_filename = &Encode::decode(locale_fs => $unicode_filename);
-	    }
-	    # else This means we did have one of the funny filenames. the getLongPathName (used in upgrade_if_dos_filename) will return unicode, so we don't need to do anything more.
-	    
-					
-	} else {
-	    # we had a utf-8 string, turn it into perl internal unicode
-	    $unicode_filename = &Encode::decode("utf-8", $unicode_filename);
-	
-		
-	}
-	#Does the filename have url encoded chars in it?
-	if (&unicode::is_url_encoded($unicode_filename)) {
-	    $unicode_filename = &unicode::url_decode($unicode_filename);
-	}
-	
-	# Normalise the filename to canonical composition - on mac, filenames use decopmposed form for accented chars
-	if ($ENV{'GSDLOS'} =~ m/^darwin$/i) {
-	    $unicode_filename = normalize('C', $unicode_filename); # Composed form 'C'
-	}
-	return $unicode_filename;
+	    $unicode_filename = &Encode::decode(locale_fs => $unicode_filename);
+	}
+	# else This means we did have one of the funny filenames. the getLongPathName (used in upgrade_if_dos_filename) will return unicode, so we don't need to do anything more.
+	
+	
+    } else {
+	# we had a utf-8 string, turn it into perl internal unicode
+	$unicode_filename = &Encode::decode("utf-8", $unicode_filename);
+	
+	
+    }
+    #Does the filename have url encoded chars in it?
+    if (&unicode::is_url_encoded($unicode_filename)) {
+	$unicode_filename = &unicode::url_decode($unicode_filename);
+    }
+    
+    # Normalise the filename to canonical composition - on mac, filenames use decopmposed form for accented chars
+    if ($ENV{'GSDLOS'} =~ m/^darwin$/i) {
+	$unicode_filename = normalize('C', $unicode_filename); # Composed form 'C'
+    }
+    return $unicode_filename;
 
 }
 sub fd_exists {
-  warnings::warnif("deprecated", "util::fd_exists() is deprecated, using FileUtils::fileTest() instead");
-  return &FileUtils::fileTest(@_);
+    warnings::warnif("deprecated", "util::fd_exists() is deprecated, using FileUtils::fileTest() instead");
+    return &FileUtils::fileTest(@_);
 }
 
 sub file_exists {
-  warnings::warnif("deprecated", "util::file_exists() is deprecated, using FileUtils::fileExists() instead");
-  return &FileUtils::fileExists(@_);
+    warnings::warnif("deprecated", "util::file_exists() is deprecated, using FileUtils::fileExists() instead");
+    return &FileUtils::fileExists(@_);
 }
 
 sub dir_exists {
-  warnings::warnif("deprecated", "util::dir_exists() is deprecated, using FileUtils::directoryExists() instead");
-  return &FileUtils::directoryExists(@_);
+    warnings::warnif("deprecated", "util::dir_exists() is deprecated, using FileUtils::directoryExists() instead");
+    return &FileUtils::directoryExists(@_);
 }
 
@@ -221,6 +221,6 @@
 # both $fromdir and $todir should be absolute paths
 sub cachedir {
-  warnings::warnif("deprecated", "util::cachedir() is deprecated, using FileUtils::synchronizeDirectories() instead");
-  return &FileUtils::synchronizeDirectories(@_);
+    warnings::warnif("deprecated", "util::cachedir() is deprecated, using FileUtils::synchronizeDirectories() instead");
+    return &FileUtils::synchronizeDirectories(@_);
 }
 
@@ -230,6 +230,6 @@
 # $file2 is allowed to be newer than $file1
 sub differentfiles {
-  warnings::warnif("deprecated", "util::differentfiles() is deprecated, using FileUtils::differentFiles() instead");
-  return &FileUtils::differentFiles(@_);
+    warnings::warnif("deprecated", "util::differentfiles() is deprecated, using FileUtils::differentFiles() instead");
+    return &FileUtils::differentFiles(@_);
 }
 
@@ -239,42 +239,42 @@
 sub determine_tmp_dir
 {
-	my $try_collect_dir = shift(@_) || 0;
-
-	my $tmp_dirname;
-	if(defined $ENV{'GS_TMP_OUTPUT_DIR'}) {
-		$tmp_dirname = $ENV{'GS_TMP_OUTPUT_DIR'};
-	} elsif($try_collect_dir && defined $ENV{'GSDLCOLLECTDIR'}) {
-		$tmp_dirname = $ENV{'GSDLCOLLECTDIR'};
+    my $try_collect_dir = shift(@_) || 0;
+
+    my $tmp_dirname;
+    if(defined $ENV{'GS_TMP_OUTPUT_DIR'}) {
+	$tmp_dirname = $ENV{'GS_TMP_OUTPUT_DIR'};
+    } elsif($try_collect_dir && defined $ENV{'GSDLCOLLECTDIR'}) {
+	$tmp_dirname = $ENV{'GSDLCOLLECTDIR'};
     } elsif(defined $ENV{'GSDLHOME'}) {
-		$tmp_dirname = $ENV{'GSDLHOME'};
+	$tmp_dirname = $ENV{'GSDLHOME'};
     } else {
-		return undef;
-    }
-	
-	if(!defined $ENV{'GS_TMP_OUTPUT_DIR'}) {
-		# test the tmp_dirname folder is writable, by trying to write out a file
-		# Unfortunately, cound not get if(-w $dirname) to work on directories on Windows
-			## http://alvinalexander.com/blog/post/perl/perl-file-test-operators-reference-cheat-sheet (test file/dir writable)
-			## http://www.makelinux.net/alp/083 (real and effective user IDs)
-		
-		my $tmp_test_file = &FileUtils::filenameConcatenate($tmp_dirname, "writability_test.tmp");
-		if (open (FOUT, ">$tmp_test_file")) {
-			close(FOUT);
-			&FileUtils::removeFiles($tmp_test_file);
-	    } else { # location not writable, use TMP location
-		if (defined $ENV{'TMP'}) {
-		    $tmp_dirname = $ENV{'TMP'};
-		} else {
-		    $tmp_dirname = "/tmp";
-		}
-		$tmp_dirname = &FileUtils::filenameConcatenate($tmp_dirname, "greenstone");
-			$ENV{'GS_TMP_OUTPUT_DIR'} = $tmp_dirname; # store for next time
-		}
-	}
-	
-	$tmp_dirname = &FileUtils::filenameConcatenate($tmp_dirname, "tmp");
-	&FileUtils::makeAllDirectories ($tmp_dirname) unless -e $tmp_dirname;
-
-	return $tmp_dirname;
+	return undef;
+    }
+    
+    if(!defined $ENV{'GS_TMP_OUTPUT_DIR'}) {
+	# test the tmp_dirname folder is writable, by trying to write out a file
+	# Unfortunately, cound not get if(-w $dirname) to work on directories on Windows
+	## http://alvinalexander.com/blog/post/perl/perl-file-test-operators-reference-cheat-sheet (test file/dir writable)
+	## http://www.makelinux.net/alp/083 (real and effective user IDs)
+	
+	my $tmp_test_file = &FileUtils::filenameConcatenate($tmp_dirname, "writability_test.tmp");
+	if (open (FOUT, ">$tmp_test_file")) {
+	    close(FOUT);
+	    &FileUtils::removeFiles($tmp_test_file);
+	} else { # location not writable, use TMP location
+	    if (defined $ENV{'TMP'}) {
+		$tmp_dirname = $ENV{'TMP'};
+	    } else {
+		$tmp_dirname = "/tmp";
+	    }
+	    $tmp_dirname = &FileUtils::filenameConcatenate($tmp_dirname, "greenstone");
+	    $ENV{'GS_TMP_OUTPUT_DIR'} = $tmp_dirname; # store for next time
+	}
+    }
+    
+    $tmp_dirname = &FileUtils::filenameConcatenate($tmp_dirname, "tmp");
+    &FileUtils::makeAllDirectories ($tmp_dirname) unless -e $tmp_dirname;
+
+    return $tmp_dirname;
 }
 
@@ -296,5 +296,5 @@
     }
 
-	my $tmpdir = &util::determine_tmp_dir(0);
+    my $tmpdir = &util::determine_tmp_dir(0);
 
     my $count = 1000;
@@ -318,25 +318,25 @@
 sub get_timestamped_tmp_folder
 {
-	my $tmp_dirname = &util::determine_tmp_dir(1);
-	
+    my $tmp_dirname = &util::determine_tmp_dir(1);
+    
     # add the timestamp into the path otherwise we can run into problems 
     # if documents have the same name
     my $timestamp = time;	
-	
-	if (!defined $previous_timestamp || ($timestamp > $previous_timestamp)) {
-		$previous_timestamp_f = 0;
-		$previous_timestamp = $timestamp;
-	} else {
-		$previous_timestamp_f++;
-	} 
-	
+    
+    if (!defined $previous_timestamp || ($timestamp > $previous_timestamp)) {
+	$previous_timestamp_f = 0;
+	$previous_timestamp = $timestamp;
+    } else {
+	$previous_timestamp_f++;
+    } 
+    
     my $time_tmp_dirname = &FileUtils::filenameConcatenate($tmp_dirname, $timestamp);
     $tmp_dirname = $time_tmp_dirname;	
     my $i = $previous_timestamp_f;
-	
-	if($previous_timestamp_f > 0) {
-		$tmp_dirname = $time_tmp_dirname."_".$i;
-		$i++;
-	}
+    
+    if($previous_timestamp_f > 0) {
+	$tmp_dirname = $time_tmp_dirname."_".$i;
+	$i++;
+    }
     while (-e $tmp_dirname) {
 	$tmp_dirname = $time_tmp_dirname."_".$i;
@@ -408,13 +408,13 @@
     # need to make single backslashes double so that regex works
     $filename =~ s/\\/\\\\/g; # if ($ENV{'GSDLOS'} =~ /^windows$/i);    
-	
+    
     # note that the first part of a substitution is a regex, so RE chars need to be escaped,
     # the second part of a substitution is not a regex, so for e.g. full-stop can be specified literally
-	$filename =~ s/\./\\./g; # in case there are extensions/other full stops, escape them
-	$filename =~ s@\(@\\(@g; # escape brackets
-	$filename =~ s@\)@\\)@g; # escape brackets
-	$filename =~ s@\[@\\[@g; # escape brackets
-	$filename =~ s@\]@\\]@g; # escape brackets
-	
+    $filename =~ s/\./\\./g; # in case there are extensions/other full stops, escape them
+    $filename =~ s@\(@\\(@g; # escape brackets
+    $filename =~ s@\)@\\)@g; # escape brackets
+    $filename =~ s@\[@\\[@g; # escape brackets
+    $filename =~ s@\]@\\]@g; # escape brackets
+    
     return $filename;
 }
@@ -424,22 +424,22 @@
 
     # need to put doubled backslashes for regex back to single
-	$filename =~ s/\\\./\./g; # remove RE syntax for .
-	$filename =~ s@\\\(@(@g; # remove RE syntax for ( => "\(" turns into "("
-	$filename =~ s@\\\)@)@g; # remove RE syntax for ) => "\)" turns into ")"
-	$filename =~ s@\\\[@[@g; # remove RE syntax for [ => "\[" turns into "["
-	$filename =~ s@\\\]@]@g; # remove RE syntax for ] => "\]" turns into "]"
-	
-	# \\ goes to \
-	# This is the last step in reverse mirroring the order of steps in filename_to_regex()
-	$filename =~ s/\\\\/\\/g; # remove RE syntax for \    
+    $filename =~ s/\\\./\./g; # remove RE syntax for .
+    $filename =~ s@\\\(@(@g; # remove RE syntax for ( => "\(" turns into "("
+    $filename =~ s@\\\)@)@g; # remove RE syntax for ) => "\)" turns into ")"
+    $filename =~ s@\\\[@[@g; # remove RE syntax for [ => "\[" turns into "["
+    $filename =~ s@\\\]@]@g; # remove RE syntax for ] => "\]" turns into "]"
+    
+    # \\ goes to \
+    # This is the last step in reverse mirroring the order of steps in filename_to_regex()
+    $filename =~ s/\\\\/\\/g; # remove RE syntax for \    
     return $filename;
 }
 
 sub filename_cat {
-  # I've disabled this warning for now, as every Greenstone perl
-  # script seems to make use of this function and so you drown in a
-  # sea of deprecated warnings [jmt12]
-#  warnings::warnif("deprecated", "util::filename_cat() is deprecated, using FileUtils::filenameConcatenate() instead");
-  return &FileUtils::filenameConcatenate(@_);
+    # I've disabled this warning for now, as every Greenstone perl
+    # script seems to make use of this function and so you drown in a
+    # sea of deprecated warnings [jmt12]
+    #  warnings::warnif("deprecated", "util::filename_cat() is deprecated, using FileUtils::filenameConcatenate() instead");
+    return &FileUtils::filenameConcatenate(@_);
 }
 
@@ -547,5 +547,5 @@
 
     # 64 bit linux can't handle ";" as path separator, so make sure to set this to the right one for the OS
-##    my $pathsep = (defined $ENV{'GSDLOS'} && $ENV{'GSDLOS'} !~ m/windows/) ? ":" : ";";
+    ##    my $pathsep = (defined $ENV{'GSDLOS'} && $ENV{'GSDLOS'} !~ m/windows/) ? ":" : ";";
 
     # Rewritten above to make ":" the default (Windows is the special
@@ -632,7 +632,7 @@
     my ($base_dir, $file) = @_;
     
-#    my ($cpackage,$cfilename,$cline,$csubr,$chas_args,$cwantarray) = caller(0);
-#    my ($lcfilename) = ($cfilename =~ m/([^\\\/]*)$/);
-#    print STDERR "** Calling method: $lcfilename:$cline $cpackage->$csubr\n";
+    #    my ($cpackage,$cfilename,$cline,$csubr,$chas_args,$cwantarray) = caller(0);
+    #    my ($lcfilename) = ($cfilename =~ m/([^\\\/]*)$/);
+    #    print STDERR "** Calling method: $lcfilename:$cline $cpackage->$csubr\n";
 
 
@@ -727,6 +727,6 @@
 	$within_dir .= $dirsep;
     }
-	
-	$within_dir = &filename_to_regex($within_dir); # escape DOS style file separator and brackets	
+    
+    $within_dir = &filename_to_regex($within_dir); # escape DOS style file separator and brackets	
     if ($filename =~ m/^$within_dir(.*)$/) {
 	$filename = $1;
@@ -742,22 +742,22 @@
 {
     my ($filename,$within_dir) = @_;
-	
-	# convert parameters only to / slashes if Windows
-    
-	my $filename_urlformat = &filepath_to_url_format($filename);
-	my $within_dir_urlformat = &filepath_to_url_format($within_dir);
-
-	#if ($within_dir_urlformat !~ m/\/$/) {
-		# make sure directory ends with a slash
-		#$within_dir_urlformat .= "/";
+    
+    # convert parameters only to / slashes if Windows
+    
+    my $filename_urlformat = &filepath_to_url_format($filename);
+    my $within_dir_urlformat = &filepath_to_url_format($within_dir);
+
+    #if ($within_dir_urlformat !~ m/\/$/) {
+    # make sure directory ends with a slash
+    #$within_dir_urlformat .= "/";
     #}
-	
-	my $within_dir_urlformat_re = &filename_to_regex($within_dir_urlformat); # escape any special RE characters, such as brackets
-	
-	#print STDERR "@@@@@ $filename_urlformat =~ $within_dir_urlformat_re\n";
-	
-	# dir prefix may or may not end with a slash (this is discarded when extracting the sub-filepath)
+    
+    my $within_dir_urlformat_re = &filename_to_regex($within_dir_urlformat); # escape any special RE characters, such as brackets
+    
+    #print STDERR "@@@@@ $filename_urlformat =~ $within_dir_urlformat_re\n";
+    
+    # dir prefix may or may not end with a slash (this is discarded when extracting the sub-filepath)
     if ($filename_urlformat =~ m/^$within_dir_urlformat_re(?:\/)*(.*)$/) {
-		$filename_urlformat = $1;
+	$filename_urlformat = $1;
     }
     
@@ -769,11 +769,11 @@
 sub filepath_to_url_format
 {
-	my ($filepath) = @_;
-	if (($ENV{'GSDLOS'} =~ /^windows$/i) && ($^O ne "cygwin")) {
-		# Only need to worry about Windows, as Unix style directories already in url-format
-		# Convert Windows style \ => /
-		$filepath =~ s@\\@/@g;		
-	}
-	return $filepath;
+    my ($filepath) = @_;
+    if (($ENV{'GSDLOS'} =~ /^windows$/i) && ($^O ne "cygwin")) {
+	# Only need to worry about Windows, as Unix style directories already in url-format
+	# Convert Windows style \ => /
+	$filepath =~ s@\\@/@g;		
+    }
+    return $filepath;
 }
 
@@ -804,5 +804,5 @@
     my ($dirs, $file) = $filepath =~ m@(.+/)([^/]+)@;
     return ($file, $dirs);
-	
+    
 }
 
@@ -866,17 +866,17 @@
 	
 	if (-e $filename_full_path) {
-	   my $long_filename = Win32::GetLongPathName($filename_full_path);
-	   if (defined $long_filename) {
+	    my $long_filename = Win32::GetLongPathName($filename_full_path);
+	    if (defined $long_filename) {
 		
-	    $filename_full_path = $long_filename;
-	}
+		$filename_full_path = $long_filename;
+	    }
 	} else {
-	 
-	   my ($tailname, $dirname, $suffix)
-			= &File::Basename::fileparse($filename_full_path, "\\.[^\\.]+\$");
-		my $long_dirname = Win32::GetLongPathName($dirname);
-		if (defined $long_dirname) {
+	    
+	    my ($tailname, $dirname, $suffix)
+		= &File::Basename::fileparse($filename_full_path, "\\.[^\\.]+\$");
+	    my $long_dirname = Win32::GetLongPathName($dirname);
+	    if (defined $long_dirname) {
 		$filename_full_path = &FileUtils::filenameConcatenate($long_dirname, "$tailname$suffix");
-		}
+	    }
 	}
 	
@@ -901,18 +901,18 @@
 	# Ensure the given long Windows filename is in a form that can
 	# be opened by Perl => convert it to a short DOS-like filename
-    # GetShortPathName doesn't work if the file doesn't exist - in this case, use the directory instead
-		if (-e $filename_full_path) {
-	my $short_filename = Win32::GetShortPathName($filename_full_path);
-	if (defined $short_filename) {
-	    $filename_full_path = $short_filename;
-	}
+	# GetShortPathName doesn't work if the file doesn't exist - in this case, use the directory instead
+	if (-e $filename_full_path) {
+	    my $short_filename = Win32::GetShortPathName($filename_full_path);
+	    if (defined $short_filename) {
+		$filename_full_path = $short_filename;
+	    }
 	} else {
-	  my ($tailname, $dirname, $suffix)
-			= &File::Basename::fileparse($filename_full_path, "\\.[^\\.]+\$");
-		my $short_dirname = Win32::GetShortPathName($dirname);
-		if (defined $short_dirname) {
+	    my ($tailname, $dirname, $suffix)
+		= &File::Basename::fileparse($filename_full_path, "\\.[^\\.]+\$");
+	    my $short_dirname = Win32::GetShortPathName($dirname);
+	    if (defined $short_dirname) {
 		$filename_full_path = &FileUtils::filenameConcatenate($short_dirname, "$tailname$suffix");
-		}
-	
+	    }
+	    
 	}
 	# Make sure initial drive letter is lower-case (to fit in
@@ -927,6 +927,6 @@
 sub filename_is_absolute
 {
-  warnings::warnif("deprecated", "util::filename_is_absolute() is deprecated, using FileUtils::isFilenameAbsolute() instead");
-  return &FileUtils::isFilenameAbsolute(@_);
+    warnings::warnif("deprecated", "util::filename_is_absolute() is deprecated, using FileUtils::isFilenameAbsolute() instead");
+    return &FileUtils::isFilenameAbsolute(@_);
 }
 
@@ -950,5 +950,5 @@
     
     my ($base_dir, $dir) = @_;
-###    print STDERR "dir = $dir\n";
+    ###    print STDERR "dir = $dir\n";
     $dir =~ s/[\\\/]+/\//g;
     $dir = $base_dir . "/$dir" unless ($dir =~ m|^(\w:)?/|); 
@@ -957,5 +957,5 @@
     $dir =~ s|/[.][.]?/|/|g;
     $dir =~ tr|/|/|s;
-###    print STDERR "dir = $dir\n";
+    ###    print STDERR "dir = $dir\n";
     
     return $dir;
@@ -1039,5 +1039,5 @@
 
     if (!defined $ENV{'GREENSTONEHOME'}) { # for GS3, would have been defined in use_site_collection, to GSDL3HOME
-	 $ENV{'GREENSTONEHOME'} = $ENV{'GSDLHOME'}; 
+	$ENV{'GREENSTONEHOME'} = $ENV{'GSDLHOME'}; 
     }
 
@@ -1163,6 +1163,6 @@
 # Code is from http://episteme.arstechnica.com/eve/forums/a/tpc/f/6330927813/m/436007700831
 sub is_dir_empty {
-  warnings::warnif("deprecated", "util::is_dir_empty() is deprecated, using FileUtils::isDirectoryEmpty() instead");
-  return &FileUtils::isDirectoryEmpty(@_);
+    warnings::warnif("deprecated", "util::is_dir_empty() is deprecated, using FileUtils::isDirectoryEmpty() instead");
+    return &FileUtils::isDirectoryEmpty(@_);
 }
 
@@ -1206,5 +1206,5 @@
     # Not sure why it was done in first place...
     #else {
-	#$suffix = lc($suffix);
+    #$suffix = lc($suffix);
     #}
 
@@ -1304,5 +1304,5 @@
     # set for the future
     $ENV{'GREENSTONE_URL_PREFIX'} = $urlprefix;
-#    print STDERR "*** in get_greenstone_url_prefix(): $urlprefix\n\n";
+    #    print STDERR "*** in get_greenstone_url_prefix(): $urlprefix\n\n";
     return $urlprefix;
 }
@@ -1322,13 +1322,13 @@
 sub get_full_greenstone_url_prefix
 {	
-	my ($gs_mode, $lib_name, $get_public_url) = @_;
-	
+    my ($gs_mode, $lib_name, $get_public_url) = @_;
+    
     # if already set on a previous occasion, just return that
     # (Don't want to keep repeating this: cost of re-opening and scanning files.)
     return $ENV{'FULL_GREENSTONE_URL_PREFIX'} if($ENV{'FULL_GREENSTONE_URL_PREFIX'});
 
-	# set gs_mode if it was not passed in (servercontrol.pm would pass it in, any other callers won't)
+    # set gs_mode if it was not passed in (servercontrol.pm would pass it in, any other callers won't)
     $gs_mode = ($ENV{'GSDL3SRCHOME'}) ? "gs3" : "gs2" unless defined $gs_mode;
-	
+    
     my $url = undef;	
     
@@ -1429,11 +1429,11 @@
 	    }
 	    close(PIN);
-		
+	    
 	    # url can be undef if tomcat.port could not be determined due to
 	    # user having wrong or conflicting server related vals in build.props
-	       if (defined $url && defined $lib_name && $lib_name ne "") {
-			# replace the servlet_name portion of the url found, with the given library_name
-			$url =~ s@/[^/]*$@/$lib_name@;
-		}
+	    if (defined $url && defined $lib_name && $lib_name ne "") {
+		# replace the servlet_name portion of the url found, with the given library_name
+		$url =~ s@/[^/]*$@/$lib_name@;
+	    }
 	} else {
 	    print STDERR "util::get_full_greenstone_url_prefix() failed to run $perl_command to work out library URL for $gs_mode\n";
@@ -1492,67 +1492,67 @@
 #
 sub setup_greenstone_env() {
-	my ($GSDLHOME, $GSDLOS) = @_;
-
-	#my %env_map = ();
-	# Get the localised ENV settings of running a localised source setup.bash 
-	# and put it into the ENV here. Need to clear GSDLHOME before running setup
-	#my $perl_command = "(cd $GSDLHOME; export GSDLHOME=; . ./setup.bash > /dev/null; env)";
-	my $perl_command = "(cd $GSDLHOME; /bin/bash -c \"export GSDLHOME=; source setup.bash > /dev/null; env\")";		
-	if (($GSDLOS =~ m/windows/i) && ($^O ne "cygwin"))  {
-		#$perl_command = "cmd /C \"cd $GSDLHOME&& set GSDLHOME=&& setup.bat > nul&& set\"";
-		$perl_command = "(cd $GSDLHOME&& set GSDLHOME=&& setup.bat > nul&& set)";
-	}
-	if (!open(PIN, "$perl_command |")) {
-		print STDERR ("Unable to execute command: $perl_command. $!\n");
-	}
-
-	my $lastkey;
-	while (defined (my $perl_output_line = <PIN>)) {
-		my($key,$value) = ($perl_output_line =~ m/^([^=]*)[=](.*)$/);
-		if(defined $key) {
-		    #$env_map{$key}=$value;		
-		    $ENV{$key}=$value;
-		    $lastkey = $key;
-		} elsif($lastkey && $perl_output_line !~ m/^\s*$/) { 
-		    # there was no equals sign in $perl_output_line, so this 
-		    # $perl_output_line may be a spillover from the previous
-		    $ENV{$lastkey} = $ENV{$lastkey}."\n".$perl_output_line;
-		}
-	}
-	close (PIN);
-
-	# If any keys in $ENV don't occur in Greenstone's localised env 
-	# (stored in $env_map), delete those entries from $ENV
-	#foreach $key (keys %ENV) {	
-	#	if(!defined $env_map{$key}) { 
-	#		print STDOUT "**** DELETING ENV KEY: $key\tVALUE: $ENV{$key}\n";
-	#		delete $ENV{$key}; # del $ENV(key, value) pair
-	#	}
-	#}
-	#undef %env_map;
+    my ($GSDLHOME, $GSDLOS) = @_;
+
+    #my %env_map = ();
+    # Get the localised ENV settings of running a localised source setup.bash 
+    # and put it into the ENV here. Need to clear GSDLHOME before running setup
+    #my $perl_command = "(cd $GSDLHOME; export GSDLHOME=; . ./setup.bash > /dev/null; env)";
+    my $perl_command = "(cd $GSDLHOME; /bin/bash -c \"export GSDLHOME=; source setup.bash > /dev/null; env\")";		
+    if (($GSDLOS =~ m/windows/i) && ($^O ne "cygwin"))  {
+	#$perl_command = "cmd /C \"cd $GSDLHOME&& set GSDLHOME=&& setup.bat > nul&& set\"";
+	$perl_command = "(cd $GSDLHOME&& set GSDLHOME=&& setup.bat > nul&& set)";
+    }
+    if (!open(PIN, "$perl_command |")) {
+	print STDERR ("Unable to execute command: $perl_command. $!\n");
+    }
+
+    my $lastkey;
+    while (defined (my $perl_output_line = <PIN>)) {
+	my($key,$value) = ($perl_output_line =~ m/^([^=]*)[=](.*)$/);
+	if(defined $key) {
+	    #$env_map{$key}=$value;		
+	    $ENV{$key}=$value;
+	    $lastkey = $key;
+	} elsif($lastkey && $perl_output_line !~ m/^\s*$/) { 
+	    # there was no equals sign in $perl_output_line, so this 
+	    # $perl_output_line may be a spillover from the previous
+	    $ENV{$lastkey} = $ENV{$lastkey}."\n".$perl_output_line;
+	}
+    }
+    close (PIN);
+
+    # If any keys in $ENV don't occur in Greenstone's localised env 
+    # (stored in $env_map), delete those entries from $ENV
+    #foreach $key (keys %ENV) {	
+    #	if(!defined $env_map{$key}) { 
+    #		print STDOUT "**** DELETING ENV KEY: $key\tVALUE: $ENV{$key}\n";
+    #		delete $ENV{$key}; # del $ENV(key, value) pair
+    #	}
+    #}
+    #undef %env_map;
 }
 
 sub get_perl_exec() {	
-	my $perl_exec = $^X; # may return just "perl"
-	
-	if($ENV{'PERLPATH'}) {
-		# OR: # $perl_exec = &FileUtils::filenameConcatenate($ENV{'PERLPATH'},"perl");
-		if (($ENV{'GSDLOS'} =~ m/windows/) && ($^O ne "cygwin")) {
-			$perl_exec = "$ENV{'PERLPATH'}\\Perl.exe";
-		} else {
-			$perl_exec = "$ENV{'PERLPATH'}/perl";
-		}
-	} else { # no PERLPATH, use Config{perlpath} else $^X: special variables
-		# containing the full path to the current perl executable we're using
-		$perl_exec = $Config{perlpath}; # configured path for perl
-		if (!-e $perl_exec) { # may not point to location on this machine
-			$perl_exec = $^X; # may return just "perl"
-			if($perl_exec =~ m/^perl/i) { # warn if just perl or Perl.exe
-				print STDERR "**** WARNING: Perl exec found contains no path: $perl_exec";				
-			}
-		}
-    }
-	
-	return $perl_exec;
+    my $perl_exec = $^X; # may return just "perl"
+    
+    if($ENV{'PERLPATH'}) {
+	# OR: # $perl_exec = &FileUtils::filenameConcatenate($ENV{'PERLPATH'},"perl");
+	if (($ENV{'GSDLOS'} =~ m/windows/) && ($^O ne "cygwin")) {
+	    $perl_exec = "$ENV{'PERLPATH'}\\Perl.exe";
+	} else {
+	    $perl_exec = "$ENV{'PERLPATH'}/perl";
+	}
+    } else { # no PERLPATH, use Config{perlpath} else $^X: special variables
+	# containing the full path to the current perl executable we're using
+	$perl_exec = $Config{perlpath}; # configured path for perl
+	if (!-e $perl_exec) { # may not point to location on this machine
+	    $perl_exec = $^X; # may return just "perl"
+	    if($perl_exec =~ m/^perl/i) { # warn if just perl or Perl.exe
+		print STDERR "**** WARNING: Perl exec found contains no path: $perl_exec";				
+	    }
+	}
+    }
+    
+    return $perl_exec;
 }
 
@@ -1563,5 +1563,5 @@
     my $java = "java";
     if(defined $ENV{'GSDLHOME'}) { # should be, as this script would be launched from the cmd line 
-	                           # after running setup.bat or from GLI which also runs setup.bat
+	# after running setup.bat or from GLI which also runs setup.bat
 	my $java_bin = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'},"packages","jre","bin");
 	if(-d $java_bin) {
@@ -1577,39 +1577,39 @@
 # returns the collection and colgroup parts
 sub get_collection_parts {
-	# http://perldoc.perl.org/File/Basename.html
-	# my($filename, $directories, $suffix) = fileparse($path);
-	# "$directories contains everything up to and including the last directory separator in the $path 
-	# including the volume (if applicable). The remainder of the $path is the $filename."
-	#my ($collection, $colgroup) = &File::Basename::fileparse($qualified_collection);	
-
-	my $qualified_collection = shift(@_); 
-
-	# Since activate.pl can be launched from the command-line, including by a user, 
-	# best not to assume colgroup uses URL-style slashes as would be the case with GLI
-	# Also allow for the accidental inclusion of multiple slashes
-	my ($colgroup, $collection) = split(/[\/\\]+/, $qualified_collection); #split('/', $qualified_collection);
-	
-	if(!defined $collection) {
-		$collection = $colgroup;
-		$colgroup = "";
-	}
-	return ($collection, $colgroup);
+    # http://perldoc.perl.org/File/Basename.html
+    # my($filename, $directories, $suffix) = fileparse($path);
+    # "$directories contains everything up to and including the last directory separator in the $path 
+    # including the volume (if applicable). The remainder of the $path is the $filename."
+    #my ($collection, $colgroup) = &File::Basename::fileparse($qualified_collection);	
+
+    my $qualified_collection = shift(@_); 
+
+    # Since activate.pl can be launched from the command-line, including by a user, 
+    # best not to assume colgroup uses URL-style slashes as would be the case with GLI
+    # Also allow for the accidental inclusion of multiple slashes
+    my ($colgroup, $collection) = split(/[\/\\]+/, $qualified_collection); #split('/', $qualified_collection);
+    
+    if(!defined $collection) {
+	$collection = $colgroup;
+	$colgroup = "";
+    }
+    return ($collection, $colgroup);
 }
 
 # work out the "collectdir/collection" location
 sub resolve_collection_dir {
-	my ($collect_dir, $qualified_collection, $site) = @_; #, $gs_mode
-	
-	if (defined $ENV{'GSDLCOLLECTDIR'}) { # a predefined collection dir exists
-	    return $ENV{'GSDLCOLLECTDIR'};
-	}
-
-	my ($colgroup, $collection) = &util::get_collection_parts($qualified_collection);	
-	
-	if (!defined $collect_dir || !$collect_dir) { # if undefined or empty string
-	    $collect_dir = &util::get_working_collect_dir($site);
-	}
-
-	return &FileUtils::filenameConcatenate($collect_dir,$colgroup,$collection);
+    my ($collect_dir, $qualified_collection, $site) = @_; #, $gs_mode
+    
+    if (defined $ENV{'GSDLCOLLECTDIR'}) { # a predefined collection dir exists
+	return $ENV{'GSDLCOLLECTDIR'};
+    }
+
+    my ($colgroup, $collection) = &util::get_collection_parts($qualified_collection);	
+    
+    if (!defined $collect_dir || !$collect_dir) { # if undefined or empty string
+	$collect_dir = &util::get_working_collect_dir($site);
+    }
+
+    return &FileUtils::filenameConcatenate($collect_dir,$colgroup,$collection);
 }
 
@@ -1673,5 +1673,5 @@
 	$path = &util::upgrade_if_dos_filename($path); # will only do something on windows
     }
-	
+    
     # now we know we're dealing with absolute paths and have to replace gs prefixes with placeholders
     my @gs_paths = ($ENV{'GSDLCOLLECTDIR'}, $ENV{'GSDLCOLLECTHOME'}, $ENV{'SITEHOME'}, $ENV{'GREENSTONEHOME'}); # list in this order: from longest to shortest path
@@ -1726,6 +1726,6 @@
 	    $path =~ s/^$re_path/$placeholder/; #case sensitive or not?
 	    #$path =~ s/^[\\\/]//; # remove gs_path's trailing separator left behind at the start of the path
-		# lowercase file extension, This is needed when shortfilenames are used, as case affects alphetical ordering, which affects diffcol		
-		$path =~ s/\.([A-Z]+)$/".".lc($1)/e;
+	    # lowercase file extension, This is needed when shortfilenames are used, as case affects alphetical ordering, which affects diffcol		
+	    $path =~ s/\.([A-Z]+)$/".".lc($1)/e;
 	    last; # done
 	}
@@ -1745,5 +1745,5 @@
     # replace placeholders with gs prefixes
     my @placeholders = ('@THISCOLLECTPATH@', '@COLLECTHOME@', '@SITEHOME@', '@GSDLHOME@'); # order of paths not crucial in this case, 
-                       # but listed here from longest to shortest once placeholders are have been resolved
+    # but listed here from longest to shortest once placeholders are have been resolved
 
     # can't use double-quotes around at-sign, else perl tries to evaluate it as referring to an array
@@ -1752,7 +1752,7 @@
 	# always replace placeholders with short file names of the absolute paths on windows?
 	%placeholder_to_gspath_map = ('@GSDLHOME@' => &util::downgrade_if_dos_filename($ENV{'GREENSTONEHOME'}),
-				     '@COLLECTHOME@' => &util::downgrade_if_dos_filename($ENV{'GSDLCOLLECTHOME'}),
-				     '@THISCOLLECTPATH@' => &util::downgrade_if_dos_filename($ENV{'GSDLCOLLECTDIR'})
-	);
+				      '@COLLECTHOME@' => &util::downgrade_if_dos_filename($ENV{'GSDLCOLLECTHOME'}),
+				      '@THISCOLLECTPATH@' => &util::downgrade_if_dos_filename($ENV{'GSDLCOLLECTDIR'})
+	    );
 	$placeholder_to_gspath_map{'@SITEHOME@'} =  &util::downgrade_if_dos_filename($ENV{'SITEHOME'}) if defined $ENV{'SITEHOME'};
     } else {
@@ -1793,5 +1793,5 @@
 	my ($dir) = @_;
 	my ($pagenum) =($dir =~ m/^.*?[-\.]?(\d+)(\.(jpg|gif|png|txt))?$/i);
-#	my ($pagenum) =($dir =~ m/(\d+)(\.(jpg|gif|png))?$/i); # this works but is not as safe/strict about input filepatterns as the above
+	#	my ($pagenum) =($dir =~ m/(\d+)(\.(jpg|gif|png))?$/i); # this works but is not as safe/strict about input filepatterns as the above
 
 	$pagenum = 1 unless defined $pagenum;
@@ -1821,5 +1821,5 @@
     # We just test if a text file exists in the same dir that matches the name of the first image file
     # if a matching txt file does not exist, don't output txtfile names into the item file
-	
+    
     my ($tailname, $dirname, $suffix) = &File::Basename::fileparse($firstfile, "\\.[^\\.]+\$"); # relative filenames so no dirname
     my $txtfilename = &FileUtils::filenameConcatenate($output_dir, $tailname . ".txt");
@@ -1882,5 +1882,5 @@
 	    }
 	}
-    
+	
 	# now set other the related env vars, 
 	# IF we've found the gnome-lib dir installed in the ext folder	
@@ -1889,5 +1889,5 @@
 	    $ENV{'GEXTGNOME'} = $gnome_dir;
 	    $ENV{'GEXTGNOME_INSTALLED'}=&FileUtils::filenameConcatenate($ENV{'GEXTGNOME'}, $ENV{'GSDLOS'});
-	   
+	    
 	    my $gnomelib_bin = &FileUtils::filenameConcatenate($ENV{'GEXTGNOME_INSTALLED'}, "bin");
 	    if(-d $gnomelib_bin) { # no bin subfolder in GS binary's cutdown gnome-lib-minimal folder
@@ -1912,8 +1912,8 @@
     }
 
-#    print STDERR "@@@@@ GEXTGNOME: ".$ENV{'GEXTGNOME'}."\n\tINSTALL".$ENV{'GEXTGNOME_INSTALLED'}."\n";
-#    print STDERR "\tPATH".$ENV{'PATH'}."\n";
-#    print STDERR "\tLD_LIB_PATH".$ENV{'LD_LIBRARY_PATH'}."\n" if $ENV{'LD_LIBRARY_PATH};
-#    print STDERR "\tDYLD_FALLBACK_LIB_PATH".$ENV{'DYLD_FALLBACK_LIBRARY_PATH'}."\n" if $ENV{'DYLD_FALLBACK_LIBRARY_PATH};
+    #    print STDERR "@@@@@ GEXTGNOME: ".$ENV{'GEXTGNOME'}."\n\tINSTALL".$ENV{'GEXTGNOME_INSTALLED'}."\n";
+    #    print STDERR "\tPATH".$ENV{'PATH'}."\n";
+    #    print STDERR "\tLD_LIB_PATH".$ENV{'LD_LIBRARY_PATH'}."\n" if $ENV{'LD_LIBRARY_PATH};
+    #    print STDERR "\tDYLD_FALLBACK_LIB_PATH".$ENV{'DYLD_FALLBACK_LIBRARY_PATH'}."\n" if $ENV{'DYLD_FALLBACK_LIBRARY_PATH};
 
     # if no GEXTGNOME, maybe users didn't need gnome-lib to run gnomelib/libiconv dependent binaries like hashfile, suffix, wget 
@@ -1931,25 +1931,25 @@
 sub augmentINC
 {
-  my ($new_path) = @_;
-  my $did_add_path = 0;
-  # might need to be replaced with FileUtils::directoryExists() call eventually
-  if (-d $new_path)
-  {
-    my $did_find_path = 0;
-    foreach my $existing_path (@INC)
+    my ($new_path) = @_;
+    my $did_add_path = 0;
+    # might need to be replaced with FileUtils::directoryExists() call eventually
+    if (-d $new_path)
     {
-      if ($existing_path eq $new_path)
-      {
-        $did_find_path = 1;
-        last;
-      }
-    }
-    if (!$did_find_path)
-    {
-      unshift(@INC, $new_path);
-      $did_add_path = 1;
-    }
-  }
-  return $did_add_path;
+	my $did_find_path = 0;
+	foreach my $existing_path (@INC)
+	{
+	    if ($existing_path eq $new_path)
+	    {
+		$did_find_path = 1;
+		last;
+	    }
+	}
+	if (!$did_find_path)
+	{
+	    unshift(@INC, $new_path);
+	    $did_add_path = 1;
+	}
+    }
+    return $did_add_path;
 }
 ## augmentINC()
