gbranden pushed a commit to branch branden-2023-07-05 in repository groff. commit 7ba4c8639e0bedada68bcf5511c8712d3c508fb5 Author: G. Branden Robinson <g.branden.robin...@gmail.com> AuthorDate: Fri May 19 04:29:29 2023 -0500
[tbl]: Refactor type size, vert spacing handling. * src/preproc/tbl/table.h (struct inc_number): Rename this... (struct size_expression): ...to this, and change its member types. The `inc` `short` becomes a `relativity` enum because it only ever takes 3 values. The `val` short becomes an `int`, undoing what I suspect to be premature optimization. * src/preproc/tbl/main.cpp (entry_modifier::entry_modifier) (entry_format::debug_print, process_format): * src/preproc/tbl/table.cpp (set_modifier, set_inline_modifier) (restore_inline_modifier): Update to reflect new types and enum literals. --- ChangeLog | 15 ++++++++++ src/preproc/tbl/main.cpp | 75 ++++++++++++++++++++++++++--------------------- src/preproc/tbl/table.cpp | 27 +++++++++-------- src/preproc/tbl/table.h | 10 +++---- 4 files changed, 76 insertions(+), 51 deletions(-) diff --git a/ChangeLog b/ChangeLog index f69b5a326..221e83cc5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2023-05-19 G. Branden Robinson <g.branden.robin...@gmail.com> + + [tbl]: Refactor handling of type size and vertical spacing. + + * src/preproc/tbl/table.h (struct inc_number): Rename this... + (struct size_expression): ...to this, and change its member + types. The `inc` `short` becomes a `relativity` enum + because it only ever takes 3 values. The `val` short becomes an + `int`, undoing what I suspect to be premature optimization. + * src/preproc/tbl/main.cpp (entry_modifier::entry_modifier) + (entry_format::debug_print, process_format): + * src/preproc/tbl/table.cpp (set_modifier, set_inline_modifier) + (restore_inline_modifier): Update to reflect new types and + enum literals. + 2023-05-19 G. Branden Robinson <g.branden.robin...@gmail.com> * src/preproc/tbl/main.cpp (process_format): Check for EOF after diff --git a/src/preproc/tbl/main.cpp b/src/preproc/tbl/main.cpp index 8ebb04b65..fbb2b2a23 100644 --- a/src/preproc/tbl/main.cpp +++ b/src/preproc/tbl/main.cpp @@ -535,8 +535,10 @@ options *process_options(table_input &in) entry_modifier::entry_modifier() : vertical_alignment(CENTER), zero_width(0), stagger(0) { - vertical_spacing.inc = vertical_spacing.val = 0; - point_size.inc = point_size.val = 0; + vertical_spacing.relativity = size_expression::ABSOLUTE; + vertical_spacing.whole = 0; + type_size.relativity = size_expression::ABSOLUTE; + type_size.whole = 0; } entry_modifier::~entry_modifier() @@ -585,21 +587,21 @@ void entry_format::debug_print() const assert(0 == "invalid column classifier in switch"); break; } - if (point_size.val != 0) { + if (type_size.whole != 0) { putc('p', stderr); - if (point_size.inc > 0) + if (type_size.relativity == size_expression::INCREMENT) putc('+', stderr); - else if (point_size.inc < 0) + else if (type_size.relativity == size_expression::DECREMENT) putc('-', stderr); - fprintf(stderr, "%d ", point_size.val); + fprintf(stderr, "%d ", type_size.whole); } - if (vertical_spacing.val != 0) { + if (vertical_spacing.whole != 0) { putc('v', stderr); - if (vertical_spacing.inc > 0) + if (vertical_spacing.relativity == size_expression::INCREMENT) putc('+', stderr); - else if (vertical_spacing.inc < 0) + else if (vertical_spacing.relativity == size_expression::DECREMENT) putc('-', stderr); - fprintf(stderr, "%d ", vertical_spacing.val); + fprintf(stderr, "%d ", vertical_spacing.whole); } if (!font.empty()) { putc('f', stderr); @@ -988,9 +990,9 @@ format *process_format(table_input &in, options *opt, case 'p': case 'P': { - inc_number &ps = list->point_size; - ps.val = 0; - ps.inc = 0; + size_expression &ps = list->type_size; + ps.relativity = size_expression::ABSOLUTE; + ps.whole = 0; c = in.get(); do { c = in.get(); @@ -1000,27 +1002,30 @@ format *process_format(table_input &in, options *opt, break; } if (c == '+' || c == '-') { - ps.inc = (c == '+' ? 1 : -1); + if (c == '+') + ps.relativity = size_expression::INCREMENT; + else if (c == '-') + ps.relativity = size_expression::DECREMENT; c = in.get(); } if (c == EOF || !csdigit(c)) { warning("'p' column modifier must be followed by" " (optionally signed) integer; ignoring"); - ps.inc = 0; + ps.relativity = size_expression::ABSOLUTE; } else { do { - ps.val *= 10; - ps.val += c - '0'; + ps.whole *= 10; + ps.whole += c - '0'; c = in.get(); } while (c != EOF && csdigit(c)); } - if (ps.val > MAX_POINT_SIZE || ps.val < -MAX_POINT_SIZE) { + if (ps.whole > MAX_POINT_SIZE || ps.whole < -MAX_POINT_SIZE) { warning("'p' column modifier argument magnitude of %1" - " points out of range (> %2); ignoring", ps.val, + " points out of range (> %2); ignoring", ps.whole, MAX_POINT_SIZE); - ps.val = 0; - ps.inc = 0; + ps.whole = 0; + ps.relativity = size_expression::ABSOLUTE; } break; } @@ -1037,9 +1042,9 @@ format *process_format(table_input &in, options *opt, case 'v': case 'V': { - inc_number &vs = list->vertical_spacing; - vs.val = 0; - vs.inc = 0; + size_expression &vs = list->vertical_spacing; + vs.whole = 0; + vs.relativity = size_expression::ABSOLUTE; c = in.get(); do { c = in.get(); @@ -1050,28 +1055,32 @@ format *process_format(table_input &in, options *opt, break; } if (c == '+' || c == '-') { - vs.inc = (c == '+' ? 1 : -1); + if (c == '+') + vs.relativity = size_expression::INCREMENT; + else if (c == '-') + vs.relativity = size_expression::DECREMENT; c = in.get(); } if (c == EOF || !csdigit(c)) { warning("'v' column modifier must be followed by" " (optionally signed) integer; ignoring"); - vs.inc = 0; + vs.whole = 0; + vs.relativity = size_expression::ABSOLUTE; } else { do { - vs.val *= 10; - vs.val += c - '0'; + vs.whole *= 10; + vs.whole += c - '0'; c = in.get(); } while (c != EOF && csdigit(c)); } - if (vs.val > MAX_VERTICAL_SPACING - || vs.val < -MAX_VERTICAL_SPACING) { + if (vs.whole > MAX_VERTICAL_SPACING + || vs.whole < -MAX_VERTICAL_SPACING) { warning("'v' column modifier argument magnitude of %1" - " points out of range (> %2); ignoring", vs.val, + " points out of range (> %2); ignoring", vs.whole, MAX_VERTICAL_SPACING); - vs.val = 0; - vs.inc = 0; + vs.whole = 0; + vs.relativity = size_expression::ABSOLUTE; } break; } diff --git a/src/preproc/tbl/table.cpp b/src/preproc/tbl/table.cpp index 9e9a371dc..bf4167303 100644 --- a/src/preproc/tbl/table.cpp +++ b/src/preproc/tbl/table.cpp @@ -1000,21 +1000,22 @@ void set_modifier(const entry_modifier *m) { if (!m->font.empty()) printfs(".ft %1\n", m->font); - if (m->point_size.val != 0) { + if (m->type_size.whole != 0) { prints(".ps "); - if (m->point_size.inc > 0) + if (m->type_size.relativity == size_expression::INCREMENT) prints('+'); - else if (m->point_size.inc < 0) + else if (m->type_size.relativity == size_expression::DECREMENT) prints('-'); - printfs("%1\n", as_string(m->point_size.val)); + printfs("%1\n", as_string(m->type_size.whole)); } - if (m->vertical_spacing.val != 0) { + if (m->vertical_spacing.whole != 0) { prints(".vs "); - if (m->vertical_spacing.inc > 0) + if (m->vertical_spacing.relativity == size_expression::INCREMENT) prints('+'); - else if (m->vertical_spacing.inc < 0) + else if (m->vertical_spacing.relativity + == size_expression::DECREMENT) prints('-'); - printfs("%1\n", as_string(m->vertical_spacing.val)); + printfs("%1\n", as_string(m->vertical_spacing.whole)); } if (!m->macro.empty()) printfs(".%1\n", m->macro); @@ -1024,13 +1025,13 @@ void set_inline_modifier(const entry_modifier *m) { if (!m->font.empty()) printfs("\\f[%1]", m->font); - if (m->point_size.val != 0) { + if (m->type_size.whole != 0) { prints("\\s["); - if (m->point_size.inc > 0) + if (m->type_size.relativity == size_expression::INCREMENT) prints('+'); - else if (m->point_size.inc < 0) + else if (m->type_size.relativity == size_expression::DECREMENT) prints('-'); - printfs("%1]", as_string(m->point_size.val)); + printfs("%1]", as_string(m->type_size.whole)); } if (m->stagger) prints("\\v'-.5v'"); @@ -1040,7 +1041,7 @@ void restore_inline_modifier(const entry_modifier *m) { if (!m->font.empty()) prints("\\f[\\n[" SAVED_FONT_REG "]]"); - if (m->point_size.val != 0) + if (m->type_size.whole != 0) prints("\\s[\\n[" SAVED_SIZE_REG "]]"); if (m->stagger) prints("\\v'.5v'"); diff --git a/src/preproc/tbl/table.h b/src/preproc/tbl/table.h index cacdcfe22..b4f4062cb 100644 --- a/src/preproc/tbl/table.h +++ b/src/preproc/tbl/table.h @@ -37,14 +37,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #define LEADER "a" #define LEADER_CHAR 'a' -struct inc_number { - short inc; - short val; +struct size_expression { + enum { DECREMENT = -1, ABSOLUTE, INCREMENT } relativity; + int whole; }; struct entry_modifier { - inc_number point_size; - inc_number vertical_spacing; + size_expression type_size; + size_expression vertical_spacing; string font; string macro; enum { CENTER, TOP, BOTTOM } vertical_alignment; _______________________________________________ Groff-commit mailing list Groff-commit@gnu.org https://lists.gnu.org/mailman/listinfo/groff-commit