[xml/sgml-commit] [SCM] linuxdoc-tools package for Debian. branch, master, updated. debian/0.9.31-5-g870695b

Agustin Martin Domingo agmartin at debian.org
Mon Jun 9 10:20:30 UTC 2008


The following commit has been merged in the master branch:
commit 30e43b5a8c3b0378d61405a601df1c8ac7ce2738
Author: Agustin Martin Domingo <agmartin at debian.org>
Date:   Wed May 28 22:16:17 2008 +0200

    Better error handling. No longer use ancient handles handling.
    
    * Make sure all system calls are checked for return codes
    * Improve error messages, making them more consistent.
    * Make sure all error messages are sent to STDERR.
    * No longer use ancient way of handling handles.
    * No longer use some perl modules:
      - FileHandle;
      - DirHandle;
      - File::Find;
      - IPC::Open2;
      - Cwd;
    * The usual cosmetic changes.

diff --git a/lib/LinuxDocTools.pm b/lib/LinuxDocTools.pm
index 24c0808..4c664f9 100755
--- a/lib/LinuxDocTools.pm
+++ b/lib/LinuxDocTools.pm
@@ -42,13 +42,14 @@ but the encapsulation should provide for a simple interface for other users as w
 
 =cut
 
-use DirHandle;
+# use FileHandle;
+# use DirHandle;
+# use File::Find;
+# use IPC::Open2;
+# use Cwd;
+
 use File::Basename;
-use File::Find;
 use File::Copy;
-use FileHandle;
-use IPC::Open2;
-use Cwd;
 use LinuxDocTools::Lang;
 use LinuxDocTools::Utils qw(process_options usage cleanup trap_signals remove_tmpfiles create_temp);
 use LinuxDocTools::Vars;
