Getting back on topic... At 2018-05-05T15:43:35+0200, Werner LEMBERG wrote: [...] > Please use `const int' – there is no single instance of `int const' in > the groff code. [...] > >> I'd suggest adding > >> > >> HYPHEN_NONE = 0, > >> HYPHEN_DEFAULT = 1, > >> HYPHEN_MAX = 63 // Or whatever the local naming convention is. > > Yes. > > >> Then test for > >> > >> n > HYPHEN_MAX > >> n & HYPHEN_DEFAULT && n & ~HYPHEN_DEFAULT > >> > >> in addition to the existing [...] > I prefer that.
Fresh patch, test case, and test case output attached. My debugging instincts tell me to always report the value of an argument being rejected. For one thing, the user could have passed .hy a register value (possibly with arithmetic manipulation), and if we screw up the validity checks it's easier to see which cases are incorrect. Comments? -- Regards, Branden
diff --git a/ChangeLog b/ChangeLog index 90b34368..7e4cf348 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2018-05-06 G. Branden Robinson <g.branden.robin...@gmail.com> + + 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 <g.branden.robin...@gmail.com> grap2graph: Parallelize changes with pic2graph. diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp index 882ad7dc..b80c6fe0 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 { + 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, + // The _usable_ maximum is 52; see hyphenate_request() below. + HYPHEN_MAX = 63, }; struct env_list { @@ -1658,9 +1662,14 @@ 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) || (n > HYPHEN_MAX)) { + warning(WARN_RANGE, "hyphenation request value '%1' out of range " + "(must be in %2..%3); ignored", n, HYPHEN_NONE, HYPHEN_MAX); + } 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 flags in hyphenation request " + "value '%1'; ignored", n); else curenv->hyphenation_flags = n; }
.hy -1 .hy 0 .hy 1 .hy 2 .hy 3 .hy 4 .hy 5 .hy 6 .hy 7 .hy 8 .hy 9 .hy 10 .hy 11 .hy 12 .hy 13 .hy 14 .hy 15 .hy 16 .hy 17 .hy 18 .hy 19 .hy 20 .hy 21 .hy 22 .hy 23 .hy 24 .hy 25 .hy 26 .hy 27 .hy 28 .hy 29 .hy 30 .hy 31 .hy 32 .hy 33 .hy 34 .hy 35 .hy 36 .hy 37 .hy 38 .hy 39 .hy 40 .hy 41 .hy 42 .hy 43 .hy 44 .hy 45 .hy 46 .hy 47 .hy 48 .hy 49 .hy 50 .hy 51 .hy 52 .hy 53 .hy 54 .hy 55 .hy 56 .hy 57 .hy 58 .hy 59 .hy 60 .hy 61 .hy 62 .hy 63 .hy 64
troff: ../hy.trf:1: warning: hyphenation request value '-1' out of range (must be in 0..63); ignored troff: ../hy.trf:5: warning: contradictory flags in hyphenation request value '3'; ignored troff: ../hy.trf:7: warning: contradictory flags in hyphenation request value '5'; ignored troff: ../hy.trf:9: warning: contradictory flags in hyphenation request value '7'; ignored troff: ../hy.trf:11: warning: contradictory flags in hyphenation request value '9'; ignored troff: ../hy.trf:13: warning: contradictory flags in hyphenation request value '11'; ignored troff: ../hy.trf:15: warning: contradictory flags in hyphenation request value '13'; ignored troff: ../hy.trf:17: warning: contradictory flags in hyphenation request value '15'; ignored troff: ../hy.trf:19: warning: contradictory flags in hyphenation request value '17'; ignored troff: ../hy.trf:21: warning: contradictory flags in hyphenation request value '19'; ignored troff: ../hy.trf:22: warning: contradictory flags in hyphenation request value '20'; ignored troff: ../hy.trf:23: warning: contradictory flags in hyphenation request value '21'; ignored troff: ../hy.trf:24: warning: contradictory flags in hyphenation request value '22'; ignored troff: ../hy.trf:25: warning: contradictory flags in hyphenation request value '23'; ignored troff: ../hy.trf:27: warning: contradictory flags in hyphenation request value '25'; ignored troff: ../hy.trf:29: warning: contradictory flags in hyphenation request value '27'; ignored troff: ../hy.trf:30: warning: contradictory flags in hyphenation request value '28'; ignored troff: ../hy.trf:31: warning: contradictory flags in hyphenation request value '29'; ignored troff: ../hy.trf:32: warning: contradictory flags in hyphenation request value '30'; ignored troff: ../hy.trf:33: warning: contradictory flags in hyphenation request value '31'; ignored troff: ../hy.trf:35: warning: contradictory flags in hyphenation request value '33'; ignored troff: ../hy.trf:37: warning: contradictory flags in hyphenation request value '35'; ignored troff: ../hy.trf:39: warning: contradictory flags in hyphenation request value '37'; ignored troff: ../hy.trf:41: warning: contradictory flags in hyphenation request value '39'; ignored troff: ../hy.trf:42: warning: contradictory flags in hyphenation request value '40'; ignored troff: ../hy.trf:43: warning: contradictory flags in hyphenation request value '41'; ignored troff: ../hy.trf:44: warning: contradictory flags in hyphenation request value '42'; ignored troff: ../hy.trf:45: warning: contradictory flags in hyphenation request value '43'; ignored troff: ../hy.trf:46: warning: contradictory flags in hyphenation request value '44'; ignored troff: ../hy.trf:47: warning: contradictory flags in hyphenation request value '45'; ignored troff: ../hy.trf:48: warning: contradictory flags in hyphenation request value '46'; ignored troff: ../hy.trf:49: warning: contradictory flags in hyphenation request value '47'; ignored troff: ../hy.trf:51: warning: contradictory flags in hyphenation request value '49'; ignored troff: ../hy.trf:53: warning: contradictory flags in hyphenation request value '51'; ignored troff: ../hy.trf:54: warning: contradictory flags in hyphenation request value '52'; ignored troff: ../hy.trf:55: warning: contradictory flags in hyphenation request value '53'; ignored troff: ../hy.trf:56: warning: contradictory flags in hyphenation request value '54'; ignored troff: ../hy.trf:57: warning: contradictory flags in hyphenation request value '55'; ignored troff: ../hy.trf:58: warning: contradictory flags in hyphenation request value '56'; ignored troff: ../hy.trf:59: warning: contradictory flags in hyphenation request value '57'; ignored troff: ../hy.trf:60: warning: contradictory flags in hyphenation request value '58'; ignored troff: ../hy.trf:61: warning: contradictory flags in hyphenation request value '59'; ignored troff: ../hy.trf:62: warning: contradictory flags in hyphenation request value '60'; ignored troff: ../hy.trf:63: warning: contradictory flags in hyphenation request value '61'; ignored troff: ../hy.trf:64: warning: contradictory flags in hyphenation request value '62'; ignored troff: ../hy.trf:65: warning: contradictory flags in hyphenation request value '63'; ignored troff: ../hy.trf:66: warning: hyphenation request value '64' out of range (must be in 0..63); ignored
signature.asc
Description: PGP signature