groff-commit
[Top][All Lists]
Advanced

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

[groff] 01/01: Improve diagnostics on bad hyphenation requests.


From: G. Branden Robinson
Subject: [groff] 01/01: Improve diagnostics on bad hyphenation requests.
Date: Mon, 7 May 2018 14:38:21 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 187f9a9600c1c486f1dd5b5c08612c43fce5074b
Author: G. Branden Robinson <address@hidden>
Date:   Mon May 7 14:36:25 2018 -0400

    Improve diagnostics on bad hyphenation requests.
    
    src/roff/troff/env.cpp:
    * Warn about hyphenation request values that are completely out
      out of range; report accepted range (caveat: much of the
      "legal" range is still rejected due to bad semantics).
    * Report bad hyphenation request value in diagnostic messages.
    
    Thanks to Ralph Corderoy and Werner Lemberg for the code reviews.
    
    Signed-off-by: G. Branden Robinson <address@hidden>
---
 ChangeLog              | 10 ++++++++++
 src/roff/troff/env.cpp | 17 ++++++++++++++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 90b3436..e473bad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2018-05-07  G. Branden Robinson <address@hidden>
+
+       Improve diagnostics on bad hyphenation requests.
+
+       src/roff/troff/env.cpp:
+       * Warn about hyphenation request values that are completely out
+         out of range; report accepted range (caveat: much of the
+         "legal" range is still rejected due to bad semantics).
+       * Report bad hyphenation request value in diagnostic messages.
+
 2018-04-28  G. Branden Robinson <address@hidden>
 
        grap2graph: Parallelize changes with pic2graph.
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 882ad7d..22b9493 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -39,11 +39,15 @@ symbol default_family("T");
 enum { ADJUST_LEFT = 0, ADJUST_BOTH = 1, ADJUST_CENTER = 3, ADJUST_RIGHT = 5 };
 
 enum {
+  // Not all combinations are legal; see hyphenate_request() below.
+  HYPHEN_NONE = 0,
+  HYPHEN_DEFAULT = 1,
   HYPHEN_NOT_LAST_LINE = 2,
   HYPHEN_NOT_LAST_CHARS = 4,
   HYPHEN_NOT_FIRST_CHARS = 8,
   HYPHEN_LAST_CHAR = 16,
-  HYPHEN_FIRST_CHAR = 32
+  HYPHEN_FIRST_CHAR = 32,
+  HYPHEN_MAX = 63,
 };
 
 struct env_list {
@@ -1658,9 +1662,16 @@ void hyphenate_request()
 {
   int n;
   if (has_arg() && get_integer(&n)) {
-    if (((n & HYPHEN_FIRST_CHAR) && (n & HYPHEN_NOT_FIRST_CHARS))
+    if (n < HYPHEN_NONE) {
+      warning(WARN_RANGE, "negative hyphenation flags ignored: %1", n);
+    } else if (n > HYPHEN_MAX) {
+      warning(WARN_RANGE, "unknown hyphenation flags ignored (maximum "
+       "%1): %2", HYPHEN_MAX, n);
+    } else if (((n & HYPHEN_DEFAULT) && (n & ~HYPHEN_DEFAULT))
+       || ((n & HYPHEN_FIRST_CHAR) && (n & HYPHEN_NOT_FIRST_CHARS))
        || ((n & HYPHEN_LAST_CHAR) && (n & HYPHEN_NOT_LAST_CHARS)))
-      warning(WARN_SYNTAX, "contradicting hyphenation flags, ignored");
+      warning(WARN_SYNTAX, "contradictory hyphenation flags ignored: "
+       "%1", n);
     else
       curenv->hyphenation_flags = n;
   }



reply via email to

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