[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 23/44: [troff]: Exercise warning category "missing" more.
From: |
G. Branden Robinson |
Subject: |
[groff] 23/44: [troff]: Exercise warning category "missing" more. |
Date: |
Tue, 3 Sep 2024 08:05:45 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 2f6a72b9e3736d130875efad249a7342d3d32e4b
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Sep 3 01:54:09 2024 -0500
[troff]: Exercise warning category "missing" more.
* src/roff/troff/reg.cpp (define_register, alter_format, remove_reg)
(alias_reg, rename_reg): Give warning category "missing" more
exercise. Handle omitted register arguments where we can communicate
more information about where request parsing has gone wrong.
* src/roff/troff/reg.cpp (define_register, alter_format, alias_reg): Add
assertions for paranoia's sake.
Exhibit:
$ cat ATTIC/missing-args-reg.groff
.af
.af a
.aln
.aln a
.nr
.nr a
.rnn
.rnn a
.rr
Before:
$ ~/groff-HEAD/bin/nroff -ww ATTIC/missing-args-reg.groff
troff:...:1: warning: missing identifier
troff:...:2: warning: missing register format
troff:...:3: warning: missing identifier
troff:...:4: warning: missing identifier
troff:...:5: warning: missing identifier
troff:...:6: warning: numeric expression missing
troff:...:7: warning: missing identifier
troff:...:8: warning: missing identifier
After:
$ ./build/test-groff -ww ATTIC/missing-args-reg.groff
troff:...:1: warning: register interpolation format assignment request
expects arguments
troff:...:2: warning: register interpolation format assignment request
register format as second argument
troff:...:3: warning: register aliasing request expects arguments
troff:...:4: warning: register aliasing request expects identifier of
existing register as second argument
troff:...:5: warning: register definition request expects arguments
troff:...:6: warning: register definition request expects a numeric
expression as second argument
troff:...:7: warning: register renaming request expects arguments
troff:...:8: warning: register renaming request exepects new identifier as
second argument
troff:...:9: warning: register removal request expects arguments
---
ChangeLog | 10 +++++++++
src/roff/troff/reg.cpp | 61 +++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 61 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ee089ce13..fd78226bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-09-03 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/roff/troff/reg.cpp (define_register, alter_format)
+ (remove_reg, alias_reg, rename_reg): Give warning category
+ "missing" more exercise. Handle omitted register arguments
+ where we can communicate more information about where request
+ parsing has gone wrong.
+ * src/roff/troff/reg.cpp (define_register, alter_format)
+ (alias_reg): Add assertions for paranoia's sake.
+
2024-09-02 G. Branden Robinson <g.branden.robinson@gmail.com>
* src/roff/troff/input.cpp (define_color, device_request):
diff --git a/src/roff/troff/reg.cpp b/src/roff/troff/reg.cpp
index 1264a6f23..e1c77b8e3 100644
--- a/src/roff/troff/reg.cpp
+++ b/src/roff/troff/reg.cpp
@@ -307,7 +307,14 @@ bool variable_reg::get_value(units *res)
void define_register()
{
- symbol nm = get_name(true /* required */);
+ if (!has_arg()) {
+ warning(WARN_MISSING, "register definition request expects"
+ " arguments");
+ skip_line();
+ return;
+ }
+ symbol nm = get_name();
+ assert(nm != 0 /* nullptr */);
if (nm.is_null()) {
skip_line();
return;
@@ -317,6 +324,12 @@ void define_register()
units prev_value;
if ((0 /* nullptr */ == r) || !r->get_value(&prev_value))
prev_value = 0;
+ if (!has_arg()) {
+ warning(WARN_MISSING, "register definition request expects"
+ " a numeric expression as second argument");
+ skip_line();
+ return;
+ }
if (read_measurement(&v, 'u', prev_value)) {
if (0 /* nullptr */ == r) {
r = new number_reg;
@@ -398,11 +411,14 @@ reg *look_up_register(symbol nm)
void alter_format()
{
- symbol nm = get_name(true /* required */);
- if (nm.is_null()) {
+ if (!has_arg()) {
+ warning(WARN_MISSING, "register interpolation format assignment"
+ " request expects arguments");
skip_line();
return;
}
+ symbol nm = get_name();
+ assert(nm != 0 /* nullptr */);
reg *r = static_cast<reg *>(register_dictionary.lookup(nm));
if (0 /* nullptr */ == r) {
r = new number_reg;
@@ -421,7 +437,8 @@ void alter_format()
else if (c == 'i' || c == 'I' || c == 'a' || c == 'A')
r->alter_format(c);
else if (tok.is_newline() || tok.is_eof())
- warning(WARN_MISSING, "missing register format");
+ warning(WARN_MISSING, "register interpolation format assignment"
+ " request register format as second argument");
else
error("invalid register format; expected 'i', 'I', 'a', 'A',"
" or decimal digits, got %1", tok.description());
@@ -430,6 +447,11 @@ void alter_format()
void remove_reg()
{
+ if (!has_arg()) {
+ warning(WARN_MISSING, "register removal request expects arguments");
+ skip_line();
+ return;
+ }
for (;;) {
symbol s = get_name();
if (s.is_null())
@@ -441,10 +463,20 @@ void remove_reg()
void alias_reg()
{
- symbol s1 = get_name(true /* required */);
+ if (!has_arg()) {
+ warning(WARN_MISSING, "register aliasing request expects"
+ " arguments");
+ skip_line();
+ return;
+ }
+ symbol s1 = get_name();
+ assert(s1 != 0 /* nullptr */);
if (!s1.is_null()) {
- symbol s2 = get_name(true /* required */);
- if (!s2.is_null()) {
+ symbol s2 = get_name();
+ if (s2.is_null())
+ warning(WARN_MISSING, "register aliasing request expects"
+ " identifier of existing register as second argument");
+ else {
if (!register_dictionary.alias(s1, s2))
error("cannot alias undefined register '%1'", s2.contents());
}
@@ -454,10 +486,19 @@ void alias_reg()
void rename_reg()
{
- symbol s1 = get_name(true /* required */);
+ if (!has_arg()) {
+ warning(WARN_MISSING, "register renaming request expects"
+ " arguments");
+ skip_line();
+ return;
+ }
+ symbol s1 = get_name();
if (!s1.is_null()) {
- symbol s2 = get_name(true /* required */);
- if (!s2.is_null())
+ symbol s2 = get_name();
+ if (s2.is_null())
+ warning(WARN_MISSING, "register renaming request exepects new"
+ " identifier as second argument");
+ else
register_dictionary.rename(s1, s2);
}
skip_line();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 23/44: [troff]: Exercise warning category "missing" more.,
G. Branden Robinson <=