From 2fb659f9459814da342399527a29c22924e4d32e Mon Sep 17 00:00:00 2001 From: schwarze Date: Fri, 10 Sep 2021 13:23:44 +0000 Subject: [PATCH] Quirk-compatibility with GNU tbl(1): With the "nospaces" option, skip space characters before and after "T{", in addition to skipping those at the beginning and end of data cells. Minor issue reported by . --- usr.bin/mandoc/tbl_data.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/usr.bin/mandoc/tbl_data.c b/usr.bin/mandoc/tbl_data.c index 315a1949c0f..7de8fa86e5c 100644 --- a/usr.bin/mandoc/tbl_data.c +++ b/usr.bin/mandoc/tbl_data.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl_data.c,v 1.45 2021/09/10 12:06:29 schwarze Exp $ */ +/* $OpenBSD: tbl_data.c,v 1.46 2021/09/10 13:23:44 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011,2015,2017-2019,2021 Ingo Schwarze @@ -145,25 +145,28 @@ getdata(struct tbl_node *tbl, struct tbl_span *dp, dp->last->next = dat; dp->last = dat; + /* Strip leading and trailing spaces, if requested. */ + + endpos = *pos; + if (dp->opts->opts & TBL_OPT_NOSPACE) { + while (p[startpos] == ' ') + startpos++; + while (endpos > startpos && p[endpos - 1] == ' ') + endpos--; + } + /* * Check for a continued-data scope opening. This consists of a * trailing `T{' at the end of the line. Subsequent lines, * until a standalone `T}', are included in our cell. */ - if (*pos - startpos == 2 && + if (endpos - startpos == 2 && p[startpos] == 'T' && p[startpos + 1] == '{') { tbl->part = TBL_PART_CDATA; return; } - endpos = *pos; - if (dp->opts->opts & TBL_OPT_NOSPACE) { - while (p[startpos] == ' ') - startpos++; - while (endpos > startpos && p[endpos - 1] == ' ') - endpos--; - } dat->string = mandoc_strndup(p + startpos, endpos - startpos); if (p[*pos] != '\0') -- 2.20.1