Skip to content

Commit b0b03f8

Browse files
src/cmd/tbl/t4.c: be robust to extensions
DWB 3.3 tbl and GNU tbl support an 'x' column modifier. (Heirloom Doctools tbl and mandoc(1) also support it.) Plan 9 tbl aborts processing of the entire input document if it encounters this characater in a table description. That's overkill; it's safe to ignore that modifier if it really is a _modifier_, and the column descriptor has a classifier already, like 'L' or 'N'. The `sawchar` local variable, of Boolean sense, in `readspec()` appears to indicate that fact. Many man pages in the wild, such as those of ncurses, use the 'x' modifier; while this change doesn't make Plan 9 tbl implement the extension, it does help Plan 9 render such pages on a best-effort basis. Extending this toleration also permits man page authors to wangle a portable hack into their pages by specifying an explicit width followed by the 'x' modifier that implementations supporting it will honor (example: 'Lw(22n)x'). The GNU tbl(1) man page says: Column modifiers Any number of modifiers can follow a column classifier. Modifier arguments, where accepted, are case‐sensitive. If a given modifier is applied to a classifier more than once, or if conflicting modifiers are applied, only the last occurrence has effect. The modifier x is mutually exclusive with e and w, but e is not mutually exclusive with w; if these are used in combination, x unsets both e and w, while either e or w overrides x. Heirloom Doctools and mandoc(1) behave compatibly with the foregoing description. Before: $ printf '.TS\nLx.\ntable cell\n.TE\n' | 9 tbl | 9 nroff -man | col | cat -s Input:2: bad table specification character x tbl quits After: $ printf '.TS\nLx.\ntable cell\n.TE\n' | 9 tbl | 9 nroff -man | col | cat -s Input:2: warning: unrecognized column modifier character 'x' table cell $ printf '.TS\nx.\ntable cell\n.TE\n' | 9 tbl | 9 nroff -man | col | cat -s Input:2: bad table specification character x tbl quits $ printf '.TS\ntab(@);\nL Lx.\ncell one@cell two\n.TE\n' | 9 tbl | 9 nroff -man | col | cat -s Input:3: warning: unrecognized column modifier character 'x' cell one cell two I confess to using my own terminology rather than Mike Lesk's. See <https://man7.org/linux/man-pages/man1/tbl.1.html>.
1 parent e5b6320 commit b0b03f8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/cmd/tbl/t4.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,18 @@ readspec(void)
4747
default:
4848
if (c != tab) {
4949
char buf[64];
50-
sprint(buf, "bad table specification character %c", c);
51-
error(buf);
50+
if (sawchar)
51+
if (c != '\'') {
52+
sprint(buf, "unrecognized column modifier character '%c'", c);
53+
warn(buf);
54+
} else {
55+
sprint(buf, "unrecognized column modifier character \"%c\"", c);
56+
warn(buf);
57+
}
58+
else {
59+
sprint(buf, "bad table specification character %c", c);
60+
error(buf);
61+
}
5262
}
5363
case ' ': /* note this is also case tab */
5464
continue;

0 commit comments

Comments
 (0)