[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 04/39: [pfbtops]: Fix code style and diagnostic nits.
From: |
G. Branden Robinson |
Subject: |
[groff] 04/39: [pfbtops]: Fix code style and diagnostic nits. |
Date: |
Sat, 29 Oct 2022 14:59:55 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 8ad4f0ad75f5a63d945e9f3f865b691fa56df484
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Oct 24 11:52:17 2022 -0500
[pfbtops]: Fix code style and diagnostic nits.
* src/utils/pfbtops/pfbtops.c (error): Exit with `EXIT_FAILURE` status
(from standard C library) instead of status 2.
(main): Exit with `EXIT_SUCCESS` status when writing version or help
information. Exit with status 2 when dying due to usage error. Use
`fprintf()` and `strerror()` to construct error message when dying due
to inability to open input file instead of using `perror()`, which
anonymizes its caller and thus should never be used in serious work.
Avoid it like `gets()`.
* NEWS: Add item for exit status changes.
Continues the long process of fixing Savannah #52463.
Also update editor aid comments.
---
ChangeLog | 16 ++++++++++++++++
NEWS | 4 ++++
src/utils/pfbtops/pfbtops.c | 32 +++++++++++++++++++++-----------
3 files changed, 41 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 893dcc49f..d446fbf46 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2022-10-24 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ [pfbtops]: Fix code style and diagnostic nits.
+
+ * src/utils/pfbtops/pfbtops.c (error): Exit with `EXIT_FAILURE`
+ status (from standard C library) instead of status 2.
+ (main): Exit with `EXIT_SUCCESS` status when writing version or
+ help information. Exit with status 2 when dying due to usage
+ error. Use `fprintf()` and `strerror()` to construct error
+ message when dying due to inability to open input file instead
+ of using `perror()`, which anonymizes its caller and thus should
+ never be used in serious work. Avoid it like `gets()`.
+ * NEWS: Add item for exit status changes.
+
+ Continues the long process of fixing Savannah #52463.
+
2022-10-24 G. Branden Robinson <g.branden.robinson@gmail.com>
[man pages]: Don't document macro package compatibility wrapper
diff --git a/NEWS b/NEWS
index c777ea1ae..ed9b4d9df 100644
--- a/NEWS
+++ b/NEWS
@@ -601,6 +601,10 @@ o The "afmtodit" utility no longer writes file names with
directory
it generates. (The `fp` request no longer accepts such names; see
"troff" above.)
+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.
+
o groffer has been deleted from the distribution.
o grog no longer supports the "--warnings" option; the one diagnostic
diff --git a/src/utils/pfbtops/pfbtops.c b/src/utils/pfbtops/pfbtops.c
index 81edee422..8fbe44a79 100644
--- a/src/utils/pfbtops/pfbtops.c
+++ b/src/utils/pfbtops/pfbtops.c
@@ -24,8 +24,10 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
#define __GETOPT_PREFIX groff_
+#include <errno.h> // errno
#include <stdio.h>
-#include <stdlib.h>
+#include <stdlib.h> // exit(), EXIT_FAILURE, EXIT_SUCCESS
+#include <string.h> // strerror()
#include <limits.h>
#include <getopt.h>
@@ -43,8 +45,8 @@ static char *program_name;
static void error(const char *s)
{
- fprintf(stderr, "%s: %s\n", program_name, s);
- exit(2);
+ fprintf(stderr, "%s: error: %s\n", program_name, s);
+ exit(EXIT_FAILURE);
}
static void usage(FILE *stream)
@@ -181,26 +183,28 @@ int main(int argc, char **argv)
switch (opt) {
case 'v':
printf("GNU pfbtops (groff) version %s\n", Version_string);
- exit(0);
+ exit(EXIT_SUCCESS);
break;
case CHAR_MAX + 1: /* --help */
usage(stdout);
- exit(0);
+ exit(EXIT_SUCCESS);
break;
case '?':
usage(stderr);
- exit(1);
+ exit(2);
break;
}
}
if (argc - optind > 1) {
usage(stderr);
- exit(1);
+ exit(2);
}
- if (argc > optind && !freopen(argv[optind], "r", stdin)) {
- perror(argv[optind]);
- exit(1);
+ const char *file = argv[optind];
+ if (argc > optind && !freopen(file, "r", stdin)) {
+ fprintf(stderr, "%s: error: unable to open file '%s': %s\n",
+ program_name, file, strerror(errno));
+ exit(EXIT_FAILURE);
}
SET_BINARY(fileno(stdin));
for (;;) {
@@ -229,5 +233,11 @@ int main(int argc, char **argv)
else
get_binary(n);
}
- exit(0);
+ exit(EXIT_SUCCESS);
}
+
+// Local Variables:
+// fill-column: 72
+// mode: C
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 04/39: [pfbtops]: Fix code style and diagnostic nits.,
G. Branden Robinson <=