[Po4a-devel]Sgml.pm: Issue an error if nsgmls is missing

Francois Gouget fgouget@codeweavers.com
Sat, 28 May 2005 20:45:13 +0200


This is a multi-part message in MIME format.
--------------020306020305080002010206
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit


Here's a better version of this patch. The perl documentation says that 
when using
open "cmd|" we can get the process exit code in '$?' after the close. So
this is what this patch does. If everything went well nsgmls returns 0
and this is what we should get. If anything went wrong we will get a
non-zero error code and print a message.

I also removed the 'cat' to not have multiple child processes though I 
don't think this is strictly necessary. But it seems cleaner and should 
be ever so slightly more efficient too.


Changelog:

  * lib/Locale/Po4a/Sgml.pm

    Francois Gouget <fgouget@codeweavers.com>
    Check the nsgmls exit code and issue an error if it is non-zero.
    This lets us detect the case where nsgmls is missing.


-- 
Francois Gouget
fgouget@codeweavers.com


--------------020306020305080002010206
Content-Type: text/plain;
 name="po4a-20050528-nsgmls.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="po4a-20050528-nsgmls.diff"

Index: lib/Locale/Po4a/Sgml.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Sgml.pm,v
retrieving revision 1.57
diff -u -p -r1.57 Sgml.pm
--- lib/Locale/Po4a/Sgml.pm	25 May 2005 16:55:20 -0000	1.57
+++ lib/Locale/Po4a/Sgml.pm	28 May 2005 18:12:06 -0000
@@ -610,7 +614,7 @@ sub parse_file {
     print $tmpfh $origfile;
     close $tmpfh || die wrap_mod("po4a::sgml", dgettext("po4a", "Can't close tempfile: %s"), $!);
 
-    my $cmd="cat $tmpfile|nsgmls -l -E 0 2>/dev/null|";
+    my $cmd="nsgmls -l -E 0 <$tmpfile 2>/dev/null|";
     print STDERR "CMD=$cmd\n" if ($debug{'generic'});
 
     open (IN,$cmd) || die wrap_mod("po4a::sgml", dgettext("po4a", "Can't run nsgmls: %s"), $!);
@@ -865,6 +876,7 @@ sub parse_file {
     # What to do after parsing
     $self->pushline($buffer);
     close(IN);
+    die "po4a::sgml: nsgmls is missing or non-functional\n" if ($? != 0);
     unlink ($tmpfile) unless $debug{'refs'};
 }
 

--------------020306020305080002010206--