summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/mandoc/html.c4
-rw-r--r--usr.bin/mandoc/main.c6
-rw-r--r--usr.bin/mandoc/main.h7
-rw-r--r--usr.bin/mandoc/mandoc.118
-rw-r--r--usr.bin/mandoc/mdoc.7113
-rw-r--r--usr.bin/mandoc/mdoc_html.c128
-rw-r--r--usr.bin/mandoc/mdoc_term.c168
-rw-r--r--usr.bin/mandoc/term.c31
8 files changed, 263 insertions, 212 deletions
diff --git a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c
index 02221b64a8c..44660aa60c0 100644
--- a/usr.bin/mandoc/html.c
+++ b/usr.bin/mandoc/html.c
@@ -1,4 +1,4 @@
-/* $Id: html.c,v 1.9 2010/05/26 02:39:58 schwarze Exp $ */
+/* $Id: html.c,v 1.10 2010/06/08 00:11:47 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -31,8 +31,6 @@
#include "html.h"
#include "main.h"
-#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a))
-
struct htmldata {
const char *name;
int flags;
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index 19ffe247f4a..37c0df0fec2 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.34 2010/06/06 20:30:08 schwarze Exp $ */
+/* $Id: main.c,v 1.35 2010/06/08 00:11:47 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -384,7 +384,7 @@ read_whole_file(struct curparse *curp, struct buf *fb, int *with_mmap)
*with_mmap = 1;
fb->sz = (size_t)st.st_size;
fb->buf = mmap(NULL, fb->sz, PROT_READ,
- MAP_FILE, curp->fd, 0);
+ MAP_FILE|MAP_SHARED, curp->fd, 0);
if (fb->buf != MAP_FAILED)
return(1);
}
@@ -590,7 +590,7 @@ fdesc(struct curparse *curp)
case (OUTT_LINT):
break;
default:
- curp->outdata = ascii_alloc(80);
+ curp->outdata = ascii_alloc(curp->outopts);
curp->outman = terminal_man;
curp->outmdoc = terminal_mdoc;
curp->outfree = terminal_free;
diff --git a/usr.bin/mandoc/main.h b/usr.bin/mandoc/main.h
index 933b7272681..0955129055a 100644
--- a/usr.bin/mandoc/main.h
+++ b/usr.bin/mandoc/main.h
@@ -1,4 +1,4 @@
-/* $Id: main.h,v 1.3 2010/05/15 21:09:53 schwarze Exp $ */
+/* $Id: main.h,v 1.4 2010/06/08 00:11:47 schwarze Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -22,6 +22,9 @@ __BEGIN_DECLS
struct mdoc;
struct man;
+#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a))
+
+
/*
* Definitions for main.c-visible output device functions, e.g., -Thtml
* and -Tascii. Note that ascii_alloc() is named as such in
@@ -38,7 +41,7 @@ void html_free(void *);
void tree_mdoc(void *, const struct mdoc *);
void tree_man(void *, const struct man *);
-void *ascii_alloc(size_t);
+void *ascii_alloc(char *);
void terminal_mdoc(void *, const struct mdoc *);
void terminal_man(void *, const struct man *);
void terminal_free(void *);
diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1
index ec42f9d9e1d..f2ac4b1a110 100644
--- a/usr.bin/mandoc/mandoc.1
+++ b/usr.bin/mandoc/mandoc.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mandoc.1,v 1.29 2010/05/14 01:54:37 schwarze Exp $
+.\" $OpenBSD: mandoc.1,v 1.30 2010/06/08 00:11:47 schwarze Exp $
.\"
.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: May 14 2010 $
+.Dd $Mdocdate: June 8 2010 $
.Dt MANDOC 1
.Os
.Sh NAME
@@ -203,11 +203,11 @@ and
.Fl f Ns Cm no-ign-macro .
.El
.Ss Output Options
-For the time being, only
+The
.Fl T Ns Ar html
and
.Fl T Ns Ar xhtml
-accept output options:
+modes accept the following output options:
.Bl -tag -width Ds
.It Fl O Ns Cm includes Ns = Ns Ar fmt
The string
@@ -245,6 +245,16 @@ is used for an external style-sheet.
This must be a valid absolute or
relative URI.
.El
+.Pp
+The
+.Fl T Ns Ar ascii
+mode accepts the following output option:
+.Bl -tag -width Ds
+.It Fl O Ns Cm width Ns = Ns Ar width
+The output width is set to
+.Ar width ,
+which will normalise to \(>=60.
+.El
.Sh OUTPUT
This section documents output details of
.Nm .
diff --git a/usr.bin/mandoc/mdoc.7 b/usr.bin/mandoc/mdoc.7
index 6eeb96e9260..aebf9c5417a 100644
--- a/usr.bin/mandoc/mdoc.7
+++ b/usr.bin/mandoc/mdoc.7
@@ -1,4 +1,4 @@
-.\" $Id: mdoc.7,v 1.34 2010/06/06 20:30:08 schwarze Exp $
+.\" $Id: mdoc.7,v 1.35 2010/06/08 00:11:47 schwarze Exp $
.\"
.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: June 6 2010 $
+.Dd $Mdocdate: June 8 2010 $
.Dt MDOC 7
.Os
.Sh NAME
@@ -55,7 +55,7 @@ Text following a
whether in a macro or free-form text line, is ignored to the end of
line. A macro line with only a control character and comment escape,
.Sq \&.\e" ,
-is also ignored. Macro lines with only a control charater and optionally
+is also ignored. Macro lines with only a control character and optionally
whitespace are stripped from input.
.Ss Reserved Characters
Within a macro line, the following characters are reserved:
@@ -167,7 +167,7 @@ also defined a set of package-specific
.Dq predefined strings ,
which, like
.Sx Special Characters ,
-demark special output characters and strings by way of input codes.
+mark special output characters and strings by way of input codes.
Predefined strings are escaped with the slash-asterisk,
.Sq \e* :
single-character
@@ -333,8 +333,11 @@ must be the NAME section, consisting of at least one
followed by
.Sx \&Nd .
.Pp
-Following that, convention dictates specifying at least the SYNOPSIS and
-DESCRIPTION sections, although this varies between manual sections.
+Following that, convention dictates specifying at least the
+.Em SYNOPSIS
+and
+.Em DESCRIPTION
+sections, although this varies between manual sections.
.Pp
The following is a well-formed skeleton
.Nm
@@ -450,13 +453,31 @@ And for the third, configurations (section 4):
Manuals not in these sections generally don't need a
.Em SYNOPSIS .
.Pp
-See
-.Sx \&Op ,
+Some macros are displayed differently in the
+.Em SYNOPSIS
+section, particularly
+.Sx \&Nm ,
.Sx \&Cd ,
+.Sx \&Fd ,
.Sx \&Fn ,
-.Sx \&Ft ,
+.Sx \&Fo ,
+.Sx \&In ,
+.Sx \&Vt ,
and
-.Sx \&Vt .
+.Sx \&Ft .
+All of these macros are output on their own line. If two such
+dissimilar macros are pair-wise invoked (except for
+.Sx \&Ft
+before
+.Sx \&Fo
+or
+.Sx \&Fn ) ,
+they are separated by a vertical space, unless in the case of
+.Sx \&Fo ,
+.Sx \&Fn ,
+and
+.Sx \&Ft ,
+which are always separated by vertical space.
.It Em DESCRIPTION
This expands upon the brief, one-line description in
.Em NAME .
@@ -952,7 +973,7 @@ See also
.Sx \&Aq .
.Ss \&Ap
Inserts an apostrophe without any surrounding white-space.
-This is generally used as a grammatic device when referring to the verb
+This is generally used as a grammatical device when referring to the verb
form of a function:
.Bd -literal -offset indent
\&.Fn execve Ap d
@@ -1656,6 +1677,8 @@ This usage has been deprecated in favour of
Do not use this macro.
.Pp
See also
+.Sx MANUAL STRUCTURE
+and
.Sx \&In .
.Ss \&Fl
Command-line flag.
@@ -1685,10 +1708,7 @@ Its syntax is as follows:
.Op Oo Cm argtype Oc Cm argname
.Ed
.Pp
-If invoked in the
-.Em SYNOPSIS
-section, vertical space is asserted before and after the macro.
-In all cases, the function arguments are surrounded in parenthesis and
+Function arguments are surrounded in parenthesis and
are delimited by commas.
If no arguments are specified, blank parenthesis are output.
.Pp
@@ -1702,9 +1722,7 @@ Examples:
.Ed
.Pp
See also
-.Sx \&Fa ,
-.Sx \&Fo ,
-.Sx \&Fc ,
+.Sx MANUAL STRUCTURE
and
.Sx \&Ft .
.Ss \&Fo
@@ -1728,42 +1746,21 @@ Invocations usually occur in the following context:
.Pf \. Sx \&Fc
.Ed
.Pp
-In the
-.Em SYNOPSIS
-section, a
-.Sx \&Fo
-block is surrounded by vertical space unless
-.Sx \&Ft
-is the prior macro, in which case it is preceded by only a newline.
-.Pp
A
.Sx \&Fo
scope is closed by
.Pp
See also
+.Sx MANUAL STRUCTURE ,
.Sx \&Fa ,
.Sx \&Fc ,
and
-.Sx \&Fn .
-.Sx \&Fc .
-.Ss \&Fr
.Ss \&Ft
A function type.
Its syntax is as follows:
.Pp
.D1 Pf \. Sx \&Ft Cm functype
.Pp
-If invoked before a
-.Sx \&Fo
-or
-.Sx \&Fn
-in the
-.Em SYNOPSIS
-section, a line-break will follow.
-Furthermore, if invoked in the
-.Em SYNOPSIS
-section, it will assert vertical space prior to its arguments.
-.Pp
Examples:
.D1 \&.Ft int
.Bd -literal -offset indent -compact
@@ -1772,10 +1769,10 @@ Examples:
.Ed
.Pp
See also
-.Sx \&Fo ,
-.Sx \&Fc ,
+.Sx MANUAL STRUCTURE ,
+.Sx \&Fn ,
and
-.Sx \&Fn .
+.Sx \&Fo .
.Ss \&Fx
Format the FreeBSD version provided as an argument, or a default value
if no argument is provided.
@@ -1804,11 +1801,13 @@ In the
section (only if invoked as the line macro), the first argument is
preceded by
.Qq #include ,
-the arguments is enclosed in angled braces, and a newline is asserted.
-In all other invocations, only angled braces will enclose the argument.
+the arguments is enclosed in angled braces.
.Pp
-Examples
+Examples:
.D1 \&.In sys/types
+.Pp
+See also
+.Sx MANUAL STRUCTURE .
.Ss \&It
A list item.
The syntax of this macro depends on the list type.
@@ -1880,12 +1879,12 @@ line itself.
Subsequent this, only the
.Sq \&Ta
pseudo-macro may be used to delimit phrases.
-Furthermore, note that quoted sections propogate over tab-delimited
+Furthermore, note that quoted sections propagate over tab-delimited
phrases on an
.Sx \&It ,
for example,
.Pp
-.D1 .It \(dqcol1 ; <TAB> col2 ;\(dq ;
+.D1 .It \(dqcol1 ; <TAB> col2 ;\(dq \&;
.Pp
will preserve the semicolon whitespace except for the last.
.Pp
@@ -2098,12 +2097,14 @@ and
.Ss \&Va
.Ss \&Vt
A variable type.
-This is also used for indicating global variables in the SYNOPSIS
+This is also used for indicating global variables in the
+.Em SYNOPSIS
section, in which case a variable name is also specified.
Note that it accepts
.Sx Block partial-implicit
-syntax when invoked as the first macro in the SYNOPSIS section, else it
-accepts ordinary
+syntax when invoked as the first macro in the
+.Em SYNOPSIS
+section, else it accepts ordinary
.Sx In-line
syntax.
.Pp
@@ -2113,10 +2114,10 @@ which is used for function return types.
.Pp
Examples:
.D1 \&.Vt unsigned char
-.D1 \&.Vt extern const char * const sys_signame[] ;
+.D1 \&.Vt extern const char * const sys_signame[] \&;
.Pp
See also
-.Sx \&Ft
+.Sx MANUAL STRUCTURE
and
.Sx \&Va .
.Ss \&Xc
@@ -2148,7 +2149,7 @@ This behaviour is for compatibility with
.Pp
Examples:
.D1 \&.Xr mandoc 1
-.D1 \&.Xr mandoc 1 ;
+.D1 \&.Xr mandoc 1 \&;
.D1 \&.Xr mandoc 1 \&Ns s behaviour
.Ss \&br
.Ss \&sp
@@ -2184,7 +2185,7 @@ and
.Sx \&Fn
in the
.Em SYNOPSIS :
-at times newline(s) are suppressed dependong on whether a prior
+at times newline(s) are suppressed depending on whether a prior
.Sx \&Fn
has been invoked.
In mandoc, this is not the case.
@@ -2249,7 +2250,7 @@ and
.Fl right
are aliases for
.Fl left
-in manodc. Furthermore, the
+in mandoc. Furthermore, the
.Fl file Ar file
argument is ignored.
Lastly, since text is not right-justified in mandoc (or even groff),
diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c
index be432204989..bf7fc126b9c 100644
--- a/usr.bin/mandoc/mdoc_html.c
+++ b/usr.bin/mandoc/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.20 2010/06/06 20:30:08 schwarze Exp $ */
+/* $Id: mdoc_html.c,v 1.21 2010/06/08 00:11:47 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -49,6 +49,8 @@ static void print_mdoc(MDOC_ARGS);
static void print_mdoc_head(MDOC_ARGS);
static void print_mdoc_node(MDOC_ARGS);
static void print_mdoc_nodelist(MDOC_ARGS);
+static void synopsis_pre(struct html *,
+ const struct mdoc_node *);
static void a2width(const char *, struct roffsu *);
static void a2offs(const char *, struct roffsu *);
@@ -80,7 +82,6 @@ static void mdoc_dq_post(MDOC_ARGS);
static int mdoc_dq_pre(MDOC_ARGS);
static int mdoc_dv_pre(MDOC_ARGS);
static int mdoc_fa_pre(MDOC_ARGS);
-static void mdoc_fd_post(MDOC_ARGS);
static int mdoc_fd_pre(MDOC_ARGS);
static int mdoc_fl_pre(MDOC_ARGS);
static int mdoc_fn_pre(MDOC_ARGS);
@@ -155,7 +156,7 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = {
{mdoc_ev_pre, NULL}, /* Ev */
{mdoc_ex_pre, NULL}, /* Ex */
{mdoc_fa_pre, NULL}, /* Fa */
- {mdoc_fd_pre, mdoc_fd_post}, /* Fd */
+ {mdoc_fd_pre, NULL}, /* Fd */
{mdoc_fl_pre, NULL}, /* Fl */
{mdoc_fn_pre, NULL}, /* Fn */
{mdoc_ft_pre, NULL}, /* Ft */
@@ -290,6 +291,55 @@ a2width(const char *p, struct roffsu *su)
/*
+ * See the same function in mdoc_term.c for documentation.
+ */
+static void
+synopsis_pre(struct html *h, const struct mdoc_node *n)
+{
+ struct roffsu su;
+ struct htmlpair tag;
+
+ if (NULL == n->prev || SEC_SYNOPSIS != n->sec)
+ return;
+
+ SCALE_VS_INIT(&su, 1);
+ bufcat_su(h, "margin-top", &su);
+ PAIR_STYLE_INIT(&tag, h);
+
+ if (n->prev->tok == n->tok &&
+ MDOC_Fo != n->tok &&
+ MDOC_Ft != n->tok &&
+ MDOC_Fn != n->tok) {
+ print_otag(h, TAG_DIV, 0, NULL);
+ return;
+ }
+
+ switch (n->prev->tok) {
+ case (MDOC_Fd):
+ /* FALLTHROUGH */
+ case (MDOC_Fn):
+ /* FALLTHROUGH */
+ case (MDOC_Fo):
+ /* FALLTHROUGH */
+ case (MDOC_In):
+ /* FALLTHROUGH */
+ case (MDOC_Vt):
+ print_otag(h, TAG_DIV, 1, &tag);
+ break;
+ case (MDOC_Ft):
+ if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
+ print_otag(h, TAG_DIV, 1, &tag);
+ break;
+ }
+ /* FALLTHROUGH */
+ default:
+ print_otag(h, TAG_DIV, 0, NULL);
+ break;
+ }
+}
+
+
+/*
* Calculate the scaling unit passed in an `-offset' argument. This
* uses either a native scaling unit (e.g., 1i, 2m), one of a set of
* predefined strings (indent, etc.), or the string length of the value.
@@ -686,18 +736,12 @@ mdoc_nm_pre(MDOC_ARGS)
if (NULL == n->child && NULL == m->name)
return(1);
- if (SEC_SYNOPSIS == n->sec &&
- n->prev && MDOC_LINE & n->flags) {
- bufcat_style(h, "clear", "both");
- PAIR_STYLE_INIT(&tag, h);
- print_otag(h, TAG_BR, 1, &tag);
- }
+ synopsis_pre(h, n);
PAIR_CLASS_INIT(&tag, "name");
print_otag(h, TAG_SPAN, 1, &tag);
if (NULL == n->child)
print_text(h, m->name);
-
return(1);
}
@@ -1434,7 +1478,7 @@ mdoc_cd_pre(MDOC_ARGS)
{
struct htmlpair tag;
- print_otag(h, TAG_DIV, 0, NULL);
+ synopsis_pre(h, n);
PAIR_CLASS_INIT(&tag, "config");
print_otag(h, TAG_SPAN, 1, &tag);
return(1);
@@ -1507,20 +1551,13 @@ mdoc_fa_pre(MDOC_ARGS)
/* ARGSUSED */
-static void
-mdoc_fd_post(MDOC_ARGS)
-{
-
- print_otag(h, TAG_BR, 0, NULL);
-}
-
-
-/* ARGSUSED */
static int
mdoc_fd_pre(MDOC_ARGS)
{
struct htmlpair tag;
+ synopsis_pre(h, n);
+
PAIR_CLASS_INIT(&tag, "macro");
print_otag(h, TAG_SPAN, 1, &tag);
return(1);
@@ -1532,18 +1569,12 @@ static int
mdoc_vt_pre(MDOC_ARGS)
{
struct htmlpair tag;
- struct roffsu su;
- if (SEC_SYNOPSIS == n->sec && MDOC_BLOCK == n->type) {
- if (n->next && MDOC_Vt != n->next->tok) {
- SCALE_VS_INIT(&su, 1);
- bufcat_su(h, "margin-bottom", &su);
- PAIR_STYLE_INIT(&tag, h);
- print_otag(h, TAG_DIV, 1, &tag);
- } else
- print_otag(h, TAG_DIV, 0, NULL);
-
+ if (MDOC_BLOCK == n->type) {
+ synopsis_pre(h, n);
return(1);
+ } else if (MDOC_ELEM == n->type) {
+ synopsis_pre(h, n);
} else if (MDOC_HEAD == n->type)
return(0);
@@ -1559,9 +1590,7 @@ mdoc_ft_pre(MDOC_ARGS)
{
struct htmlpair tag;
- if (SEC_SYNOPSIS == n->sec && n->prev)
- print_otag(h, TAG_BR, 0, NULL);
-
+ synopsis_pre(h, n);
PAIR_CLASS_INIT(&tag, "ftype");
print_otag(h, TAG_SPAN, 1, &tag);
return(1);
@@ -1578,21 +1607,8 @@ mdoc_fn_pre(MDOC_ARGS)
char nbuf[BUFSIZ];
const char *sp, *ep;
int sz, i;
- struct roffsu su;
- /* NB: MDOC_LINE has no effect on this macro! */
- if (SEC_SYNOPSIS == n->sec) {
- SCALE_HS_INIT(&su, INDENT);
- bufcat_su(h, "margin-left", &su);
- su.scale = -su.scale;
- bufcat_su(h, "text-indent", &su);
- if (n->prev && MDOC_Ft != n->prev->tok) {
- SCALE_VS_INIT(&su, 1);
- bufcat_su(h, "margin-top", &su);
- }
- PAIR_STYLE_INIT(&tag[0], h);
- print_otag(h, TAG_DIV, 1, tag);
- }
+ synopsis_pre(h, n);
/* Split apart into type and name. */
assert(n->child->string);
@@ -1778,7 +1794,6 @@ static int
mdoc_fo_pre(MDOC_ARGS)
{
struct htmlpair tag;
- struct roffsu su;
struct tag *t;
if (MDOC_BODY == n->type) {
@@ -1787,16 +1802,7 @@ mdoc_fo_pre(MDOC_ARGS)
h->flags |= HTML_NOSPACE;
return(1);
} else if (MDOC_BLOCK == n->type) {
- if (SEC_SYNOPSIS != n->sec)
- return(1);
- if (NULL == n->prev || MDOC_Ft == n->prev->tok) {
- print_otag(h, TAG_DIV, 0, NULL);
- return(1);
- }
- SCALE_VS_INIT(&su, 1);
- bufcat_su(h, "margin-top", &su);
- PAIR_STYLE_INIT(&tag, h);
- print_otag(h, TAG_DIV, 1, &tag);
+ synopsis_pre(h, n);
return(1);
}
@@ -1817,6 +1823,7 @@ mdoc_fo_pre(MDOC_ARGS)
static void
mdoc_fo_post(MDOC_ARGS)
{
+
if (MDOC_BODY != n->type)
return;
h->flags |= HTML_NOSPACE;
@@ -1835,6 +1842,8 @@ mdoc_in_pre(MDOC_ARGS)
struct htmlpair tag[2];
int i;
+ synopsis_pre(h, n);
+
PAIR_CLASS_INIT(&tag[0], "includes");
print_otag(h, TAG_SPAN, 1, tag);
@@ -1861,9 +1870,6 @@ mdoc_in_pre(MDOC_ARGS)
h->flags |= HTML_NOSPACE;
print_text(h, ">");
- if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
- print_otag(h, TAG_BR, 0, NULL);
-
return(0);
}
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index 733edc54b34..be49a2f7af5 100644
--- a/usr.bin/mandoc/mdoc_term.c
+++ b/usr.bin/mandoc/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.85 2010/06/06 20:30:08 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.86 2010/06/08 00:11:47 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -64,6 +64,8 @@ static void print_mdoc_node(DECL_ARGS);
static void print_mdoc_head(DECL_ARGS);
static void print_mdoc_nodelist(DECL_ARGS);
static void print_foot(DECL_ARGS);
+static void synopsis_pre(struct termp *,
+ const struct mdoc_node *);
static void termp____post(DECL_ARGS);
static void termp_an_post(DECL_ARGS);
@@ -75,8 +77,7 @@ static void termp_brq_post(DECL_ARGS);
static void termp_bx_post(DECL_ARGS);
static void termp_d1_post(DECL_ARGS);
static void termp_dq_post(DECL_ARGS);
-static void termp_fd_post(DECL_ARGS);
-static void termp_fn_post(DECL_ARGS);
+static int termp_fd_pre(DECL_ARGS);
static void termp_fo_post(DECL_ARGS);
static void termp_in_post(DECL_ARGS);
static void termp_it_post(DECL_ARGS);
@@ -88,7 +89,6 @@ static void termp_qq_post(DECL_ARGS);
static void termp_sh_post(DECL_ARGS);
static void termp_sq_post(DECL_ARGS);
static void termp_ss_post(DECL_ARGS);
-static void termp_vt_post(DECL_ARGS);
static int termp_an_pre(DECL_ARGS);
static int termp_ap_pre(DECL_ARGS);
@@ -158,9 +158,9 @@ static const struct termact termacts[MDOC_MAX] = {
{ NULL, NULL }, /* Ev */
{ termp_ex_pre, NULL }, /* Ex */
{ termp_fa_pre, NULL }, /* Fa */
- { termp_bold_pre, termp_fd_post }, /* Fd */
+ { termp_fd_pre, NULL }, /* Fd */
{ termp_fl_pre, NULL }, /* Fl */
- { termp_fn_pre, termp_fn_post }, /* Fn */
+ { termp_fn_pre, NULL }, /* Fn */
{ termp_ft_pre, NULL }, /* Ft */
{ termp_bold_pre, NULL }, /* Ic */
{ termp_in_pre, termp_in_post }, /* In */
@@ -173,7 +173,7 @@ static const struct termact termacts[MDOC_MAX] = {
{ termp_rv_pre, NULL }, /* Rv */
{ NULL, NULL }, /* St */
{ termp_under_pre, NULL }, /* Va */
- { termp_vt_pre, termp_vt_post }, /* Vt */
+ { termp_vt_pre, NULL }, /* Vt */
{ termp_xr_pre, NULL }, /* Xr */
{ NULL, termp____post }, /* %A */
{ termp_under_pre, termp____post }, /* %B */
@@ -1051,14 +1051,11 @@ termp_nm_pre(DECL_ARGS)
if (NULL == n->child && NULL == m->name)
return(1);
- if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
- term_newln(p);
+ synopsis_pre(p, n);
term_fontpush(p, TERMFONT_BOLD);
-
if (NULL == n->child)
term_word(p, m->name);
-
return(1);
}
@@ -1309,32 +1306,78 @@ termp_xr_pre(DECL_ARGS)
}
-static int
-termp_vt_pre(DECL_ARGS)
+/*
+ * This decides how to assert whitespace before any of the SYNOPSIS set
+ * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
+ * macro combos).
+ */
+static void
+synopsis_pre(struct termp *p, const struct mdoc_node *n)
{
+ /*
+ * Obviously, if we're not in a SYNOPSIS or no prior macros
+ * exist, do nothing.
+ */
+ if (NULL == n->prev || SEC_SYNOPSIS != n->sec)
+ return;
- if (MDOC_ELEM == n->type)
- return(termp_under_pre(p, pair, m, n));
- else if (MDOC_HEAD == n->type)
- return(0);
- else if (MDOC_BLOCK == n->type)
- return(1);
+ /*
+ * If we're the second in a pair of like elements, emit our
+ * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
+ * case we soldier on.
+ */
+ if (n->prev->tok == n->tok &&
+ MDOC_Ft != n->tok &&
+ MDOC_Fo != n->tok &&
+ MDOC_Fn != n->tok) {
+ term_newln(p);
+ return;
+ }
- return(termp_under_pre(p, pair, m, n));
+ /*
+ * If we're one of the SYNOPSIS set and non-like pair-wise after
+ * another (or Fn/Fo, which we've let slip through) then assert
+ * vertical space, else only newline and move on.
+ */
+ switch (n->prev->tok) {
+ case (MDOC_Fd):
+ /* FALLTHROUGH */
+ case (MDOC_Fn):
+ /* FALLTHROUGH */
+ case (MDOC_Fo):
+ /* FALLTHROUGH */
+ case (MDOC_In):
+ /* FALLTHROUGH */
+ case (MDOC_Vt):
+ term_vspace(p);
+ break;
+ case (MDOC_Ft):
+ if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
+ term_vspace(p);
+ break;
+ }
+ /* FALLTHROUGH */
+ default:
+ term_newln(p);
+ break;
+ }
}
-/* ARGSUSED */
-static void
-termp_vt_post(DECL_ARGS)
+static int
+termp_vt_pre(DECL_ARGS)
{
- if (MDOC_BLOCK != n->type)
- return;
- if (n->next && MDOC_Vt == n->next->tok)
- term_newln(p);
- else if (n->next)
- term_vspace(p);
+ if (MDOC_ELEM == n->type) {
+ synopsis_pre(p, n);
+ return(termp_under_pre(p, pair, m, n));
+ } else if (MDOC_BLOCK == n->type) {
+ synopsis_pre(p, n);
+ return(1);
+ } else if (MDOC_HEAD == n->type)
+ return(0);
+
+ return(termp_under_pre(p, pair, m, n));
}
@@ -1349,11 +1392,12 @@ termp_bold_pre(DECL_ARGS)
/* ARGSUSED */
-static void
-termp_fd_post(DECL_ARGS)
+static int
+termp_fd_pre(DECL_ARGS)
{
- term_newln(p);
+ synopsis_pre(p, n);
+ return(termp_bold_pre(p, pair, m, n));
}
@@ -1507,9 +1551,7 @@ termp_ft_pre(DECL_ARGS)
{
/* NB: MDOC_LINE does not effect this! */
- if (SEC_SYNOPSIS == n->sec && n->prev)
- term_vspace(p);
-
+ synopsis_pre(p, n);
term_fontpush(p, TERMFONT_UNDER);
return(1);
}
@@ -1521,13 +1563,7 @@ termp_fn_pre(DECL_ARGS)
{
const struct mdoc_node *nn;
- /* NB: MDOC_LINE has no effect on this macro! */
- if (SEC_SYNOPSIS == n->sec) {
- if (n->prev && MDOC_Ft == n->prev->tok)
- term_newln(p);
- else if (n->prev)
- term_vspace(p);
- }
+ synopsis_pre(p, n);
term_fontpush(p, TERMFONT_BOLD);
term_word(p, n->child->string);
@@ -1555,17 +1591,6 @@ termp_fn_pre(DECL_ARGS)
/* ARGSUSED */
-static void
-termp_fn_post(DECL_ARGS)
-{
-
- /* NB: MDOC_LINE has no effect on this macro! */
- if (SEC_SYNOPSIS == n->sec)
- term_newln(p);
-}
-
-
-/* ARGSUSED */
static int
termp_fa_pre(DECL_ARGS)
{
@@ -1830,8 +1855,8 @@ static int
termp_cd_pre(DECL_ARGS)
{
+ synopsis_pre(p, n);
term_fontpush(p, TERMFONT_BOLD);
- term_newln(p);
return(1);
}
@@ -1841,8 +1866,7 @@ static int
termp_in_pre(DECL_ARGS)
{
- if (SEC_SYNOPSIS == n->sec && n->prev && MDOC_In != n->prev->tok)
- term_vspace(p);
+ synopsis_pre(p, n);
if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) {
term_fontpush(p, TERMFONT_BOLD);
@@ -1863,16 +1887,14 @@ static void
termp_in_post(DECL_ARGS)
{
- if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags)
+ if (SEC_SYNOPSIS == n->sec)
term_fontpush(p, TERMFONT_BOLD);
p->flags |= TERMP_NOSPACE;
term_word(p, ">");
- if (SEC_SYNOPSIS == n->sec && MDOC_LINE & n->flags) {
+ if (SEC_SYNOPSIS == n->sec)
term_fontpop(p);
- term_newln(p);
- }
}
@@ -1983,13 +2005,7 @@ termp_fo_pre(DECL_ARGS)
{
if (MDOC_BLOCK == n->type) {
- /* NB: MDOC_LINE has no effect on this macro! */
- if (SEC_SYNOPSIS != n->sec)
- return(1);
- if (n->prev && MDOC_Ft == n->prev->tok)
- term_newln(p);
- else if (n->prev)
- term_vspace(p);
+ synopsis_pre(p, n);
return(1);
} else if (MDOC_BODY == n->type) {
p->flags |= TERMP_NOSPACE;
@@ -2013,17 +2029,15 @@ static void
termp_fo_post(DECL_ARGS)
{
- if (MDOC_BLOCK == n->type) {
- /* NB: MDOC_LINE has no effect on this macro! */
- if (SEC_SYNOPSIS == n->sec)
- term_newln(p);
- } else if (MDOC_BODY == n->type) {
+ if (MDOC_BODY != n->type)
+ return;
+
+ p->flags |= TERMP_NOSPACE;
+ term_word(p, ")");
+
+ if (SEC_SYNOPSIS == n->sec) {
p->flags |= TERMP_NOSPACE;
- term_word(p, ")");
- if (SEC_SYNOPSIS == n->sec) {
- p->flags |= TERMP_NOSPACE;
- term_word(p, ";");
- }
+ term_word(p, ";");
}
}
diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c
index 28799b3d0ac..c6058447e75 100644
--- a/usr.bin/mandoc/term.c
+++ b/usr.bin/mandoc/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.35 2010/05/26 02:39:58 schwarze Exp $ */
+/* $Id: term.c,v 1.36 2010/06/08 00:11:47 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -18,6 +18,7 @@
#include <assert.h>
#include <ctype.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -31,7 +32,7 @@
#include "mdoc.h"
#include "main.h"
-static struct termp *term_alloc(enum termenc, size_t);
+static struct termp *term_alloc(char *, enum termenc);
static void term_free(struct termp *);
static void spec(struct termp *, const char *, size_t);
static void res(struct termp *, const char *, size_t);
@@ -42,10 +43,10 @@ static void encode(struct termp *, const char *, size_t);
void *
-ascii_alloc(size_t width)
+ascii_alloc(char *outopts)
{
- return(term_alloc(TERMENC_ASCII, width));
+ return(term_alloc(outopts, TERMENC_ASCII));
}
@@ -71,17 +72,35 @@ term_free(struct termp *p)
static struct termp *
-term_alloc(enum termenc enc, size_t width)
+term_alloc(char *outopts, enum termenc enc)
{
- struct termp *p;
+ struct termp *p;
+ const char *toks[2];
+ char *v;
+ size_t width;
+
+ toks[0] = "width";
+ toks[1] = NULL;
p = calloc(1, sizeof(struct termp));
if (NULL == p) {
perror(NULL);
exit(EXIT_FAILURE);
}
+
p->tabwidth = 5;
p->enc = enc;
+ width = 80;
+
+ while (outopts && *outopts)
+ switch (getsubopt(&outopts, UNCONST(toks), &v)) {
+ case (0):
+ width = (size_t)atoi(v);
+ break;
+ default:
+ break;
+ }
+
/* Enforce some lower boundary. */
if (width < 60)
width = 60;