summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-07-30 00:19:16 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-07-30 00:19:16 +0000
commit146dcfc953f48acd462342b3dfc86200e3e0a195 (patch)
tree0d9ad99301bef877f5f3f9f3a12ec73e0626d84d
parent308a6398bf0d71bbf420513b557132e32e95285d (diff)
downloadmandoc-146dcfc953f48acd462342b3dfc86200e3e0a195.tar.gz
Various improvements related to .Ex and .Rv:
* let .Nm fall back to the empty string, not to UNKNOWN * never let .Rv copy an argument from .Nm * avoid spurious \fR after empty .Nm in -Tman * correct handling of .Ex and .Rv in -Tman * correct the wording of the output for .Rv without arguments * use non-breaking spaces in .Ex and .Rv output where required * split MANDOCERR_NONAME into a warning for .Ex and an error for .Nm
-rw-r--r--mandoc.h3
-rw-r--r--mdoc_html.c54
-rw-r--r--mdoc_man.c103
-rw-r--r--mdoc_term.c51
-rw-r--r--mdoc_validate.c41
-rw-r--r--read.c3
6 files changed, 174 insertions, 81 deletions
diff --git a/mandoc.h b/mandoc.h
index 5df81b46..e1d6ed49 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -92,6 +92,7 @@ enum mandocerr {
MANDOCERR_BD_NOTYPE, /* missing display type, using -ragged */
MANDOCERR_BL_LATETYPE, /* list type is not the first argument: arg */
MANDOCERR_BL_NOWIDTH, /* missing -width in -tag list, using 8n */
+ MANDOCERR_EX_NONAME, /* missing name for .Ex, using "" */
MANDOCERR_IT_NOHEAD, /* empty head in list item: type */
MANDOCERR_IT_NOBODY, /* empty list item: type */
MANDOCERR_BF_NOFONT, /* missing font type, using \fR */
@@ -147,8 +148,8 @@ enum mandocerr {
/* related to request and macro arguments */
MANDOCERR_NAMESC, /* escaped character not allowed in a name */
- MANDOCERR_NONAME, /* manual name not yet set */
MANDOCERR_ARGCOUNT, /* argument count wrong */
+ MANDOCERR_NM_NONAME, /* missing manual name, using "" */
MANDOCERR_ST_BAD, /* unknown standard specifier: standard */
MANDOCERR_UNAME, /* uname(3) system call failed */
MANDOCERR_NUMERIC, /* request requires a numeric argument */
diff --git a/mdoc_html.c b/mdoc_html.c
index 5c69b689..7130c376 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -1069,11 +1069,11 @@ mdoc_ex_pre(MDOC_ARGS)
}
if (nchild > 1)
- print_text(h, "utilities exit");
+ print_text(h, "utilities exit\\~0");
else
- print_text(h, "utility exits");
+ print_text(h, "utility exits\\~0");
- print_text(h, "0 on success, and >0 if an error occurs.");
+ print_text(h, "on success, and\\~>0 if an error occurs.");
return(0);
}
@@ -1744,35 +1744,41 @@ mdoc_rv_pre(MDOC_ARGS)
PAIR_CLASS_INIT(&tag, "fname");
- print_text(h, "The");
-
nchild = n->nchild;
- for (n = n->child; n; n = n->next) {
- assert(MDOC_TEXT == n->type);
+ if (nchild > 0) {
+ print_text(h, "The");
- t = print_otag(h, TAG_B, 1, &tag);
- print_text(h, n->string);
- print_tagq(h, t);
-
- h->flags |= HTML_NOSPACE;
- print_text(h, "()");
+ for (n = n->child; n; n = n->next) {
+ t = print_otag(h, TAG_B, 1, &tag);
+ print_text(h, n->string);
+ print_tagq(h, t);
- if (nchild > 2 && n->next) {
h->flags |= HTML_NOSPACE;
- print_text(h, ",");
+ print_text(h, "()");
+
+ if (n->next == NULL)
+ continue;
+
+ if (nchild > 2) {
+ h->flags |= HTML_NOSPACE;
+ print_text(h, ",");
+ }
+ if (n->next->next == NULL)
+ print_text(h, "and");
}
- if (n->next && NULL == n->next->next)
- print_text(h, "and");
- }
+ if (nchild > 1)
+ print_text(h, "functions return");
+ else
+ print_text(h, "function returns");
- if (nchild > 1)
- print_text(h, "functions return");
- else
- print_text(h, "function returns");
+ print_text(h, "the value\\~0 if successful;");
+ } else
+ print_text(h, "Upon successful completion,"
+ " the value\\~0 is returned;");
- print_text(h, "the value 0 if successful; otherwise the "
- "value -1 is returned and the global variable");
+ print_text(h, "otherwise the value\\~\\-1 is returned"
+ " and the global variable");
PAIR_CLASS_INIT(&tag, "var");
t = print_otag(h, TAG_B, 1, &tag);
diff --git a/mdoc_man.c b/mdoc_man.c
index e27c9432..504790b9 100644
--- a/mdoc_man.c
+++ b/mdoc_man.c
@@ -83,6 +83,7 @@ static int pre_en(DECL_ARGS);
static int pre_enc(DECL_ARGS);
static int pre_em(DECL_ARGS);
static int pre_es(DECL_ARGS);
+static int pre_ex(DECL_ARGS);
static int pre_fa(DECL_ARGS);
static int pre_fd(DECL_ARGS);
static int pre_fl(DECL_ARGS);
@@ -99,6 +100,7 @@ static int pre_no(DECL_ARGS);
static int pre_ns(DECL_ARGS);
static int pre_pp(DECL_ARGS);
static int pre_rs(DECL_ARGS);
+static int pre_rv(DECL_ARGS);
static int pre_sm(DECL_ARGS);
static int pre_sp(DECL_ARGS);
static int pre_sect(DECL_ARGS);
@@ -139,9 +141,7 @@ static const struct manact manacts[MDOC_MAX + 1] = {
{ NULL, pre_li, post_font, NULL, NULL }, /* Dv */
{ NULL, pre_li, post_font, NULL, NULL }, /* Er */
{ NULL, pre_li, post_font, NULL, NULL }, /* Ev */
- { NULL, pre_enc, post_enc, "The \\fB",
- "\\fP\nutility exits 0 on success, and >0 if an error occurs."
- }, /* Ex */
+ { NULL, pre_ex, NULL, NULL, NULL }, /* Ex */
{ NULL, pre_fa, post_fa, NULL, NULL }, /* Fa */
{ NULL, pre_fd, post_fd, NULL, NULL }, /* Fd */
{ NULL, pre_fl, post_fl, NULL, NULL }, /* Fl */
@@ -155,11 +155,7 @@ static const struct manact manacts[MDOC_MAX + 1] = {
{ cond_body, pre_enc, post_enc, "[", "]" }, /* Op */
{ NULL, pre_ft, post_font, NULL, NULL }, /* Ot */
{ NULL, pre_em, post_font, NULL, NULL }, /* Pa */
- { NULL, pre_enc, post_enc, "The \\fB",
- "\\fP\nfunction returns the value 0 if successful;\n"
- "otherwise the value -1 is returned and the global\n"
- "variable \\fIerrno\\fP is set to indicate the error."
- }, /* Rv */
+ { NULL, pre_rv, NULL, NULL, NULL }, /* Rv */
{ NULL, NULL, NULL, NULL, NULL }, /* St */
{ NULL, pre_em, post_font, NULL, NULL }, /* Va */
{ NULL, pre_vt, post_vt, NULL, NULL }, /* Vt */
@@ -673,6 +669,42 @@ post_enc(DECL_ARGS)
print_word(suffix);
}
+static int
+pre_ex(DECL_ARGS)
+{
+ int nchild;
+
+ outflags |= MMAN_br | MMAN_nl;
+
+ print_word("The");
+
+ nchild = n->nchild;
+ for (n = n->child; n; n = n->next) {
+ font_push('B');
+ print_word(n->string);
+ font_pop();
+
+ if (n->next == NULL)
+ continue;
+
+ if (nchild > 2) {
+ outflags &= ~MMAN_spc;
+ print_word(",");
+ }
+ if (n->next->next == NULL)
+ print_word("and");
+ }
+
+ if (nchild > 1)
+ print_word("utilities exit\\~0");
+ else
+ print_word("utility exits\\~0");
+
+ print_word("on success, and\\~>0 if an error occurs.");
+ outflags |= MMAN_nl;
+ return(0);
+}
+
static void
post_font(DECL_ARGS)
{
@@ -1511,7 +1543,8 @@ post_nm(DECL_ARGS)
case MDOC_HEAD:
/* FALLTHROUGH */
case MDOC_ELEM:
- font_pop();
+ if (n->child != NULL || meta->name != NULL)
+ font_pop();
break;
default:
break;
@@ -1564,6 +1597,58 @@ pre_rs(DECL_ARGS)
}
static int
+pre_rv(DECL_ARGS)
+{
+ int nchild;
+
+ outflags |= MMAN_br | MMAN_nl;
+
+ nchild = n->nchild;
+ if (nchild > 0) {
+ print_word("The");
+
+ for (n = n->child; n; n = n->next) {
+ font_push('B');
+ print_word(n->string);
+ font_pop();
+
+ outflags &= ~MMAN_spc;
+ print_word("()");
+
+ if (n->next == NULL)
+ continue;
+
+ if (nchild > 2) {
+ outflags &= ~MMAN_spc;
+ print_word(",");
+ }
+ if (n->next->next == NULL)
+ print_word("and");
+ }
+
+ if (nchild > 1)
+ print_word("functions return");
+ else
+ print_word("function returns");
+
+ print_word("the value\\~0 if successful;");
+ } else
+ print_word("Upon successful completion, "
+ "the value\\~0 is returned;");
+
+ print_word("otherwise the value\\~\\-1 is returned"
+ " and the global variable");
+
+ font_push('I');
+ print_word("errno");
+ font_pop();
+
+ print_word("is set to indicate the error.");
+ outflags |= MMAN_nl;
+ return(0);
+}
+
+static int
pre_sm(DECL_ARGS)
{
diff --git a/mdoc_term.c b/mdoc_term.c
index e05b9f96..63829263 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1167,33 +1167,42 @@ termp_rv_pre(DECL_ARGS)
int nchild;
term_newln(p);
- term_word(p, "The");
nchild = n->nchild;
- for (n = n->child; n; n = n->next) {
- term_fontpush(p, TERMFONT_BOLD);
- term_word(p, n->string);
- term_fontpop(p);
+ if (nchild > 0) {
+ term_word(p, "The");
- p->flags |= TERMP_NOSPACE;
- term_word(p, "()");
+ for (n = n->child; n; n = n->next) {
+ term_fontpush(p, TERMFONT_BOLD);
+ term_word(p, n->string);
+ term_fontpop(p);
- if (nchild > 2 && n->next) {
p->flags |= TERMP_NOSPACE;
- term_word(p, ",");
+ term_word(p, "()");
+
+ if (n->next == NULL)
+ continue;
+
+ if (nchild > 2) {
+ p->flags |= TERMP_NOSPACE;
+ term_word(p, ",");
+ }
+ if (n->next->next == NULL)
+ term_word(p, "and");
}
- if (n->next && NULL == n->next->next)
- term_word(p, "and");
- }
+ if (nchild > 1)
+ term_word(p, "functions return");
+ else
+ term_word(p, "function returns");
- if (nchild > 1)
- term_word(p, "functions return");
- else
- term_word(p, "function returns");
+ term_word(p, "the value\\~0 if successful;");
+ } else
+ term_word(p, "Upon successful completion,"
+ " the value\\~0 is returned;");
- term_word(p, "the value 0 if successful; otherwise the "
- "value -1 is returned and the global variable");
+ term_word(p, "otherwise the value\\~\\-1 is returned"
+ " and the global variable");
term_fontpush(p, TERMFONT_UNDER);
term_word(p, "errno");
@@ -1229,11 +1238,11 @@ termp_ex_pre(DECL_ARGS)
}
if (nchild > 1)
- term_word(p, "utilities exit");
+ term_word(p, "utilities exit\\~0");
else
- term_word(p, "utility exits");
+ term_word(p, "utility exits\\~0");
- term_word(p, "0 on success, and >0 if an error occurs.");
+ term_word(p, "on success, and\\~>0 if an error occurs.");
p->flags |= TERMP_SENTENCE;
return(0);
diff --git a/mdoc_validate.c b/mdoc_validate.c
index c8596140..37236293 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -100,6 +100,7 @@ static int post_dt(POST_ARGS);
static int post_en(POST_ARGS);
static int post_es(POST_ARGS);
static int post_eoln(POST_ARGS);
+static int post_ex(POST_ARGS);
static int post_hyph(POST_ARGS);
static int post_ignpar(POST_ARGS);
static int post_it(POST_ARGS);
@@ -116,7 +117,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_std(POST_ARGS);
static int post_vt(POST_ARGS);
static int pre_an(PRE_ARGS);
static int pre_bd(PRE_ARGS);
@@ -149,6 +149,7 @@ static v_post posts_dl[] = { post_literal, bwarn_ge1, NULL };
static v_post posts_dt[] = { post_dt, post_prol, NULL };
static v_post posts_en[] = { post_en, NULL };
static v_post posts_es[] = { post_es, NULL };
+static v_post posts_ex[] = { post_ex, NULL };
static v_post posts_fo[] = { hwarn_eq1, bwarn_ge1, NULL };
static v_post posts_hyph[] = { post_hyph, NULL };
static v_post posts_hyphtext[] = { ewarn_ge1, post_hyph, NULL };
@@ -165,7 +166,6 @@ static v_post posts_sh[] = { post_ignpar,hwarn_ge1,post_sh,post_hyph,NULL };
static v_post posts_sp[] = { post_par, ewarn_le1, NULL };
static v_post posts_ss[] = { post_ignpar, hwarn_ge1, post_hyph, NULL };
static v_post posts_st[] = { post_st, NULL };
-static v_post posts_std[] = { post_std, NULL };
static v_post posts_text[] = { ewarn_ge1, NULL };
static v_post posts_text1[] = { ewarn_eq1, NULL };
static v_post posts_vt[] = { post_vt, NULL };
@@ -207,7 +207,7 @@ static const struct valids mdoc_valids[MDOC_MAX] = {
{ NULL, NULL }, /* Dv */
{ NULL, NULL }, /* Er */
{ NULL, NULL }, /* Ev */
- { pres_std, posts_std }, /* Ex */
+ { pres_std, posts_ex }, /* Ex */
{ NULL, NULL }, /* Fa */
{ NULL, posts_text }, /* Fd */
{ NULL, NULL }, /* Fl */
@@ -221,7 +221,7 @@ static const struct valids mdoc_valids[MDOC_MAX] = {
{ NULL, NULL }, /* Op */
{ pres_obsolete, NULL }, /* Ot */
{ NULL, posts_defaults }, /* Pa */
- { pres_std, posts_std }, /* Rv */
+ { pres_std, NULL }, /* Rv */
{ NULL, posts_st }, /* St */
{ NULL, NULL }, /* Va */
{ NULL, posts_vt }, /* Vt */
@@ -534,12 +534,6 @@ check_argv(struct mdoc *mdoc, struct mdoc_node *n, struct mdoc_argv *v)
for (i = 0; i < (int)v->sz; i++)
check_text(mdoc, v->line, v->pos, v->value[i]);
-
- /* FIXME: move to post_std(). */
-
- if (MDOC_Std == v->arg)
- if ( ! (v->sz || mdoc->meta.name))
- mdoc_nmsg(mdoc, n, MANDOCERR_NONAME);
}
static void
@@ -1128,10 +1122,8 @@ post_nm(POST_ARGS)
mdoc_deroff(&mdoc->meta.name, mdoc->last);
- if (NULL == mdoc->meta.name) {
- mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NONAME);
- mdoc->meta.name = mandoc_strdup("UNKNOWN");
- }
+ if (NULL == mdoc->meta.name)
+ mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NM_NONAME);
return(1);
}
@@ -2395,32 +2387,31 @@ post_os(POST_ARGS)
return(1);
}
+/*
+ * If no argument is provided,
+ * fill in the name of the current manual page.
+ */
static int
-post_std(POST_ARGS)
+post_ex(POST_ARGS)
{
- struct mdoc_node *nn, *n;
+ struct mdoc_node *n;
n = mdoc->last;
- /*
- * Macros accepting `-std' as an argument have the name of the
- * current document (`Nm') filled in as the argument if it's not
- * provided.
- */
-
if (n->child)
return(1);
- if (NULL == mdoc->meta.name)
+ if (mdoc->meta.name == NULL) {
+ mdoc_nmsg(mdoc, n, MANDOCERR_EX_NONAME);
return(1);
+ }
- nn = n;
mdoc->next = MDOC_NEXT_CHILD;
if ( ! mdoc_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name))
return(0);
- mdoc->last = nn;
+ mdoc->last = n;
return(1);
}
diff --git a/read.c b/read.c
index 20fa2640..0292b645 100644
--- a/read.c
+++ b/read.c
@@ -136,6 +136,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
"missing display type, using -ragged",
"list type is not the first argument",
"missing -width in -tag list, using 8n",
+ "missing name for .Ex, using \"\"",
"empty head in list item",
"empty list item",
"missing font type, using \\fR",
@@ -191,8 +192,8 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
/* related to request and macro arguments */
"escaped character not allowed in a name",
- "manual name not yet set",
"argument count wrong",
+ "missing manual name, using \"\"",
"unknown standard specifier",
"uname(3) system call failed",
"request requires a numeric argument",