[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 03/03: tmac/s.tmac: Improve diagnostic messages.
From: |
G. Branden Robinson |
Subject: |
[groff] 03/03: tmac/s.tmac: Improve diagnostic messages. |
Date: |
Mon, 1 Mar 2021 19:41:37 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit c7b14cb8f84b102dd591843a4e7fc2fbfe2a25a3
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Mar 2 10:38:01 2021 +1100
tmac/s.tmac: Improve diagnostic messages.
(@diag): New macro wraps .tm request, always prefixing it with the name
of the macro package, as well as file and line indicators only if these
are set to non-empty or non-zero values, respectively.
(@error, @warning): Call @diag instead of .tm directly.
(@fatal): Retire; it had only one call site and it would have greatly
complicated @diag to support calling .ab instead of .tm. An ugly
alternative would have been to call .ab with a redundant message after
calling @diag.
(@divert): New macro wraps .di request, remembering the name of
the current file (\n[.F]) when a diversion is started.
(@error-recover): Call .ab instead of (deleted) @fatal.
(pg@super-eject): Tell user what the last file name seen was when
recovering from an unfinished diversion when processing ends.
Examples of improved output compared to groff 1.22.4 follow.
$ (printf ".TL\n" > foo.ms; nroff -ms foo.ms | sed '/^$/d'; rm foo.ms)
:0: macro error: diversion open while ejecting page (recovering)
$ (printf ".TL\n" > foo.ms; ./build/test-groff -ms foo.ms \
| sed '/^$/d'; rm foo.ms)
s.tmac: error: diversion open while ejecting page (last file seen: foo.ms)
(recovering)
$ (printf '.nr a 23 1\n.while \\n-a .di d\\na\n' > foo.ms; \
nroff -ms foo.ms | sed '/^$/d'; \rm foo.ms)
:0: macro error: diversion open while ejecting page (recovering)
:0: fatal macro error: recovery failed
$ (printf '.nr a 23 1\n.while \\n-a .di d\\na\n' > foo.ms; \
./build/test-groff -ms foo.ms | sed '/^$/d'; \rm foo.ms)
s.tmac: error: diversion open while ejecting page (last file seen: foo.ms)
(recovering)
s.tmac: fatal error: recovery failed
---
ChangeLog | 19 +++++++++++++++++++
tmac/s.tmac | 38 +++++++++++++++++++++++++++++++-------
2 files changed, 50 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 464eaea..e52790a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2021-03-01 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * tmac/s.tmac: Improve diagnostic messages.
+ (@diag): New macro wraps .tm request, always prefixing it with
+ the name of the macro package, as well as file and line
+ indicators only if these are set to non-empty or non-zero
+ values, respectively.
+ (@error, @warning): Call @diag instead of .tm directly.
+ (@fatal): Retire; it had only one call site and it would have
+ greatly complicated @diag to support calling .ab instead of .tm.
+ An ugly alternative would have been to call .ab with a redundant
+ message after calling @diag.
+ (@divert): New macro wraps .di request, remembering the name of
+ the current file (\n[.F]) when a diversion is started.
+ (@error-recover): Call .ab instead of (deleted) @fatal.
+ (pg@super-eject): Tell user what the last file name seen was
+ when recovering from an unfinished diversion when processing
+ ends.
+
2021-02-25 G. Branden Robinson <g.branden.robinson@gmail.com>
Fix bug where having line numbering off but the output line
diff --git a/tmac/s.tmac b/tmac/s.tmac
index 1978ae9..f00fecd 100644
--- a/tmac/s.tmac
+++ b/tmac/s.tmac
@@ -36,15 +36,24 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>.
.\" Define a string for use in diagnostic messages.
.ds @s s.tmac\"
.
+.de @diag
+. ds *file \" empty
+. ds *line \" empty
+. if !'\\n[.F]'' .ds *file \\n[.F]:\"
+. if !'\\n[.c]'0' .ds *line \\n[.c]:\"
+. tm \*[@s]:\\*[*file]\\*[*line] \\$*
+. rm *file
+. rm *line
+..
+.
.de @error
-.tm \*[@s]:\\n(.F:\\n(.c: error: \\$*
+. @diag error: \\$*
..
+.
.de @warning
-.tm \*[@s]:\\n(.F:\\n(.c: warning: \\$*
-..
-.de @fatal
-.ab \*[@s]:\\n(.F:\\n(.c: fatal error: \\$*
+. @diag warning: \\$*
..
+.
.de @not-implemented
.@error sorry, .\\$0 not implemented
.als \\$0 @nop
@@ -56,6 +65,16 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>.
.als CT @not-implemented
.de @nop
..
+.
+.\" Wrap the .di request to save the name of the file being processed
+.\" when a diversion is started. This aids diagnostics when diversions
+.\" are still open after input has been processed and \n[.F] is empty.
+.als @divert di
+.de di
+. if \\n[.$] .ds @last-file-seen \\n[.F]\"
+. @divert \\$*
+..
+.
.de @init
.if !rPO .nr PO \\n(.o
.\" a non-empty environment
@@ -104,7 +123,7 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>.
. el .*div-end-default
. nr *pop-count +1
. \" ensure that we don't loop forever
-. if \\n[*pop-count]>20 .@fatal recovery failed
+. if \\n[*pop-count]>20 .ab \*[@s]: fatal error: recovery failed
.\}
.while !'\\n[.ev]'0' .ev
.par@reset-env
@@ -633,7 +652,12 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>.
.\" flush out any keeps or footnotes
.de pg@super-eject
.br
-.if !'\\n(.z'' .@error-recover diversion open while ejecting page
+.if !'\\n(.z'' \{\
+. ds @msg diversion open while ejecting page\"
+. as @msg " (last file seen: \\*[@last-file-seen])\"
+. @error-recover \\*[@msg]
+. rm @msg
+.\}
.\" Make sure we stay in the end macro while there is still footnote
.\" overflow left, or floating keeps.
.while \\n[kp@tail]>\\n[kp@head]:\\n[pg@fn-flag] \{\
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 03/03: tmac/s.tmac: Improve diagnostic messages.,
G. Branden Robinson <=