diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2012-07-18 11:09:31 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2012-07-18 11:09:31 +0000 |
commit | f0649356f08ec54bfa01c6ab733db8d7e0d04e42 (patch) | |
tree | 4a292fcca0b81b1732f41387e6413b7550b55338 /usr.bin | |
parent | 60dd10dead840994ee21087a8fcdcf92aa139c64 (diff) |
Fix handling of paragraph macros inside lists:
* When they are trailing the last item, move them outside the list.
* When they are trailing any other none-compact item, drop them.
Improves formatting of 40 pages, e.g. grep(1), ksh(1), netstat(1),
ath(4), bsd.port.mk(5), pf.conf(5), mount(8), crypto(9).
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/libmdoc.h | 3 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.h | 3 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.c | 12 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_validate.c | 39 | ||||
-rw-r--r-- | usr.bin/mandoc/read.c | 3 |
5 files changed, 50 insertions, 10 deletions
diff --git a/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h index b2903007b1e..f82dfb58140 100644 --- a/usr.bin/mandoc/libmdoc.h +++ b/usr.bin/mandoc/libmdoc.h @@ -1,4 +1,4 @@ -/* $Id: libmdoc.h,v 1.49 2012/05/24 23:33:23 schwarze Exp $ */ +/* $Id: libmdoc.h,v 1.50 2012/07/18 11:09:30 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -118,6 +118,7 @@ int mdoc_endbody_alloc(struct mdoc *m, int line, int pos, enum mdoct tok, struct mdoc_node *body, enum mdoc_endbody end); void mdoc_node_delete(struct mdoc *, struct mdoc_node *); +int mdoc_node_relink(struct mdoc *, struct mdoc_node *); void mdoc_hash_init(void); enum mdoct mdoc_hash_find(const char *); const char *mdoc_a2att(const char *); diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index 2e615dd4fac..4eec27dabc4 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $Id: mandoc.h,v 1.47 2012/07/12 15:09:50 schwarze Exp $ */ +/* $Id: mandoc.h,v 1.48 2012/07/18 11:09:30 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -68,6 +68,7 @@ enum mandocerr { /* related to macros and nesting */ MANDOCERR_MACROOBS, /* skipping obsolete macro */ MANDOCERR_IGNPAR, /* skipping paragraph macro */ + MANDOCERR_MOVEPAR, /* moving paragraph macro out of list */ MANDOCERR_IGNNS, /* skipping no-space macro */ MANDOCERR_SCOPENEST, /* blocks badly nested */ MANDOCERR_CHILD, /* child violates parent syntax */ diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c index ca5b09b2550..9ffc5dab783 100644 --- a/usr.bin/mandoc/mdoc.c +++ b/usr.bin/mandoc/mdoc.c @@ -1,7 +1,7 @@ -/* $Id: mdoc.c,v 1.90 2012/07/18 10:36:20 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.91 2012/07/18 11:09:30 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010, 2012 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -644,6 +644,14 @@ mdoc_node_delete(struct mdoc *m, struct mdoc_node *p) mdoc_node_free(p); } +int +mdoc_node_relink(struct mdoc *m, struct mdoc_node *p) +{ + + mdoc_node_unlink(m, p); + return(node_append(m, p)); +} + #if 0 /* * Pre-treat a text line. diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 52632492afa..5523381b672 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.106 2012/07/16 09:51:03 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.107 2012/07/18 11:09:30 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org> @@ -1349,7 +1349,7 @@ post_it(POST_ARGS) static int post_bl_block(POST_ARGS) { - struct mdoc_node *n; + struct mdoc_node *n, *ni, *nc; /* * These are fairly complicated, so we've broken them into two @@ -1365,13 +1365,42 @@ post_bl_block(POST_ARGS) NULL == n->norm->Bl.width) { if ( ! post_bl_block_tag(mdoc)) return(0); + assert(n->norm->Bl.width); } else if (NULL != n->norm->Bl.width) { if ( ! post_bl_block_width(mdoc)) return(0); - } else - return(1); + assert(n->norm->Bl.width); + } - assert(n->norm->Bl.width); + for (ni = n->body->child; ni; ni = ni->next) { + if (NULL == ni->body) + continue; + nc = ni->body->last; + while (NULL != nc) { + switch (nc->tok) { + case (MDOC_Pp): + /* FALLTHROUGH */ + case (MDOC_Lp): + /* FALLTHROUGH */ + case (MDOC_br): + break; + default: + nc = NULL; + continue; + } + if (NULL == ni->next) { + mdoc_nmsg(mdoc, nc, MANDOCERR_MOVEPAR); + if ( ! mdoc_node_relink(mdoc, nc)) + return(0); + } else if (0 == n->norm->Bl.comp && + LIST_column != n->norm->Bl.type) { + mdoc_nmsg(mdoc, nc, MANDOCERR_IGNPAR); + mdoc_node_delete(mdoc, nc); + } else + break; + nc = ni->body->last; + } + } return(1); } diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 38218aae620..2cc0f6a27ed 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.9 2012/07/12 15:09:50 schwarze Exp $ */ +/* $Id: read.c,v 1.10 2012/07/18 11:09:30 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -102,6 +102,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { /* related to macros and nesting */ "skipping obsolete macro", "skipping paragraph macro", + "moving paragraph macro out of list", "skipping no-space macro", "blocks badly nested", "child violates parent syntax", |