gbranden pushed a commit to branch master
in repository groff.
commit d7fdc9f415005f2ee2c26e02497199f2dfe87ddb
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Nov 30 15:38:21 2023 -0600
[troff]: Improve font-related diagnostics.
* src/roff/troff/node.cpp (mount_font_at_position)
(associate_style_with_font_position, select_underline_font)
(define_font_specific_character, remove_font_specific_character)
(configure_track_kerning, (constantly_space_font): Throw warning in
category `missing` if given no arguments.
(set_font_specific_special_fonts, set_special_fonts): Demote
diagnostic when given no arguments to warning in category `missing`.
(mount_font_at_position, associate_style_with_font_position): Report
invalid font mounting position in error diagostic.
(associate_style_with_font_position): Throw warning in category
`missing` if given only one argument.
This commit omits updates to indentation to clarify the logic change.
This also results in a more consistent 1-to-1 relationship between
diagnostics and invalid input lines, a more reliable line number report,
and diagnostic wording that doesn't presume that requests haven't been
renamed.
See commit 44db6efc01, 3 November.
Input:
$ nl node-diags.groff
1 .fp
2 .fp -1
3 .sty
4 .sty -1
5 .uf
6 .fschar
7 .rfschar
8 .fspecial
9 .special
10 .tkf
11 .cs
Before:
$ ~/groff-stable/bin/groff -ww ATTIC/node-diags.groff
troff:node-diags.groff:0: warning: numeric expression missing
troff:node-diags.groff:1: error: negative font position
troff:node-diags.groff:2: warning: numeric expression missing
troff:node-diags.groff:3: error: negative font position
troff:node-diags.groff:4: warning: numeric expression missing
troff:node-diags.groff:4: error: cannot load font at position -1 to make it
the underline font
troff:node-diags.groff:5: warning: numeric expression missing
troff:node-diags.groff:6: error: cannot load font at position -1 to define
font-specific fallback glyph
troff:node-diags.groff:7: warning: numeric expression missing
troff:node-diags.groff:7: error: cannot load font at position -1 to remove
font-specific fallback glyph
troff:node-diags.groff:8: warning: numeric expression missing
troff:node-diags.groff:8: error: cannot load font at position -1 to mark
other fonts as special contingently upon it
troff:node-diags.groff:10: warning: numeric expression missing
troff:node-diags.groff:10: error: cannot load font at position -1 for track
kerning
troff:node-diags.groff:11: warning: numeric expression missing
troff:node-diags.groff:11: error: cannot load font at position -1 for
constant spacing
Now:
$ ./build/test-groff -ww ATTIC/node-diags.groff
troff:ATTIC/node-diags.groff:1: warning: font mounting request expects
arguments
troff:ATTIC/node-diags.groff:2: error: font mounting position -1 is negative
troff:ATTIC/node-diags.groff:3: warning: abstract style configuration
request expects arguments
troff:ATTIC/node-diags.groff:4: error: font mounting position -1 is negative
troff:ATTIC/node-diags.groff:5: warning: underline font selection request
expects arguments
troff:ATTIC/node-diags.groff:6: warning: font-specific fallback character
definition request expects arguments
troff:ATTIC/node-diags.groff:7: warning: font-specific fallback character
removal request expects arguments
troff:ATTIC/node-diags.groff:8: warning: font-specific special font
configuration request expects one or more arguments
troff:ATTIC/node-diags.groff:9: warning: global special font configuration
request expects one or more arguments
troff:ATTIC/node-diags.groff:10: warning: track kerning request expects
arguments
troff:ATTIC/node-diags.groff:11: warning: constant spacing request expects
arguments
---
ChangeLog | 20 ++++++++++++++++++
src/roff/troff/node.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 72 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4a16ebf0d..c6ac99863 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2023-11-29 G. Branden Robinson <[email protected]>
+
+ [troff]: Improve font-related diagnostics.
+
+ * src/roff/troff/node.cpp (mount_font_at_position)
+ (associate_style_with_font_position, select_underline_font)
+ (define_font_specific_character, remove_font_specific_character)
+ (configure_track_kerning, (constantly_space_font): Throw warning
+ in category `missing` if given no arguments.
+
+ (set_font_specific_special_fonts, set_special_fonts): Demote
+ diagnostic when given no arguments to warning in category
+ `missing`.
+
+ (mount_font_at_position, associate_style_with_font_position):
+ Report invalid font mounting position in error diagostic.
+
+ (associate_style_with_font_position): Throw warning in category
+ `missing` if given only one argument.
+
2023-11-29 G. Branden Robinson <[email protected]>
[troff]: Improve `hcode` request validation.
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 0b6122157..c9e31be77 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -6061,11 +6061,17 @@ static void translate_font()
static void mount_font_at_position()
{
+ if (!has_arg()) {
+ warning(WARN_MISSING, "font mounting request expects arguments");
+ skip_line();
+ return;
+ }
int n;
if (get_integer(&n)) {
if (n < 0)
- error("negative font position");
+ error("font mounting position %1 is negative", n);
else {
+ // TODO: Make argument optional to clear the mounting position?
symbol internal_name = get_name(true /* required */);
if (!internal_name.is_null()) {
symbol external_name = get_long_name();
@@ -6173,14 +6179,26 @@ void font_family::invalidate_fontno(int n)
static void associate_style_with_font_position()
{
+ if (!has_arg()) {
+ warning(WARN_MISSING, "abstract style configuration request expects"
+ " arguments");
+ skip_line();
+ return;
+ }
int n;
if (get_integer(&n)) {
if (n < 0)
- error("negative font position");
+ error("font mounting position %1 is negative", n);
else {
+ // TODO: Make argument optional to clear the mounting position?
+ if (!has_arg())
+ warning(WARN_MISSING, "abstract style configuration request"
+ " expects a second argument");
+ else {
symbol internal_name = get_name(true /* required */);
if (!internal_name.is_null())
(void) mount_style(n, internal_name);
+ }
}
}
skip_line();
@@ -6229,6 +6247,12 @@ static int underline_fontno = 2;
static void select_underline_font()
{
+ if (!has_arg()) {
+ warning(WARN_MISSING, "underline font selection request expects"
+ " arguments");
+ skip_line();
+ return;
+ }
font_lookup_info finfo;
if (!has_font(&finfo))
font_lookup_error(finfo, "to make it the underline font");
@@ -6244,6 +6268,12 @@ int get_underline_fontno()
static void define_font_specific_character()
{
+ if (!has_arg()) {
+ warning(WARN_MISSING, "font-specific fallback character definition"
+ " request expects arguments");
+ skip_line();
+ return;
+ }
font_lookup_info finfo;
if (!has_font(&finfo)) {
font_lookup_error(finfo, "to define font-specific fallback glyph");
@@ -6260,6 +6290,12 @@ static void define_font_specific_character()
static void remove_font_specific_character()
{
+ if (!has_arg()) {
+ warning(WARN_MISSING, "font-specific fallback character removal"
+ " request expects arguments");
+ skip_line();
+ return;
+ }
font_lookup_info finfo;
if (!has_font(&finfo))
font_lookup_error(finfo, "to remove font-specific fallback glyph");
@@ -6312,7 +6348,8 @@ static void read_special_fonts(special_font_list **sp)
static void set_font_specific_special_fonts()
{
if (!has_arg()) {
- error("fspecial request requires at least one font argument");
+ warning(WARN_MISSING, "font-specific special font configuration"
+ " request expects one or more arguments");
skip_line();
return;
}
@@ -6328,7 +6365,8 @@ static void set_font_specific_special_fonts()
static void set_special_fonts()
{
if (!has_arg()) {
- error("special request requires at least one font argument");
+ warning(WARN_MISSING, "global special font configuration request"
+ " expects one or more arguments");
skip_line();
return;
}
@@ -6586,6 +6624,11 @@ hunits track_kerning_function::compute(int size)
static void configure_track_kerning()
{
+ if (!(has_arg())) {
+ warning(WARN_MISSING, "track kerning request expects arguments");
+ skip_line();
+ return;
+ }
font_lookup_info finfo;
if (!has_font(&finfo))
font_lookup_error(finfo, "for track kerning");
@@ -6610,6 +6653,11 @@ static void configure_track_kerning()
static void constantly_space_font()
{
+ if (!(has_arg())) {
+ warning(WARN_MISSING, "constant spacing request expects arguments");
+ skip_line();
+ return;
+ }
font_lookup_info finfo;
if (!has_font(&finfo))
font_lookup_error(finfo, "for constant spacing");
_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit