summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2010-12-21 23:46:17 +0000
committerschwarze <schwarze@openbsd.org>2010-12-21 23:46:17 +0000
commitf6127a735c5d22cdbf4757fe714a3ffc0126d565 (patch)
tree7971e4fc09056249e8ebc1639394cd673cb8c41c
parentStore sessions in an RB tree by name rather than a list, this is tidier (diff)
downloadwireguard-openbsd-f6127a735c5d22cdbf4757fe714a3ffc0126d565.tar.xz
wireguard-openbsd-f6127a735c5d22cdbf4757fe714a3ffc0126d565.zip
Vertical spacing improvements from kristaps@, small tweaks by me:
Add a "last child" member to struct mdoc_node. Remove .Pp or .Lp if it is the first or last child of an .Sh or .Ss body. Thus, no need to do the same in the front-ends any longer. Tolerate some cases of .Pp inside .Bl.
-rw-r--r--usr.bin/mandoc/mdoc.c4
-rw-r--r--usr.bin/mandoc/mdoc.h3
-rw-r--r--usr.bin/mandoc/mdoc_macro.c5
-rw-r--r--usr.bin/mandoc/mdoc_term.c7
-rw-r--r--usr.bin/mandoc/mdoc_validate.c66
5 files changed, 55 insertions, 30 deletions
diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c
index 117f587c19d..214a752b94c 100644
--- a/usr.bin/mandoc/mdoc.c
+++ b/usr.bin/mandoc/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.71 2010/12/02 19:42:47 schwarze Exp $ */
+/* $Id: mdoc.c,v 1.72 2010/12/21 23:46:17 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -567,6 +567,8 @@ mdoc_node_unlink(struct mdoc *m, struct mdoc_node *n)
n->parent->nchild--;
if (n->parent->child == n)
n->parent->child = n->prev ? n->prev : n->next;
+ if (n->parent->last == n)
+ n->parent->last = n->prev ? n->prev : NULL;
}
/* Adjust parse point, if applicable. */
diff --git a/usr.bin/mandoc/mdoc.h b/usr.bin/mandoc/mdoc.h
index 4ab129e270d..b8510c9f625 100644
--- a/usr.bin/mandoc/mdoc.h
+++ b/usr.bin/mandoc/mdoc.h
@@ -1,4 +1,4 @@
-/* $Id: mdoc.h,v 1.36 2010/12/19 09:22:35 schwarze Exp $ */
+/* $Id: mdoc.h,v 1.37 2010/12/21 23:46:18 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -374,6 +374,7 @@ union mdoc_data {
struct mdoc_node {
struct mdoc_node *parent; /* parent AST node */
struct mdoc_node *child; /* first child AST node */
+ struct mdoc_node *last; /* last child AST node */
struct mdoc_node *next; /* sibling AST node */
struct mdoc_node *prev; /* prior sibling AST node */
int nchild; /* number children */
diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c
index de16673d093..77c4d3d25cf 100644
--- a/usr.bin/mandoc/mdoc_macro.c
+++ b/usr.bin/mandoc/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_macro.c,v 1.60 2010/12/01 22:02:29 schwarze Exp $ */
+/* $Id: mdoc_macro.c,v 1.61 2010/12/21 23:46:18 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -250,6 +250,7 @@ lookup_raw(const char *p)
static int
rew_last(struct mdoc *mdoc, const struct mdoc_node *to)
{
+ struct mdoc_node *n;
assert(to);
mdoc->next = MDOC_NEXT_SIBLING;
@@ -258,8 +259,10 @@ rew_last(struct mdoc *mdoc, const struct mdoc_node *to)
while (mdoc->last != to) {
if ( ! mdoc_valid_post(mdoc))
return(0);
+ n = mdoc->last;
mdoc->last = mdoc->last->parent;
assert(mdoc->last);
+ mdoc->last->last = n;
}
return(mdoc_valid_post(mdoc));
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index d80a4880de8..2f05c4bc607 100644
--- a/usr.bin/mandoc/mdoc_term.c
+++ b/usr.bin/mandoc/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.117 2010/12/19 12:10:33 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.118 2010/12/21 23:46:18 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -1815,11 +1815,6 @@ termp_sp_pre(DECL_ARGS)
len = 0;
break;
default:
- assert(n->parent);
- if ((NULL == n->next || NULL == n->prev) &&
- (MDOC_Ss == n->parent->tok ||
- MDOC_Sh == n->parent->tok))
- return(0);
len = 1;
break;
}
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index d2de0a74062..9d22a0f9b65 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.78 2010/12/09 21:29:17 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.79 2010/12/21 23:46:18 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -107,6 +107,7 @@ static int post_it(POST_ARGS);
static int post_lb(POST_ARGS);
static int post_nm(POST_ARGS);
static int post_os(POST_ARGS);
+static int post_ignpar(POST_ARGS);
static int post_prol(POST_ARGS);
static int post_root(POST_ARGS);
static int post_rs(POST_ARGS);
@@ -151,9 +152,9 @@ static v_post posts_nm[] = { post_nm, NULL };
static v_post posts_notext[] = { ewarn_eq0, NULL };
static v_post posts_os[] = { post_os, post_prol, NULL };
static v_post posts_rs[] = { berr_ge1, herr_eq0, post_rs, NULL };
-static v_post posts_sh[] = { herr_ge1, bwarn_ge1, post_sh, NULL };
+static v_post posts_sh[] = { post_ignpar, herr_ge1, bwarn_ge1, post_sh, NULL };
static v_post posts_sp[] = { eerr_le1, NULL };
-static v_post posts_ss[] = { herr_ge1, NULL };
+static v_post posts_ss[] = { post_ignpar, herr_ge1, bwarn_ge1, NULL };
static v_post posts_st[] = { eerr_eq1, post_st, NULL };
static v_post posts_std[] = { post_std, NULL };
static v_post posts_text[] = { eerr_ge1, NULL };
@@ -170,7 +171,7 @@ static v_pre pres_dd[] = { pre_dd, NULL };
static v_pre pres_dt[] = { pre_dt, NULL };
static v_pre pres_er[] = { NULL, NULL };
static v_pre pres_fd[] = { NULL, NULL };
-static v_pre pres_it[] = { pre_it, NULL };
+static v_pre pres_it[] = { pre_it, pre_par, NULL };
static v_pre pres_os[] = { pre_os, NULL };
static v_pre pres_pp[] = { pre_par, NULL };
static v_pre pres_sh[] = { pre_sh, NULL };
@@ -898,10 +899,6 @@ pre_it(PRE_ARGS)
if (MDOC_BLOCK != n->type)
return(1);
- /*
- * FIXME: this can probably be lifted if we make the It into
- * something else on-the-fly?
- */
return(check_parent(mdoc, n, MDOC_Bl, MDOC_BODY));
}
@@ -1571,21 +1568,22 @@ post_bl(POST_ARGS)
return(post_bl_block(mdoc));
if (MDOC_BODY != mdoc->last->type)
return(1);
- if (NULL == mdoc->last->child)
- return(1);
- /*
- * We only allow certain children of `Bl'. This is usually on
- * `It', but apparently `Sm' occurs here and there, so we let
- * that one through, too.
- */
-
- /* LINTED */
for (n = mdoc->last->child; n; n = n->next) {
- if (MDOC_BLOCK == n->type && MDOC_It == n->tok)
- continue;
- if (MDOC_Sm == n->tok)
+ switch (n->tok) {
+ case (MDOC_Lp):
+ /* FALLTHROUGH */
+ case (MDOC_Pp):
+ mdoc_nmsg(mdoc, n, MANDOCERR_CHILD);
+ /* FALLTHROUGH */
+ case (MDOC_It):
+ /* FALLTHROUGH */
+ case (MDOC_Sm):
continue;
+ default:
+ break;
+ }
+
mdoc_nmsg(mdoc, n, MANDOCERR_SYNTCHILD);
return(0);
}
@@ -1887,6 +1885,29 @@ post_sh_head(POST_ARGS)
}
static int
+post_ignpar(POST_ARGS)
+{
+ struct mdoc_node *np;
+
+ if (MDOC_BODY != mdoc->last->type)
+ return(1);
+
+ if (NULL != (np = mdoc->last->child))
+ if (MDOC_Pp == np->tok || MDOC_Lp == np->tok) {
+ mdoc_nmsg(mdoc, np, MANDOCERR_IGNPAR);
+ mdoc_node_delete(mdoc, np);
+ }
+
+ if (NULL != (np = mdoc->last->last))
+ if (MDOC_Pp == np->tok || MDOC_Lp == np->tok) {
+ mdoc_nmsg(mdoc, np, MANDOCERR_IGNPAR);
+ mdoc_node_delete(mdoc, np);
+ }
+
+ return(1);
+}
+
+static int
pre_ts(PRE_ARGS)
{
@@ -1902,6 +1923,8 @@ pre_par(PRE_ARGS)
if (NULL == mdoc->last)
return(1);
+ if (MDOC_ELEM != n->type && MDOC_BLOCK != n->type)
+ return(1);
/*
* Don't allow prior `Lp' or `Pp' prior to a paragraph-type
@@ -1910,11 +1933,12 @@ pre_par(PRE_ARGS)
if (MDOC_Pp != mdoc->last->tok && MDOC_Lp != mdoc->last->tok)
return(1);
-
if (MDOC_Bl == n->tok && n->data.Bl->comp)
return(1);
if (MDOC_Bd == n->tok && n->data.Bd->comp)
return(1);
+ if (MDOC_It == n->tok && n->parent->data.Bl->comp)
+ return(1);
mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_IGNPAR);
mdoc_node_delete(mdoc, mdoc->last);