From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: If an .Nd block contains macros, avoid fragmented entries in
Date: Sun, 23 Mar 2014 08:44:56 -0400 (EDT) [thread overview]
Message-ID: <201403231244.s2NCiu8o028577@krisdoz.my.domain> (raw)
Log Message:
-----------
If an .Nd block contains macros, avoid fragmented entries in mandocdb(8),
instead use the .Nd content recursively.
Modified Files:
--------------
mdocml:
mandocdb.c
mdoc.c
mdoc.h
Revision Data
-------------
Index: mandocdb.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v
retrieving revision 1.121
retrieving revision 1.122
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.121 -r1.122
--- mandocdb.c
+++ mandocdb.c
@@ -1506,32 +1506,10 @@ parse_mdoc_Xr(struct mpage *mpage, const
static int
parse_mdoc_Nd(struct mpage *mpage, const struct mdoc_node *n)
{
- size_t sz;
- if (MDOC_BODY != n->type)
- return(0);
-
- /*
- * Special-case the `Nd' because we need to put the description
- * into the document table.
- */
-
- for (n = n->child; NULL != n; n = n->next) {
- if (MDOC_TEXT == n->type) {
- if (NULL != mpage->desc) {
- sz = strlen(mpage->desc) +
- strlen(n->string) + 2;
- mpage->desc = mandoc_realloc(
- mpage->desc, sz);
- strlcat(mpage->desc, " ", sz);
- strlcat(mpage->desc, n->string, sz);
- } else
- mpage->desc = mandoc_strdup(n->string);
- }
- if (NULL != n->child)
- parse_mdoc_Nd(mpage, n);
- }
- return(1);
+ if (MDOC_BODY == n->type)
+ mdoc_deroff(&mpage->desc, n);
+ return(0);
}
static int
Index: mdoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.h,v
retrieving revision 1.125
retrieving revision 1.126
diff -Lmdoc.h -Lmdoc.h -u -p -r1.125 -r1.126
--- mdoc.h
+++ mdoc.h
@@ -389,6 +389,7 @@ struct mdoc;
const struct mdoc_node *mdoc_node(const struct mdoc *);
const struct mdoc_meta *mdoc_meta(const struct mdoc *);
+void mdoc_deroff(char **, const struct mdoc_node *);
__END_DECLS
Index: mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v
retrieving revision 1.210
retrieving revision 1.211
diff -Lmdoc.c -Lmdoc.c -u -p -r1.210 -r1.211
--- mdoc.c
+++ mdoc.c
@@ -22,6 +22,7 @@
#include <sys/types.h>
#include <assert.h>
+#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -1019,4 +1020,43 @@ mdoc_isdelim(const char *p)
return(DELIM_MIDDLE);
return(DELIM_NONE);
+}
+
+void
+mdoc_deroff(char **dest, const struct mdoc_node *n)
+{
+ char *cp;
+ size_t sz;
+
+ if (MDOC_TEXT != n->type) {
+ for (n = n->child; n; n = n->next)
+ mdoc_deroff(dest, n);
+ return;
+ }
+
+ /* Skip leading whitespace. */
+
+ for (cp = n->string; '\0' != *cp; cp++)
+ if (0 == isspace((unsigned char)*cp))
+ break;
+
+ /* Skip trailing whitespace. */
+
+ for (sz = strlen(cp); sz; sz--)
+ if (0 == isspace((unsigned char)cp[sz-1]))
+ break;
+
+ /* Skip empty strings. */
+
+ if (0 == sz)
+ return;
+
+ if (NULL == *dest) {
+ *dest = mandoc_strndup(cp, sz);
+ return;
+ }
+
+ mandoc_asprintf(&cp, "%s %*s", *dest, (int)sz, cp);
+ free(*dest);
+ *dest = cp;
}
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2014-03-23 12:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201403231244.s2NCiu8o028577@krisdoz.my.domain \
--to=schwarze@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).