[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 06/14: [grog]: Revise arg handling, diagnostics, exit.
From: |
G. Branden Robinson |
Subject: |
[groff] 06/14: [grog]: Revise arg handling, diagnostics, exit. |
Date: |
Mon, 28 Jun 2021 00:44:50 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 350002e984e8472ed49385202e2bc32f02bf5b8e
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Jun 27 14:20:56 2021 +1000
[grog]: Revise arg handling, diagnostics, exit.
* src/utils/grog/grog.pl: Track more state so that we can process the
argument list more intelligently and exit with a meaningful status.
Add `had_inference_problem`, `had_processing_problem`, and
`have_any_valid_args` Boolean scalars.
(fail): Add diagnostic subroutine for serious problems; sets
`had_processing_problem`.
(handle_args, handle_file_ext): Stop complaining here about unopenable
file operands.
(handle_whole_files): Complain only here, with `fail` if a file
operand cannot be opened.
(make_groff_line_rest): Don't exit immediately if there is a macro
package inference clash, because there might be more operands to
process. Instead, set `had_inference_problem`. Stop exiting from
this subroutine.
(top level): Only call the inference subroutines if we had a valid
operand to work with (including an implicit read from stdin). Exit
with a status corresponding to the Booleans declared above.
* src/utils/grog/grog.1.man (Exit status): Add section; describe
semantics of exit status values.
Fixes <https://savannah.gnu.org/bugs/index.php?60833>.
---
ChangeLog | 29 +++++++++++++++++++++++++++++
src/utils/grog/grog.1.man | 23 +++++++++++++++++++++++
src/utils/grog/grog.pl | 46 ++++++++++++++++++++++++++--------------------
3 files changed, 78 insertions(+), 20 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 030e428..284c342 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,34 @@
2021-06-27 G. Branden Robinson <g.branden.robinson@gmail.com>
+ [grog]: Revise operand handling, diagnostics, and exit status.
+
+ * src/utils/grog/grog.pl: Track more state so that we can
+ process the argument list more intelligently and exit with a
+ meaningful status. Add `had_inference_problem`,
+ `had_processing_problem`, and `have_any_valid_args` Boolean
+ scalars.
+ (fail): Add diagnostic subroutine for serious problems; sets
+ `had_processing_problem`.
+ (handle_args, handle_file_ext): Stop complaining here about
+ unopenable file operands.
+ (handle_whole_files): Complain only here, with `fail` if a file
+ operand cannot be opened.
+ (make_groff_line_rest): Don't exit immediately if there is a
+ macro package inference clash, because there might be more
+ operands to process. Instead, set `had_inference_problem`.
+ Stop exiting from this subroutine.
+ (top level): Only call the inference subroutines if we had a
+ valid operand to work with (including an implicit read from
+ stdin). Exit with a status corresponding to the Booleans
+ declared above.
+
+ * src/utils/grog/grog.1.man (Exit status): Add section; describe
+ semantics of exit status values.
+
+ Fixes <https://savannah.gnu.org/bugs/index.php?60833>.
+
+2021-06-27 G. Branden Robinson <g.branden.robinson@gmail.com>
+
[grog]: Revise diagnostic messages.
* src/utils/grog/grog.1.man (err): Rename from this...
diff --git a/src/utils/grog/grog.1.man b/src/utils/grog/grog.1.man
index 5f255c0..2996c28 100644
--- a/src/utils/grog/grog.1.man
+++ b/src/utils/grog/grog.1.man
@@ -361,6 +361,29 @@ groff \-s \-t \-T ps 1.roff
.
.
.\" ====================================================================
+.SH "Exit status"
+.\" ====================================================================
+.
+.I grog
+exits with error status
+.B 1
+if the input document appears to be malformed,
+or
+.B 2
+if there were problems handling an option or operand.
+.
+It otherwise exits with status
+.BR 0 .
+.
+Inferring no preprocessors or macro packages is not an error condition;
+a valid
+.I roff
+document need not use either,
+and even plain text is valid input,
+if one is mindful of the syntax of the control and escape characters.
+.
+.
+.\" ====================================================================
.SH Examples
.\" ====================================================================
.
diff --git a/src/utils/grog/grog.pl b/src/utils/grog/grog.pl
index 9782234..cfcfd51 100644
--- a/src/utils/grog/grog.pl
+++ b/src/utils/grog/grog.pl
@@ -163,6 +163,17 @@ my @filespec;
my $tmac_ext = '';
+my $had_inference_problem = 0;
+my $had_processing_problem = 0;
+my $have_any_valid_args = 0;
+
+
+sub fail {
+ my $text = shift;
+ print STDERR "$Prog: error: $text";
+ $had_processing_problem = 1;
+}
+
sub warn {
my $text = shift;
@@ -202,9 +213,6 @@ sub handle_args {
}
unless ( $arg =~ /^-/ ) { # file name, no opt, no optarg
- unless (-f $arg && -r $arg) {
- print 'unknown file name: ' . $arg;
- }
push @filespec, $arg;
next;
}
@@ -299,13 +307,8 @@ sub handle_file_ext {
# globals: @filespec, $tmac_ext;
foreach my $file ( @filespec ) {
- # test for each file name in the arguments
- unless ( open(FILE, $file eq "-" ? $file : "< $file") ) {
- print STDERR __FILE__ . ' ' . __LINE__ . ': ' .
- "$Prog: can't open \'$file\': $!";
- next;
- }
-
+ # We will complain about unopenable files in &handle_whole_files.
+ next unless ( open(FILE, $file eq "-" ? $file : "< $file") );
next unless ( $file =~ /\./ ); # file name has no dot '.'
# get extension
@@ -397,10 +400,10 @@ sub handle_whole_files {
foreach my $file ( @filespec ) {
unless ( open(FILE, $file eq "-" ? $file : "< $file") ) {
- print STDERR __FILE__ . ' ' . __LINE__ . ': ' .
- "$Prog: can't open \'$file\': $!";
+ &fail("cannot open '$file': $!");
next;
}
+ $have_any_valid_args = 1;
my $line = <FILE>; # get single line
unless ( defined($line) ) {
@@ -1107,7 +1110,7 @@ sub make_groff_line_rest {
print STDERR __FILE__ . ' ' . __LINE__ . ': ' .
'More than 1 -m arguments were guessed: ' . @m;
print STDERR __FILE__ . ' ' . __LINE__ . ': ' . 'Guessing stopped.';
- exit 1;
+ $had_inference_problem = 1;
} elsif ( $nr_m_guessed == 1 ) {
$final_m = $m[0];
} else {
@@ -1127,8 +1130,6 @@ sub make_groff_line_rest {
} else {
print "@Command";
}
-
- exit 0;
} # make_groff_line_rest()
@@ -1184,15 +1185,20 @@ if ($before_make) {
$at_at{'GROFF_VERSION'} = '@VERSION@';
}
-
&handle_args();
&handle_file_ext(); # see $tmac_ext for gotten value
&handle_whole_files();
-&make_groff_device();
-&make_groff_preproc();
-&make_groff_tmac_man_ms() || &make_groff_tmac_others();
-&make_groff_line_rest();
+if ($have_any_valid_args) {
+ &make_groff_device();
+ &make_groff_preproc();
+ &make_groff_tmac_man_ms() || &make_groff_tmac_others();
+ &make_groff_line_rest();
+}
+
+exit 2 if ($had_processing_problem);
+exit 1 if ($had_inference_problem);
+exit 0;
1;
# Local Variables:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 06/14: [grog]: Revise arg handling, diagnostics, exit.,
G. Branden Robinson <=