gbranden pushed a commit to branch master
in repository groff.

commit 599db456140749533c76d826a5e81c12af00c692
Author: G. Branden Robinson <g.branden.robin...@gmail.com>
AuthorDate: Thu Aug 24 01:40:13 2023 -0500

    [mm]: Fix code style nits in mmroff.
    
    * contrib/mm/mmroff.pl: Fix code style nits; resolve Perl warnings.
      Initialize scalars `max_height` and `max_width` before using them.
      Add to `cur` hash instead of reinitializing it when reading "PIC id"
      comment from input.
    
      (ps_calc): Return early if bounding box keys in `cur` hash not
      populated.
    
      (psbb): Use `return` instead of `next` to exit early from non-loop.
      Improve diagnostic message: identify who is speaking, what operation
      failed, and end with newline.
---
 contrib/mm/ChangeLog | 12 ++++++++++++
 contrib/mm/mmroff.pl | 15 ++++++++-------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/contrib/mm/ChangeLog b/contrib/mm/ChangeLog
index 818a8d96b..3d055c57a 100644
--- a/contrib/mm/ChangeLog
+++ b/contrib/mm/ChangeLog
@@ -1,3 +1,15 @@
+2023-08-24  G. Branden Robinson <g.branden.robin...@gmail.com>
+
+       * mmroff.pl: Fix code style nits; resolve Perl warnings.
+       Initialize scalars `max_height` and `max_width` before using
+       them.  Add to `cur` hash instead of reinitializing it when
+       reading "PIC id" comment from input.
+       (ps_calc): Return early if bounding box keys in `cur` hash not
+       populated.
+       (psbb): Use `return` instead of `next` to exit early from
+       non-loop.  Improve diagnostic message: identify who is speaking,
+       what operation failed, and end with newline.
+
 2023-08-23  G. Branden Robinson <g.branden.robin...@gmail.com>
 
        Validate reference system state and user input.
diff --git a/contrib/mm/mmroff.pl b/contrib/mm/mmroff.pl
index bcd86ab83..da68e4cbc 100644
--- a/contrib/mm/mmroff.pl
+++ b/contrib/mm/mmroff.pl
@@ -70,7 +70,9 @@ $groff = "groff" if (!$groff);
 my $first_pass = "$groff -rRef=1 -z -mm @ARGV";
 my $second_pass = "$groff -mm @ARGV";
 
-my (%cur, $rfilename, $max_height, $imacro, $max_width, @out, @indi);
+my (%cur, $rfilename, $imacro, @out, @indi);
+my $max_height = 0;
+my $max_width = 0;
 open(MACRO, "$first_pass 2>&1 |") || die "run $first_pass:$!";
 while(<MACRO>) {
        if (m#^\.\\" Rfilename: (\S+)#) {
@@ -101,7 +103,7 @@ while(<MACRO>) {
                next;
        }
        if (m#^\.\\" PIC id (\d+)#) {
-               %cur = ('id', $1);
+               %cur = ('id' => $1);
                next;
        }
        if (m#^\.\\" PIC file (\S+)#) {
@@ -155,8 +157,8 @@ sub print_index {
 }
 
 sub ps_calc {
+       return unless exists($cur{'llx'});
        my ($f) = @_;
-
        my $w = abs($cur{'llx'}-$cur{'urx'});
        my $h = abs($cur{'lly'}-$cur{'ury'});
        $max_width = $w if $w > $max_width;
@@ -172,14 +174,14 @@ sub ps_calc {
        push(@out, ".nr pict*w!$id $w\n");
        push(@out, ".nr pict*h!$id $h\n");
 }
-               
 
 sub psbb {
        my ($f) = @_;
 
        unless (open(IN, $f)) {
-               print STDERR "Warning: Postscript file $f:$!";
-               next;
+               print STDERR "$progname: warning: cannot open"
+                       . " PostScript file $f: $!\n";
+               return;
        }
        while(<IN>) {
                if (/^%%BoundingBox:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {
@@ -192,7 +194,6 @@ sub psbb {
        close(IN);
 }
 
-
 1;
 # Local Variables:
 # mode: CPerl

_______________________________________________
Groff-commit mailing list
Groff-commit@gnu.org
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to