groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 18/39: [mm]: Add `Die` subroutine to mmroff script.


From: G. Branden Robinson
Subject: [groff] 18/39: [mm]: Add `Die` subroutine to mmroff script.
Date: Sun, 9 Oct 2022 23:53:37 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 2b4b95bfd401caeb1beab0a75ccd215eb9a66892
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Oct 9 05:26:46 2022 -0500

    [mm]: Add `Die` subroutine to mmroff script.
    
    * contrib/mm/mmroff.pl: Add proper diagnostic subroutine.  Add
      "progname" scalar to store the name of the program.
    
      (Die): New subroutine.
    
      (print_index, top level): Call Die() when encountering prohibitive
      problems instead of flinging a string into a void context.
    
    squash [mm]: Add `Die` subroutine to mmroff script.
---
 contrib/mm/ChangeLog |  9 +++++++++
 contrib/mm/mmroff.pl | 12 ++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/contrib/mm/ChangeLog b/contrib/mm/ChangeLog
index 56b5a7cfd..3cd877b75 100644
--- a/contrib/mm/ChangeLog
+++ b/contrib/mm/ChangeLog
@@ -1,3 +1,12 @@
+2022-10-09  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * mmroff.pl: Add proper diagnostic subroutine.  Add "progname"
+       scalar to store the name of the program.
+       (Die): New subroutine.
+       (print_index, top level): Call Die() when encountering
+       prohibitive problems instead of flinging a string into a void
+       context.
+
 2022-10-09  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * mmroff.pl: Enable Perl warnings.
diff --git a/contrib/mm/mmroff.pl b/contrib/mm/mmroff.pl
index 209e2e7b8..3c56af397 100644
--- a/contrib/mm/mmroff.pl
+++ b/contrib/mm/mmroff.pl
@@ -18,6 +18,9 @@
 
 use strict;
 use warnings;
+
+(my $progname = $0) =~s @.*/@@;
+
 # runs groff in safe mode, that seems to be the default
 # installation now. That means that I have to fix all nice
 # features outside groff. Sigh.
@@ -84,12 +87,17 @@ while(<MACRO>) {
 }
 close(MACRO);
 
+sub Die {
+       print STDERR "$progname: fatal error: @_\n";
+       exit 1;
+}
 
 if ($rfilename) {
        push(@out, ".nr pict*max-height $max_height\n") if defined $max_height;
        push(@out, ".nr pict*max-width $max_width\n") if defined $max_width;
 
-       open(OUT, ">$rfilename") || "create $rfilename:$!";
+       open(OUT, ">$rfilename")
+               or &Die("unable to create $rfilename:$!");
        print OUT '.\" references', "\n";
        my $i;
        for $i (@out) {
@@ -104,7 +112,7 @@ exit system($run_macro);
 sub print_index {
        my ($f, $ind, $macro) = @_;
 
-       open(OUT, ">$f") || "create $f:$!";
+       open(OUT, ">$f") or &Die("unable to create $f:$!");
        my $i;
        for $i (sort @$ind) {
                if ($macro) {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]