diff options
-rw-r--r-- | usr.bin/mandoc/mdoc.7 | 10 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_action.c | 53 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_argv.c | 16 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_validate.c | 55 |
4 files changed, 98 insertions, 36 deletions
diff --git a/usr.bin/mandoc/mdoc.7 b/usr.bin/mandoc/mdoc.7 index 689ed385203..47b4645dc40 100644 --- a/usr.bin/mandoc/mdoc.7 +++ b/usr.bin/mandoc/mdoc.7 @@ -1,4 +1,4 @@ -.\" $Id: mdoc.7,v 1.4 2009/06/18 23:34:53 schwarze Exp $ +.\" $Id: mdoc.7,v 1.5 2009/06/21 19:09:58 schwarze Exp $ .\" .\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 18 2009 $ +.Dd $Mdocdate: June 21 2009 $ .Dt MDOC 7 .Os .\" SECTION @@ -90,7 +90,7 @@ optionally followed by whitespace, is ignored. .\" SUB-SECTION .Ss Reserved Characters Within a macro line, the following characters are reserved: -.Bl -tag -width 12n -offset XXXX -compact +.Bl -tag -width Ds -offset XXXX -compact .It \&. .Pq period .It \&, @@ -301,7 +301,7 @@ some .Pc don't have heads. .Pp -.Bl -column "MacroX" "CallableX" "ParsableX" "Closing" -compact -offset XXXX +.Bl -column -compact -offset XXXX "MacroX" "CallableX" "ParsableX" "Closing" .It Em Macro Ta Em Callable Ta Em Parsable Ta Em Closing .It \&.Sh Ta \&No Ta \&No Ta \&.Sh .It \&.Ss Ta \&No Ta \&No Ta \&.Sh, \&.Ss @@ -313,7 +313,7 @@ None of these macros are callable or parsed. The last column indicates the explicit scope rules. All contains bodies, some may contain heads .Pq So \&Bf Sc . .Pp -.Bl -column "MacroX" "CallableX" "ParsableX" "closed by XXX" -compact -offset XXXX +.Bl -column -compact -offset XXXX "MacroX" "CallableX" "ParsableX" "closed by XXX" .It Em Macro Ta Em Callable Ta Em Parsable Ta Em Scope .It \&.Bd Ta \&No Ta \&No Ta closed by \&.Ed .It \&.Ed Ta \&No Ta \&No Ta opened by \&.Bd diff --git a/usr.bin/mandoc/mdoc_action.c b/usr.bin/mandoc/mdoc_action.c index 8d94b37efd9..6265695c2a9 100644 --- a/usr.bin/mandoc/mdoc_action.c +++ b/usr.bin/mandoc/mdoc_action.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_action.c,v 1.5 2009/06/19 07:20:19 schwarze Exp $ */ +/* $Id: mdoc_action.c,v 1.6 2009/06/21 19:09:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -51,6 +51,7 @@ static int concat(struct mdoc *, const struct mdoc_node *, static int post_ar(POST_ARGS); static int post_bl(POST_ARGS); +static int post_bl_head(POST_ARGS); static int post_bl_width(POST_ARGS); static int post_bl_tagwidth(POST_ARGS); static int post_dd(POST_ARGS); @@ -629,10 +630,60 @@ post_bl_width(struct mdoc *m) static int +post_bl_head(POST_ARGS) +{ + int i, c; + struct mdoc_node *n, *nn, *nnp; + + if (NULL == m->last->child) + return(1); + + n = m->last->parent; + assert(n->args); + + for (c = 0; c < (int)n->args->argc; c++) + if (MDOC_Column == n->args->argv[c].arg) + break; + + /* Only process -column. */ + + if (c == (int)n->args->argc) + return(1); + + assert(0 == n->args->argv[c].sz); + + /* + * Accomodate for new-style groff column syntax. Shuffle the + * child nodes, all of which must be TEXT, as arguments for the + * column field. Then, delete the head children. + */ + + for (i = 0, nn = m->last->child; nn; nn = nn->next, i++) + /* Count children. */; + + n->args->argv[c].sz = (size_t)i; + n->args->argv[c].value = malloc((size_t)i * sizeof(char *)); + + for (i = 0, nn = m->last->child; nn; i++) { + n->args->argv[c].value[i] = nn->string; + nn->string = NULL; + nnp = nn; + nn = nn->next; + mdoc_node_free(nnp); + } + + m->last->child = NULL; + return(1); +} + + +static int post_bl(POST_ARGS) { int i, r, len; + if (MDOC_HEAD == m->last->type) + return(post_bl_head(m)); if (MDOC_BLOCK != m->last->type) return(1); diff --git a/usr.bin/mandoc/mdoc_argv.c b/usr.bin/mandoc/mdoc_argv.c index 6b107c1a52a..beb43406190 100644 --- a/usr.bin/mandoc/mdoc_argv.c +++ b/usr.bin/mandoc/mdoc_argv.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_argv.c,v 1.3 2009/06/18 23:34:53 schwarze Exp $ */ +/* $Id: mdoc_argv.c,v 1.4 2009/06/21 19:09:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -32,6 +32,9 @@ * There's no limit to the number or arguments that may be allocated. */ +/* FIXME .Bf Li raises "macro-like parameter". */ +/* FIXME .Bl -column should deprecate old-groff syntax. */ + #define ARGS_QUOTED (1 << 0) #define ARGS_DELIM (1 << 1) #define ARGS_TABSEP (1 << 2) @@ -116,7 +119,7 @@ static int mdoc_argflags[MDOC_MAX] = { ARGS_DELIM | ARGS_QUOTED, /* Dl */ 0, /* Bd */ 0, /* Ed */ - 0, /* Bl */ + ARGS_QUOTED, /* Bl */ 0, /* El */ 0, /* It */ ARGS_DELIM, /* Ad */ @@ -753,11 +756,9 @@ static int argv_multi(struct mdoc *mdoc, int line, struct mdoc_argv *v, int *pos, char *buf) { - int c, ppos; + int c; char *p; - ppos = *pos; - for (v->sz = 0; ; v->sz++) { if ('-' == buf[*pos]) break; @@ -779,10 +780,7 @@ argv_multi(struct mdoc *mdoc, int line, return(verr(mdoc, EMALLOC)); } - if (v->sz) - return(1); - - return(perr(mdoc, line, ppos, EARGVAL)); + return(1); } diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 32771fdffd4..22f45b2c538 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.10 2009/06/21 18:15:03 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.11 2009/06/21 19:09:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -46,6 +46,7 @@ enum merr { EMULTILIST, EARGREP, EBOOL, + ECOLMIS, ENESTDISP }; @@ -138,6 +139,7 @@ static int post_args(POST_ARGS); static int post_at(POST_ARGS); static int post_bf(POST_ARGS); static int post_bl(POST_ARGS); +static int post_bl_head(POST_ARGS); static int post_it(POST_ARGS); static int post_nm(POST_ARGS); static int post_root(POST_ARGS); @@ -174,7 +176,7 @@ static v_post posts_wtext[] = { ewarn_ge1, NULL }; static v_post posts_notext[] = { eerr_eq0, NULL }; static v_post posts_wline[] = { bwarn_ge1, herr_eq0, NULL }; static v_post posts_sh[] = { herr_ge1, bwarn_ge1, post_sh, NULL }; -static v_post posts_bl[] = { herr_eq0, bwarn_ge1, post_bl, NULL }; +static v_post posts_bl[] = { bwarn_ge1, post_bl, NULL }; static v_post posts_it[] = { post_it, NULL }; static v_post posts_in[] = { ewarn_eq1, NULL }; static v_post posts_ss[] = { herr_ge1, NULL }; @@ -420,6 +422,9 @@ perr(struct mdoc *m, int line, int pos, enum merr type) case (ENODATA): p = "document has no data"; break; + case (ECOLMIS): + p = "column syntax style mismatch"; + break; case (EATT): p = "expected valid AT&T symbol"; break; @@ -792,7 +797,7 @@ pre_display(PRE_ARGS) static int pre_bl(PRE_ARGS) { - int pos, col, type, width, offset; + int pos, type, width, offset; if (MDOC_BLOCK != n->type) return(1); @@ -801,7 +806,7 @@ pre_bl(PRE_ARGS) /* Make sure that only one type of list is specified. */ - type = offset = width = col = -1; + type = offset = width = -1; /* LINTED */ for (pos = 0; pos < (int)n->args->argc; pos++) @@ -830,7 +835,6 @@ pre_bl(PRE_ARGS) if (-1 != type) return(nerr(mdoc, n, EMULTILIST)); type = n->args->argv[pos].arg; - col = pos; break; case (MDOC_Width): if (-1 != width) @@ -874,22 +878,6 @@ pre_bl(PRE_ARGS) break; } - /* - * General validation of fields. - */ - - switch (type) { - case (MDOC_Column): - assert(col >= 0); - if (0 == n->args->argv[col].sz) - break; - if ( ! nwarn(mdoc, n, WDEPCOL)) - return(0); - break; - default: - break; - } - return(1); } @@ -1252,10 +1240,35 @@ post_it(POST_ARGS) static int +post_bl_head(POST_ARGS) +{ + int i; + const struct mdoc_node *n; + + n = mdoc->last->parent; + assert(n->args); + + for (i = 0; i < (int)n->args->argc; i++) + if (n->args->argv[i].arg == MDOC_Column) + break; + + if (i == (int)n->args->argc) + return(1); + + if (n->args->argv[i].sz && mdoc->last->child) + return(nerr(mdoc, n, ECOLMIS)); + + return(1); +} + + +static int post_bl(POST_ARGS) { struct mdoc_node *n; + if (MDOC_HEAD == mdoc->last->type) + return(post_bl_head(mdoc)); if (MDOC_BODY != mdoc->last->type) return(1); if (NULL == mdoc->last->child) |