summaryrefslogtreecommitdiffstats
path: root/mdoc_man.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-01-11 17:39:53 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-01-11 17:39:53 +0000
commitb319284232133fdd31db9dc5894da706c99eda06 (patch)
tree83ab8d1f6f6dd343a1fc796d73b9551f8fafeb2c /mdoc_man.c
parentf1073511b0d42c759d7f3aac33e0f567c69e7dfe (diff)
downloadmandoc-b319284232133fdd31db9dc5894da706c99eda06.tar.gz
Do text production for .Bt, .Ex, .Rv, .Ud at the validation stage
rather than in the formatters. Use NODE_NOSRC flag for .Lb and NODE_NOSRC and NODE_NOPRT for .St. Results in a more rigorous syntax tree and in 135 lines less code. This work was triggered by a question from Abhinav Upadhyay <er dot abhinav dot upadhyay at gmail dot com> (NetBSD) on discuss@.
Diffstat (limited to 'mdoc_man.c')
-rw-r--r--mdoc_man.c110
1 files changed, 10 insertions, 100 deletions
diff --git a/mdoc_man.c b/mdoc_man.c
index 393d362c..adb76b34 100644
--- a/mdoc_man.c
+++ b/mdoc_man.c
@@ -102,14 +102,12 @@ 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);
static int pre_sy(DECL_ARGS);
static void pre_syn(const struct roff_node *);
static int pre_vt(DECL_ARGS);
-static int pre_ux(DECL_ARGS);
static int pre_xr(DECL_ARGS);
static void print_word(const char *);
static void print_line(const char *, int);
@@ -157,7 +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_rv, NULL, NULL, NULL }, /* Rv */
+ { NULL, pre_ex, 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 */
@@ -223,10 +221,10 @@ static const struct manact manacts[MDOC_MAX + 1] = {
{ NULL, NULL, NULL, NULL, NULL }, /* Oc */
{ NULL, pre_bk, post_bk, NULL, NULL }, /* Bk */
{ NULL, NULL, NULL, NULL, NULL }, /* Ek */
- { NULL, pre_ux, NULL, "is currently in beta test.", NULL }, /* Bt */
+ { NULL, NULL, NULL, NULL, NULL }, /* Bt */
{ NULL, NULL, NULL, NULL, NULL }, /* Hf */
{ NULL, pre_em, post_font, NULL, NULL }, /* Fr */
- { NULL, pre_ux, NULL, "currently under development.", NULL }, /* Ud */
+ { NULL, NULL, NULL, NULL, NULL }, /* Ud */
{ NULL, NULL, post_lb, NULL, NULL }, /* Lb */
{ NULL, pre_pp, NULL, NULL, NULL }, /* Lp */
{ NULL, pre_lk, NULL, NULL, NULL }, /* Lk */
@@ -600,10 +598,14 @@ print_node(DECL_ARGS)
printf("\\&");
outflags &= ~MMAN_spc;
}
- if (outflags & MMAN_Sm && ! (n->flags & NODE_DELIMC))
+ if (n->flags & NODE_DELIMC)
+ outflags &= ~(MMAN_spc | MMAN_spc_force);
+ else if (outflags & MMAN_Sm)
outflags |= MMAN_spc_force;
print_word(n->string);
- if (outflags & MMAN_Sm && ! (n->flags & NODE_DELIMO))
+ if (n->flags & NODE_DELIMO)
+ outflags &= ~(MMAN_spc | MMAN_spc_force);
+ else if (outflags & MMAN_Sm)
outflags |= MMAN_spc;
} else {
/*
@@ -684,36 +686,8 @@ post_enc(DECL_ARGS)
static int
pre_ex(DECL_ARGS)
{
- struct roff_node *nch;
-
outflags |= MMAN_br | MMAN_nl;
-
- print_word("The");
-
- for (nch = n->child; nch != NULL; nch = nch->next) {
- font_push('B');
- print_word(nch->string);
- font_pop();
-
- if (nch->next == NULL)
- continue;
-
- if (nch->prev != NULL || nch->next->next != NULL) {
- outflags &= ~MMAN_spc;
- print_word(",");
- }
- if (nch->next->next == NULL)
- print_word("and");
- }
-
- if (n->child != NULL && n->child->next != NULL)
- 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;
+ return 1;
}
static void
@@ -1625,57 +1599,6 @@ pre_rs(DECL_ARGS)
}
static int
-pre_rv(DECL_ARGS)
-{
- struct roff_node *nch;
-
- outflags |= MMAN_br | MMAN_nl;
-
- if (n->child != NULL) {
- print_word("The");
-
- for (nch = n->child; nch != NULL; nch = nch->next) {
- font_push('B');
- print_word(nch->string);
- font_pop();
-
- outflags &= ~MMAN_spc;
- print_word("()");
-
- if (nch->next == NULL)
- continue;
-
- if (nch->prev != NULL || nch->next->next != NULL) {
- outflags &= ~MMAN_spc;
- print_word(",");
- }
- if (nch->next->next == NULL)
- print_word("and");
- }
-
- if (n->child != NULL && n->child->next != NULL)
- 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_skip(DECL_ARGS)
{
@@ -1771,16 +1694,3 @@ pre_xr(DECL_ARGS)
print_word(")");
return 0;
}
-
-static int
-pre_ux(DECL_ARGS)
-{
-
- print_word(manacts[n->tok].prefix);
- if (NULL == n->child)
- return 0;
- outflags &= ~MMAN_spc;
- print_word("\\ ");
- outflags &= ~MMAN_spc;
- return 1;
-}