groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 01/01: Improve point-size escape diagnostics.


From: G. Branden Robinson
Subject: [groff] 01/01: Improve point-size escape diagnostics.
Date: Fri, 3 Apr 2020 11:46:27 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit a09d9c4aa325cde5695967ac6221078e74843b91
Author: G. Branden Robinson <address@hidden>
AuthorDate: Sat Apr 4 02:37:17 2020 +1100

    Improve point-size escape diagnostics.
    
    src/roff/troff/input.cpp (read_size): Disclose context (point-size
    escape intepretation) in diagnostic messages.  When a "bad digit" is
    encountered, describe it if possible.  When a relative adjustment
    results in a negative point size, report the computed value.  Also
    rename a variable for slightly more clarity ("bad" does not refer to all
    bad parses, just some cases of bad digits), and update an insufficiently
    generalized comment ("\s(00" is also an acceptable expression for
    point-size zero).
    
    Based on suggestions by Ingo Schwarze and Bjarni Ingi Gislason.
    
    Tested with -ww on:
    \s[1
    \s'1
    \s(1A\s(1\%\s4\s-6
---
 ChangeLog                | 15 +++++++++++++++
 src/roff/troff/input.cpp | 31 ++++++++++++++++++-------------
 2 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d965739..ab971e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2020-04-04  G. Branden Robinson <address@hidden>
+
+       Improve point-size escape diagnostics.
+
+       * src/roff/troff/input.cpp (read_size): Disclose context
+       {point-size escape intepretation} in diagnostic messages.  When
+       a "bad digit" is encountered, describe it if possible.  When a
+       relative adjustment results in a negative point size, report the
+       computed value.  Also rename a variable for slightly more
+       clarity ("bad" does not refer to all bad parses, just some cases
+       of bad digits), and update an insufficiently generalized comment
+       {"\s(00" is also an acceptable expression for point-size zero}.
+
+       Based on suggestions by Ingo Schwarze and Bjarni Ingi Gislason.
+
 2020-04-01  G. Branden Robinson <address@hidden>
 
        Align diagnostic message format.
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index fb990bd..d9190fa 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -5043,7 +5043,7 @@ static int read_size(int *x)
     c = tok.ch();
   }
   int val = 0;         // pacify compiler
-  int bad = 0;
+  int bad_digit = 0;
   if (c == '(') {
     tok.next();
     c = tok.ch();
@@ -5061,13 +5061,13 @@ static int read_size(int *x)
       }
     }
     if (!csdigit(c))
-      bad = 1;
+      bad_digit = 1;
     else {
       val = c - '0';
       tok.next();
       c = tok.ch();
       if (!csdigit(c))
-       bad = 1;
+       bad_digit = 1;
       else {
        val = val*10 + (c - '0');
        val *= sizescale;
@@ -5080,7 +5080,7 @@ static int read_size(int *x)
       tok.next();
       c = tok.ch();
       if (!csdigit(c))
-       bad = 1;
+       bad_digit = 1;
       else
        val = val*10 + (c - '0');
     }
@@ -5100,17 +5100,25 @@ static int read_size(int *x)
       return 0;
     if (!(start.ch() == '[' && tok.ch() == ']') && start != tok) {
       if (start.ch() == '[')
-       error("missing ']'");
+       error("missing ']' in point-size escape");
       else
-       error("missing closing delimiter");
+       error("missing closing delimiter in point-size escape");
       return 0;
     }
   }
-  if (!bad) {
+  if (bad_digit) {
+    if (c)
+      error("bad digit in point-size escape: %1",
+           input_char_description(c));
+    else
+      error("bad digit in point-size escape");
+    return 0;
+  }
+  else {
     switch (inc) {
     case 0:
       if (val == 0) {
-       // special case -- \s[0] and \s0 means to revert to previous size
+       // special case -- point size 0 means "revert to previous size"
        *x = 0;
        return 1;
       }
@@ -5127,15 +5135,12 @@ static int read_size(int *x)
     }
     if (*x <= 0) {
       warning(WARN_RANGE,
-             "\\s escape results in non-positive point size; set to 1");
+             "point-size escape results in non-positive argument %1;"
+             " set to 1", *x);
       *x = 1;
     }
     return 1;
   }
-  else {
-    error("bad digit in point size");
-    return 0;
-  }
 }
 
 static symbol get_delim_name()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]