summaryrefslogtreecommitdiffstats
path: root/mdoc_man.c
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 /mdoc_man.c
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
Diffstat (limited to 'mdoc_man.c')
-rw-r--r--mdoc_man.c103
1 files changed, 94 insertions, 9 deletions
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)
{