summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2009-10-19 16:27:53 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2009-10-19 16:27:53 +0000
commit0acce05dffb50e17026bb3b370bf60c106b0af62 (patch)
tree977c8a78da02fea8eb448d57cb64be3c220278c7
parent34989243f5941a4b64182d8a60a5f0ed48c2c518 (diff)
sync to 1.9.6: multiple improvements to references (.Rs)
* validate and order .Rs child nodes * underline book title (.%B) and issuer (.%I) * enclose title of article (.%T) in quotes * avoid calling mdoc_verr directly, use a proper error code instead
-rw-r--r--usr.bin/mandoc/libmdoc.h3
-rw-r--r--usr.bin/mandoc/mdoc.c5
-rw-r--r--usr.bin/mandoc/mdoc_action.c91
-rw-r--r--usr.bin/mandoc/mdoc_term.c38
-rw-r--r--usr.bin/mandoc/mdoc_validate.c54
5 files changed, 170 insertions, 21 deletions
diff --git a/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h
index f51f9d709a1..916064f5e11 100644
--- a/usr.bin/mandoc/libmdoc.h
+++ b/usr.bin/mandoc/libmdoc.h
@@ -1,4 +1,4 @@
-/* $Id: libmdoc.h,v 1.21 2009/09/21 21:11:37 schwarze Exp $ */
+/* $Id: libmdoc.h,v 1.22 2009/10/19 16:27:52 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -92,6 +92,7 @@ enum merr {
EQUOTPHR,
ENOCTX,
ELIB,
+ EBADCHILD,
MERRMAX
};
diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c
index e5f3fc12f3d..64b1ca0a0af 100644
--- a/usr.bin/mandoc/mdoc.c
+++ b/usr.bin/mandoc/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.28 2009/10/19 10:20:24 schwarze Exp $ */
+/* $Id: mdoc.c,v 1.29 2009/10/19 16:27:52 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -76,7 +76,8 @@ const char *const __mdoc_merrnames[MERRMAX] = {
"unclosed explicit scope", /* EOPEN */
"unterminated quoted phrase", /* EQUOTPHR */
"closure macro without prior context", /* ENOCTX */
- "no description found for library" /* ELIB */
+ "no description found for library", /* ELIB */
+ "bad child for parent context", /* EBADCHILD */
};
const char *const __mdoc_macronames[MDOC_MAX] = {
diff --git a/usr.bin/mandoc/mdoc_action.c b/usr.bin/mandoc/mdoc_action.c
index a1aec656899..764093e35fa 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.22 2009/10/19 15:44:01 schwarze Exp $ */
+/* $Id: mdoc_action.c,v 1.23 2009/10/19 16:27:52 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -32,6 +32,11 @@ struct actions {
int (*post)(POST_ARGS);
};
+static int concat(struct mdoc *,
+ const struct mdoc_node *,
+ char *, size_t);
+static inline int order_rs(int);
+
static int post_ar(POST_ARGS);
static int post_at(POST_ARGS);
static int post_bl(POST_ARGS);
@@ -45,6 +50,7 @@ static int post_lb(POST_ARGS);
static int post_nm(POST_ARGS);
static int post_os(POST_ARGS);
static int post_prol(POST_ARGS);
+static int post_rs(POST_ARGS);
static int post_sh(POST_ARGS);
static int post_st(POST_ARGS);
static int post_std(POST_ARGS);
@@ -141,7 +147,7 @@ static const struct actions mdoc_actions[MDOC_MAX] = {
{ NULL, NULL }, /* Qo */
{ NULL, NULL }, /* Qq */
{ NULL, NULL }, /* Re */
- { NULL, NULL }, /* Rs */
+ { NULL, post_rs }, /* Rs */
{ NULL, NULL }, /* Sc */
{ NULL, NULL }, /* So */
{ NULL, NULL }, /* Sq */
@@ -178,8 +184,23 @@ static const struct actions mdoc_actions[MDOC_MAX] = {
{ NULL, NULL }, /* sp */
};
-static int concat(struct mdoc *, const struct mdoc_node *,
- char *, size_t);
+#define RSORD_MAX 13
+
+static const int rsord[RSORD_MAX] = {
+ MDOC__A,
+ MDOC__T,
+ MDOC__B,
+ MDOC__I,
+ MDOC__J,
+ MDOC__R,
+ MDOC__N,
+ MDOC__V,
+ MDOC__P,
+ MDOC__Q,
+ MDOC__D,
+ MDOC__O,
+ MDOC__C
+};
int
@@ -895,3 +916,65 @@ post_display(POST_ARGS)
}
+static inline int
+order_rs(int t)
+{
+ int i;
+
+ for (i = 0; i < RSORD_MAX; i++)
+ if (rsord[i] == t)
+ return(i);
+
+ abort();
+ /* NOTREACHED */
+}
+
+
+/* ARGSUSED */
+static int
+post_rs(POST_ARGS)
+{
+ struct mdoc_node *nn, *next, *prev;
+ int o;
+
+ if (MDOC_BLOCK != n->type)
+ return(1);
+
+ assert(n->body->child);
+ for (next = NULL, nn = n->body->child->next; nn; nn = next) {
+ o = order_rs(nn->tok);
+
+ /* Remove `nn' from the chain. */
+ next = nn->next;
+ if (next)
+ next->prev = nn->prev;
+
+ prev = nn->prev;
+ if (prev)
+ prev->next = nn->next;
+
+ nn->prev = nn->next = NULL;
+
+ /*
+ * Scan back until we reach a node that's ordered before
+ * us, then set ourselves as being the next.
+ */
+ for ( ; prev; prev = prev->prev)
+ if (order_rs(prev->tok) <= o)
+ break;
+
+ nn->prev = prev;
+ if (prev) {
+ if (prev->next)
+ prev->next->prev = nn;
+ nn->next = prev->next;
+ prev->next = nn;
+ continue;
+ }
+
+ n->body->child->prev = nn;
+ nn->next = n->body->child;
+ n->body->child = nn;
+ }
+ return(1);
+}
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index c81e7fab920..59f32f8983a 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.57 2009/10/19 13:29:56 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.58 2009/10/19 16:27:52 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -106,6 +106,7 @@ static void termp_sq_post(DECL_ARGS);
static void termp_ss_post(DECL_ARGS);
static void termp_vt_post(DECL_ARGS);
+static int termp__t_pre(DECL_ARGS);
static int termp_an_pre(DECL_ARGS);
static int termp_ap_pre(DECL_ARGS);
static int termp_aq_pre(DECL_ARGS);
@@ -189,15 +190,15 @@ static const struct termact termacts[MDOC_MAX] = {
{ termp_under_pre, termp_vt_post }, /* Vt */
{ termp_xr_pre, NULL }, /* Xr */
{ NULL, termp____post }, /* %A */
- { NULL, termp____post }, /* %B */
+ { termp_under_pre, termp____post }, /* %B */
{ NULL, termp____post }, /* %D */
- { NULL, termp____post }, /* %I */
+ { termp_under_pre, termp____post }, /* %I */
{ termp_under_pre, termp____post }, /* %J */
{ NULL, termp____post }, /* %N */
{ NULL, termp____post }, /* %O */
{ NULL, termp____post }, /* %P */
{ NULL, termp____post }, /* %R */
- { termp_under_pre, termp____post }, /* %T */
+ { termp__t_pre, termp____post }, /* %T */
{ NULL, termp____post }, /* %V */
{ NULL, NULL }, /* Ac */
{ termp_aq_pre, termp_aq_post }, /* Ao */
@@ -218,7 +219,7 @@ static const struct termact termacts[MDOC_MAX] = {
{ termp_under_pre, NULL }, /* Em */
{ NULL, NULL }, /* Eo */
{ termp_xx_pre, NULL }, /* Fx */
- { termp_bold_pre, NULL }, /* Ms */
+ { termp_bold_pre, NULL }, /* Ms */ /* FIXME: convert to symbol? */
{ NULL, NULL }, /* No */
{ termp_ns_pre, NULL }, /* Ns */
{ termp_xx_pre, NULL }, /* Nx */
@@ -260,11 +261,11 @@ static const struct termact termacts[MDOC_MAX] = {
{ termp_brq_pre, termp_brq_post }, /* Brq */
{ termp_brq_pre, termp_brq_post }, /* Bro */
{ NULL, NULL }, /* Brc */
- { NULL, NULL }, /* %C */
- { NULL, NULL }, /* Es */
- { NULL, NULL }, /* En */
+ { NULL, termp____post }, /* %C */
+ { NULL, NULL }, /* Es */ /* TODO */
+ { NULL, NULL }, /* En */ /* TODO */
{ termp_xx_pre, NULL }, /* Dx */
- { NULL, NULL }, /* %Q */
+ { NULL, termp____post }, /* %Q */
{ termp_sp_pre, NULL }, /* br */
{ termp_sp_pre, NULL }, /* sp */
};
@@ -2063,6 +2064,14 @@ termp____post(DECL_ARGS)
{
p->flags |= TERMP_NOSPACE;
+ switch (node->tok) {
+ case (MDOC__T):
+ term_word(p, "\\(rq");
+ p->flags |= TERMP_NOSPACE;
+ break;
+ default:
+ break;
+ }
term_word(p, node->next ? "," : ".");
}
@@ -2104,3 +2113,14 @@ termp_under_pre(DECL_ARGS)
p->under++;
return(1);
}
+
+
+/* ARGSUSED */
+static int
+termp__t_pre(DECL_ARGS)
+{
+
+ term_word(p, "\\(lq");
+ p->flags |= TERMP_NOSPACE;
+ return(1);
+}
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index e4eb8748aff..6eb0a89b100 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.35 2009/08/22 22:50:17 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.36 2009/10/19 16:27:52 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -85,6 +85,7 @@ static int post_it(POST_ARGS);
static int post_lb(POST_ARGS);
static int post_nm(POST_ARGS);
static int post_root(POST_ARGS);
+static int post_rs(POST_ARGS);
static int post_sh(POST_ARGS);
static int post_sh_body(POST_ARGS);
static int post_sh_head(POST_ARGS);
@@ -121,6 +122,7 @@ static v_post posts_nd[] = { berr_ge1, NULL };
static v_post posts_nm[] = { post_nm, NULL };
static v_post posts_notext[] = { eerr_eq0, NULL };
static v_post posts_pf[] = { eerr_eq1, 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_sp[] = { post_sp, NULL };
static v_post posts_ss[] = { herr_ge1, NULL };
@@ -232,7 +234,7 @@ const struct valids mdoc_valids[MDOC_MAX] = {
{ NULL, NULL }, /* Qo */
{ NULL, posts_wline }, /* Qq */
{ NULL, NULL }, /* Re */
- { NULL, posts_wline }, /* Rs */
+ { NULL, posts_rs }, /* Rs */
{ NULL, NULL }, /* Sc */
{ NULL, NULL }, /* So */
{ NULL, posts_wline }, /* Sq */
@@ -1073,9 +1075,7 @@ post_bl(POST_ARGS)
if (MDOC_BLOCK == n->type)
if (MDOC_It == n->tok)
continue;
- return(mdoc_verr(mdoc, n->line, n->pos,
- "bad child of parent %s",
- mdoc_macronames[mdoc->last->tok]));
+ return(mdoc_nerr(mdoc, n, EBADCHILD));
}
return(1);
@@ -1164,6 +1164,50 @@ post_st(POST_ARGS)
static int
+post_rs(POST_ARGS)
+{
+ struct mdoc_node *nn;
+
+ if (MDOC_BODY != mdoc->last->type)
+ return(1);
+
+ for (nn = mdoc->last->child; nn; nn = nn->next)
+ switch (nn->tok) {
+ case(MDOC__Q):
+ /* FALLTHROUGH */
+ case(MDOC__C):
+ /* FALLTHROUGH */
+ case(MDOC__A):
+ /* FALLTHROUGH */
+ case(MDOC__B):
+ /* FALLTHROUGH */
+ case(MDOC__D):
+ /* FALLTHROUGH */
+ case(MDOC__I):
+ /* FALLTHROUGH */
+ case(MDOC__J):
+ /* FALLTHROUGH */
+ case(MDOC__N):
+ /* FALLTHROUGH */
+ case(MDOC__O):
+ /* FALLTHROUGH */
+ case(MDOC__P):
+ /* FALLTHROUGH */
+ case(MDOC__R):
+ /* FALLTHROUGH */
+ case(MDOC__T):
+ /* FALLTHROUGH */
+ case(MDOC__V):
+ break;
+ default:
+ return(mdoc_nerr(mdoc, nn, EBADCHILD));
+ }
+
+ return(1);
+}
+
+
+static int
post_sh(POST_ARGS)
{