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

Francois Gouget fgouget@codeweavers.com
Wed, 25 May 2005 03:09:00 +0200


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


When the nsgmls parser is missing po4a-translate just reports success 
and that the documentation is translated to 100% when in fact it does 
nothing. This could be pretty confusing. Reporting that nsgmls is 
missing would be better.

So I propose this patch to detect that nsgmls is missing and issue an 
error. The trick here is we run it on an empty Sgml document and check 
that it returned success which should ensure that it works, etc. The 
'document' in question uses DocBook and that may be an issue if all the 
user wants to use if DebianDoc or some other Sgml document type. Also 
the check is performed in initialize() and this may not be the best place.

Alternate solutions would be to:
  * we could look for nsgmls in $PATH manually and issue an error if we 
could not find it.
  * we could check nsgmls' return code after the close(IN) in parse(). 
What makes this tricky is the way we invoke nsgmls but I think it would 
be feasible anyway.

So let me know which approach seems best.

Changelog:

  * lib/Locale/Po4a/Sgml.pm

    Francois Gouget <fgouget@codeweavers.com>
    Check for nsgmls and issue an error if it is missing.

-- 
Francois Gouget
fgouget@codeweavers.com


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

Index: lib/Locale/Po4a/Sgml.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Sgml.pm,v
retrieving revision 1.55
diff -u -p -r1.55 Sgml.pm
--- lib/Locale/Po4a/Sgml.pm	21 May 2005 18:42:21 -0000	1.55
+++ lib/Locale/Po4a/Sgml.pm	25 May 2005 01:04:39 -0000
@@ -195,7 +195,15 @@ my $xmlprolog = undef; # the '<?xml ... 
 sub initialize {
     my $self = shift;
     my %options = @_;
-    
+
+    # Check that nsgmls is installed
+    my $cmd="echo '<!doctype article PUBLIC \"-//OASIS//DTD DocBook V3.1//EN\"><article><para></para></article>' | nsgmls 2>&1";
+    my $output=`$cmd`;
+    if ($? != 0)
+    {
+	die "po4a::sgml: nsgmls is missing or non-functional:\n$output";
+    }
+
     $self->{options}{'translate'}='';
     $self->{options}{'section'}='';
     $self->{options}{'indent'}='';

--------------050003070000020809010607--