[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 20/40: [afmtodit]: Handle fatal exits more idiomatically.
From: |
G. Branden Robinson |
Subject: |
[groff] 20/40: [afmtodit]: Handle fatal exits more idiomatically. |
Date: |
Sat, 12 Nov 2022 14:43:37 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit acec1d96bd226698dcd5232b384f6b473e5a104e
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Nov 11 15:48:51 2022 -0600
[afmtodit]: Handle fatal exits more idiomatically.
* src/utils/afmtodit/afmtodit.pl: Use our own fatal exit function
instead of Perl's "die".
(croak): New subroutine emits argument as part of diagnostic message
and exits with status 1.
(usage): Exit with status 2, not 1, on usage errors.
* NEWS: Document new exit behavior.
---
ChangeLog | 10 ++++++++++
NEWS | 2 ++
src/utils/afmtodit/afmtodit.pl | 21 +++++++++++++++------
3 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8bc759fda..e2a74725f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2022-11-09 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/utils/afmtodit/afmtodit.pl: Use our own fatal exit
+ function instead of Perl's "die".
+ (croak): New subroutine emits argument as part of diagnostic
+ message and exits with status 1.
+ (usage): Exit with status 2, not 1, on usage errors.
+
+ * NEWS: Document new exit behavior.
+
2022-11-09 G. Branden Robinson <g.branden.robinson@gmail.com>
* font/devpdf/devpdf.am (font/devpdf/download): Improve
diff --git a/NEWS b/NEWS
index 3e99c6ef4..58839e233 100644
--- a/NEWS
+++ b/NEWS
@@ -604,6 +604,8 @@ o afmtodit no longer writes file names with directory
information in
them to the "name" directives of the font descriptions it generates.
(The `fp` request no longer accepts such names; see "troff" above.)
+o afmtodit now exits with status 2 (not 1) upon usage errors.
+
o pfbtops now exits with status 2 upon usage errors and the standard C
library's `EXIT_FAILURE` status (usually 1) on operational failures
instead of vice versa.
diff --git a/src/utils/afmtodit/afmtodit.pl b/src/utils/afmtodit/afmtodit.pl
index b8183a249..3c40f1597 100644
--- a/src/utils/afmtodit/afmtodit.pl
+++ b/src/utils/afmtodit/afmtodit.pl
@@ -41,6 +41,12 @@ if ($opt_v) {
exit 0;
}
+sub croak {
+ my $msg = shift;
+ print STDERR "$prog: error: $msg";
+ exit(1);
+}
+
sub usage {
my $stream = *STDOUT;
my $had_error = shift;
@@ -57,7 +63,9 @@ sub usage {
"and 'pdf' output devices of groff(1). See the afmtodit(1) manual " .
"page.\n";
}
- exit($had_error);
+ my $status = 0;
+ $status = 2 if ($had_error);
+ exit($status);
}
&usage(0) if ($want_help);
@@ -89,7 +97,7 @@ my (@encoding, %in_encoding);
my (%width, %height, %depth);
my (%left_side_bearing, %right_side_bearing);
-open(AFM, $afm) || die "$prog: can't open '$ARGV[0]': $!\n";
+open(AFM, $afm) || croak("unable to open '$ARGV[0]': $!\n");
while (<AFM>) {
chomp;
@@ -203,7 +211,7 @@ my ($sizescale, $resolution, $unitwidth);
$sizescale = 1;
open(DESC, $desc) || open(DESC, $sys_desc) ||
- die "$prog: can't open '$desc' or '$sys_desc': $!\n";
+ croak("unable to open '$desc' or '$sys_desc': $!\n");
while (<DESC>) {
next if /^#/;
chop;
@@ -227,7 +235,7 @@ if ($opt_e) {
my $sys_opt_e = $groff_sys_fontdir . "/devps/" . $opt_e;
open(ENCODING, $opt_e) || open(ENCODING, $sys_opt_e) ||
- die "$prog: can't open '$opt_e' or '$sys_opt_e': $!\n";
+ croak("unable to open '$opt_e' or '$sys_opt_e': $!\n");
while (<ENCODING>) {
next if /^#/;
chop;
@@ -248,7 +256,7 @@ if ($opt_e) {
my (%nmap, %map);
open(MAP, $map) || open(MAP, $sys_map) ||
- die "$prog: can't open '$map' or '$sys_map': $!\n";
+ croak("unable to open '$map' or '$sys_map': $!\n");
while (<MAP>) {
next if /^#/;
chop;
@@ -441,7 +449,8 @@ foreach my $lig (sort keys %default_ligatures) {
# print it all out
-open(FONT, ">$outfile") || die "$prog: can't open '$outfile' for output: $!\n";
+open(FONT, ">$outfile") ||
+ croak("unable to open '$outfile' for writing: $!\n");
select(FONT);
print("# This file was generated with $afmtodit_version.\n");
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 20/40: [afmtodit]: Handle fatal exits more idiomatically.,
G. Branden Robinson <=