@@ -81,11 +82,12 @@ sub ldt_getdtd_v1 {
 # Get the dtd
 # -----------------------------------------------------------------------------------
   my $file = shift;
+  my $error_header = "LinuxdocTools::ldt_getdtd_v1";
   my $dtd;
   my $FILE;
 
   open ($FILE, "< $file")
-    or die "Could not open \"$file\" for reading. Aborting ...\n";
+    or die "$error_header: Could not open \"$file\" for reading. Aborting ...\n";
 
   while ( <$FILE> ) {
     tr/A-Z/a-z/;
@@ -112,21 +114,21 @@ sub ldt_getdtd_v1 {
 
   # Warn about non-supported DTDs
   if ( ( $dtd ne "linuxdoc" ) && ( $dtd ne "linuxdoctr" ) ) {
-    print " DTD check - Error: this linuxdoc-tools package supports";
-    print " Linuxdoc DTD only.\n\n";
+    print STDERR " DTD check - Error: this linuxdoc-tools package supports";
+    print STDERR " Linuxdoc DTD only.\n\n";
 
     # This is Debian Specific, but if debiandoc dtd is used on other system,
     # then that user may needs the debiandoc-sgml anyway.
     if ( $dtd eq "debiandoc" ) {
-      print "   If you wish to convert DebianDoc DTD files,\n";
-      print "     then please install and use";
-      print " debiandoc-sgml package.\n\n";
+      print STDERR "   If you wish to convert DebianDoc DTD files,\n";
+      print STDERR "     then please install and use";
+      print STDERR " debiandoc-sgml package.\n\n";
     } else {
-      print "   If you wish to convert DocBook or other DTD files,\n";
-      print "     then please install and use";
-      print " SGMLTools-Lite or Jade/OpenJade package.\n\n";
+      print STDERR "   If you wish to convert DocBook or other DTD files,\n";
+      print STDERR "     then please install and use";
+      print STDERR " SGMLTools-Lite or Jade/OpenJade package.\n\n";
     }
-      die " --- LinuxDoc-Tools aborting.\n";
+    die " --- LinuxDoc-Tools aborting.\n";
   }
 
   return $dtd;
@@ -138,11 +140,12 @@ sub ldt_getdtd_v2 {
 # Second way of getting dtd, fron nsgmls output.
 # -----------------------------------------------------------------------------------
   my $preaspout = shift;
+  my $error_header = "LinuxdocTools::ldt_getdtd_v2";
   my $dtd2;
   my $TMP;
 
   open ($TMP,"< $preaspout")
-    or die "Could not open $preaspout for reading\n";
+    or die "%error_header: Could not open $preaspout for reading. Aborting ...\n";
   while ( ($dtd2 = <$TMP>) && ! ( $dtd2 =~ /^\(/) ) { };
   close $TMP;
   $dtd2 =~ s/^\(//;
@@ -294,11 +297,12 @@ sub init {
   $Formats{$global->{NAME}} = $global;	# All formats we know.
   $FmtList{$global->{NAME}} = $global;  # List of formats for help msgs.
 
-  $global->{sgmlpre}     = "sgmlpre";
+  $global->{sgmlpre}   = "sgmlpre";
+  my $error_header     = "LinuxdocTools::init";
 
   if ( -e "/etc/papersize" ){
     open (PAPERSIZE,"< /etc/papersize") ||
-      die "Count not open \"/etc/papersize\" for reading\n";
+      die "$error_header: Count not open \"/etc/papersize\" for reading\n";
     chomp (my $paper = <PAPERSIZE>);
     $global->{papersize} = "letter" if ( $paper eq "letter");
     close PAPERSIZE;
@@ -398,7 +402,7 @@ sub process_options {
       $format = "latex2e";
     }
     $FmtList{$format} = $Formats{$format} or
-      &usage ("$format: unknown format");
+      &usage ("$format: Unknown format");
     $global->{format} = $format;
   } else {
     &usage("");
@@ -408,7 +412,7 @@ sub process_options {
   my @files    = LinuxDocTools::Utils::process_options (@args);
 
   # Check the number of given files
-  $#files > -1 || usage ("no filenames given");
+  $#files > -1 || usage ("No filenames given");
 
   # Normalize language string
   $global->{language} = Any2ISO ($global->{language});
@@ -468,10 +472,12 @@ sub process_file {
 # ------------------------------------------------------------------------
   my $file = shift (@_);
   my $saved_umask = umask;
+  my $error_header = "LinuxdocTools::process_file";
   my $IFILE;
   my $WRITENSGMLS;
   my $PREASP_IN;
   my $PREASP_OUT;
+  my $INPOSTASP;
 
   print "Processing file $file\n";
   umask 0077;
@@ -481,7 +487,7 @@ sub process_file {
   $global->{filepath} = $filepath;
   $global->{file}     = &ldt_searchfile(["$filepath/$filename.sgml",
 					 "$filepath/$filename.SGML"])
-    or die "Cannot find $file\n";
+    or die "$error_header: Cannot find $file. Aborting ...\n";
 
   my $dtd = &ldt_getdtd_v1("$global->{file}");
   print STDERR "DTD: " . $dtd . "\n" if $global->{debug};
@@ -490,10 +496,10 @@ sub process_file {
   my $tmpdir = $ENV{'TMPDIR'} || '/tmp';
   $tmpdir = $tmpdir . '/' . 'linuxdoc-dir-' . $$;
   if ( -e $tmpdir ) {
-    die "$tmpdir already exists. Aborting ...\n";
+    die "$error_header: $tmpdir already exists. Aborting ...\n";
   } else {
     mkdir ($tmpdir, 0700) ||
-      die " - temporary files can not be created, aborted - \n";
+      die "$error_header: Temporary files can not be created. Aborting ...\n";
   }
 
   # Set common base name for temp files and temp file names
@@ -529,15 +535,15 @@ sub process_file {
   if ( defined $Formats{$global->{format}}{preNSGMLS} ) {
     $global->{NsgmlsPrePipe} = &{$Formats{$global->{format}}{preNSGMLS}};
     open ($IFILE,"$global->{NsgmlsPrePipe} |")
-      || die "Could not open pipe from $global->{NsgmlsPrePipe}. Aborting ...\n";
+      || die "$error_header: Could not open pipe from $global->{NsgmlsPrePipe}. Aborting ...\n";
   } else {
     open ($IFILE,"< $global->{file}")
-      || die "Could not open $global->{file} for reading. Aborting ...\n";
+      || die "$error_header: Could not open $global->{file} for reading. Aborting ...\n";
   }
 
   open ($WRITENSGMLS,
 	"$precmd | $main::progs->{NSGMLS} $global->{NsgmlsOpts} $ENV{SGMLDECL} > $nsgmlsout")
-    or die "Could not open pipe to $nsgmlsout\n";
+    or die "$error_header: Could not open pipe to $nsgmlsout. Aborting ...\n";
 
   if ($global->{charset} eq "latin") {
     print $WRITENSGMLS &ldt_latin1tosgml($IFILE);
@@ -553,9 +559,9 @@ sub process_file {
 
   #  If output file does not exists or is empty, something went wrong.
   if ( ! -e "$nsgmlsout" ) {
-    die "can't create file $nsgmlsout - exiting";
+    die "$error_header: Can't create file $nsgmlsout. Aborting ...\n";
   } elsif ( -z "$nsgmlsout" ){
-    die "$nsgmlsout empty, SGML parsing error - exiting";
+    die "$error_header: $nsgmlsout empty, SGML parsing error. Aborting ...\n";
   }
 
   print "- Nsgmls stage finished.\n" if $global->{debug};
@@ -563,28 +569,29 @@ sub process_file {
   #  If a preASP stage is defined, let the format handle it.
   #  --------------------------------------------------------
   open ($PREASP_IN, "< $nsgmlsout")
-    or die "Could not open $nsgmlsout for reading\n";
+    or die "$error_header: Could not open $nsgmlsout for reading. Aborting ...\n";
   open ($PREASP_OUT, "> $preaspout")
-    or die "Could not open $preaspout for writing\n";
+    or die "$error_header: Could not open $preaspout for writing. Aborting ...\n";
 
   if (defined $Formats{$global->{format}}{preASP}) {
     # preASP ($INHANDLE, $OUTHANDLE);
     &{$Formats{$global->{format}}{preASP}}($PREASP_IN, $PREASP_OUT) == 0
-      or die "error pre-processing $global->{format}.\n";
+      or die "$error_header: Error pre-processing $global->{format}.\n";
   } else {
     copy ($PREASP_IN, $PREASP_OUT);
   }
 
   close $PREASP_IN;
   close $PREASP_OUT;
-  die "Can't create $preaspout file - exiting" unless -e "$preaspout";
+  die "$error_header: Can't create $preaspout file. Aborting ...\n"
+    unless -e "$preaspout";
 
   print "- PreASP stage finished.\n" if ( $global->{debug} );
 
   # Run sgmlsasp, with an optional style if specified.
   # -----------------------------------------------------------
   my $dtd2 = &ldt_getdtd_v2($preaspout)
-    or "Could not read dtd from $preaspout. Aborting ...\n";
+    or die "$error_header: Could not read dtd from $preaspout. Aborting ...\n";
 
   unless ( $dtd eq $dtd2 ){
     print STDERR "Warning: Two different values for dtd, dtd1: $dtd, dtd2: $dtd2\n";
@@ -603,7 +610,7 @@ sub process_file {
 
   my $mapping = &ldt_searchfile(["$main::DataDir/site/$dtd/$global->{format}/mapping",
 				 "$main::DataDir/dist/$dtd/$global->{format}/mapping"])
-    or die "Could not find mapping file for $dtd/$global->{format}\n";
+    or die "$error_header: Could not find mapping file for $dtd/$global->{format}. Aborting ...\n";
 
   $mapping = "$style $mapping" if $style;
 
@@ -627,23 +634,26 @@ sub process_file {
   my $sgmlsasp_command = "$main::progs->{SGMLSASP} $mapping < $preaspout |
       expand -t $global->{tabsize} > $aspout";
   system ($sgmlsasp_command) == 0
-    or die "Error running $sgmlsasp_command\n";
+    or die "$error_header: Error running $sgmlsasp_command. Aborting ...\n";
 
-  die "Can't create $aspout file - exiting\n" unless -e "$aspout";
+  die "$error_header: Can't create $aspout file. Aborting ...\n"
+    unless -e "$aspout";
 
   print "- ASP stage finished.\n" if ( $global->{debug} );
 
   #  If a postASP stage is defined, let the format handle it.
   # ----------------------------------------------------------------
   umask $saved_umask;
-  my $inpostasp = new FileHandle "<$aspout";
+
+  open ($INPOSTASP, "< $aspout" )
+    or die "$error_header: Could not open $aspout for reading. Aborting ...\n";
   if (defined $Formats{$global->{format}}{postASP}) {
     # postASP ($INHANDLE)
     # Should leave whatever it thinks is right based on $INHANDLE.
-    &{$Formats{$global->{format}}{postASP}}($inpostasp) == 0
-      or die "error post-processing $global->{format}.\n";
+    &{$Formats{$global->{format}}{postASP}}($INPOSTASP) == 0
+      or die "$error_header: Error post-processing $global->{format}. Aborting ...\n";
   }
-  $inpostasp->close;
+  close $INPOSTASP;
 
   print "- postASP stage finished.\n" if ( $global->{debug} );
 

-- 
linuxdoc-tools package for Debian.



More information about the debian-xml-sgml-commit mailing list