Index: main/trunk/greenstone2/perllib/mgppbuilder.pm
===================================================================
--- main/trunk/greenstone2/perllib/mgppbuilder.pm	(revision 28118)
+++ main/trunk/greenstone2/perllib/mgppbuilder.pm	(revision 28119)
@@ -253,5 +253,11 @@
 	    die "mgppbuilder::compress_text - couldn't run $mgpp_compression_dict_exe\n";
 	}
-	system ("mgpp_compression_dict$exe -f \"$fulltextprefix\" -S -H -2 -k 5120 $osextra");
+	my $comp_dict_status = system ("mgpp_compression_dict$exe -f \"$fulltextprefix\" -S -H -2 -k 5120 $osextra");
+	if($comp_dict_status != 0) {
+	    print $outhandle "\nmgppbuilder::compress_text - Warning: there's no compressed text\n";
+	    $self->{'notbuilt'}->{'compressedtext'} = 1;
+	    print STDERR "<Warning name='NoCompressedText'/>\n</Stage>\n" if $self->{'gli'};
+	    return;
+	}
 
 	if (!$self->{'debug'}) {
@@ -564,5 +570,13 @@
 	my $weights_cmd = "mgpp_weights_build$exe -f \"$fullindexprefix\" $osextra";
 	print $outhandle "\ncmd: $weights_cmd\n" if ($self->{'verbosity'} >= 4);	
-	system ($weights_cmd);
+	my $weights_status = system ($weights_cmd);
+	# check that it worked - if not, don't carry on
+	if ($weights_status !=0) {
+	    print $outhandle "mgppbuilder::build_index - No Index: couldn't create weights file, error calling mggp_weights_build.\n";
+	    print STDERR "<Warning name='NoIndex'/>\n</Stage>\n" if $self->{'gli'};
+	    $self->{'notbuilt'}->{$index}=1;
+	    return;
+	    
+	}
 
 	# create 'on-disk' stemmed dictionary
@@ -572,6 +586,13 @@
 	    die "mgppbuilder::build_index - couldn't run $mgpp_invf_dict_exe\n";
 	}
-	system ("mgpp_invf_dict$exe -f \"$fullindexprefix\" $osextra" );
-
+	my $invdict_status = system ("mgpp_invf_dict$exe -f \"$fullindexprefix\" $osextra" );
+	# check that it worked - if not, don't carry on
+	if ($invdict_status !=0) {
+	    print $outhandle "mgppbuilder::build_index - No Index: couldn't create on-disk stemmed dictionary, error calling mggp_invf_dict.\n";
+	    print STDERR "<Warning name='NoIndex'/>\n</Stage>\n" if $self->{'gli'};
+	    $self->{'notbuilt'}->{$index}=1;
+	    return;
+	    
+	}
 
 	# creates stem index files for the various stemming methods
