[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 06/14: [tbl]: Slightly refactor table format validation.
From: |
G. Branden Robinson |
Subject: |
[groff] 06/14: [tbl]: Slightly refactor table format validation. |
Date: |
Wed, 1 Dec 2021 13:06:15 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit a960d316865c67f9fc30121546879862b0342ad3
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Nov 26 02:45:23 2021 +1100
[tbl]: Slightly refactor table format validation.
...of `p` and `v` column modifiers.
* src/preproc/tbl/main.cpp (process_format): Make code terser by
introducing references to `list->point_size` and
`list->vertical_spacing`. Doing this requires a new scope (because a
switch case isn't one) so add it, without updating indentation for
this commit. When complaining of out-of-range type size or vertical
spacing, report the limit.
---
ChangeLog | 12 ++++++++++++
src/preproc/tbl/main.cpp | 49 ++++++++++++++++++++++++++----------------------
2 files changed, 39 insertions(+), 22 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 12e36a6..f912eba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2021-11-26 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ [tbl]: Slightly refactor table format column modifier `p` and
+ `v` validation.
+
+ * src/preproc/tbl/main.cpp (process_format): Make code terser by
+ introducing references to `list->point_size` and
+ `list->vertical_spacing`. Doing this requires a new scope
+ {because a switch case isn't one} so add it, without updating
+ indentation for this commit. When complaining of out-of-range
+ type size or vertical spacing, report the limit.
+
2021-11-25 G. Branden Robinson <g.branden.robinson@gmail.com>
[tbl]: Improve diagnostic messages.
diff --git a/src/preproc/tbl/main.cpp b/src/preproc/tbl/main.cpp
index 13315ca..2deca93 100644
--- a/src/preproc/tbl/main.cpp
+++ b/src/preproc/tbl/main.cpp
@@ -970,34 +970,36 @@ format *process_format(table_input &in, options *opt,
break;
case 'p':
case 'P':
+ {
+ inc_number &ps = list->point_size;
+ ps.val = 0;
+ ps.inc = 0;
c = in.get();
- list->point_size.val = 0;
- list->point_size.inc = 0;
if (c == '+' || c == '-') {
- list->point_size.inc = (c == '+' ? 1 : -1);
+ ps.inc = (c == '+' ? 1 : -1);
c = in.get();
}
if (c == EOF || !csdigit(c)) {
warning("'p' column modifier must be followed by (optionally"
" signed) integer; ignoring");
- list->point_size.inc = 0;
+ ps.inc = 0;
}
else {
do {
- list->point_size.val *= 10;
- list->point_size.val += c - '0';
+ ps.val *= 10;
+ ps.val += c - '0';
c = in.get();
} while (c != EOF && csdigit(c));
}
- if (list->point_size.val > MAX_POINT_SIZE
- || list->point_size.val < -MAX_POINT_SIZE) {
+ if (ps.val > MAX_POINT_SIZE || ps.val < -MAX_POINT_SIZE) {
warning("'p' column modifier argument magnitude of %1"
- " points out of range (> %2); ignoring",
- list->point_size.val, MAX_POINT_SIZE);
- list->point_size.val = 0;
- list->point_size.inc = 0;
+ " points out of range (> %2); ignoring", ps.val,
+ MAX_POINT_SIZE);
+ ps.val = 0;
+ ps.inc = 0;
}
break;
+ }
case 't':
case 'T':
c = in.get();
@@ -1010,34 +1012,37 @@ format *process_format(table_input &in, options *opt,
break;
case 'v':
case 'V':
+ {
+ inc_number &vs = list->vertical_spacing;
+ vs.val = 0;
+ vs.inc = 0;
c = in.get();
- list->vertical_spacing.val = 0;
- list->vertical_spacing.inc = 0;
if (c == '+' || c == '-') {
- list->vertical_spacing.inc = (c == '+' ? 1 : -1);
+ vs.inc = (c == '+' ? 1 : -1);
c = in.get();
}
if (c == EOF || !csdigit(c)) {
warning("'v' column modifier must be followed by (optionally"
" signed) integer; ignoring");
- list->vertical_spacing.inc = 0;
+ vs.inc = 0;
}
else {
do {
- list->vertical_spacing.val *= 10;
- list->vertical_spacing.val += c - '0';
+ vs.val *= 10;
+ vs.val += c - '0';
c = in.get();
} while (c != EOF && csdigit(c));
}
- if (list->vertical_spacing.val > MAX_VERTICAL_SPACING
- || list->vertical_spacing.val < -MAX_VERTICAL_SPACING) {
+ if (vs.val > MAX_VERTICAL_SPACING
+ || vs.val < -MAX_VERTICAL_SPACING) {
warning("'v' column modifier argument magnitude of %1"
" points out of range (> %2); ignoring", vs.val,
MAX_VERTICAL_SPACING);
- list->vertical_spacing.val = 0;
- list->vertical_spacing.inc = 0;
+ vs.val = 0;
+ vs.inc = 0;
}
break;
+ }
case 'w':
case 'W':
c = in.get();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 06/14: [tbl]: Slightly refactor table format validation.,
G. Branden Robinson <=