aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_validate.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-11-29 13:02:47 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-11-29 13:02:47 +0000
commita974d4be58d9f1f741b4e1b5e0b69934a2eeacec (patch)
tree9781e2a3539eda2cf81676bf78c987a6491672ef /mdoc_validate.c
parent3242f86b1e29a933cc8ab3bd8022d2296d5c5d9b (diff)
downloadmandoc-a974d4be58d9f1f741b4e1b5e0b69934a2eeacec.tar.gz
mandoc-a974d4be58d9f1f741b4e1b5e0b69934a2eeacec.tar.zst
mandoc-a974d4be58d9f1f741b4e1b5e0b69934a2eeacec.zip
Move `Mt', `Ar', and `Li' handling from mdoc_action.c into mdoc_validate.c.
Clarify that `Mt' gets a default `~' (as per groff 1.20) and document it in mdoc.7. Made `Lk' be removed in mdoc_macro.c if it has no arguments. This fixes segfaults in mdoc_{term,html}.c that nobody's managed to raise yet.
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r--mdoc_validate.c52
1 files changed, 47 insertions, 5 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 3acab0dc..a10be56c 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.122 2010/11/29 12:22:28 kristaps Exp $ */
+/* $Id: mdoc_validate.c,v 1.123 2010/11/29 13:02:47 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -85,6 +85,8 @@ 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_defaults(POST_ARGS);
+static int post_eoln(POST_ARGS);
static int post_dt(POST_ARGS);
static int post_it(POST_ARGS);
static int post_lb(POST_ARGS);
@@ -95,7 +97,6 @@ static int post_sh(POST_ARGS);
static int post_sh_body(POST_ARGS);
static int post_sh_head(POST_ARGS);
static int post_st(POST_ARGS);
-static int post_eoln(POST_ARGS);
static int post_vt(POST_ARGS);
static int pre_an(PRE_ARGS);
static int pre_bd(PRE_ARGS);
@@ -117,6 +118,7 @@ static v_post posts_bf[] = { hwarn_le1, post_bf, NULL };
static v_post posts_bl[] = { bwarn_ge1, post_bl, NULL };
static v_post posts_bool[] = { eerr_eq1, ebool, NULL };
static v_post posts_eoln[] = { post_eoln, NULL };
+static v_post posts_defaults[] = { post_defaults, NULL };
static v_post posts_dt[] = { post_dt, NULL };
static v_post posts_fo[] = { hwarn_eq1, bwarn_ge1, NULL };
static v_post posts_it[] = { post_it, NULL };
@@ -167,7 +169,7 @@ const struct valids mdoc_valids[MDOC_MAX] = {
{ pres_it, posts_it }, /* It */
{ NULL, posts_text }, /* Ad */
{ pres_an, posts_an }, /* An */
- { NULL, NULL }, /* Ar */
+ { NULL, posts_defaults }, /* Ar */
{ NULL, posts_text }, /* Cd */
{ NULL, NULL }, /* Cm */
{ NULL, NULL }, /* Dv */
@@ -181,7 +183,7 @@ const struct valids mdoc_valids[MDOC_MAX] = {
{ NULL, posts_wtext }, /* Ft */
{ NULL, posts_text }, /* Ic */
{ NULL, posts_text1 }, /* In */
- { NULL, NULL }, /* Li */
+ { NULL, posts_defaults }, /* Li */
{ NULL, posts_nd }, /* Nd */
{ NULL, posts_nm }, /* Nm */
{ NULL, posts_wline }, /* Op */
@@ -260,7 +262,7 @@ const struct valids mdoc_valids[MDOC_MAX] = {
{ NULL, posts_lb }, /* Lb */
{ NULL, posts_notext }, /* Lp */
{ NULL, posts_text }, /* Lk */
- { NULL, posts_text }, /* Mt */
+ { NULL, posts_defaults }, /* Mt */
{ NULL, posts_wline }, /* Brq */
{ NULL, NULL }, /* Bro */
{ NULL, NULL }, /* Brc */
@@ -1133,6 +1135,46 @@ post_nm(POST_ARGS)
return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NONAME));
}
+static int
+post_defaults(POST_ARGS)
+{
+ struct mdoc_node *nn;
+
+ /*
+ * The `Ar' defaults to "file ..." if no value is provided as an
+ * argument; the `Mt' macro uses "~"; the `Li' just gets an
+ * empty string.
+ */
+
+ if (mdoc->last->child)
+ return(1);
+
+ nn = mdoc->last;
+ mdoc->next = MDOC_NEXT_CHILD;
+
+ switch (nn->tok) {
+ case (MDOC_Ar):
+ if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "file"))
+ return(0);
+ if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "..."))
+ return(0);
+ break;
+ case (MDOC_Li):
+ if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, ""))
+ return(0);
+ break;
+ case (MDOC_Mt):
+ if ( ! mdoc_word_alloc(mdoc, nn->line, nn->pos, "~"))
+ return(0);
+ break;
+ default:
+ abort();
+ /* NOTREACHED */
+ }
+
+ mdoc->last = nn;
+ return(1);
+}
static int
post_at(POST_ARGS)