NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/45164: mandoc(1) do not expand macros in sub-section definition
The following reply was made to PR bin/45164; it has been noted by GNATS.
From: Thomas Klausner <wiz%NetBSD.org@localhost>
To: NetBSD bugtracking <gnats-bugs%NetBSD.org@localhost>
Cc:
Subject: Re: bin/45164: mandoc(1) do not expand macros in sub-section
definition
Date: Wed, 10 Aug 2011 16:16:35 +0200
Kristaps fixed this in the upstream repository. The diff is below, I
don't know if it applies to our by now quite old 1.11.1. So if you
can, please test this, or wait for 1.11.6 which will include this
change.
Thomas
----- Forwarded message from kristaps%mdocml.bsd.lv@localhost -----
Log Message:
-----------
Allow `Sx' and `Ss' to have child nodes. Fixes manuals in NetBSD.
Originally pointed out by joerg@ then again by Thomas Klausner by way of
Nicolas Joy. Note: don't use these constructions as you can't link to
the sections with `Sx'.
Modified Files:
--------------
mdocml:
mdoc.7
mdoc_html.c
mdoc_macro.c
mdoc_validate.c
Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.172
retrieving revision 1.173
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.172 -r1.173
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -72,9 +72,7 @@ static void check_text(struct mdoc *, i
static void check_argv(struct mdoc *,
struct mdoc_node *, struct mdoc_argv *);
static void check_args(struct mdoc *, struct mdoc_node *);
-
-static int concat(struct mdoc *, char *,
- const struct mdoc_node *, size_t);
+static int concat(char *, const struct mdoc_node *, size_t);
static enum mdoc_sec a2sec(const char *);
static size_t macro2len(enum mdoct);
@@ -1107,6 +1105,7 @@ static int
post_nm(POST_ARGS)
{
char buf[BUFSIZ];
+ int c;
/* If no child specified, make sure we have the meta name. */
@@ -1118,11 +1117,14 @@ post_nm(POST_ARGS)
/* If no meta name, set it from the child. */
- if ( ! concat(mdoc, buf, mdoc->last->child, BUFSIZ))
+ buf[0] = '\0';
+ if (-1 == (c = concat(buf, mdoc->last->child, BUFSIZ))) {
+ mdoc_nmsg(mdoc, mdoc->last->child, MANDOCERR_MEM);
return(0);
+ }
+ assert(c);
mdoc->meta.name = mandoc_strdup(buf);
-
return(1);
}
@@ -1818,6 +1820,7 @@ post_sh_head(POST_ARGS)
{
char buf[BUFSIZ];
enum mdoc_sec sec;
+ int c;
/*
* Process a new section. Sections are either "named" or
@@ -1826,10 +1829,13 @@ post_sh_head(POST_ARGS)
* manual sections.
*/
- if ( ! concat(mdoc, buf, mdoc->last->child, BUFSIZ))
+ sec = SEC_CUSTOM;
+ buf[0] = '\0';
+ if (-1 == (c = concat(buf, mdoc->last->child, BUFSIZ))) {
+ mdoc_nmsg(mdoc, mdoc->last->child, MANDOCERR_MEM);
return(0);
-
- sec = a2sec(buf);
+ } else if (1 == c)
+ sec = a2sec(buf);
/* The NAME should be first. */
@@ -1978,6 +1984,7 @@ post_dd(POST_ARGS)
{
char buf[DATESIZE];
struct mdoc_node *n;
+ int c;
if (mdoc->meta.date)
free(mdoc->meta.date);
@@ -1989,9 +1996,13 @@ post_dd(POST_ARGS)
return(1);
}
- if ( ! concat(mdoc, buf, n->child, DATESIZE))
+ buf[0] = '\0';
+ if (-1 == (c = concat(buf, n->child, DATESIZE))) {
+ mdoc_nmsg(mdoc, n->child, MANDOCERR_MEM);
return(0);
+ }
+ assert(c);
mdoc->meta.date = mandoc_normdate
(mdoc->parse, buf, n->line, n->pos);
@@ -2146,6 +2157,7 @@ post_os(POST_ARGS)
{
struct mdoc_node *n;
char buf[BUFSIZ];
+ int c;
#ifndef OSNAME
struct utsname utsname;
#endif
@@ -2162,8 +2174,13 @@ post_os(POST_ARGS)
if (mdoc->meta.os)
free(mdoc->meta.os);
- if ( ! concat(mdoc, buf, n->child, BUFSIZ))
+ buf[0] = '\0';
+ if (-1 == (c = concat(buf, n->child, BUFSIZ))) {
+ mdoc_nmsg(mdoc, n->child, MANDOCERR_MEM);
return(0);
+ }
+
+ assert(c);
/* XXX: yes, these can all be dynamically-adjusted buffers, but
* it's really not worth the extra hackery.
@@ -2230,34 +2247,24 @@ post_std(POST_ARGS)
return(1);
}
+/*
+ * Concatenate a node, stopping at the first non-text.
+ * Concatenation is separated by a single whitespace.
+ * Returns -1 on fatal (string overrun) error, 0 if child nodes were
+ * encountered, 1 otherwise.
+ */
static int
-concat(struct mdoc *m, char *p, const struct mdoc_node *n, size_t sz)
+concat(char *p, const struct mdoc_node *n, size_t sz)
{
- p[0] = '\0';
-
- /*
- * Concatenate sibling nodes together. All siblings must be of
- * type MDOC_TEXT or an assertion is raised. Concatenation is
- * separated by a single whitespace. Returns 0 on fatal (string
- * overrun) error.
- */
-
- for ( ; n; n = n->next) {
- assert(MDOC_TEXT == n->type);
-
- if (strlcat(p, n->string, sz) >= sz) {
- mdoc_nmsg(m, n, MANDOCERR_MEM);
- return(0);
- }
-
- if (NULL == n->next)
- continue;
-
- if (strlcat(p, " ", sz) >= sz) {
- mdoc_nmsg(m, n, MANDOCERR_MEM);
+ for ( ; NULL != n; n = n->next) {
+ if (MDOC_TEXT != n->type)
return(0);
- }
+ if ('\0' != p[0] && strlcat(p, " ", sz) >= sz)
+ return(-1);
+ if (strlcat(p, n->string, sz) >= sz)
+ return(-1);
+ concat(p, n->child, sz);
}
return(1);
Index: mdoc_macro.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_macro.c,v
retrieving revision 1.109
retrieving revision 1.110
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.109 -r1.110
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -74,8 +74,8 @@ const struct mdoc_macro __mdoc_macros[MD
{ in_line_eoln, MDOC_PROLOGUE }, /* Dd */
{ in_line_eoln, MDOC_PROLOGUE }, /* Dt */
{ in_line_eoln, MDOC_PROLOGUE }, /* Os */
- { blk_full, 0 }, /* Sh */
- { blk_full, 0 }, /* Ss */
+ { blk_full, MDOC_PARSED }, /* Sh */
+ { blk_full, MDOC_PARSED }, /* Ss */
{ in_line_eoln, 0 }, /* Pp */
{ blk_part_imp, MDOC_PARSED }, /* D1 */
{ blk_part_imp, MDOC_PARSED }, /* Dl */
Index: mdoc_html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_html.c,v
retrieving revision 1.174
retrieving revision 1.175
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.174 -r1.175
--- mdoc_html.c
+++ mdoc_html.c
@@ -608,18 +608,22 @@ mdoc_sh_pre(MDOC_ARGS)
bufinit(h);
bufcat(h, "x");
- for (n = n->child; n; n = n->next) {
+
+ for (n = n->child; n && MDOC_TEXT == n->type; ) {
bufcat_id(h, n->string);
- if (n->next)
+ if (NULL != (n = n->next))
bufcat_id(h, " ");
}
- PAIR_ID_INIT(&tag, h->buf);
- print_otag(h, TAG_H1, 1, &tag);
+ if (NULL == n) {
+ PAIR_ID_INIT(&tag, h->buf);
+ print_otag(h, TAG_H1, 1, &tag);
+ } else
+ print_otag(h, TAG_H1, 0, NULL);
+
return(1);
}
-
/* ARGSUSED */
static int
mdoc_ss_pre(MDOC_ARGS)
@@ -635,14 +639,19 @@ mdoc_ss_pre(MDOC_ARGS)
bufinit(h);
bufcat(h, "x");
- for (n = n->child; n; n = n->next) {
+
+ for (n = n->child; n && MDOC_TEXT == n->type; ) {
bufcat_id(h, n->string);
- if (n->next)
+ if (NULL != (n = n->next))
bufcat_id(h, " ");
}
- PAIR_ID_INIT(&tag, h->buf);
- print_otag(h, TAG_H2, 1, &tag);
+ if (NULL == n) {
+ PAIR_ID_INIT(&tag, h->buf);
+ print_otag(h, TAG_H2, 1, &tag);
+ } else
+ print_otag(h, TAG_H2, 0, NULL);
+
return(1);
}
@@ -1171,9 +1180,10 @@ mdoc_sx_pre(MDOC_ARGS)
bufinit(h);
bufcat(h, "#x");
- for (n = n->child; n; n = n->next) {
+
+ for (n = n->child; n; ) {
bufcat_id(h, n->string);
- if (n->next)
+ if (NULL != (n = n->next))
bufcat_id(h, " ");
}
Index: mdoc.7
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.7,v
retrieving revision 1.196
retrieving revision 1.197
diff -Lmdoc.7 -Lmdoc.7 -u -p -r1.196 -r1.197
--- mdoc.7
+++ mdoc.7
@@ -664,11 +664,11 @@ has multiple heads.
.Pp
.Bl -column -compact -offset indent "MacroX" "CallableX" "ParsedX" "closed by
XXXXXXXXXXX"
.It Em Macro Ta Em Callable Ta Em Parsed Ta Em Scope
-.It Sx \&It Ta \&No Ta Yes Ta closed by Sx \&It , Sx \&El
-.It Sx \&Nd Ta \&No Ta \&No Ta closed by Sx \&Sh
-.It Sx \&Nm Ta \&No Ta Yes Ta closed by Sx \&Nm , Sx \&Sh , Sx \&Ss
-.It Sx \&Sh Ta \&No Ta \&No Ta closed by Sx \&Sh
-.It Sx \&Ss Ta \&No Ta \&No Ta closed by Sx \&Sh , Sx \&Ss
+.It Sx \&It Ta \&No Ta Yes Ta closed by Sx \&It , Sx \&El
+.It Sx \&Nd Ta \&No Ta \&No Ta closed by Sx \&Sh
+.It Sx \&Nm Ta \&No Ta Yes Ta closed by Sx \&Nm , Sx \&Sh , Sx \&Ss
+.It Sx \&Sh Ta \&No Ta Yes Ta closed by Sx \&Sh
+.It Sx \&Ss Ta \&No Ta Yes Ta closed by Sx \&Sh , Sx \&Ss
.El
.Pp
Note that the
@@ -2613,6 +2613,9 @@ custom sections be used.
.Pp
Section names should be unique so that they may be keyed by
.Sx \&Sx .
+Although this macro is parsed, it should not consist of child node or it
+may not be linked with
+.Sx \&Sx .
.Pp
See also
.Sx \&Pp ,
@@ -2655,6 +2658,9 @@ Conventional sections, as described in
rarely have sub-sections.
.Pp
Sub-section names should be unique so that they may be keyed by
+.Sx \&Sx .
+Although this macro is parsed, it should not consist of child node or it
+may not be linked with
.Sx \&Sx .
.Pp
See also
--
To unsubscribe send an email to source+unsubscribe%mdocml.bsd.lv@localhost
----- End forwarded message -----
Home |
Main Index |
Thread Index |
Old Index