gbranden pushed a commit to branch master
in repository groff.

commit 647856053a46e0e29b1ca8d0bb62a0021250b6a1
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Aug 21 08:15:26 2024 -0500

    src/utils/afmtodit/afmtodit.pl: Refactor (4/4).
    
    * src/utils/afmtodit/afmtodit.pl: Update call sites of `croak` and new
      `whine` subroutines to use `&` sigil and omit trailing newline.
    
      (croak): Assume responsibility for writing a newline at the end of the
      message.
    
      (whine): New subroutine throws a diagnostic marked "warning".  Perl's
      `warn` output is ugly and not structured like other groff diagnostics.
      Give it responsibility for emitting the name of the program.
---
 ChangeLog                      |  9 ++++++++-
 src/utils/afmtodit/afmtodit.pl | 27 ++++++++++++++++-----------
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1190f3a00..a30d47d0e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,7 +14,14 @@
        stub and the short version; and existing `afmtodit_version`,
        which holds the stub and the (full) groff version.  Write
        `output_version` instead of `afmtodit_version` to the generated
-       file.
+       file.  Update call sites of `croak` and new `whine` subroutines
+       to use `&` sigil and omit trailing newline.
+       (croak): Assume responsibility for writing a newline at the end
+       of the message.
+       (whine): New subroutine throws a diagnostic marked "warning".
+       Perl's `warn` output is ugly and not structured like other groff
+       diagnostics.  Give it responsibility for emitting the name of
+       the program.
 
 2024-08-21  G. Branden Robinson <[email protected]>
 
diff --git a/src/utils/afmtodit/afmtodit.pl b/src/utils/afmtodit/afmtodit.pl
index e6ad84eee..7b79ef991 100644
--- a/src/utils/afmtodit/afmtodit.pl
+++ b/src/utils/afmtodit/afmtodit.pl
@@ -58,10 +58,15 @@ if ($opt_v) {
 
 sub croak {
   my $msg = shift;
-  print STDERR "$prog: error: $msg";
+  print STDERR "$prog: error: $msg\n";
   exit(1);
 }
 
+sub whine {
+  my $msg = shift;
+  print STDERR "$prog: warning: $msg\n";
+}
+
 sub usage {
     my $stream = *STDOUT;
     my $had_error = shift;
@@ -113,7 +118,7 @@ my (@encoding, %in_encoding);
 my (%width, %height, %depth);
 my (%left_side_bearing, %right_side_bearing);
 
-open(AFM, $afm) || croak("unable to open '$ARGV[0]': $!\n");
+open(AFM, $afm) || &croak("unable to open '$ARGV[0]': $!");
 
 while (<AFM>) {
     chomp;
@@ -227,7 +232,7 @@ my ($sizescale, $resolution, $unitwidth);
 $sizescale = 1;
 
 open(DESC, $desc) || open(DESC, $sys_desc) ||
-    croak("unable to open '$desc' or '$sys_desc': $!\n");
+    &croak("unable to open '$desc' or '$sys_desc': $!");
 while (<DESC>) {
     next if /^#/;
     chop;
@@ -251,7 +256,7 @@ if ($opt_e) {
 
     my $sys_opt_e = $groff_sys_fontdir . "/devps/" . $opt_e;
     open(ENCODING, $opt_e) || open(ENCODING, $sys_opt_e) ||
-       croak("unable to open '$opt_e' or '$sys_opt_e': $!\n");
+       &croak("unable to open '$opt_e' or '$sys_opt_e': $!");
     while (<ENCODING>) {
        next if /^#/;
        chop;
@@ -272,7 +277,7 @@ if ($opt_e) {
 my (%nmap, %map);
 
 open(MAP, $map) || open(MAP, $sys_map) ||
-    croak("unable to open '$map' or '$sys_map': $!\n");
+    &croak("unable to open '$map' or '$sys_map': $!");
 while (<MAP>) {
     next if /^#/;
     chop;
@@ -282,12 +287,12 @@ while (<MAP>) {
        if ($field[1] eq "space") {
            # The PostScript character "space" is automatically mapped
            # to the groff character "space"; this is for grops.
-           warn "$prog: you are not allowed to map to " .
-                "the groff character 'space'";
+           &whine("you are not allowed to map to the groff character"
+                  . " 'space'");
        }
        elsif ($field[0] eq "space") {
-           warn "$prog: you are not allowed to map " .
-                "the PostScript character 'space'";
+           &whine("you are not allowed to map the PostScript character"
+                  . " 'space'");
        }
        else {
            $nmap{$field[0]} += 0;
@@ -434,7 +439,7 @@ if (!$opt_x) {
            $u =~ s/^_/u/;
            if ($u) {
                if (defined $mapped{$u}) {
-                   warn "$prog: both $mapped{$u} and $ch map to $u";
+                   &whine("both $mapped{$u} and $ch map to $u");
                }
                else {
                    $mapped{$u} = $ch;
@@ -466,7 +471,7 @@ foreach my $lig (sort keys %default_ligatures) {
 # print it all out
 
 open(FONT, ">$outfile") ||
-  croak("unable to open '$outfile' for writing: $!\n");
+  &croak("unable to open '$outfile' for writing: $!");
 select(FONT);
 
 print("# generated by $output_version\n");

_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to