Index: trunk/gsdl/bin/script/fromsearch.pl
===================================================================
--- trunk/gsdl/bin/script/fromsearch.pl	(revision 5499)
+++ 	(revision )
@@ -1,270 +1,0 @@
-#!/usr/bin/perl
-
-###########################################################################
-#
-# fromsearch.pl
-#
-# A component of the Greenstone digital library software
-# from the New Zealand Digital Library Project at the 
-# University of Waikato, New Zealand.
-#
-# Copyright (C) 1999 New Zealand Digital Library Project
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-###########################################################################
-
-# This code generates a single page version of the Greenstone Interface
-# Translation Agency when accessed from a search of the Macro Collection.
-# This allows users to correct mistakes made in translations.
-
-BEGIN {
-    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
-    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
-}
-
-use parsargv;
-use util;
-use Cwd;
-use File::Basename;
-use GDBM_File;
-use CGI;
-#require utf8;
-#use unicode;
-
-&main(@ARGV);
-
-sub main {
-    
-    $macroname = shift(@_);
-    $language = shift(@_);
-    $baselanguage = shift(@_);
-    
-    $dir = util::filename_cat($ENV{'GSDLHOME'},"tmp","lang","gdbmfiles");
-
-    #finds the macroname in the dbfiles
-    my $db1_blang = util::filename_cat($dir,$baselanguage.".db");
-    my $db1_lang  = util::filename_cat($dir,language.".db");
-    my $db2_blang = util::filename_cat($dir,$baselanguage."2.db");
-    my $db2_lang  = util::filename_cat($dir,language."2.db");
-
-    my ($formhash) = &db_db_diffs ($db1_blang, $db1_lang, $macroname);
-    my ($formhash2) = &db_db_diffs($db2_blang, $db2_lang, $macroname);
-
-    #puts results of above calls into one hash
-    $formhash = &combine_hashes($formhash,$formhash2);
-
-    #generates form using the one macro and macrotext from above
-    &generate_form($formhash, $language, $baselanguage);
-
-}
-#loops through each hash which is passed to it, appending each value
-#to a new third hash. Returns the third hash as result.
-sub combine_hashes {
-    
-    my ($hash1, $hash2) = @_;
-    my %combined = ();
-
-    foreach $key (sort (keys %$hash1)) {
-	$combined{$key} = $hash1->{$key};
-    }
-    foreach $key (sort (keys %$hash2)) {
-	$combined{$key} = $hash2->{$key};
-    }
-
-    return (\%combined);
-
-}
-
-sub db_db_diffs
-{
-    my ($db_one, $db_two, $macroname) = @_;
-
-    my %db1hash = ();
-    my %db2hash = ();
-    my %months = ("Jan",1,"Feb",2,"Mar",3,"Apr",4,"May",5,"Jun",6,
-		  "Jul",7,"Aug",8,"Sep",9,"Oct",10,"Nov",11,"Dec",12);
-    
-    # this hash holds the database entries that are in 
-    # english.db but not in $filename.db
-    my %diffhash = ();
-
-    #ties the hash to database so when you read from hash it fetches from external
-    #database and when you set hash it writes to external database
-    tie(%db1hash, "GDBM_File", $db_one, GDBM_READER, 0640);
-    tie(%db2hash, "GDBM_File", $db_two, GDBM_READER, 0640);
-
-    #the key is the name of the macro
-    foreach $key (sort keys(%db1hash)) {
-
-	#the macro has to be in one of the dbfiles so just want to keep scrolling
-	#through until we hit it...
-	if ($key eq $macroname) {
-	    $foreigntext = $db2hash{$key};
-	    if ($foreigntext =~ m/\#\# /) {
-		$foreigntext = $& if ($foreigntext =~ m/\"(.|^)*\"/);
-	    }
-	    else {
-		$foreigntext =~ s/^.*\n//;
-		$foreigntext =~ s/.*\{//;
-		$foreigntext =~ s/\}\Z//;
-		$foreigntext =~ s/\n\Z//;
-	    }
-	    #puts the macroname as a key with the array containing the macro text in
-	    #the base language and in the translation language
-	    $diffhash{$key} = [$db1hash{$key}, $foreigntext];
-	}
-    }
-    untie %db1hash;
-    untie %db2hash;
-
-    return \%diffhash;    
-} 
-
-sub generate_form
-{
-    my ($formhash) = shift(@_);
-    my $language = shift(@_);
-    my $baselanguage = shift(@_);
-    my $fs_fname = util::filename_cat($ENV{'GSDLHOME'},"tmp","lang",
-				      "package_forms", "$lang", "fromsearch.lang");
-
-    open (FILE, ">$fs_fname") or die "Unable to open $fs_fname: $!\n";
-    # common gateway interface for writing the stuff to the web
-    my $query = new CGI;
-    
-    #used to indicate whether or not content of table has been generated
-    my $processed = "false";
-    
-    #prints table headings and passes hidden data for page
-    print FILE ($query->hidden(-name=>"hiddenlanguage",-default=>"$language"),
-		$query->hidden(-name=>"baselanguage",-default=>"$baselanguage"),
-		"</center><table cellpadding=\"10\">\n",
-		"<tr><td><strong><center>".uc ($baselanguage)."</strong></center></td>\n",
-		"<td><strong><center>". uc ($language)."</strong></center></td></tr>\n");
-    
-
-    foreach $key (keys(%$formhash)) {
-
-	#changes to indicate hash did contain data and table content will be created
-	$processed = "true";
-	
-	#gets the base language text from the hash
-	my $text = $formhash->{$key}[0];
-	my $keyname = $key;
-	$keyname  =~ s/_/\\_/g;
-	# strip off the date
-	$text =~ s/.*//;
-	$text =~ s/(\[l=.*\])//;
-	
-        # must take care of image macros single and multiple line ones
-	$text =~ s/(\<br\>\#\#.*\#\#\s*\<br\>).*/$1/g;
-	
-	# format the text for displaying in the browser
-	$text =~ s/[\{\}]//g unless($text =~ m/\#\# /);
-	$text =~ s/(\A\n)//;
-	$text =~ s/(\n\Z)//;
-	
-	#gets the translation language text from the hash
-	my $default = $formhash->{$key}[1];    
-	
-        # so that when it is an image only get the text to translate not coding stuff aswell
-	if ($text =~ m/\#\# (^|.)*/) {
-	    if ($& =~ m/".*"/) {
-		#prints to file two text fields, the left contains the base language text
-		#and cannot be modified, the right contains the translation language text
-		#to be modified and submitted
-		print FILE ("<tr><td>",
-
-			   $query->textfield(-name=>"whocares",
-					     -default=>"$&",
-					     -size=>50,
-					     -readonly=>1),
-			   "</td><td>",
-			   $query->hidden(-name=>"$keyname",-default=>"$`"));
-		print FILE ($query->textfield(-name=>"$keyname",
-					     -default=>"$default",
-					     -size=>50));
-		print FILE ($query->hidden(-name=>"$keyname",-default=>"$'"),
-			   "</td></tr>\n");
-	    }
-	}
-	#else have a normal macro of form _this_
-	elsif ($text =~ m/\S+/) {
-		$text =~ s/\s+/ /g;
-		
-		$text =~ s/<p>/<p>\n/g;
-		$text =~ s/<br>/<br>\n/g;
-		$text =~ s/<\/td>/<\/td>\n/g;
-
-		#see how long the macro text is to determine whether to use a text
-		#field or a text area
-		my @words = split(/ /, $text);
-		my $words = scalar(@words);
-		my $rows = sprintf("%.0f", $words/5);
-		print FILE ("<tr><td>\n");
-		#prints to file two text regions, the left contains the base language text
-		#and cannot be modified, the right contains the translation language text
-		#to be modified and submitted
-		if ($rows > 1) {
-		    print FILE ($query->textarea(-name=>"whocares",
-						-rows=>$rows * 2,
-						-default=>"$text",
-						-columns=>50,
-						-readonly=>1), 
-			       "</td><td>\n",
-			       $query->textarea(-name=>"$keyname",
-						-rows=>$rows * 2,
-						-default=>"$default",
-						-columns=>50), 
-			       "<br></td></tr>\n");  
-		}
-		else {
-		    print FILE ($query->textfield(-name=>"whocares",
-						 -default=>"$text",
-						 -size=>50,
-						 -readonly=>1),
-			       "</td><td>\n",
-			       $query->textfield(-name=>"$keyname",
-						 -default=>"$default",
-						 -size=>50),
-			       "<br></td></tr>\n");
-		}
-	    }
-    }
-
-    #catch where hash is empty and print appropriate error message for user
-    if ($processed eq "false") {
-	print FILE ("<tr><td colspan=2 align=center>",
-		    "An error occurred while processing your request\n<br>",
-		    "</td></tr>")
-	}
-
-    #finishes table and adds a SUBMIT CHANGES option on the end
-    print FILE ("</table><br><center>\n",
-	       "<table><tr><td align=left width=\"50%\">",
-	       $query->reset("RESET FORM"),
-	       "</td><td align=right width=\"50%\">",
-	       $query->submit($pageno, "_textsubmit_"),
-	       "</td></tr><tr><td width=\"50%\"></td><td align=right width=\"50%\">",
-	       "<br> _textsubmittext_ \n",
-	       "</td></tr></table>");
-
-    # adds the CGI area just written to the array of CGI areas
-    push (@queries, $query);
-    
-    return $query;
-}
-
Index: trunk/gsdl/bin/script/inittranslation.pl
===================================================================
--- trunk/gsdl/bin/script/inittranslation.pl	(revision 5499)
+++ 	(revision )
@@ -1,756 +1,0 @@
-#!/usr/bin/perl -w
-
-###########################################################################
-#
-# inittranslation.pl
-#
-# A component of the Greenstone digital library software
-# from the New Zealand Digital Library Project at the 
-# University of Waikato, New Zealand.
-#
-# Copyright (C) 1999 New Zealand Digital Library Project
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-###########################################################################
-
-
-BEGIN {
-    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
-    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
-}
-
-
-use util;
-use GDBM_File;
-
-
-my %updatedata = ();
-
-
-sub main
-{
-    # Get the name of the source (base) language
-    my $sourcelang = shift(@_);
-    # Get the name of the target language
-    my $targetlang = shift(@_);
-    my $usecvs = shift(@_);
-
-    # Check that both arguments were supplied
-    if (!$sourcelang) {
-	die "Error: You didn't supply the name of the source language!\n";
-    }
-    if (!$targetlang) {
-	die "Error: You didn't supply the name of the target language!\n";
-    }
-
-    # Casefold both language names
-    $sourcelang =~ tr/A-Z/a-z/;
-    $targetlang =~ tr/A-Z/a-z/;
-
-    my $gsdldir = "$ENV{'GSDLHOME'}";
-    my $macrosdir = util::filename_cat($gsdldir, "macros");
-    my $langdir = util::filename_cat($gsdldir, "tmp", "lang");
-
-    # Make sure this is a new translation process
-    my $translationdir = util::filename_cat($langdir, "$sourcelang-$targetlang");
-    if (-e $translationdir) {
-	print STDERR "Note: Translation has already been initialised (exiting).\n";
-	return;
-    }
-
-    # If the source language is not English, it may not be up to date
-    if ($sourcelang !~ m/english/) {
-	print STDERR "Warning: Source language is not English. You should check that" .
-	             " the source language is up to date before beginning.\n";
-    }
-
-    # Check that the source language macro files exist, and parse them
-    my $sourcedmname1 = &get_macrofile_name($sourcelang, "");
-    my $sourcehash1 = &parse_macrofile($macrosdir, $sourcedmname1);
-    my $sourcedmname2 = &get_macrofile_name($sourcelang, "2");
-    my $sourcehash2 = &parse_macrofile($macrosdir, $sourcedmname2);
-
-    # Make sure some macros exist to be translated
-    if (!$sourcehash1 && !$sourcehash2) {
-	die "Error: No source macro information exists.\n";
-    }
-
-    # Combine the two source hashes
-    my $sourcehash = &combine_hashes($sourcehash1, $sourcehash2);
-
-    # Create a directory to store the data for the new translation, make world-writeable
-    my $currentmask = umask;
-    umask(0000);
-    if (! mkdir($translationdir, 0777)) {
-	umask($currentmask);
-	die "Error: Couldn't create directory $translationdir.\n";
-    }
-
-    # Start a new database for the translation information
-    my $translationdb = util::filename_cat($translationdir, "translation.db");
-    my %translationdata = ();
-    tie(%translationdata, "GDBM_File", $translationdb, GDBM_WRCREAT, 0666);
-
-    # Work out what the target language code should be, and store it in the database
-    my $maincfgfile = util::filename_cat($gsdldir, "etc", "main.cfg");
-    my $languagecodes = &get_language_codes();
-    my $targetcode = &get_language_code($targetlang, $maincfgfile, $languagecodes);
-    $translationdata{"*target_lang_code*"} = $targetcode;
-
-    # Start a new update database
-    my $updatedb = util::filename_cat($translationdir, "update.db");
-    tie(%updatedata, "GDBM_File", $updatedb, GDBM_WRCREAT, 0666);
-    umask($currentmask);
-
-    # Create the target language macro files if they don't exist
-    my $targetdmname1 = &get_macrofile_name($targetlang, "");
-    my $targetdmfile1 = util::filename_cat($macrosdir, $targetdmname1);
-    if (! -e $targetdmfile1) {
-	my $sourcedmfile1 = util::filename_cat($macrosdir, $sourcedmname1);
-	&create_empty_macrofile($sourcedmfile1, $targetdmfile1);
-    }
-    my $targetdmname2 = &get_macrofile_name($targetlang, "2");
-    my $targetdmfile2 = util::filename_cat($macrosdir, $targetdmname2);
-    if (! -e $targetdmfile2) {
-	my $sourcedmfile2 = util::filename_cat($macrosdir, $sourcedmname2);
-	&create_empty_macrofile($sourcedmfile2, $targetdmfile2);
-    }
-
-    # Parse the target language macro files
-    my $targethash1 = &parse_macrofile($macrosdir, $targetdmname1);
-    my $targethash2 = &parse_macrofile($macrosdir, $targetdmname2);
-
-    # Combine the two target hashes
-    my $targethash = &combine_hashes($targethash1, $targethash2);
-
-    # Initialise the translation database with the current contents of the macrofiles
-    foreach $sourcekey (sort keys(%$sourcehash)) {
-	$translationdata{$sourcekey} = $sourcehash->{$sourcekey};
-    }
-    foreach $targetkey (sort keys(%$targethash)) {
-	$translationdata{$targetkey} = $targethash->{$targetkey};
-    }
-
-    # Use CVS to initialise the update database, if desired
-    if ($usecvs && $usecvs eq "true") {
-	&initialise_update_db($sourcelang, $targetlang, $targethash, $macrosdir);
-    }
-
-    # Clean up
-    untie %translationdata;
-    untie %updatedata;
-}
-
-
-sub get_macrofile_name
-{
-    my ($language, $suffix) = @_;
-
-    my $macrofilename = $language;
-
-    # Handles cases where the macro file name is different to the language name
-    $macrofilename = "port" if ($language =~ m/portuguese/);
-    $macrofilename = "indo" if ($language =~ m/indonesian/);
-
-    # Add suffix (if any) and file extension, and return
-    $macrofilename = $macrofilename . $suffix . ".dm";
-    return $macrofilename;
-}
-
-
-sub get_language_code
-{
-    my ($language, $maincfgfile, $languagecodes) = @_;
-
-    # Check if the language is in the main.cfg file
-    open(MAIN_CFG_IN, "<$maincfgfile") or die "Error: Could not open $maincfgfile.\n";
-    my $lastlangline;
-    while (<MAIN_CFG_IN>) {
-	$line = $_;
-	chomp($line);
-	# print "Line: $line\n";
-	if ($line =~ m/^Language\s+/i) {
-	    my @args = split(/ +/,$line);
-	    my ($lang_abbr) = ($args[1] =~ m/^shortname=(.*)$/);
-	    $lang_abbr =~ tr/A-Z/a-z/;
-	    my ($lang_long) = ($args[2] =~ m/^longname=(.*)$/);
-	    $lang_long =~ tr/A-Z/a-z/;
-
-	    # Is this the language we are translating into?
-	    if ($lang_long eq $language) {
-		return $lang_abbr;
-	    }
-
-	    $lastlangline = $line;
-	}
-    }
-    close MAIN_CFG_IN;
-
-    # Try to find it using the ISO 639 language codes
-    my $langcode;
-    if ($languagecodes->{$language}) {
-	$langcode = $languagecodes->{$language};
-    }
-    # Otherwise we just have to make something up
-    else {
-	$langcode = &make_up_language_code($language, $languagecodes);
-    }
-
-    # Add the new language code into the main.cfg file, and make sure it is world writeable
-    my $currentmask = umask;
-    umask(0000);
-    if (! open(MAIN_CFG_OUT,">$maincfgfile.new")) {
-	umask($currentmask);
-	die "Error: Could not create $maincfgfile.new: $!\n";
-    }
-    umask($currentmask);
-
-    open MAIN_CFG_IN, "<$maincfgfile" or die "Error: Could not open $maincfgfile.\n";
-    my $inmacros = "false";
-    while (<MAIN_CFG_IN>) {
-	$line = $_;
-	chomp($line);
-	print MAIN_CFG_OUT $line;
-	if ($line =~ m/^macrofiles /) {
-	    $inmacros = "true";
-	}
-	if ($inmacros eq "true" && $line !~ m/\\$/) {
-	    print MAIN_CFG_OUT " \\\n";
-	    print MAIN_CFG_OUT "                $language" . ".dm $language" . "2.dm";
-	    $inmacros = "false";
-	}
-	print MAIN_CFG_OUT "\n";
-
-	if ($line eq $lastlangline) {
-	    # Change language into title case
-	    my $langtitlecase = $language;
-	    substr($langtitlecase, 0, 1) =~ tr/a-z/A-Z/;
-	    print MAIN_CFG_OUT ("Language shortname=$langcode longname=$langtitlecase ",
-				"default_encoding=utf-8\n");
-	}
-    }
-    close MAIN_CFG_IN;
-    close MAIN_CFG_OUT;
-
-    # Delete the old main.cfg and replace it with the new one
-    unlink($maincfgfile);
-    rename("$maincfgfile.new", $maincfgfile);
-
-    return $langcode;
-}
-
-
-sub make_up_language_code
-{
-    my ($language, $languagecodes) = @_;
-
-    # !! TO FINISH !!
-    print STDERR "Making up language code...\n";
-    $langcode = $& if ($language =~ m/\w\w/);
-    $language =~ s/\A.//;
-
-    return $langcode;
-}
-
-
-sub create_empty_macrofile
-{
-    my ($sourcedmfile, $targetdmfile) = @_;
-
-    open(SOURCE_DM_FILE_IN, "<$sourcedmfile") or die "Error: Could not open file.\n";
-    open(TARGET_DM_FILE_OUT, ">$targetdmfile") or die "Error: Could not write file.\n";
-
-    # Reads in contents of macro file, line by line
-    while (<SOURCE_DM_FILE_IN>) {
-	# Check if a new package is being defined
-	if (s/^package //) {
-	    $packagename = $_;
-	    chomp($packagename);
-
-	    # It is, so write an empty package section to the target macro file
-	    print TARGET_DM_FILE_OUT "package $packagename\n";
-	    print TARGET_DM_FILE_OUT "# text macros\n";
-	    print TARGET_DM_FILE_OUT "# icons\n";	    
-	}
-    }
-
-    close SOURCE_DM_FILE_IN;
-    close TARGET_DM_FILE_OUT;
-}
-
-
-sub parse_macrofile
-{
-    my ($macrosdir, $macrofile) = @_;
-
-    # Opens macro file or returns
-    my $macropath = util::filename_cat($macrosdir, $macrofile);
-    open(IN, "<$macropath") or return;
-
-    # Initialises some local variables
-    my $currpackage;
-    my %macros = ();
-
-    # Reads in contents of macro file, line by line
-    while (<IN>) {
-	# Check if a new package is being defined
-	if (s/^package //) {
-	    $currpackage = $_;
-	    chomp($currpackage);
-	}
-
-	# Line contains a macro name
-	elsif (/^(_\w+_)/) {
-	    # gets the name of the macro ($1 contains text matched by corresponding
-	    # set of parentheses in the last matched pattern within the dynamic scope
-	    # which here matches (_\w+_) )
-	    my $macroname = $1;
-	    my $macrotext;
-
-	    # get the first line of the macro
-	    $_ =~ s/^_\w+_ *//;
-	    # while there is still text of the macro to go...
-	    while ($_ !~ /.*\}/) {
-		# ... adds it to the macrotext variable
-		$macrotext .= $_;
-		$_ = <IN>;
-	    }
-	    $macrotext .= $_;
-
-	    # The key consists of macro file, package name, and macro name
-	    my $key = $macrofile . "::" . $currpackage . "::" . $macroname;
-	    # Store the macro text in the database
-	    $macros{$key} = $macrotext;
-	}
-
-	# Icon: line in format ## "sometext" ## macro ## macroname ##
-	elsif (/^\#\# .*/) {
-	    my $macroname = $_;
-	    my $macrotext;
-
-	    #if the macro text contains a new line will run over two lines
-	    unless ($macroname =~ m/^\#\# .*\#\#/) {		
-		$macroname = $_;
-		chomp($macroname);
-		$_ = <IN>;
-		$macroname .= $_;
-	    }
-
-	    #split the image macro header on ##
-	    my @names = split(/\s*\#\#\s*/, $macroname);
-	    #save current contents of macroname into macrotext
-	    $macrotext .= $macroname;
-	    $_ = <IN>;
-	    # overwrite macroname with macroname from ## ... ## ... ## HERE ###
-	    $macroname = $names[(scalar @names) - 1];
-
-	    # read in the rest of the text associated with the image macro
-	    while ($_ !~ /^\s+/) {
-		$macrotext .= $_;
-		$_ = <IN>;
-	    }
-
-	    # key to the hash and the database
-	    my $key = $macrofile . "::" . $currpackage . "::" . $macroname;
-	    # print "Icon, key: $key\n text: $macrotext\n";
-	    # hashes macroname and macrotext
-	    $macros{$key} = $macrotext;
-	}
-    }
-    close IN;
-
-    return (\%macros);
-}
-
-
-# Combines two existing hashes of the same format together
-sub combine_hashes
-{
-    my ($hash1, $hash2) = @_;
-    my %combined = ();
-
-    foreach $key (sort (keys %$hash1)) {
-	$combined{$key} = $hash1->{$key};
-    }
-    foreach $key (sort (keys %$hash2)) {
-	$combined{$key} = $hash2->{$key};
-    }
-
-    return (\%combined);
-}
-
-
-sub initialise_update_db
-{
-    my ($sourcelang, $targetlang, $targethash, $macrosdir) = @_;
-
-    # Use CVS to annotate each line of the source files with the date it was last edited
-    my $sourcedmfile1 = &get_macrofile_name($sourcelang, "");
-    my $annotatedsourcefile1 = qx/cd $macrosdir; cvs annotate $sourcedmfile1/;
-    my $annotatedsourcehash1 = &parse_annotated_macrofile($annotatedsourcefile1);
-    my $sourcedmfile2 = &get_macrofile_name($sourcelang, "2");
-    my $annotatedsourcefile2 = qx/cd $macrosdir; cvs annotate $sourcedmfile2/;
-    my $annotatedsourcehash2 = &parse_annotated_macrofile($annotatedsourcefile2);
-
-    # Use CVS to annotate each line of the target files with the date it was last edited
-    my $targetdmfile1 = &get_macrofile_name($targetlang, "");
-    my $annotatedtargetfile1 = qx/cd $macrosdir; cvs annotate $targetdmfile1/;
-    my $annotatedtargethash1 = &parse_annotated_macrofile($annotatedtargetfile1);
-    my $targetdmfile2 = &get_macrofile_name($targetlang, "2");
-    my $annotatedtargetfile2 = qx/cd $macrosdir; cvs annotate $targetdmfile2/;
-    my $annotatedtargethash2 = &parse_annotated_macrofile($annotatedtargetfile2);
-
-    # Macros needing updating are those in the target file that have been more recently
-    #   edited in the source file
-    foreach $targetkey (sort (keys(%$annotatedtargethash1))) {
-	my $targetdate = $annotatedtargethash1->{$targetkey};
-	my $sourcedate = $annotatedsourcehash1->{$targetkey};
-	if (&is_date_before($targetdate, $sourcedate) eq "true") {
-	    # print "Macro needs updating!!\n";
-	    $targetkey = &get_macrofile_name($targetlang, "") . "::" . $targetkey;
-	    # print "Target key: $targetkey";
-	    # print " Original target text: $targethash->{$targetkey}\n";
-	    $updatedata{$targetkey} = $targethash->{$targetkey};
-	}
-    }
-
-    foreach $targetkey (sort (keys(%$annotatedtargethash2))) {
-	my $targetdate = $annotatedtargethash2->{$targetkey};
-	my $sourcedate = $annotatedsourcehash2->{$targetkey};
-	if (&is_date_before($targetdate, $sourcedate) eq "true") {
-	    # print "Macro needs updating!!\n";
-	    $targetkey = &get_macrofile_name($targetlang, "2") . "::" . $targetkey;
-	    # print "Target key: $targetkey";
-	    # print " Original target text: $targethash->{$targetkey}\n";
-	    $updatedata{$targetkey} = $targethash->{$targetkey};
-	}
-    }
-}
-
-
-sub parse_annotated_macrofile
-{
-    my ($annotatedfile) = @_;
-
-    # Initialises some local variables
-    my $currpackage;
-    my %macros = ();
-
-    my @annotations = split(/\n/, $annotatedfile);
-    for ($i = 0; $i < scalar(@annotations); $i++) {
-	$annotatedline = $annotations[$i];
-	chomp($annotatedline);
-	# print "Line: $annotatedline\n";
-	($line = $annotatedline) =~ s/.*\(.*\):\s//;
-
-	# Check if a new package is being defined
-	if ($line =~ m/^package (.*)/) {
-	    $currpackage = $1;
-	    chomp($currpackage);
-	}
-
-	# Line contains a macro name
-	elsif ($line =~ m/^(_\w+_)/) {
-	    # Gets the name of the macro ($1 contains text matched by corresponding set
-	    #   of parentheses in the last matched pattern within the dynamic scope)
-	    my $macroname = $1;
-	    my $macrodate = &extract_cvs_date($annotatedline);
-
-	    # while there is still text of the macro to go...
-	    while ($line !~ /.*\}/) {
-		$annotatedline = $annotations[++$i];
-		chomp($annotatedline);
-		my $linedate = &extract_cvs_date($annotatedline);
-		if (&is_date_before($macrodate, $linedate) eq "true") {
-		    # This part of the macro has been updated more recently
-		    $macrodate = $linedate;
-		}
-		($line = $annotatedline) =~ s/.*\(.*\):\s//;
-	    }
-
-	    # The key consists of package name and macro name
-	    my $key = $currpackage . "::" . $macroname;
-	    # The key maps to the macrodate
-	    $macros{$key} = $macrodate;
-	    # print "Macro: $key Date: $macrodate\n\n";
-	}
-
-	# Icon: line in format ## "sometext" ## macro ## macroname ##
-	elsif ($line =~ m/^\#\# (.*)/) {
-	    my $macroname = $1;
-	    my $macrodate = &extract_cvs_date($annotatedline);
-
-	    #if the macro text contains a new line will run over two lines
-	    unless ($line =~ m/^\#\# .*\#\#/) {		
-		$annotatedline = $annotations[++$i];
-		chomp($annotatedline);
-		($line = $annotatedline) =~ s/.*\(.*\):\s//;
-		$macroname .= $line;
-	    }
-
-	    # Split the image macro header on ##
-	    my @names = split(/\s*\#\#\s*/, $macroname);
-	    # Overwrite macroname with macroname from ## ... ## ... ## HERE ###
-	    $macroname = $names[(scalar @names) - 1];
-
-	    # Read the rest of the text associated with the image macro
-	    while ($line !~ /^\s*$/) {
-		$annotatedline = $annotations[++$i];
-		chomp($annotatedline);
-		my $linedate = &extract_cvs_date($annotatedline);
-		if (&is_date_before($macrodate, $linedate) eq "true") {
-		    # This part of the macro has been updated more recently
-		    $macrodate = $linedate;
-		}
-		($line = $annotatedline) =~ s/.*\(.*\):\s//;
-	    }
-
-	    # The key consists of package name and macro name
-	    my $key = $currpackage . "::" . $macroname;
-	    # The key maps to the macrodate
-	    $macros{$key} = $macrodate;
-	    # print "Macro: $key Date: $macrodate\n\n";
-	}
-    }
-
-    return (\%macros);
-}
-
-
-sub extract_cvs_date
-{
-    my ($line) = @_;
-
-    # Cut the CVS annotation off the front and extract the date
-    $line =~ s/.*\(.*\):\s//;
-    $annotation = $&;
-    ($macrodate = $annotation) =~ s/.*\(.*(\s)+(.*)\): /$2/;
-    return $macrodate;
-}
-
-
-# Returns true if $date1 is before $date2, false otherwise
-sub is_date_before
-{
-    my ($date1, $date2) = @_;
-    my %months = ("Jan", 1, "Feb", 2, "Mar", 3, "Apr",  4, "May",  5, "Jun",  6,
-		  "Jul", 7, "Aug", 8, "Sep", 9, "Oct", 10, "Nov", 11, "Dec", 12);
-
-    @date1parts = split(/-/,$date1);
-    @date2parts = split(/-/,$date2);
-
-    # Compare year - nasty because we have rolled over into a new century
-    $year1 = $date1parts[2];
-    if ($year1 < 80) {
-	$year1 += 100;
-    }
-    $year2 = $date2parts[2];
-    if ($year2 < 80) {
-	$year2 += 100;
-    }
-
-    # Compare year
-    if ($year1 < $year2) {
-	return "true";
-    }
-    elsif ($year1 == $year2) {
-	# Year is the same, so compare month
-	if ($months{$date1parts[1]} < $months{$date2parts[1]}) {
-	    return "true";
-	}
-	elsif ($months{$date1parts[1]} == $months{$date2parts[1]}) {
-	    # Month is the same, so compare day
-	    if ($date1parts[0] < $date2parts[0]) {
-		return "true";
-	    }
-	}
-    }
-
-    return "false";
-}
-
-
-sub display_hash
-{
-    my ($hash) = @_;
-
-    foreach $key (sort (keys %$hash)) {
-	print $key . "\n";
-	print $hash->{$key} . "\n";
-    }
-}
-
-
-&main(@ARGV);
-
-
-sub get_language_codes
-{
-    %languagecodes = (
-		      'abkhazian', 'ab',
-		      'afar', 'aa',
-		      'afrikaans', 'af',
-		      'albanian', 'sq',
-		      'amharic', 'am',
-		      'arabic', 'ar',
-		      'armenian', 'hy',
-		      'assamese', 'as',
-		      'aymara', 'ay',
-		      'azerbaijani', 'az',
-		      'bashkir', 'ba',
-		      'basque', 'eu',
-		      'bengali', 'bn',
-		        'bangla', 'bn',
-		      'bhutani', 'dz',
-		      'bihari', 'bh',
-		      'bislama', 'bi',
-		      'breton', 'br',
-		      'bulgarian', 'bg',
-		      'burmese', 'my',
-		      'byelorussian', 'be',
-		        'belarusian', 'be',
-		      'cambodian', 'km',
-		      'catalan', 'ca',
-		      'chinese', 'zh',
-		      'corsican', 'co',
-		      'croatian', 'hr',
-		      'czech', 'cs',
-		      'danish', 'da',
-		      'dutch', 'nl',
-		      'english', 'en',
-		      'esperanto', 'eo',
-		      'estonian', 'et',
-		      'faeroese', 'fo',
-		      'farsi', 'fa',
-		      'fiji', 'fj',
-		      'finnish', 'fi',
-		      'french', 'fr',
-		      'frisian', 'fy',
-		      'galician', 'gl',
-		      'gaelic (scottish)', 'gd',
-		      'gaelic (manx)', 'gv',
-		      'georgian', 'ka',
-		      'german', 'de',
-		      'greek', 'el',
-		      'greenlandic', 'kl',
-		      'guarani', 'gn',
-		      'gujarati', 'gu',
-		      'hausa', 'ha',
-		      'hebrew', 'iw',
-		      'hindi', 'hi',
-		      'hungarian', 'hu',
-		      'icelandic', 'is',
-		      'indonesian', 'id',  # Should be 'in' for backward compatibility
-		      'interlingua', 'ia',
-		      'interlingue', 'ie',
-		      'inuktitut', 'iu',
-		      'inupiak', 'ik',
-		      'irish', 'ga',
-		      'italian', 'it',
-		      'japanese', 'ja',
-		      'javanese', 'jv',
-		      'kannada', 'kn',
-		      'kashmiri', 'ks',
-		      'kazakh', 'kk',
-		      'kinyarwanda', 'rw',
-		        'ruanda', 'rw',
-		      'kirghiz', 'ky',
-		      'kirundi', 'rn',
-		        'rundi', 'rn',
-		      'korean', 'ko',
-		      'kurdish', 'ku',
-		      'laothian', 'lo',
-		      'latin', 'la',
-		      'latvian', 'lv',
-		        'lettish', 'lv',
-		      'limburgish', 'li',
-		        'limburger', 'li',
-		      'lingala', 'ln',
-		      'lithuanian', 'lt',
-		      'macedonian', 'mk',
-		      'malagasy', 'mg',
-		      'malay', 'ms',
-		      'malayalam', 'ml',
-		      'maltese', 'mt',
-		      'maori', 'mi',
-		      'marathi', 'mr',
-		      'moldavian', 'mo',
-		      'mongolian', 'mn',
-		      'nauru', 'na',
-		      'nepali', 'ne',
-		      'norwegian', 'no',
-		      'occitan', 'oc',
-		      'oriya', 'or',
-		      'oromo', 'om',
-		        'afan', 'om',
-		        'galla', 'om',
-		      'pashto', 'ps',
-		        'pushto', 'ps',
-		      'polish', 'pl',
-		      'portuguese', 'pt',
-		      'punjabi', 'pa',
-		      'quechua', 'qu',
-		      'rhaeto-romance', 'rm',
-		      'romanian', 'ro',
-		      'russian', 'ru',
-		      'samoan', 'sm',
-		      'sangro', 'sg',
-		      'sanskrit', 'sa',
-		      'serbian', 'sr',
-		      'serbo-croatian', 'sh',
-		      'sesotho', 'st',
-		      'setswana', 'tn',
-		      'shona', 'sn',
-		      'sindhi', 'sd',
-		      'sinhalese', 'si',
-		      'siswati', 'ss',
-		      'slovak', 'sk',
-		      'slovenian', 'sl',
-		      'somali', 'so',
-		      'spanish', 'es',
-		      'sundanese', 'su',
-		      'swahili', 'sw',
-		        'kiswahili', 'sw',
-		      'swedish', 'sv',
-		      'tagalog', 'tl',
-		      'tajik', 'tg',
-		      'tamil', 'ta',
-		      'tatar', 'tt',
-		      'telugu', 'te',
-		      'thai', 'th',
-		      'tibetan', 'bo',
-		      'tigrinya', 'ti',
-		      'tonga', 'to',
-		      'tsonga', 'ts',
-		      'turkish', 'tr',
-		      'turkmen', 'tk',
-		      'twi', 'tw',
-		      'uighur', 'ug',
-		      'ukrainian', 'uk',
-		      'urdu', 'ur',
-		      'uzbek', 'uz',
-		      'vietnamese', 'vi',
-		      'volapÃŒk', 'vo',
-		      'welsh', 'cy',
-		      'wolof', 'wo',
-		      'xhosa', 'xh',
-		      'yiddish', 'ji',
-		      'yoruba', 'yo',
-		      'zulu', 'zu'
-		      );
-
-    return (\%languagecodes);
-}
Index: trunk/gsdl/bin/script/picklanguage.pl
===================================================================
--- trunk/gsdl/bin/script/picklanguage.pl	(revision 5499)
+++ 	(revision )
@@ -1,119 +1,0 @@
-#!/usr/bin/perl -w
-
-###########################################################################
-#
-# picklanguage.pl
-#
-# A component of the Greenstone digital library software
-# from the New Zealand Digital Library Project at the 
-# University of Waikato, New Zealand.
-#
-# Copyright (C) 1999 New Zealand Digital Library Project
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-###########################################################################
-
-# This code generates the front page of the Greenstone Interface Translation Agency
-# which asks the user to pick their base language and translating language before
-# proceeding into the translation pages
-
-BEGIN {
-    if (!defined($ENV{'GSDLHOME'})) {
-	print STDERR "GSDLHOME not set\n";
-	return 1;
-    }
-    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
-}
-
-
-use util;
-use CGI;
-
-
-sub main
-{
-    my $gsdldir = "$ENV{'GSDLHOME'}";
-    # Read the languages available from etc/main.cfg
-    my $maincfg_fname = util::filename_cat($gsdldir, "etc", "main.cfg");
-    if (!open(MCFILE, "<$maincfg_fname")) {
-	print STDERR "Error: Could not open $maincfg_fname: $!\n";
-	return 2;
-    }
-
-    my @languages;
-    my $line;
-    while (defined ($line=<MCFILE>)) {
-	chomp($line);
-	if ($line =~ m/^Language\s+/i) {
-	    my @args = split(/ +/,$line);
-	    my ($lang_abbr) = ($args[1] =~ m/^shortname=(.*)$/);
-	    my ($lang_long) = ($args[2] =~ m/^longname=(.*)$/);
-	    push(@languages, $lang_long);
-	}
-    }
-    close MCFILE;
-
-    # Write the HTML content of the page to tmp/lang/picklanguage.lang
-    my $dir = util::filename_cat($gsdldir, "tmp", "lang");
-    # creates directory if it doesn't already exist
-    my $currentmask = umask;
-    umask(0000);
-    if (!-e $dir) {
-	if (! mkdir($dir, 0777)) {
-	    print STDERR "Couldn't create directory $dir\n";
-	    return 3;
-	}
-    }
-    my $picklang_fname = util::filename_cat($dir, "picklanguage.lang");
-
-    # Make the file world writeable
-    if (! open(HTMLFILE,">$picklang_fname")) {
-	umask($currentmask);
-	print STDERR "Error: Could not create $picklang_fname: $!\n";
-	return 4;
-    }
-    umask($currentmask);
-
-    # Writes to file the instructions on how to use the interface (_textinitial_)
-    #   and then displays a table at the end with menu options from which the user
-    #   selects their base and translation languages, and submits these choices
-    #   to proceed into the interface translation agency
-    my $query = new CGI;
-    print HTMLFILE (" _textinitial_ <br>\n",
-		    "<table border=\"2\" cellpadding=\"8\"><tr><td><center>",
-		    "_textselectbase_ <p>\n",
-		    $query->popup_menu(-name=>"bl",
-				       -values=>\@languages,
-				       -default=>'English'),
-		    "<p></center></td><td><center>\n",
-		    "_textselectforeign_ <p>\n",
-		    $query->popup_menu(-name=>"tlng",
-				       -values=>\@languages),
-		    "<p>\n",
-		    "_textselectnew_ <p>\n",
-		    $query->textfield(-name=>"ownchoice",
-				      -default=>"",
-				      -size=>50),
-		    "<p></center></td></tr></table>\n",
-		    $query->submit("submitlanguage","_textenter_"),
-		    "</center><p>\n",
-		    "<center><img src=\"_httpimg_/divb.gif\"></center><p>");
-    close HTMLFILE;
-    return 0;
-}
-
-
-exit &main();
Index: trunk/gsdl/bin/script/submit_translation.pl
===================================================================
--- trunk/gsdl/bin/script/submit_translation.pl	(revision 5499)
+++ 	(revision )
@@ -1,521 +1,0 @@
-#!/usr/bin/perl -w
-
-###########################################################################
-# submit_translation.pl
-#
-# A component of the Greenstone digital library software
-# from the New Zealand Digital Library Project at the 
-# University of Waikato, New Zealand.
-#
-# Copyright (C) 1999 New Zealand Digital Library Project
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-###########################################################################
-
-#SYNOPSIS OF CODE:
-#Processes translation when user clicks the 'SUBMIT TRANSLATION >>' button on
-#greenstone site. Takes the cgiargsclass and the language being translated
-#into, extracts the macronames and macrotext from the cgi data and hashes
-#them, then links this hash to a database and updates database appropriately
-
-BEGIN {
-    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
-    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
-}
-
-
-use util;
-use GDBM_File;
-
-
-my %translationdata = ();
-my %updatedata = ();
-
-
-sub main
-{
-    # Get the name of the source (base) language
-    my $sourcelang = shift(@_);
-    # Get the name of the target language
-    my $targetlang = shift(@_);
-    # Get the name of the args file with the cgiargsclass data in it
-    my $argsfile = shift(@_);
-
-    # Check that all arguments were supplied
-    if (!$sourcelang) {
-	die "Error: You didn't supply the name of the source language!\n";
-    }
-    if (!$targetlang) {
-	die "Error: You didn't supply the name of the target language!\n";
-    }
-    if (!$argsfile) {
-	die "Error: You didn't supply the name of the arguments file!\n";
-    }
-
-    # Casefold both language names
-    $sourcelang =~ tr/A-Z/a-z/;
-    $targetlang =~ tr/A-Z/a-z/;
-
-    my $gsdldir = "$ENV{'GSDLHOME'}";
-    my $langdir = util::filename_cat($gsdldir, "tmp", "lang");
-    my $translationdir = util::filename_cat($langdir, $sourcelang . "-" . $targetlang);
-    my $translationdb = util::filename_cat($translationdir, "translation.db");
-    my $updatedb = util::filename_cat($translationdir, "update.db");
-
-    # Open the two database files for the translation
-    tie(%translationdata, "GDBM_File", $translationdb, 1, 0640);
-    tie(%updatedata, "GDBM_File", $updatedb, 1, 0640);
-
-    # Parse the translation submissions
-    my $targetcode = $translationdata{"*target_lang_code*"};
-    print "Target code: $targetcode\n";
-    my $submissions = &parse_user_submission($sourcelang, $targetlang, $targetcode,
-					     util::filename_cat($translationdir, $argsfile));
-
-    # Add the submissions to the translation database
-    &add_submissions_to_database($submissions);
-
-    # Writes the target macro files
-    my $macrosdir = util::filename_cat($gsdldir, "macros");
-    &update_target_macrofiles($targetlang, $macrosdir, $submissions);
-
-    # Clean up
-    untie %translationdata;
-    untie %updatedata;
-}
-
-
-sub parse_user_submission
-{
-    my ($sourcelang, $targetlang, $targetcode, $filename) = @_;
-
-    #opens the args file or kills program
-    open(ARGUMENTS, "<$filename") or die("Error: Could not open $filename.\n");
-
-    #stores a hash of macronames with numbers still appended and their values
-    my %distinctkeys = ();
-    my %icontextvals = ();
-
-    #while there are still lines left to read
-    my $macroname = "";
-    my $macrovalue = "";
-    while (<ARGUMENTS>) {
-	#gets the line
-	$line = $_;
-	#chomps off the final newline character
-	chomp($line);
-	# removes nasty carriage returns and formfeeds
-	$line =~ s/\r$//;
-	$line =~ s/\f$//;
-	# print "Line: $line\n";
-
-	# Does the line contain a new CGI argument?
-	if ($line =~ m/^ \"/) {
-	    # If the line contains :: (browser converts to %3A%3A) then it has a macroname
-	    if ($line =~ m/%3A%3A/) {
-		#hashes the previous macro and its value, provided the value is non-empty
-		if ($macrovalue =~ m/\S+/) {
-		    # Add the icontext macros to a separate list
-		    if ($macroname =~ m/::icontext$/) {
-			$icontextvals{$macroname} = $macrovalue;
-		    }
-		    else {
-			$distinctkeys{$macroname} = $macrovalue;
-		    }
-		}
-
-		$macroname = $line;
-		#changes the codes back to ::
-		$macroname =~ s/%3A%3A/::/g;
-		#removes value of macro leaving just the name
-		$macroname =~ s/=.*//;
-		#saves the value
-		$macrovalue = $&;
-		#removes all " from macro
-		$macroname =~ s/\"//g;
-		#removes any whitespace from macro
-		$macroname =~ s/\s+//g;
-
-		#removes all " and = from value
-		$macrovalue =~ s/=//g;
-		$macrovalue =~ s/\A\"//;
-		$macrovalue =~ s/\"\Z//;
-		$macrovalue =~ s/<br>/\n/g;
-	    }
-	    else {
-		#hashes the previous macro and its value, provided the value is non-empty
-		if ($macroname ne "" && $macrovalue =~ m/\S+/) {
-		    # Add the icontext macros to a separate list
-		    if ($macroname =~ m/::icontext$/) {
-			$icontextvals{$macroname} = $macrovalue;
-		    }
-		    else {
-			$distinctkeys{$macroname} = $macrovalue;
-		    }
-		}
-		$macroname = "";
-		$macrovalue = "";
-	    }
-	}
-	# No, so check if it is part of a multi-line macro
-	else {
-	    if ($macroname ne "") {
-		$extravalue = $line;
-		#removes all " and = from value
-		$extravalue =~ s/=//g;
-		$extravalue =~ s/\A\"//;
-		$extravalue =~ s/\"\Z//;
-		$extravalue =~ s/<br>/\n/g;
-		# add this line to the current macro value
-		$macrovalue = $macrovalue . "\n" . $extravalue;
-	    }
-	}
-    }
-
-    close ARGUMENTS;
-
-    # Create a hash map containing the translations to add
-    my %translations = ();
-
-    for $sourcekey (sort keys %distinctkeys) {
-	my $macrotext = "";
-
-	# Check if this macro is an icon macro
-	my $iconkey = $sourcekey . "::icontext";
-	if ($icontextvals{$iconkey}) {
-	    my $icontext = $icontextvals{$iconkey};
-
-	    # Add the language code to each part of the icon macro
-	    # -- This should be done by translate.pl when the images are created --
-	    $icontext =~ s/(\n_[^_]+_)(\s*)/$1 \[l=$targetcode\] /g;
-	    $icontext =~ s/( {_[^_]+_)(.*)(\/([^\/]+)})/$1\/$targetcode$3/g;
-
-	    $macrotext = "## \"" . $distinctkeys{$sourcekey} . "\" " . $icontext . "\n";
-	}
-	# It must be a text macro
-	else {
-	    $macrotext = "[l=$targetcode] {" . $distinctkeys{$sourcekey} . "}\n";
-	}
-
-	my $targetkey = &get_macroname_equivalent($sourcelang, $targetlang, $sourcekey);
-	$translations{$targetkey} = $macrotext;
-    }
-
-    return (\%translations);
-}
-
-
-sub get_macrofile_name
-{
-    my ($language, $suffix) = @_;
-
-    my $macrofilename = $language;
-
-    # Handles cases where the macro file name is different to the language name
-    $macrofilename = "port" if ($language =~ m/portuguese/);
-    $macrofilename = "indo" if ($language =~ m/indonesian/);
-
-    # Add suffix (if any) and file extension, and return
-    $macrofilename = $macrofilename . $suffix . ".dm";
-    return $macrofilename;
-}
-
-
-sub get_macroname_equivalent
-{
-    my ($languageA, $languageB, $languageAkey) = @_;
-
-    my $macrofile = $languageAkey;
-    $macrofile =~ s/^([^:]+)::(.*)/$1/;
-    my $key = $languageAkey;
-    $key =~ s/^([^:])+::(.*)/$2/;
-
-    my $languageBkey;
-    if ($macrofile eq &get_macrofile_name($languageA, "")) {
-	$languageBkey = &get_macrofile_name($languageB, "") . "::" . $key;
-    }
-    if ($macrofile eq &get_macrofile_name($languageA, "2")) {
-	$languageBkey = &get_macrofile_name($languageB, "2") . "::" . $key;
-    }
-
-    return ($languageBkey);
-}
-
-
-sub add_submissions_to_database
-{
-    my ($submissions) = @_;
-
-    # Write each submission to the database
-    foreach $key (sort keys(%$submissions)) {
-	$translationdata{$key} = $submissions->{$key};
-
-	# If this was one of the macros needing updating, it has been
-	if ($updatedata{$key}) {
-	    delete $updatedata{$key};
-	}
-    }
-}
-
-
-sub update_target_macrofiles
-{
-    my ($targetlang, $macrosdir, $submissions) = @_;
-
-    # Split the submissions by macrofile
-    my %submissions1 = ();
-    my %submissions2 = ();
-    foreach $key (keys %$submissions) {
-	if (&core_or_auxiliary_macro($targetlang, $key) eq "core") {
-	    $submissions1->{$key} = $submissions->{$key};
-	}
-	else {
-	    $submissions2->{$key} = $submissions->{$key};
-	}
-    }
-
-    # Add the submissions into the appropriate files
-    my $macrofile1 = &get_macrofile_name($targetlang, "");
-    &add_submissions_into_macrofile($targetlang, $macrosdir, $macrofile1, $submissions1);
-    my $macrofile2 = &get_macrofile_name($targetlang, "2");
-    &add_submissions_into_macrofile($targetlang, $macrosdir, $macrofile2, $submissions2);
-}
-
-
-sub core_or_auxiliary_macro
-{
-    my ($language, $sourcekey) = @_;
-
-    my $macrofile = $sourcekey;
-    $macrofile =~ s/^([^:]+)::(.*)/$1/;
-
-    if ($macrofile eq ($language . ".dm")) {
-	return "core";
-    }
-    if ($macrofile eq ($language . "2.dm")) {
-	return "auxiliary";
-    }
-}
-
-
-sub add_submissions_into_macrofile
-{
-    my ($targetlang, $macrosdir, $macrofile, $submissions) = @_;
-
-    # Opens the macro file or dies a miserable death
-    my $macropath = util::filename_cat($macrosdir, $macrofile);
-    open(MACROFILE_IN, "<$macropath") or die "Error: Could not open $macropath.\n";
-    open(MACROFILE_TMP, ">$macrofile.tmp") or die "Error: Could not write $macrofile.tmp\n";
-
-    my $curroutline = 0;
-    my $currpackage;
-    my $currpackageinsertionpoint = $curroutline;
-    my %insertionpoints = ();
-    while (<MACROFILE_IN>) {
-	#currline++;
-
-	# Check if a new package is being defined
-	if (/^package (.*)/) {
-	    # Is this the end of a previous package?
-	    if ($currpackage) {
-		# Yes, so remember the insertion point for the package
-		$insertionpoints{$currpackageinsertionpoint} = $currpackage;
-	    }
-	    $currpackage = $1;
-	    print MACROFILE_TMP $_;
-	    $curroutline++;
-	}
-
-	# Check if an icon macro is being defined
-	elsif (/^(\#\# .*)/) {
-	    my $iconmacro = $1;
-
-	    # In the case where the macroname contains a new line, read the next line too
-	    unless ($iconmacro =~ m/^\#\# .*\#\#/) {
-		$iconmacro .= "\n" . <MACROFILE_IN>;
-		chomp($iconmacro);
-		# $currline++;
-		$curroutline++;
-	    }
-
-	    # Split the icon macro header on "##"
-	    my @iconparts = split(/\s*\#\#\s*/, $iconmacro);
-	    # The macroname is the last element of the header (ie. ## ... ## ... ## this ##)
-	    my $macroname = $iconparts[(scalar @iconparts) - 1];
-
-	    # The key consists of macro file, package name, and macro name
-	    my $macrokey = $macrofile . "::" . $currpackage . "::" . $macroname;
-
-	    # Check if this macro has just been submitted
-	    my $newsubmission = "false";
-	    if ($submissions->{$macrokey}) {
-		# It has, so write the submitted text
-		$newsubmission = "true";
-		print MACROFILE_TMP $submissions->{$macrokey} . "\n";
-		$count = ($submissions->{$macrokey} =~ tr/\n/\n/);
-		$curroutline = $curroutline + $count;
-		delete $submissions->{$macrokey};
-	    }
-	    else {
-		# It hasn't, so write the old macro
-		print MACROFILE_TMP $iconmacro . "\n";
-		$curroutline++;
-	    }
-
-	    # Chew up the old macro text, spitting it out if necessary
-	    do {
-		$_ = <MACROFILE_IN>;
-		# $currline++;
-		if ($newsubmission ne "true") {
-		    print MACROFILE_TMP $_;
-		    $curroutline++;
-		}
-	    } until ($_ =~ /^\s+/);
-
-	    # Remember where this macro finished
-	    $currpackageinsertionpoint = $curroutline;
-	}
-
-	# Check if a text macro is being defined
-	elsif (/^(_\w+_)(.*)/) {
-	    # Get the name of the macro
-	    my $macroname = $1;
-	    print MACROFILE_TMP $macroname;
-
-	    # The key consists of macro file, package name, and macro name
-	    my $macrokey = $macrofile . "::" . $currpackage . "::" . $macroname;
-
-	    # Check if this macro has just been submitted
-	    my $newsubmission = "false";
-	    if ($submissions->{$macrokey}) {
-		# It has, so write the submitted text
-		$newsubmission = "true";
-		print MACROFILE_TMP $submissions->{$macrokey};
-		$count = ($submissions->{$macrokey} =~ tr/\n/\n/);
-		$curroutline = $curroutline + $count;
-		delete $submissions->{$macrokey};
-	    }
-	    else {
-		# It hasn't, so write the old macro text
-		print MACROFILE_TMP $2 . "\n";
-		$curroutline++;
-	    }
-
-	    # Chew up the old macro text, spitting it out if necessary
-	    while ($_ !~ /.*\}/) {
-		$_ = <MACROFILE_IN>;
-		# $currline++;
-		if ($newsubmission ne "true") {
-		    print MACROFILE_TMP $_;
-		    $curroutline++;
-		}
-	    }
-
-	    # Remember where this macro finished
-	    $currpackageinsertionpoint = $curroutline;
-	}
-
-	# The line must just be a comment or whitespace
-	else {
-	    print MACROFILE_TMP $_;
-	    $curroutline++;
-	}
-    }
-
-    # Close opened files
-    close MACROFILE_TMP;
-    close MACROFILE_IN;
-
-    open(MACROFILE_TMP, "<$macrofile.tmp") or die "Error: Could not open $macrofile.tmp\n";
-    # open(MACROFILE_OUT, ">$macrofile.out") or die "Error: Could not write $macrofile.out\n";
-    open(MACROFILE_OUT, ">$macropath") or die "Error: Could not write $macropath\n";
-
-    # Insert the new macro submissions in the correct place
-    $currline = 0;
-    while (<MACROFILE_TMP>) {
-	$currline++;
-
-	# Are we at a package insertion point?
-	if ($insertionpoints{$currline}) {
-	    $currpackage = $insertionpoints{$currline};
-
-	    # Yes, so check if there are any macros to insert here
-	    foreach $key (keys %$submissions) {
-		$key =~ m/^[^:]+::([^:]+)::(.*)/;
-		my $packagename = $1;
-		my $macroname = $2;
-
-		if ($packagename eq $currpackage) {
-		    # Insert this macro here
-		    &write_macro_to_file($macroname, $submissions->{$key}, MACROFILE_OUT);
-		    delete $submissions->{$key};
-		}
-	    }
-	}
-
-	print MACROFILE_OUT $_;
-    }
-
-    # If there are any submissions still remaining, write them to a new package at the end
-    $currpackage = "";
-    foreach $key (sort (keys %$submissions)) {
-	$key =~ m/^[^:]+::([^:]+)::(.*)/;
-	my $packagename = $1;
-	my $macroname = $2;
-
-	if ($packagename ne $currpackage) {
-	    # Write package header
-	    print MACROFILE_OUT "\n";
-	    print MACROFILE_OUT "########################################################\n";
-	    print MACROFILE_OUT "package $packagename\n";
-	    print MACROFILE_OUT "########################################################\n";
-
-	    $currpackage = $packagename;
-	}
-
-	# Write macro
-	&write_macro_to_file($macroname, $submissions->{$key}, MACROFILE_OUT);
-	delete $submissions->{$key};
-    }
-
-    # Close opened files
-    close MACROFILE_OUT;
-    close MACROFILE_TMP;
-
-    # Delete the temporary file
-    unlink("$macrofile.tmp");
-}
-
-
-sub write_macro_to_file
-{
-    my ($macroname, $macrotext, $filehandle) = @_;
-
-    print MACROFILE_OUT "\n";
-    print MACROFILE_OUT "# Macro added using the translation agency\n";
-
-    if ($macrotext =~ m/\#\# (^|.)*/) {
-	# Icon macro
-	print MACROFILE_OUT $macrotext;
-    }
-    else {
-	# Text macro
-	print MACROFILE_OUT $macroname . $macrotext;
-    }
-}
-
-
-&main(@ARGV);
Index: trunk/gsdl/bin/script/translator.pl
===================================================================
--- trunk/gsdl/bin/script/translator.pl	(revision 5499)
+++ 	(revision )
@@ -1,630 +1,0 @@
-#!/usr/bin/perl -w
-
-###########################################################################
-#
-# translator.pl
-#
-# A component of the Greenstone digital library software
-# from the New Zealand Digital Library Project at the 
-# University of Waikato, New Zealand.
-#
-# Copyright (C) 1999 New Zealand Digital Library Project
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-###########################################################################
-
-
-BEGIN {
-    if (!defined($ENV{'GSDLHOME'})) {
-	print STDERR "GSDLHOME not set\n";
-	return 1;
-    }
-    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
-}
-
-
-use util;
-use GDBM_File;
-use CGI;
-
-
-my $translationdir;
-my $translationdb;
-my %translationdata = ();
-my $updatedb;
-my %updatedata = ();
-
-
-sub main
-{
-    # Get the name of the source (base) language
-    my $sourcelang = shift(@_);
-    # Get the name of the target language
-    my $targetlang = shift(@_);
-
-    # Check that both arguments were supplied
-    if (!$sourcelang) {
-	print STDERR "Error: You didn't supply the name of the source language!\n";
-	return 2;
-    }
-    if (!$targetlang) {
-	print STDERR "Error: You didn't supply the name of the target language!\n";
-	return 2;
-    }
-
-    # Casefold both language names
-    $sourcelang =~ tr/A-Z/a-z/;
-    $targetlang =~ tr/A-Z/a-z/;
-
-    my $gsdldir = "$ENV{'GSDLHOME'}";
-    my $macrosdir = util::filename_cat($gsdldir, "macros");
-    my $langdir = util::filename_cat($gsdldir, "tmp", "lang");
-
-    # Make sure this is a continuation of a previously initialised translation process
-    $translationdir = util::filename_cat($langdir, "$sourcelang-$targetlang");
-    if (! -e $translationdir) {
-	print STDERR "Error: Translation has not been initialised (exiting).\n";
-	return 3;
-    }
-
-    # Parse the source language macro files
-    my $sourcedmname1 = &get_macrofile_name($sourcelang, "");
-    my $sourcehash1 = &parse_macrofile($macrosdir, $sourcedmname1);
-    my $sourcedmname2 = &get_macrofile_name($sourcelang, "2");
-    my $sourcehash2 = &parse_macrofile($macrosdir, $sourcedmname2);
-
-    # Make sure some macros exist to be translated
-    if (!$sourcehash1 && !$sourcehash2) {
-	print STDERR "Error: No source macro information exists.\n";
-	return 4;
-    }
-
-    # Combine the two source hashes
-    my $sourcehash = &combine_hashes($sourcehash1, $sourcehash2);
-
-    # Open the existing translation and update databases
-    $translationdb = util::filename_cat($translationdir, "translation.db");
-    $updatedb = util::filename_cat($translationdir, "update.db");
-
-    # This translation is a continuation of an old one, so open the database files for it
-    tie(%translationdata, "GDBM_File", $translationdb, 1, 0640);
-    tie(%updatedata, "GDBM_File", $updatedb, 1, 0640);
-
-    # Parse the target language macro files
-    my $targetdmname1 = &get_macrofile_name($targetlang, "");
-    my $targethash1 = &parse_macrofile($macrosdir, $targetdmname1);
-    my $targetdmname2 = &get_macrofile_name($targetlang, "2");
-    my $targethash2 = &parse_macrofile($macrosdir, $targetdmname2);
-
-    # Combine the two target hashes
-    my $targethash = &combine_hashes($targethash1, $targethash2);
-
-    # Determine the macros that need translating
-    my $needstranslating = &find_macros_needing_translation($sourcelang, $sourcehash,
-							    $targetlang, $targethash);
-
-    # Generates HTML code to display user interface on webpage with what needs translation
-    my $targetcode = $translationdata{"*target_lang_code*"};
-    print STDERR "Target language code: $targetcode\n";
-    &generate_pages($sourcelang, $targetlang, $targetcode, $needstranslating);
-
-    # Clean up
-    untie %translationdata;
-    untie %updatedata;
-
-    return 0;
-}
-
-
-sub get_macrofile_name
-{
-    my ($language, $suffix) = @_;
-
-    my $macrofilename = $language;
-
-    # Handles cases where the macro file name is different to the language name
-    $macrofilename = "port" if ($language =~ m/portuguese/);
-    $macrofilename = "indo" if ($language =~ m/indonesian/);
-
-    # Add suffix (if any) and file extension, and return
-    $macrofilename = $macrofilename . $suffix . ".dm";
-    return $macrofilename;
-}
-
-
-sub parse_macrofile
-{
-    my ($macrosdir, $macrofile) = @_;
-
-    # Opens macro file or returns
-    my $macropath = util::filename_cat($macrosdir, $macrofile);
-    open(IN, "<$macropath") or return;
-
-    # Initialises some local variables
-    my $currpackage;
-    my %macros = ();
-
-    # Reads in contents of macro file, line by line
-    while (<IN>) {
-	# Check if a new package is being defined
-	if (s/^package //) {
-	    $currpackage = $_;
-	    chomp($currpackage);
-	}
-
-	# Line contains a macro name
-	elsif (/^(_\w+_)/) {
-	    # gets the name of the macro ($1 contains text matched by corresponding
-	    # set of parentheses in the last matched pattern within the dynamic scope
-	    # which here matches (_\w+_) )
-	    my $macroname = $1;
-	    my $macrotext;
-
-	    # get the first line of the macro
-	    $_ =~ s/^_\w+_ *//;
-	    # while there is still text of the macro to go...
-	    while ($_ !~ /.*\}/) {
-		# ... adds it to the macrotext variable
-		$macrotext .= $_;
-		$_ = <IN>;
-	    }
-	    $macrotext .= $_;
-
-	    # The key consists of macro file, package name, and macro name
-	    my $key = $macrofile . "::" . $currpackage . "::" . $macroname;
-	    # Store the macro text in the database
-	    $macros{$key} = $macrotext;
-	}
-
-	# Icon: line in format ## "sometext" ## macro ## macroname ##
-	elsif (/^\#\# .*/) {
-	    my $macroname = $_;
-	    my $macrotext;
-
-	    #if the macro text contains a new line will run over two lines
-	    unless ($macroname =~ m/^\#\# .*\#\#/) {		
-		$macroname = $_;
-		chomp($macroname);
-		$_ = <IN>;
-		$macroname .= $_;
-	    }
-
-	    #split the image macro header on ##
-	    my @names = split(/\s*\#\#\s*/, $macroname);
-	    #save current contents of macroname into macrotext
-	    $macrotext .= $macroname;
-	    $_ = <IN>;
-	    # overwrite macroname with macroname from ## ... ## ... ## HERE ###
-	    $macroname = $names[(scalar @names) - 1];
-
-	    # read in the rest of the text associated with the image macro
-	    while ($_ !~ /^\s+/) {
-		$macrotext .= $_;
-		$_ = <IN>;
-	    }
-
-	    # key to the hash and the database
-	    my $key = $macrofile . "::" . $currpackage . "::" . $macroname;
-	    # print "Icon, key: $key\n text: $macrotext\n";
-	    # hashes macroname and macrotext
-	    $macros{$key} = $macrotext;
-	}
-    }
-    close IN;
-
-    return (\%macros);
-}
-
-
-# Combines two existing hashes of the same format together
-sub combine_hashes
-{
-    my ($hash1, $hash2) = @_;
-    my %combined = ();
-
-    foreach $key (sort (keys %$hash1)) {
-	$combined{$key} = $hash1->{$key};
-    }
-    foreach $key (sort (keys %$hash2)) {
-	$combined{$key} = $hash2->{$key};
-    }
-
-    return (\%combined);
-}
-
-
-sub find_macros_needing_translation
-{
-    my ($sourcelang, $sourcehash, $targetlang, $targethash) = @_;
-
-    # Find source macros whose text has changed
-    foreach $sourcekey (sort keys(%$sourcehash)) {
-	if ($translationdata{$sourcekey}) {
-	    if ($translationdata{$sourcekey} ne $sourcehash->{$sourcekey}) {
-		my $targetkey = &get_macroname_equivalent($sourcelang, $targetlang,
-							  $sourcekey);
-		if ($targethash->{$targetkey}) {
-		    $updatedata{$targetkey} = $targethash->{$targetkey};
-		}
-		else {
-		    $updatedata{$targetkey} = "";
-		}
-	    }
-	}
-    }
-
-    # Clear out the translation database
-    my $targetcode = $translationdata{"*target_lang_code*"};
-    untie %translationdata;
-    unlink($translationdb);
-    %translationdata = ();
-    tie(%translationdata, "GDBM_File", $translationdb, GDBM_WRCREAT, 0640);
-    $translationdata{"*target_lang_code*"} = $targetcode;
-
-    # Re-add source and target macros
-    foreach $sourcekey (sort keys(%$sourcehash)) {
-	$translationdata{$sourcekey} = $sourcehash->{$sourcekey};
-    }
-    foreach $targetkey (sort keys(%$targethash)) {
-	$translationdata{$targetkey} = $targethash->{$targetkey};
-    }
-
-    my %needstranslating = ();
-
-    # Macros that need translating are those that are in the source language macro file
-    #  but no translation exists in the translation database...
-    foreach $sourcekey (sort keys(%$sourcehash)) {
-	my $targetkey = &get_macroname_equivalent($sourcelang, $targetlang, $sourcekey);
-	if (!$translationdata{$targetkey}) {
-	    $needstranslating{$sourcekey}[0] = $sourcehash->{$sourcekey};
-	    $needstranslating{$sourcekey}[1] = "";
-	}
-    }
-
-    # ...and those in the database of macros to update
-    foreach $targetkey (sort keys(%updatedata)) {
-	my $sourcekey = &get_macroname_equivalent($targetlang, $sourcelang, $targetkey);
-	$needstranslating{$sourcekey}[0] = $sourcehash->{$sourcekey};
-	$needstranslating{$sourcekey}[1] = $updatedata{$targetkey};
-    }
-
-    return (\%needstranslating);
-}
-
-
-sub get_macroname_equivalent
-{
-    my ($languageA, $languageB, $languageAkey) = @_;
-
-    my $macrofile = $languageAkey;
-    $macrofile =~ s/^([^:]+)::(.*)/$1/;
-    my $key = $languageAkey;
-    $key =~ s/^([^:])+::(.*)/$2/;
-
-    my $languageBkey;
-    if ($macrofile eq &get_macrofile_name($languageA, "")) {
-	$languageBkey = &get_macrofile_name($languageB, "") . "::" . $key;
-    }
-    if ($macrofile eq &get_macrofile_name($languageA, "2")) {
-	$languageBkey = &get_macrofile_name($languageB, "2") . "::" . $key;
-    }
-
-    return ($languageBkey);
-}
-
-
-# generates whole website by seperating hash of differences into groups
-# of at most 15 macros and then generating a page from each group
-sub generate_pages
-{
-    my ($sourcelang, $targetlang, $targetcode, $needstranslating) = @_;
-
-    my %pagehash = ();
-
-    $pageno = 1;
-    $keysperpage = 0;
-    $limit = 15;
-
-    # goes through hash of differences between base language and translation
-    # sorted first by whether it is from the core or auxiliary macrofile then
-    # alphabetically by macroname
-    foreach $sourcekey (sort keys(%$needstranslating)) {
-	#nested hash. The pagehash contains a hash of all of the translation pages.
-	#Then each page is itself contains a hash of all the macros on that page, where
-	#each macro is associated with some macrotext and whether it was from the core
-	#or auxiliary macrofile
-	$pagehash->{$pageno}->{$sourcekey} = $needstranslating->{$sourcekey};
-	$keysperpage++;
-
-	# If have enough keys to generate a page with
-	if ($keysperpage == $limit) {
-	    #opens a file to write the HTML code to for current page
-	    my $transpagefile = util::filename_cat($translationdir, $pageno . ".lang");
-	    open HTMLFILE, ">$transpagefile";
-
-	    #passes hash of keys for current page and filehandle, returns CGI data
-	    &generate_form($sourcelang, $targetlang, $targetcode,
-			   $pagehash->{$pageno}, \*HTMLFILE);
-	    close HTMLFILE;
-	    $pageno++;
-
-	    #resets key counting variable
-	    $keysperpage = 0;
-	    $limit = 15;
-	}
-    }
-
-    # if you exit the loop with keys still to write
-    if ($keysperpage != 0) {
-	# writes out the remaining keys, same format as above
-	my $transpagefile = util::filename_cat($translationdir, $pageno . ".lang");
-	open HTMLFILE, ">$transpagefile";
-	&generate_form($sourcelang, $targetlang, $targetcode, $pagehash->{$pageno}, \*HTMLFILE);
-	close HTMLFILE;
-	$pageno++;
-    }
-
-    # Write the number of pages to a file for use by the receptionist
-    my $numpagesfile = util::filename_cat($translationdir, "numpages.log");
-    if (!open NUMPAGESLOG, ">$numpagesfile") {
-	print STDERR "Error: Could not write $numpagesfile.\n";
-	return 5;
-    }
-    print NUMPAGESLOG ($pageno - 1);
-    close NUMPAGESLOG;
-
-    # Write thankyou page for language translator once translation is complete
-    my $thankyoufile = util::filename_cat($translationdir, "thankyou.lang");
-    if (!open THANKYOU, ">$thankyoufile") {
-	print STDERR "Error: Could not write $thankyoufile.\n";
-	return 6;
-    }
-    print THANKYOU ("<center> _textthanks_ $targetlang _texttrans_ ",
-		    "<br> _textviewtranslation_ ",
-		    "<a href=\"_gwcgi_?a=p&p=home&l=$targetcode\">_texthere_</a>.",
-		    # "_textgetdmfiles_ ",
-		    # "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . ".dm\">_texthere_</a>",
-		    # " &amp; ",
-		    # "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . "2.dm\">_texthere_</a>.",
-		    "<p></center>\n");
-    close THANKYOU;
-}
-
-
-sub generate_form
-{
-    my $sourcelang = shift(@_);
-    my $targetlang = shift(@_);
-    my $targetcode = shift(@_);
-    my $formhash = shift(@_);
-    my $fh = shift(@_);
-
-    # common gateway interface for writing the stuff to the web
-    my $query = new CGI;
-    my $keynamecount;
-
-    $first = "true";
-    foreach $key (sort (keys(%$formhash))) {
-
-	my $text = $formhash->{$key}[0];
-	my $default = $formhash->{$key}[1];
-	# print "Text: $text Default: $default\n";
-
-	# whole lot of formatting on strings
-	# escape all the '_' with '\' so that Greenstone doesn't substitute
-	# the macro names for the contents of the macro itself
-	my $keyname = $key;
-	$keyname  =~ s/_/\\_/g;
-
-	$text =~ s/_/\\_/g;
-	$text =~ s/(\[l=.*\])//;
-	$default =~ s/_/\\_/g;
-	$default =~ s/(\[l=.*\] )//;
-
-        # must take care of image macros single and multiple line ones
-	$text =~ s/(\<br\>\#\#.*\#\#\s*\<br\>).*/$1/g;
-	$default =~ s/(\<br\>\#\#.*\#\#\s*\<br\>).*/$1/g;
-
-	# format the text for displaying in the browser
-	$text =~ s/[\{\}]//g unless($text =~ m/\#\# /);
-	$default =~ s/[\{\}]//g unless($text =~ m/\#\# /);
-
-	$text =~ s/(\A\n)//;
-	$text =~ s/(\n\Z)//;
-	$default =~ s/(\A\n)//;
-	$default =~ s/(\n\Z)//;
-
-	#tells whether is a core or auxiliary macro
-	my $priority = &core_or_auxiliary_macro($sourcelang, $keyname);
-
-	if ($first eq "true") {
-	    print $fh ($query->hidden(-name=>"tlng",-default=>"$targetlang"),
-		       $query->hidden(-name=>"bl",-default=>"$sourcelang"));
-
-	    # If it is a core macro, table header displays core
-	    if ($priority eq "1") {
-		print $fh "</center><img src=\"_httpimg_/core.gif\">";
-
-		#shows that have seen first macro of core type
-		$first = "been";
-	    }
-
-	    # If it is an auxiliary macro, table header displays auxiliary
-	    if ($priority eq "2") {
-		print $fh "</center><img src=\"_httpimg_/auxiliary.gif\">";
-		$first = "false";
-	    }
-
-	    print $fh ("<table cellpadding=\"10\">\n<tr>",
-		       "<td><strong><center>". uc ($sourcelang) . "</center></strong></td>\n",
-		       "<td><strong><center>". uc ($targetlang) . "</center></strong></td>\n",
-		       "</tr>\n");
-	}
-
-	# If this is the first auxiliary macro, but not the first macro, finish the
-	#   current table and start a new auxiliary table underneath
-	if($priority eq "2" and $first eq "been") {
-	    print $fh ("</table><br></center><img src=\"_httpimg_/auxiliary.gif\">",
-		       "<table cellpadding=\"10\">\n<tr>",
-		       "<td><strong><center>". uc ($sourcelang) . "</strong></center></td>\n",
-		       "<td><strong><center>". uc ($targetlang) . "</strong></center></td>\n",
-		       "</tr>\n");
-	    $first = "false";
-	}
-
-        # so that when it is an image only get the text to translate not coding stuff aswell
-	if ($text =~ m/\#\# (^|.)*/) {
-	    # print STDERR "\nIcon -- Key: $keyname\nText: $text\n"; # Default: $default\n";
-	    if ($& =~ m/".*"/) {
-		#prints to the file two text fields, the left one contains the base language
-		#macro text, the right contains the translation language macro text if any exists
-		my $icontext = $&;
-		$icontext =~ s/"(.*)"/$1/;
-		# print "Text to translate: $icontext\n";
-
-		if ($default =~ m/\#\# (^|.)*/) {
-		    if ($& =~ m/".*"/) {
-			$default = $&;
-			$default =~ s/"(.*)"/$1/;
-		    }
-		}
-		# print "Default: $default\n";
-
-		my $remainder = $text;
-		$remainder =~ s/^\#\# ([^\#]*)//;
-		# print "Remainder: $remainder\n";
-
-		$rows = 1;
-
-		my $textbox1;
-		if (1) {
-		    $textbox1 = "<textarea name=\"whocaresh\" rows=\"$rows\" cols=\"50\" readonly=\"1\">";
-		    $textbox1 .= "$icontext</textarea>\n";
-		}
-		else {
-		    $textbox1 = $query->textfield(-name=>"whocares", -default=>"$icontext",
-						  -size=>50, -readonly=>1);
-		}
-		print $fh ("<tr><td align=center>", $textbox1, "</td><td align=center>");
-
-		my $textbox2;
-		if (1) {
-		    $textbox2 = "<textarea name=\"$keyname\" rows=\"$rows\" cols=\"50\">";
-		    $textbox2 .= "$default</textarea><br>\n";
-		}
-		else {
-		    $textbox2 = $query->textfield(-name=>"$keyname", -default=>"$default",
-						  -size=>50);
-		}
-		print $fh $textbox2;
-
-		print $fh $query->hidden(-name=>"$keyname" . "::icontext",
-					 -default=>"$remainder");
-		print $fh "</td></tr>\n";
-	    }
-	}
-	# Text macro
-	elsif ($text =~ m/\S+/) {
-	    $text =~ s/\s+/ /g;
-
-	    my @words = split(/ /, $text);
-	    my $words = scalar(@words);
-	    my $rows = sprintf("%.0f", $words/5);
-	    print $fh ("<tr><td align=center>\n");
-	    #determines how many rows of text are required to display the base language
-	    #macro text then use this value to determine whether we should use a text area
-	    #or a text field
-
-	    # Experimenting with textfield and text area
-	    # for now use exclusively textareas.
-
-	    # if ($rows >= 0) { 
-	    if (1) { 
-		$rows = 1 if ($rows < 1);
-
-		#prints to the file two text areas, the left one contains the base language
-		#macro text, the right contains the translation language macro text if any exists
-		    
-		$text =~ s/<p>/<p>\n/g;
-		$text =~ s/<br>/<br>\n/g;
-		$text =~ s/<\/td>/<\/td>\n/g;
-
-		print $fh ("<textarea name=\"whocaresh\" rows=\"$rows\" cols=\"50\" readonly=\"1\">",
-			   "$text</textarea>\n",
-			   "</td><td align=center>\n",
-			   "<textarea name=\"$keyname\" rows=\"$rows\" cols=\"50\">", 
-			   "$default</textarea><br></td></tr>\n");  
-	    }
-	    else {
-		#prints to the file two text fields, the left one contains the base language
-		#macro text, the right contains the translation language macro text if any exists
-		print $fh ($query->textfield(-name=>"whocares",
-					     -default=>"$text",
-					     -size=>50,
-					     -readonly=>1),
-			   "</td><td align=center>\n",
-			   $query->textfield(-name=>"$keyname" . "$keynamecount",
-					     -default=>"$default",
-					     -size=>50),
-			   "<br></td></tr>\n");
-	    }
-	}
-    }
-
-    #finishes table and adds a SUBMIT CHANGES option on the end
-    print $fh ("</table><br><center>\n",
-	       "<table><tr><td align=left width=\"50%\">",
-	       $query->reset("RESET FORM"),
-	       "</td><td align=right width=\"50%\">",
-	       $query->submit($pageno, "_textsubmit_"),
-	       "</td></tr><tr><td width=\"50%\"></td><td align=right width=\"50%\">",
-	       "<br> _textsubmittext_ <br> _textviewtranslation_ ",
-	       "<a href=\"_gwcgi_?a=p&p=home&l=$targetcode\">_texthere_</a>.",
-	       # "_textgetdmfiles_ ",
-	       # "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . ".dm\">_texthere_</a>",
-	       # " &amp; ",
-	       # "<a href=\"_httpprefix_/gsdl/macros/$targetlang" . "2.dm\">_texthere_</a>.",
-	       "</td></tr></table>");
-}
-
-
-sub core_or_auxiliary_macro
-{
-    my ($language, $sourcekey) = @_;
-
-    my $macrofile = $sourcekey;
-    $macrofile =~ s/^([^:]+)::(.*)/$1/;
-
-    if ($macrofile eq ($language . ".dm")) {
-	return "1";  # Core macro
-    }
-    if ($macrofile eq ($language . "2.dm")) {
-	return "2";  # Auxiliary macro
-    }
-}
-
-
-sub display_hash
-{
-    my ($hash) = @_;
-
-    foreach $key (sort (keys %$hash)) {
-	print $key . "\n";
-	print $hash->{$key} . "\n";
-    }
-}
-
-exit &main(@ARGV);
