From: schwarze Date: Tue, 16 Dec 2014 23:44:16 +0000 (+0000) Subject: Ignore mdoc(7) and man(7) macros inside tbl(7) code because they X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a2c9ff1aab5eeef19574a8ea7c921bed9b7a33ad;p=openbsd Ignore mdoc(7) and man(7) macros inside tbl(7) code because they would abort the table in an unclean way, causing assertion failures found by jsg@. --- diff --git a/regress/usr.bin/mandoc/tbl/Makefile b/regress/usr.bin/mandoc/tbl/Makefile index ce88001b7c0..95f1bb4f971 100644 --- a/regress/usr.bin/mandoc/tbl/Makefile +++ b/regress/usr.bin/mandoc/tbl/Makefile @@ -1,7 +1,9 @@ -# $OpenBSD: Makefile,v 1.4 2014/10/13 23:31:26 schwarze Exp $ +# $OpenBSD: Makefile,v 1.5 2014/12/16 23:44:16 schwarze Exp $ -REGRESS_TARGETS = center fonts numbers span vert -SKIP_TMAN ?= ALL +REGRESS_TARGETS = center fonts macro nested numbers span vert +LINT_TARGETS = macro nested +SKIP_GROFF = nested +SKIP_TMAN ?= ALL TBL = /usr/local/bin/tbl diff --git a/regress/usr.bin/mandoc/tbl/macro.in b/regress/usr.bin/mandoc/tbl/macro.in new file mode 100644 index 00000000000..f97907d87ae --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/macro.in @@ -0,0 +1,15 @@ +.TH TBL-MACRO 1 "December 16, 2014" +.SH NAME +tbl-macro \- macro in a table +.SH DESCRIPTION +normal text +.TS +box tab(:); +l | l . +a:b +_ +.PD 1 +c:d +.TE +.PP +normal text diff --git a/regress/usr.bin/mandoc/tbl/macro.out_ascii b/regress/usr.bin/mandoc/tbl/macro.out_ascii new file mode 100644 index 00000000000..ee0ddc9e5e5 --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/macro.out_ascii @@ -0,0 +1,20 @@ +TBL-MACRO(1) General Commands Manual TBL-MACRO(1) + + + +NNAAMMEE + tbl-macro - macro in a table + +DDEESSCCRRIIPPTTIIOONN + normal text + + +--+---+ + |a | b | + +--+---+ + |c | d | + +--+---+ + normal text + + + + December 16, 2014 TBL-MACRO(1) diff --git a/regress/usr.bin/mandoc/tbl/macro.out_lint b/regress/usr.bin/mandoc/tbl/macro.out_lint new file mode 100644 index 00000000000..63139f4b4f9 --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/macro.out_lint @@ -0,0 +1 @@ +mandoc: macro.in:11:2: ERROR: ignoring macro in table: PD 1 diff --git a/regress/usr.bin/mandoc/tbl/nested.in b/regress/usr.bin/mandoc/tbl/nested.in new file mode 100644 index 00000000000..7231f56b177 --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/nested.in @@ -0,0 +1,16 @@ +.TH TBL-NESTED 1 "December 16, 2014" +.SH NAME +tbl-nested \- nested table +.SH DESCRIPTION +normal text +.TS +box tab(:); +l | l . +a:b +_ +c:d +.TS +e:f +.TE +.PP +normal text diff --git a/regress/usr.bin/mandoc/tbl/nested.out_ascii b/regress/usr.bin/mandoc/tbl/nested.out_ascii new file mode 100644 index 00000000000..550270fca1e --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/nested.out_ascii @@ -0,0 +1,21 @@ +TBL-NESTED(1) General Commands Manual TBL-NESTED(1) + + + +NNAAMMEE + tbl-nested - nested table + +DDEESSCCRRIIPPTTIIOONN + normal text + + +--+---+ + |a | b | + +--+---+ + |c | d | + |e | f | + +--+---+ + normal text + + + + December 16, 2014 TBL-NESTED(1) diff --git a/regress/usr.bin/mandoc/tbl/nested.out_lint b/regress/usr.bin/mandoc/tbl/nested.out_lint new file mode 100644 index 00000000000..6422786837a --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/nested.out_lint @@ -0,0 +1 @@ +mandoc: nested.in:12:4: ERROR: ignoring macro in table: TS diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index 14428c58643..bcf99b2d2a8 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.118 2014/12/01 08:05:02 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.119 2014/12/16 23:44:16 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -144,6 +144,7 @@ enum mandocerr { MANDOCERR_TBLIGNDATA, /* ignore data in cell */ MANDOCERR_TBLBLOCK, /* data block still open */ MANDOCERR_TBLEXTRADAT, /* ignoring extra data cells */ + MANDOCERR_TBLMACRO, /* ignoring macro in table: macro */ /* related to document structure and macros */ MANDOCERR_ROFFLOOP, /* input stack limit exceeded, infinite loop? */ diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 040861bc55c..a386ade8f88 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.79 2014/11/30 05:28:00 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.80 2014/12/16 23:44:16 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -183,6 +183,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "ignore data in cell", "data block still open", "ignoring extra data cells", + "ignoring macro in table", /* related to document structure and macros */ "input stack limit exceeded, infinite loop?", diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index 9f85d50e756..10b566ab564 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.c,v 1.114 2014/12/16 03:52:31 schwarze Exp $ */ +/* $OpenBSD: roff.c,v 1.115 2014/12/16 23:44:16 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -728,6 +728,7 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs) enum rofft t; enum rofferr e; int pos; /* parse point */ + int spos; /* saved parse point for messages */ int ppos; /* original offset in buf->buf */ int ctl; /* macro line (boolean) */ @@ -798,15 +799,29 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs) return((*roffs[t].sub)(r, t, buf, ln, ppos, pos, offs)); } + /* No scope is open. This is a new request or macro. */ + + spos = pos; + t = roff_parse(r, buf->buf, &pos, ln, ppos); + + /* Tables ignore most macros. */ + + if (r->tbl != NULL && (t == ROFF_MAX || t == ROFF_TS)) { + mandoc_msg(MANDOCERR_TBLMACRO, r->parse, + ln, pos, buf->buf + spos); + return(ROFF_IGN); + } + /* - * Lastly, as we've no scope open, try to look up and execute - * the new macro. If no macro is found, simply return and let - * the compilers handle it. + * This is neither a roff request nor a user-defined macro. + * Let the standard macro set parsers handle it. */ - if ((t = roff_parse(r, buf->buf, &pos, ln, ppos)) == ROFF_MAX) + if (t == ROFF_MAX) return(ROFF_CONT); + /* Execute a roff request or a user defined macro. */ + assert(roffs[t].proc); return((*roffs[t].proc)(r, t, buf, ln, ppos, pos, offs)); }