summaryrefslogtreecommitdiffstats
path: root/mandocdb.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-12-04 17:36:00 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-12-04 17:36:00 +0000
commitf0dc503a02157f27d976f25b0144e2077524c5d9 (patch)
treedd9865918d9cee40cba68e715010d29b772b1bc8 /mandocdb.c
parent281d416eceffce59e0fae5083eda1dd251311db9 (diff)
downloadmandoc-f0dc503a02157f27d976f25b0144e2077524c5d9.tar.gz
In the SYNOPSIS, if .Nm occurs without argument, give the first .Nm
that occurred in the document a NAME_SYN entry in the names table.
Diffstat (limited to 'mandocdb.c')
-rw-r--r--mandocdb.c71
1 files changed, 47 insertions, 24 deletions
diff --git a/mandocdb.c b/mandocdb.c
index b1784fb1..c1356822 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -128,7 +128,8 @@ enum stmt {
STMT__MAX
};
-typedef int (*mdoc_fp)(struct mpage *, const struct mdoc_node *);
+typedef int (*mdoc_fp)(struct mpage *, const struct mdoc_meta *,
+ const struct mdoc_node *);
struct mdoc_handler {
mdoc_fp fp; /* optional handler */
@@ -154,15 +155,24 @@ static void mpages_merge(struct mchars *, struct mparse *);
static void names_check(void);
static void parse_cat(struct mpage *, int);
static void parse_man(struct mpage *, const struct man_node *);
-static void parse_mdoc(struct mpage *, const struct mdoc_node *);
-static int parse_mdoc_body(struct mpage *, const struct mdoc_node *);
-static int parse_mdoc_head(struct mpage *, const struct mdoc_node *);
-static int parse_mdoc_Fd(struct mpage *, const struct mdoc_node *);
-static int parse_mdoc_Fn(struct mpage *, const struct mdoc_node *);
-static int parse_mdoc_Nd(struct mpage *, const struct mdoc_node *);
-static int parse_mdoc_Nm(struct mpage *, const struct mdoc_node *);
-static int parse_mdoc_Sh(struct mpage *, const struct mdoc_node *);
-static int parse_mdoc_Xr(struct mpage *, const struct mdoc_node *);
+static void parse_mdoc(struct mpage *, const struct mdoc_meta *,
+ const struct mdoc_node *);
+static int parse_mdoc_body(struct mpage *, const struct mdoc_meta *,
+ const struct mdoc_node *);
+static int parse_mdoc_head(struct mpage *, const struct mdoc_meta *,
+ const struct mdoc_node *);
+static int parse_mdoc_Fd(struct mpage *, const struct mdoc_meta *,
+ const struct mdoc_node *);
+static int parse_mdoc_Fn(struct mpage *, const struct mdoc_meta *,
+ const struct mdoc_node *);
+static int parse_mdoc_Nd(struct mpage *, const struct mdoc_meta *,
+ const struct mdoc_node *);
+static int parse_mdoc_Nm(struct mpage *, const struct mdoc_meta *,
+ const struct mdoc_node *);
+static int parse_mdoc_Sh(struct mpage *, const struct mdoc_meta *,
+ const struct mdoc_node *);
+static int parse_mdoc_Xr(struct mpage *, const struct mdoc_meta *,
+ const struct mdoc_node *);
static void putkey(const struct mpage *, char *, uint64_t);
static void putkeys(const struct mpage *,
const char *, size_t, uint64_t);
@@ -1217,7 +1227,7 @@ mpages_merge(struct mchars *mc, struct mparse *mp)
if (NULL != mdoc) {
if (NULL != (cp = mdoc_meta(mdoc)->name))
putkey(mpage, cp, NAME_HEAD);
- parse_mdoc(mpage, mdoc_node(mdoc));
+ parse_mdoc(mpage, mdoc_meta(mdoc), mdoc_node(mdoc));
} else if (NULL != man)
parse_man(mpage, man_node(man));
else
@@ -1542,7 +1552,8 @@ parse_man(struct mpage *mpage, const struct man_node *n)
}
static void
-parse_mdoc(struct mpage *mpage, const struct mdoc_node *n)
+parse_mdoc(struct mpage *mpage, const struct mdoc_meta *meta,
+ const struct mdoc_node *n)
{
assert(NULL != n);
@@ -1558,7 +1569,7 @@ parse_mdoc(struct mpage *mpage, const struct mdoc_node *n)
/* FALLTHROUGH */
case MDOC_TAIL:
if (NULL != mdocs[n->tok].fp)
- if (0 == (*mdocs[n->tok].fp)(mpage, n))
+ if (0 == (*mdocs[n->tok].fp)(mpage, meta, n))
break;
if (mdocs[n->tok].mask)
putmdockey(mpage, n->child,
@@ -1569,12 +1580,13 @@ parse_mdoc(struct mpage *mpage, const struct mdoc_node *n)
continue;
}
if (NULL != n->child)
- parse_mdoc(mpage, n);
+ parse_mdoc(mpage, meta, n);
}
}
static int
-parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_node *n)
+parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_meta *meta,
+ const struct mdoc_node *n)
{
const char *start, *end;
size_t sz;
@@ -1617,7 +1629,8 @@ parse_mdoc_Fd(struct mpage *mpage, const struct mdoc_node *n)
}
static int
-parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_node *n)
+parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_meta *meta,
+ const struct mdoc_node *n)
{
char *cp;
@@ -1650,7 +1663,8 @@ parse_mdoc_Fn(struct mpage *mpage, const struct mdoc_node *n)
}
static int
-parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_node *n)
+parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_meta *meta,
+ const struct mdoc_node *n)
{
char *cp;
@@ -1669,7 +1683,8 @@ parse_mdoc_Xr(struct mpage *mpage, const struct mdoc_node *n)
}
static int
-parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_node *n)
+parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_meta *meta,
+ const struct mdoc_node *n)
{
if (MDOC_BODY == n->type)
@@ -1678,32 +1693,40 @@ parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_node *n)
}
static int
-parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_node *n)
+parse_mdoc_Nm(struct mpage *mpage, const struct mdoc_meta *meta,
+ const struct mdoc_node *n)
{
if (SEC_NAME == n->sec)
putmdockey(mpage, n->child, NAME_TITLE);
- else if (SEC_SYNOPSIS == n->sec && MDOC_HEAD == n->type)
- putmdockey(mpage, n->child, NAME_SYN);
+ else if (SEC_SYNOPSIS == n->sec && MDOC_HEAD == n->type) {
+ if (n->child == NULL)
+ putkey(mpage, meta->name, NAME_SYN);
+ else
+ putmdockey(mpage, n->child, NAME_SYN);
+ }
return(0);
}
static int
-parse_mdoc_Sh(struct mpage *mpage, const struct mdoc_node *n)
+parse_mdoc_Sh(struct mpage *mpage, const struct mdoc_meta *meta,
+ const struct mdoc_node *n)
{
return(SEC_CUSTOM == n->sec && MDOC_HEAD == n->type);
}
static int
-parse_mdoc_head(struct mpage *mpage, const struct mdoc_node *n)
+parse_mdoc_head(struct mpage *mpage, const struct mdoc_meta *meta,
+ const struct mdoc_node *n)
{
return(MDOC_HEAD == n->type);
}
static int
-parse_mdoc_body(struct mpage *mpage, const struct mdoc_node *n)
+parse_mdoc_body(struct mpage *mpage, const struct mdoc_meta *meta,
+ const struct mdoc_node *n)
{
return(MDOC_BODY == n->type);