@@ -585,26 +606,64 @@
 	if ($self->{'accentfold'}) {
 	    # the first time we do this, we test for accent folding enabled
-	    if (system ("mgpp_stem_idx$exe -b 4096 -s4 -f \"$fullindexprefix\" $osextra") == 2) {
+	    my $accent_status = system ("mgpp_stem_idx$exe -b 4096 -s4 -f \"$fullindexprefix\" $osextra");
+	    if ($accent_status == 2) {
 		# accent folding has not been enabled in mgpp
 		$accent_folding_enabled = 0;
 		$self->{'stemindexes'} -= 4;
+	    } elsif ($accent_status != 0) {
+		print $outhandle "\nAccent folding failed: mgpp_stem_idx exit status $accent_status\n" if ($self->{'verbosity'} >= 4);
+		$self->{'accentfold'} = 0; 
+		#$accent_folding_enabled = 0;
+		$self->{'stemindexes'} -= 4;
 	    }
 	}
 	if ($self->{'casefold'}) {
-	    system ("mgpp_stem_idx$exe -b 4096 -s1 -f \"$fullindexprefix\" $osextra");
-	    if ($accent_folding_enabled && $self->{'accentfold'}) {
-		system ("mgpp_stem_idx$exe -b 4096 -s5 -f \"$fullindexprefix\" $osextra");
+	    my $casefold_status = system ("mgpp_stem_idx$exe -b 4096 -s1 -f \"$fullindexprefix\" $osextra");
+	    if ($casefold_status != 0) {
+		print $outhandle "\nCase folding failed: mgpp_stem_idx exit status $casefold_status\n" if ($self->{'verbosity'} >= 4);
+		$self->{'casefold'} = 0;
+		$self->{'stemindexes'} -= 1;
+	    }
+	    
+	    elsif ($accent_folding_enabled && $self->{'accentfold'}) {
+		my $status = system ("mgpp_stem_idx$exe -b 4096 -s5 -f \"$fullindexprefix\" $osextra");
+		if($status != 0) {
+		    print $outhandle "\nAccent folding (with casefolding) failed: mgpp_stem_idx exit status $status\n" if ($self->{'verbosity'} >= 4);
+		    $self->{'accentfold'} = 0;
+		    $self->{'stemindexes'} -= 4; # casefold worked, only accentfold failed, so -= 4, not -= 5
+		}
 	    }
 	}
 	if ($self->{'stem'}) {
-	    system ("mgpp_stem_idx$exe -b 4096 -s2 -f \"$fullindexprefix\" $osextra");
-	    if ($accent_folding_enabled && $self->{'accentfold'}) {
-		system ("mgpp_stem_idx$exe -b 4096 -s6 -f \"$fullindexprefix\" $osextra");
+	    my $stem_status = system ("mgpp_stem_idx$exe -b 4096 -s2 -f \"$fullindexprefix\" $osextra");
+	    if ($stem_status != 0) {
+		print $outhandle "\nStemming failed: mgpp_stem_idx exit status $stem_status\n" if ($self->{'verbosity'} >= 4);
+		$self->{'stem'} = 0;
+		$self->{'stemindexes'} -= 2;
+	    }
+	    elsif ($accent_folding_enabled && $self->{'accentfold'}) {
+		my $status = system ("mgpp_stem_idx$exe -b 4096 -s6 -f \"$fullindexprefix\" $osextra");
+		if($status != 0) {
+		    print $outhandle "\nAccent folding (with stemming) failed: mgpp_stem_idx exit status $status\n" if ($self->{'verbosity'} >= 4);
+		    $self->{'accentfold'} = 0;
+		    $self->{'stemindexes'} -= 4; # stem worked, only accentfold failed, so -= 4, not -= 6
+		}
 	    }
 	}
 	if ($self->{'casefold'} && $self->{'stem'}) {
-	    system ("mgpp_stem_idx$exe -b 4096 -s3 -f \"$fullindexprefix\" $osextra");
-	    if ($accent_folding_enabled && $self->{'accentfold'}) {
-		system ("mgpp_stem_idx$exe -b 4096 -s7 -f \"$fullindexprefix\" $osextra");
+	    my $case_and_stem_status = system ("mgpp_stem_idx$exe -b 4096 -s3 -f \"$fullindexprefix\" $osextra");
+	    if ($case_and_stem_status != 0) {
+		print $outhandle "\nCasefolding and stemming failed: mgpp_stem_idx exit status $case_and_stem_status\n" if ($self->{'verbosity'} >= 4);
+		$self->{'stem'} = 0;
+		$self->{'casefold'} = 0;
+		$self->{'stemindexes'} -= 3;
+	    }
+	    elsif ($accent_folding_enabled && $self->{'accentfold'}) {
+		my $status = system ("mgpp_stem_idx$exe -b 4096 -s7 -f \"$fullindexprefix\" $osextra");
+		if($status != 0) {
+		    print $outhandle "\nAccent folding (with stemming and casefolding) failed: mgpp_stem_idx exit status $status\n" if ($self->{'verbosity'} >= 4);
+		    $self->{'accentfold'} = 0;
+		    $self->{'stemindexes'} -= 4; # casefold and stem worked, only accentfold failed, so -= 4, not -= 7
+		}
 	    }
 	}
