summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/Makefile4
-rw-r--r--usr.bin/mandoc/html.c8
-rw-r--r--usr.bin/mandoc/libmdoc.h39
-rw-r--r--usr.bin/mandoc/main.c8
-rw-r--r--usr.bin/mandoc/man.348
-rw-r--r--usr.bin/mandoc/man.7156
-rw-r--r--usr.bin/mandoc/man.c87
-rw-r--r--usr.bin/mandoc/man_hash.c7
-rw-r--r--usr.bin/mandoc/mandoc.18
-rw-r--r--usr.bin/mandoc/manuals.78
-rw-r--r--usr.bin/mandoc/mdoc.7252
-rw-r--r--usr.bin/mandoc/mdoc.c123
-rw-r--r--usr.bin/mandoc/mdoc_action.c10
-rw-r--r--usr.bin/mandoc/mdoc_argv.c51
-rw-r--r--usr.bin/mandoc/mdoc_hash.c4
-rw-r--r--usr.bin/mandoc/mdoc_macro.c342
-rw-r--r--usr.bin/mandoc/mdoc_strings.c10
-rw-r--r--usr.bin/mandoc/mdoc_validate.c18
18 files changed, 426 insertions, 757 deletions
diff --git a/usr.bin/mandoc/Makefile b/usr.bin/mandoc/Makefile
index 0a1b5dac4b0..eb11454f98d 100644
--- a/usr.bin/mandoc/Makefile
+++ b/usr.bin/mandoc/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.34 2010/05/10 18:20:31 drahn Exp $
+# $OpenBSD: Makefile,v 1.35 2010/05/14 01:54:37 schwarze Exp $
.include <bsd.own.mk>
-VERSION=1.9.23
+VERSION=1.9.24
CFLAGS+=-DVERSION=\"${VERSION}\"
CFLAGS+=-W -Wall -Wstrict-prototypes
diff --git a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c
index 8b747ffd0ab..ac71994c12a 100644
--- a/usr.bin/mandoc/html.c
+++ b/usr.bin/mandoc/html.c
@@ -1,4 +1,4 @@
-/* $Id: html.c,v 1.7 2010/04/07 23:15:05 schwarze Exp $ */
+/* $Id: html.c,v 1.8 2010/05/14 01:54:37 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -50,7 +50,7 @@ static const struct htmldata htmltags[TAG_MAX] = {
{"h1", 0}, /* TAG_H1 */
{"h2", 0}, /* TAG_H2 */
{"span", 0}, /* TAG_SPAN */
- {"link", HTML_CLRLINE | HTML_NOSTACK}, /* TAG_LINK */
+ {"link", HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_LINK */
{"br", HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_BR */
{"a", 0}, /* TAG_A */
{"table", HTML_CLRLINE}, /* TAG_TABLE */
@@ -517,6 +517,10 @@ print_text(struct html *h, const char *p)
if ( ! print_encode(h, p, 0))
h->flags &= ~HTML_NOSPACE;
+ /*
+ * Note that we don't process the pipe: the parser sees it as
+ * punctuation, but we don't in terms of typography.
+ */
if (*p && 0 == *(p + 1))
switch (*p) {
case('('):
diff --git a/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h
index 196361493ff..902a9e06988 100644
--- a/usr.bin/mandoc/libmdoc.h
+++ b/usr.bin/mandoc/libmdoc.h
@@ -1,4 +1,4 @@
-/* $Id: libmdoc.h,v 1.28 2010/05/08 01:52:07 schwarze Exp $ */
+/* $Id: libmdoc.h,v 1.29 2010/05/14 01:54:37 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -111,6 +111,23 @@ struct mdoc_macro {
/* Reserved words in arguments treated as text. */
};
+enum margserr {
+ ARGS_ERROR,
+ ARGS_EOLN,
+ ARGS_WORD,
+ ARGS_PUNCT,
+ ARGS_QWORD,
+ ARGS_PHRASE,
+ ARGS_PPHRASE
+};
+
+enum margverr {
+ ARGV_ERROR,
+ ARGV_EOLN,
+ ARGV_ARG,
+ ARGV_WORD
+};
+
extern const struct mdoc_macro *const mdoc_macros;
__BEGIN_DECLS
@@ -146,8 +163,7 @@ int mdoc_isdelim(const char *);
size_t mdoc_isescape(const char *);
enum mdoc_sec mdoc_atosec(const char *);
time_t mdoc_atotime(const char *);
-
-size_t mdoc_macro2len(int);
+size_t mdoc_macro2len(enum mdoct);
const char *mdoc_a2att(const char *);
const char *mdoc_a2lib(const char *);
const char *mdoc_a2st(const char *);
@@ -160,27 +176,18 @@ int mdoc_valid_post(struct mdoc *);
int mdoc_action_pre(struct mdoc *,
const struct mdoc_node *);
int mdoc_action_post(struct mdoc *);
-int mdoc_argv(struct mdoc *, int, enum mdoct,
+enum margverr mdoc_argv(struct mdoc *, int, enum mdoct,
struct mdoc_arg **, int *, char *);
-#define ARGV_ERROR (-1)
-#define ARGV_EOLN (0)
-#define ARGV_ARG (1)
-#define ARGV_WORD (2)
void mdoc_argv_free(struct mdoc_arg *);
void mdoc_argn_free(struct mdoc_arg *, int);
-int mdoc_args(struct mdoc *, int,
+enum margserr mdoc_args(struct mdoc *, int,
int *, char *, enum mdoct, char **);
-int mdoc_zargs(struct mdoc *, int,
+enum margserr mdoc_zargs(struct mdoc *, int,
int *, char *, int, char **);
#define ARGS_DELIM (1 << 1) /* See args(). */
#define ARGS_TABSEP (1 << 2) /* See args(). */
#define ARGS_NOWARN (1 << 3) /* See args(). */
-#define ARGS_ERROR (-1)
-#define ARGS_EOLN (0)
-#define ARGS_WORD (1)
-#define ARGS_PUNCT (2)
-#define ARGS_QWORD (3)
-#define ARGS_PHRASE (4)
+
int mdoc_macroend(struct mdoc *);
__END_DECLS
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index 069c9436ad4..a9f0e5b5dcb 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.24 2010/05/13 20:34:29 schwarze Exp $ */
+/* $Id: main.c,v 1.25 2010/05/14 01:54:37 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -362,6 +362,12 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse *curp)
comment = 1;
pos -= 2;
+ for (; pos > 0; --pos) {
+ if (ln->buf[pos] != ' ')
+ break;
+ if (ln->buf[pos - 1] == '\\')
+ break;
+ }
continue;
}
diff --git a/usr.bin/mandoc/man.3 b/usr.bin/mandoc/man.3
index 420dba343f7..f8e4b4ca3b5 100644
--- a/usr.bin/mandoc/man.3
+++ b/usr.bin/mandoc/man.3
@@ -1,4 +1,4 @@
-.\" $Id: man.3,v 1.9 2010/04/04 13:41:23 schwarze Exp $
+.\" $Id: man.3,v 1.10 2010/05/14 01:54:37 schwarze Exp $
.\"
.\" Copyright (c) 2009-2010 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
@@ -14,11 +14,9 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: April 4 2010 $
+.Dd $Mdocdate: May 14 2010 $
.Dt MAN 3
.Os
-.
-.
.Sh NAME
.Nm man ,
.Nm man_alloc ,
@@ -29,8 +27,6 @@
.Nm man_free ,
.Nm man_reset
.Nd man macro compiler library
-.
-.
.Sh SYNOPSIS
.In man.h
.Vt extern const char * const * man_macronames;
@@ -48,8 +44,6 @@
.Fn man_meta "const struct man *man"
.Ft int
.Fn man_endparse "struct man *man"
-.
-.
.Sh DESCRIPTION
The
.Nm
@@ -58,7 +52,6 @@ library parses lines of
input (and
.Em only
man) into an abstract syntax tree (AST).
-.
.Pp
In general, applications initiate a parsing sequence with
.Fn man_alloc ,
@@ -78,14 +71,12 @@ function may be used in order to reset the parser for another input
sequence. See the
.Sx EXAMPLES
section for a full example.
-.
.Pp
Beyond the full set of macros defined in
.Xr man 7 ,
the
.Nm
library also accepts the following macros:
-.
.Pp
.Bl -tag -width Ds -compact
.It am
@@ -100,25 +91,20 @@ and may begin anywhere, although they may not break the next-line
scoping rules specified in
.Xr man 7 .
These blocks are discarded.
-.
.It PD
Has no effect. Handled as a current-scope line macro.
-.
.It Sp
A synonym for
.Sq sp 0.5v
.Pq part of the standard preamble for Perl documentation .
Handled as a line macro.
-.
.It UC
Has no effect. Handled as a current-scope line macro.
-.
.It Vb
A synonym for
.Sq nf
.Pq part of the standard preamble for Perl documentation .
Handled as a current-scope line macro.
-.
.It Ve
A synonym for
.Sq fi ,
@@ -151,8 +137,6 @@ documents to be correctly formatted:
\e*(Th (Thorn),
and
\e*(th (thorn).
-.
-.
.Sh REFERENCE
This section further defines the
.Sx Types ,
@@ -162,8 +146,6 @@ and
available to programmers. Following that, the
.Sx Abstract Syntax Tree
section documents the output tree.
-.
-.
.Ss Types
Both functions (see
.Sx Functions )
@@ -171,16 +153,13 @@ and variables (see
.Sx Variables )
may use the following types:
.Bl -ohang
-.
.It Vt struct man
An opaque type defined in
.Pa man.c .
Its values are only used privately within the library.
-.
.It Vt struct man_cb
A set of message callbacks defined in
.Pa man.h .
-.
.It Vt struct man_node
A parsed node. Defined in
.Pa man.h .
@@ -188,12 +167,9 @@ See
.Sx Abstract Syntax Tree
for details.
.El
-.
-.
.Ss Functions
Function descriptions follow:
.Bl -ohang
-.
.It Fn man_alloc
Allocates a parsing structure. The
.Fa data
@@ -206,29 +182,24 @@ arguments are defined in
.Pa man.h .
Returns NULL on failure. If non-NULL, the pointer must be freed with
.Fn man_free .
-.
.It Fn man_reset
Reset the parser for another parse routine. After its use,
.Fn man_parseln
behaves as if invoked for the first time.
-.
.It Fn man_free
Free all resources of a parser. The pointer is no longer valid after
invocation.
-.
.It Fn man_parseln
Parse a nil-terminated line of input. This line should not contain the
trailing newline. Returns 0 on failure, 1 on success. The input buffer
.Fa buf
is modified by this function.
-.
.It Fn man_endparse
Signals that the parse is complete. Note that if
.Fn man_endparse
is called subsequent to
.Fn man_node ,
the resulting tree is incomplete. Returns 0 on failure, 1 on success.
-.
.It Fn man_node
Returns the first node of the parse. Note that if
.Fn man_parseln
@@ -243,17 +214,12 @@ or
.Fn man_endparse
return 0, the data will be incomplete.
.El
-.
-.
.Ss Variables
The following variables are also defined:
.Bl -ohang
-.
.It Va man_macronames
An array of string-ified token names.
.El
-.
-.
.Ss Abstract Syntax Tree
The
.Nm
@@ -267,13 +233,11 @@ or after
or
.Fn man_parseln
fail, it may be incomplete.
-.
.Pp
This AST is governed by the ontological
rules dictated in
.Xr man 7
and derives its terminology accordingly.
-.
.Pp
The AST is composed of
.Vt struct man_node
@@ -292,7 +256,6 @@ fields), its position in the tree (the
and
.Va prev
fields) and some type-specific data.
-.
.Pp
The tree itself is arranged according to the following normal form,
where capitalised non-terminals represent nodes.
@@ -313,13 +276,10 @@ where capitalised non-terminals represent nodes.
.It TEXT
\(<- [[:alpha:]]*
.El
-.
.Pp
The only elements capable of nesting other elements are those with
next-lint scope as documented in
.Xr man 7 .
-.
-.
.Sh EXAMPLES
The following example reads lines from stdin and parses them, operating
on the finished parse tree with
@@ -355,13 +315,9 @@ if (NULL == (node = man_node(man)))
parsed(man, node);
man_free(man);
.Ed
-.
-.
.Sh SEE ALSO
.Xr mandoc 1 ,
.Xr man 7
-.
-.
.Sh AUTHORS
The
.Nm
diff --git a/usr.bin/mandoc/man.7 b/usr.bin/mandoc/man.7
index 4174cb04361..75b242e29b7 100644
--- a/usr.bin/mandoc/man.7
+++ b/usr.bin/mandoc/man.7
@@ -1,6 +1,6 @@
-.\" $Id: man.7,v 1.20 2010/04/07 23:15:05 schwarze Exp $
+.\" $Id: man.7,v 1.21 2010/05/14 01:54:37 schwarze Exp $
.\"
-.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
+.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
@@ -14,16 +14,12 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: April 7 2010 $
+.Dd $Mdocdate: May 14 2010 $
.Dt MAN 7
.Os
-.
-.
.Sh NAME
.Nm man
.Nd man language reference
-.
-.
.Sh DESCRIPTION
The
.Nm man
@@ -31,7 +27,6 @@ language was historically used to format
.Ux
manuals. This reference document describes its syntax, structure, and
usage.
-.
.Pp
.Bf -emphasis
Do not use
@@ -41,7 +36,6 @@ to write your manuals.
Use the
.Xr mdoc 7
language, instead.
-.
.Pp
An
.Nm
@@ -54,20 +48,15 @@ prior macros:
\&.SH Macro lines change control state.
Other lines are interpreted within the current state.
.Ed
-.
-.
.Sh INPUT ENCODING
.Nm
documents may contain only graphable 7-bit ASCII characters, the
space character, and the tabs character. All manuals must have
.Ux
line termination.
-.
.Pp
Blank lines are acceptable; where found, the output will assert a
vertical space.
-.
-.
.Ss Comments
Text following a
.Sq \e\*" ,
@@ -76,8 +65,6 @@ line. A macro line with only a control character and comment escape,
.Sq \&.\e" ,
is also ignored. Macro lines with only a control character and
optionally whitespace are stripped from input.
-.
-.
.Ss Special Characters
Special characters may occur in both macro and free-form lines.
Sequences begin with the escape character
@@ -96,8 +83,6 @@ for a complete list. Examples include
and
.Sq \ee
.Pq back-slash .
-.
-.
.Ss Text Decoration
Terms may be text-decorated using the
.Sq \ef
@@ -140,15 +125,15 @@ Both
and
.Sq \ef
attributes are forgotten when entering or exiting a macro block.
-.
-.
.Ss Whitespace
-Unless specifically escaped, consecutive blocks of whitespace are pruned
-from input. These are later re-added, if applicable, by a front-end
-utility such as
-.Xr mandoc 1 .
-.
-.
+Whitespace consists of the space character.
+In free-form lines, whitespace is preserved within a line; un-escaped
+trailing spaces are stripped from input (unless in a literal context).
+Blank free-form lines, which may include spaces, are permitted and
+rendered as an empty line.
+.Pp
+In macro lines, whitespace delimits arguments and is discarded. If
+arguments are quoted, whitespace within the quotes is retained.
.Ss Dates
The
.Sx \&TH
@@ -157,22 +142,18 @@ macro is the only
macro that requires a date. The form for this date is the ISO-8601
standard
.Cm YYYY-MM-DD .
-.
-.
.Ss Scaling Widths
Many macros support scaled widths for their arguments, such as
stipulating a two-inch paragraph indentation with the following:
.Bd -literal -offset indent
\&.HP 2i
.Ed
-.
.Pp
The syntax for scaled widths is
.Sq Li [+-]?[0-9]*.[0-9]*[:unit:]? ,
where a decimal must be preceded or proceeded by at least one digit.
Negative numbers, while accepted, are truncated to zero. The following
scaling units are accepted:
-.
.Pp
.Bl -tag -width Ds -offset indent -compact
.It c
@@ -211,7 +192,6 @@ Using anything other than
or
.Sq v
is necessarily non-portable across output media.
-.
.Pp
If a scaling unit is not provided, the numerical value is interpreted
under the default rules of
@@ -224,8 +204,6 @@ this differs from
.Xr mdoc 7 ,
which, if a unit is not provided, will instead interpret the string as
literal text.
-.
-.
.Sh MANUAL STRUCTURE
Each
.Nm
@@ -234,7 +212,6 @@ document must contain contains at least the
macro describing the document's section and title. It may occur
anywhere in the document, although conventionally, it appears as the
first macro.
-.
.Pp
Beyond
.Sx \&TH ,
@@ -329,36 +306,29 @@ which is used for functions. Historically, this information was
described in
.Em DIAGNOSTICS ,
a practise that is now discouraged.
-.
.It Em RETURN VALUES
This section is the dual of
.Em EXIT STATUS ,
which is used for commands. It documents the return values of functions
in sections 2, 3, and 9.
-.
.It Em ENVIRONMENT
Documents any usages of environment variables, e.g.,
.Xr environ 7 .
-.
.It Em FILES
Documents files used. It's helpful to document both the file and a
short description of how the file is used (created, modified, etc.).
-.
.It Em EXAMPLES
Example usages. This often contains snippets of well-formed,
well-tested invocations. Make doubly sure that your examples work
properly!
-.
.It Em DIAGNOSTICS
Documents error conditions. This is most useful in section 4 manuals.
Historically, this section was used in place of
.Em EXIT STATUS
for manuals in sections 1, 6, and 8; however, this practise is
discouraged.
-.
.It Em ERRORS
Documents error handling in sections 2, 3, and 9.
-.
.It Em SEE ALSO
References other manuals with related topics. This section should exist
for most manuals.
@@ -367,7 +337,6 @@ for most manuals.
.Pp
Cross-references should conventionally be ordered
first by section, then alphabetically.
-.
.It Em STANDARDS
References any standards implemented or used, such as
.Pp
@@ -376,29 +345,21 @@ References any standards implemented or used, such as
If not adhering to any standards, the
.Em HISTORY
section should be used.
-.
.It Em HISTORY
The history of any manual without a
.Em STANDARDS
section should be described in this section.
-.
.It Em AUTHORS
Credits to authors, if applicable, should appear in this section.
Authors should generally be noted by both name and an e-mail address.
-.
.It Em CAVEATS
Explanations of common misuses and misunderstandings should be explained
in this section.
-.
.It Em BUGS
Extant bugs should be described in this section.
-.
.It Em SECURITY CONSIDERATIONS
Documents any security precautions that operators should consider.
-.
.El
-.
-.
.Sh MACRO SYNTAX
Macros are one to three three characters in length and begin with a
control character ,
@@ -412,7 +373,6 @@ the macro name. Thus, the following are equivalent:
\&.PP
\&.\ \ \ PP
.Ed
-.
.Pp
The
.Nm
@@ -420,8 +380,6 @@ macros are classified by scope: line scope or block scope. Line
macros are only scoped to the current line (and, in some situations,
the subsequent line). Block macros are scoped to the current line and
subsequent lines until closed by another block macro.
-.
-.
.Ss Line Macros
Line macros are generally scoped to the current line, with the body
consisting of zero or more arguments. If a macro is scoped to the next
@@ -431,7 +389,6 @@ text, is used instead. Thus:
\&.I
foo
.Ed
-.
.Pp
is equivalent to
.Sq \&.I foo .
@@ -448,7 +405,6 @@ The syntax is as follows:
\&.YO \(lBbody...\(rB
\(lBbody...\(rB
.Ed
-.
.Pp
.Bl -column -compact -offset indent "MacroX" "ArgumentsX" "ScopeXXXXX" "CompatX"
.It Em Macro Ta Em Arguments Ta Em Scope Ta Em Notes
@@ -478,7 +434,6 @@ The syntax is as follows:
.\" .It Sx \&Vb Ta <1 Ta current Ta compat
.\" .It Sx \&Ve Ta 0 Ta current Ta compat
.El
-.
.Pp
Macros marked as
.Qq compat
@@ -487,8 +442,6 @@ manuals that mix dialects of roff. These macros should not be used for
portable
.Nm
manuals.
-.
-.
.Ss Block Macros
Block macros are comprised of a head and body. Like for in-line macros,
the head is scoped to the current line and, in one circumstance, the
@@ -502,7 +455,6 @@ The syntax is as follows:
\(lBhead...\(rB
\(lBbody...\(rB
.Ed
-.
.Pp
The closure of body scope may be to the section, where a macro is closed
by
@@ -520,12 +472,10 @@ or paragraph, closed by a section, sub-section, part,
or
.Sx \&TP .
No closure refers to an explicit block closing macro.
-.
.Pp
As a rule, block macros may not be nested; thus, calling a block macro
while another block macro scope is open, and the open scope is not
implicitly closed, is syntactically incorrect.
-.
.Pp
.Bl -column -compact -offset indent "MacroX" "ArgumentsX" "Head ScopeX" "sub-sectionX" "compatX"
.It Em Macro Ta Em Arguments Ta Em Head Scope Ta Em Body Scope Ta Em Notes
@@ -541,23 +491,17 @@ implicitly closed, is syntactically incorrect.
.It Sx \&TP Ta n Ta next-line Ta paragraph Ta \&
.El
.Pp
-.
Macros marked
.Qq compat
are as mentioned in
.Sx Line Macros .
-.
.Pp
If a block macro is next-line scoped, it may only be followed by in-line
macros for decorating text.
-.
-.
.Sh REFERENCE
This section is a canonical reference to all macros, arranged
alphabetically. For the scoping of individual macros, see
.Sx MACRO SYNTAX .
-.
-.
.Ss \&B
Text is rendered in bold face.
.Pp
@@ -568,8 +512,6 @@ See also
.Sx \&i ,
and
.Sx \&r .
-.
-.
.Ss \&BI
Text is rendered alternately in bold face and italic. Thus,
.Sq .BI this word and that
@@ -600,8 +542,6 @@ See also
.Sx \&RI ,
and
.Sx \&IR .
-.
-.
.Ss \&BR
Text is rendered alternately in bold face and roman (the default font).
Whitespace between arguments is omitted in output.
@@ -617,12 +557,8 @@ See also
.Sx \&RI ,
and
.Sx \&IR .
-.
-.
.Ss \&DT
Has no effect. Included for compatibility.
-.
-.
.Ss \&HP
Begin a paragraph whose initial output line is left-justified, but
subsequent output lines are indented, with the following syntax:
@@ -645,8 +581,6 @@ See also
.Sx \&PP ,
and
.Sx \&TP .
-.
-.
.Ss \&I
Text is rendered in italics.
.Pp
@@ -657,8 +591,6 @@ See also
.Sx \&i ,
and
.Sx \&r .
-.
-.
.Ss \&IB
Text is rendered alternately in italics and bold face. Whitespace
between arguments is omitted in output.
@@ -674,8 +606,6 @@ See also
.Sx \&RI ,
and
.Sx \&IR .
-.
-.
.Ss \&IP
Begin an indented paragraph with the following syntax:
.Bd -filled -offset indent
@@ -702,8 +632,6 @@ See also
.Sx \&PP ,
and
.Sx \&TP .
-.
-.
.Ss \&IR
Text is rendered alternately in italics and roman (the default font).
Whitespace between arguments is omitted in output.
@@ -719,8 +647,6 @@ See also
.Sx \&RB ,
and
.Sx \&RI .
-.
-.
.Ss \&LP
Begin an undecorated paragraph. The scope of a paragraph is closed by a
subsequent paragraph, sub-section, section, or end of file. The saved
@@ -733,8 +659,6 @@ See also
.Sx \&PP ,
and
.Sx \&TP .
-.
-.
.Ss \&P
Synonym for
.Sx \&LP .
@@ -746,8 +670,6 @@ See also
.Sx \&PP ,
and
.Sx \&TP .
-.
-.
.Ss \&PP
Synonym for
.Sx \&LP .
@@ -759,8 +681,6 @@ See also
.Sx \&P ,
and
.Sx \&TP .
-.
-.
.Ss \&R
Text is rendered in roman (the default font).
.Pp
@@ -771,8 +691,6 @@ See also
.Sx \&i ,
and
.Sx \&r .
-.
-.
.Ss \&RB
Text is rendered alternately in roman (the default font) and bold face.
Whitespace between arguments is omitted in output.
@@ -788,13 +706,9 @@ See also
.Sx \&RI ,
and
.Sx \&IR .
-.
-.
.Ss \&RE
Explicitly close out the scope of a prior
.Sx \&RS .
-.
-.
.Ss \&RI
Text is rendered alternately in roman (the default font) and italics.
Whitespace between arguments is omitted in output.
@@ -810,8 +724,6 @@ See also
.Sx \&RB ,
and
.Sx \&IR .
-.
-.
.Ss \&RS
Begin a part setting the left margin. The left margin controls the
offset, following an initial indentation, to un-indented text such as
@@ -828,30 +740,20 @@ The
argument must conform to
.Sx Scaling Widths .
If not specified, the saved or default width is used.
-.
-.
.Ss \&SB
Text is rendered in small size (one point smaller than the default font)
bold face.
-.
-.
.Ss \&SH
Begin a section. The scope of a section is only closed by another
section or the end of file. The paragraph left-margin width is re-set
to the default.
-.
-.
.Ss \&SM
Text is rendered in small size (one point smaller than the default
font).
-.
-.
.Ss \&SS
Begin a sub-section. The scope of a sub-section is closed by a
subsequent sub-section, section, or end of file. The paragraph
left-margin width is re-set to the default.
-.
-.
.Ss \&TH
Sets the title of the manual page with the following syntax:
.Bd -filled -offset indent
@@ -878,8 +780,6 @@ manual section.
Examples:
.Pp
.D1 \&.TH CVS 5 "1992-02-12" GNU
-.
-.
.Ss \&TP
Begin a paragraph where the head, if exceeding the indentation width, is
followed by a newline; if not, the body follows on the same line after a
@@ -912,20 +812,14 @@ and
.\" .
.\" .Ss \&UC
.\" Has no effect. Included for compatibility.
-.
-.
.Ss \&br
Breaks the current line. Consecutive invocations have no further effect.
.Pp
See also
.Sx \&sp .
-.
-.
.Ss \&fi
End literal mode begun by
.Sx \&nf .
-.
-.
.Ss \&i
Italicise arguments. Synonym for
.Sx \&I .
@@ -937,18 +831,12 @@ See also
.Sx \&b ,
and
.Sx \&r .
-.
-.
.Ss \&na
Don't align to the right margin.
-.
-.
.Ss \&nf
Begin literal mode: all subsequent free-form lines have their end of
line boundaries preserved. May be ended by
.Sx \&fi .
-.
-.
.Ss \&r
Fonts and styles (bold face, italics) reset to roman (default font).
.Pp
@@ -959,8 +847,6 @@ See also
.Sx \&b ,
and
.Sx \&i .
-.
-.
.Ss \&sp
Insert vertical spaces into output with the following syntax:
.Bd -filled -offset indent
@@ -978,7 +864,6 @@ macro. Defaults to 1, if unspecified.
.Pp
See also
.Sx \&br .
-.
.\" .Ss \&Sp
.\" A synonym for
.\" .Sx \&sp
@@ -994,32 +879,22 @@ See also
.\" A synonym for
.\" .Sx \&fi .
.\" .
-.
.Sh COMPATIBILITY
This section documents areas of questionable portability between
implementations of the
.Nm
language.
-.
.Pp
.Bl -dash -compact
.It
In quoted literals, GNU troff allowed pair-wise double-quotes to produce
a standalone double-quote in formatted output. It is not known whether
this behaviour is exhibited by other formatters.
-.
-.It
-Blocks of whitespace are stripped from macro and free-form text lines
-(except when in literal mode) in mandoc. This is not the case for GNU
-troff: for maximum portability, whitespace sensitive blocks should be
-enclosed in literal contexts.
-.
.It
The
.Sx \&sp
macro does not accept negative values in mandoc. In GNU troff, this
would result in strange behaviour.
-.
.It
The
.Sq \(aq
@@ -1028,22 +903,15 @@ newline before macro output; in mandoc, it is an alias for the standard
.Sq \&.
control character.
.El
-.
-.
.Sh SEE ALSO
.Xr mandoc 1 ,
.Xr mandoc_char 7
-.
-.
.Sh AUTHORS
The
.Nm
reference was written by
-.An Kristaps Dzonsons Aq kristaps@kth.se .
-.
-.
+.An Kristaps Dzonsons Aq kristaps@bsd.lv .
.Sh CAVEATS
Do not use this language. Use
.Xr mdoc 7 ,
instead.
-.
diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c
index 7592c7b0b80..3d0c5bf50a4 100644
--- a/usr.bin/mandoc/man.c
+++ b/usr.bin/mandoc/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.26 2010/05/08 01:52:07 schwarze Exp $ */
+/* $Id: man.c,v 1.27 2010/05/14 01:54:37 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -79,8 +79,6 @@ static int man_ptext(struct man *, int, char *);
static int man_pmacro(struct man *, int, char *);
static void man_free1(struct man *);
static void man_alloc1(struct man *);
-static int pstring(struct man *, int, int,
- const char *, size_t);
static int macrowarn(struct man *, int, const char *);
@@ -331,35 +329,29 @@ man_block_alloc(struct man *m, int line, int pos, enum mant tok)
}
-static int
-pstring(struct man *m, int line, int pos,
- const char *p, size_t len)
+int
+man_word_alloc(struct man *m, int line, int pos, const char *word)
{
struct man_node *n;
- size_t sv;
+ size_t sv, len;
+
+ len = strlen(word);
n = man_node_alloc(line, pos, MAN_TEXT, MAN_MAX);
n->string = mandoc_malloc(len + 1);
- sv = strlcpy(n->string, p, len + 1);
+ sv = strlcpy(n->string, word, len + 1);
/* Prohibit truncation. */
assert(sv < len + 1);
if ( ! man_node_append(m, n))
return(0);
+
m->next = MAN_NEXT_SIBLING;
return(1);
}
-int
-man_word_alloc(struct man *m, int line, int pos, const char *word)
-{
-
- return(pstring(m, line, pos, word, strlen(word)));
-}
-
-
/*
* Free all of the resources held by a node. This does NOT unlink a
* node from its context; for that, see man_node_unlink().
@@ -389,8 +381,7 @@ man_node_delete(struct man *m, struct man_node *p)
static int
man_ptext(struct man *m, int line, char *buf)
{
- int i, j;
- char sv;
+ int i;
/* Ignore bogus comments. */
@@ -405,61 +396,44 @@ man_ptext(struct man *m, int line, char *buf)
goto descope;
}
- /* First de-chunk and allocate words. */
+ /* Pump blank lines directly into the backend. */
for (i = 0; ' ' == buf[i]; i++)
/* Skip leading whitespace. */ ;
if ('\0' == buf[i]) {
- /* Trailing whitespace? */
- if (i && ' ' == buf[i - 1])
- if ( ! man_pwarn(m, line, i - 1, WTSPACE))
- return(0);
- if ( ! pstring(m, line, 0, &buf[i], 0))
+ /* Allocate a blank entry. */
+ if ( ! man_word_alloc(m, line, 0, ""))
return(0);
goto descope;
}
- for (j = i; buf[i]; i++) {
- if (' ' != buf[i])
- continue;
-
- /* Escaped whitespace. */
- if (i && ' ' == buf[i] && '\\' == buf[i - 1])
- continue;
-
- sv = buf[i];
- buf[i++] = '\0';
-
- if ( ! pstring(m, line, j, &buf[j], (size_t)(i - j)))
- return(0);
+ /*
+ * Warn if the last un-escaped character is whitespace. Then
+ * strip away the remaining spaces (tabs stay!).
+ */
- /* Trailing whitespace? Check at overwritten byte. */
+ i = (int)strlen(buf);
+ assert(i);
- if (' ' == sv && '\0' == buf[i])
+ if (' ' == buf[i - 1] || '\t' == buf[i - 1]) {
+ if (i > 1 && '\\' != buf[i - 2])
if ( ! man_pwarn(m, line, i - 1, WTSPACE))
return(0);
- for ( ; ' ' == buf[i]; i++)
- /* Skip trailing whitespace. */ ;
-
- j = i;
-
- /* Trailing whitespace? */
+ for (--i; i && ' ' == buf[i]; i--)
+ /* Spin back to non-space. */ ;
- if (' ' == buf[i - 1] && '\0' == buf[i])
- if ( ! man_pwarn(m, line, i - 1, WTSPACE))
- return(0);
+ /* Jump ahead of escaped whitespace. */
+ i += '\\' == buf[i] ? 2 : 1;
- if ('\0' == buf[i])
- break;
+ buf[i] = '\0';
}
- if (j != i && ! pstring(m, line, j, &buf[j], (size_t)(i - j)))
+ if ( ! man_word_alloc(m, line, 0, buf))
return(0);
descope:
-
/*
* Co-ordinate what happens with having a next-line scope open:
* first close out the element scope (if applicable), then close
@@ -486,8 +460,7 @@ static int
macrowarn(struct man *m, int ln, const char *buf)
{
if ( ! (MAN_IGN_MACRO & m->pflags))
- return(man_verr(m, ln, 0,
- "unknown macro: %s%s",
+ return(man_verr(m, ln, 0, "unknown macro: %s%s",
buf, strlen(buf) > 3 ? "..." : ""));
return(man_vwarn(m, ln, 0, "unknown macro: %s%s",
buf, strlen(buf) > 3 ? "..." : ""));
@@ -513,6 +486,7 @@ man_pmacro(struct man *m, int ln, char *buf)
* Skip whitespace between the control character and initial
* text. "Whitespace" is both spaces and tabs.
*/
+
if (' ' == buf[i] || '\t' == buf[i]) {
i++;
while (buf[i] && (' ' == buf[i] || '\t' == buf[i]))
@@ -561,7 +535,10 @@ man_pmacro(struct man *m, int ln, char *buf)
while (buf[i] && ' ' == buf[i])
i++;
- /* Trailing whitespace? */
+ /*
+ * Trailing whitespace. Note that tabs are allowed to be passed
+ * into the parser as "text", so we only warn about spaces here.
+ */
if ('\0' == buf[i] && ' ' == buf[i - 1])
if ( ! man_pwarn(m, ln, i - 1, WTSPACE))
diff --git a/usr.bin/mandoc/man_hash.c b/usr.bin/mandoc/man_hash.c
index 81610efe8c9..18daea0786c 100644
--- a/usr.bin/mandoc/man_hash.c
+++ b/usr.bin/mandoc/man_hash.c
@@ -1,4 +1,4 @@
-/* $Id: man_hash.c,v 1.9 2010/04/25 16:32:19 schwarze Exp $ */
+/* $Id: man_hash.c,v 1.10 2010/05/14 01:54:37 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -56,9 +56,10 @@ man_hash_init(void)
memset(table, UCHAR_MAX, sizeof(table));
- assert(/* CONSTCOND */ MAN_MAX < UCHAR_MAX);
+ assert(/* LINTED */
+ MAN_MAX < UCHAR_MAX);
- for (i = 0; i < MAN_MAX; i++) {
+ for (i = 0; i < (int)MAN_MAX; i++) {
x = man_macronames[i][0];
assert(isalpha((u_char)x) || '.' == x);
diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1
index 9fecf524639..ec42f9d9e1d 100644
--- a/usr.bin/mandoc/mandoc.1
+++ b/usr.bin/mandoc/mandoc.1
@@ -1,6 +1,6 @@
-.\" $OpenBSD: mandoc.1,v 1.28 2010/05/13 20:34:29 schwarze Exp $
+.\" $OpenBSD: mandoc.1,v 1.29 2010/05/14 01:54:37 schwarze Exp $
.\"
-.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
+.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
@@ -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 13 2010 $
+.Dd $Mdocdate: May 14 2010 $
.Dt MANDOC 1
.Os
.Sh NAME
@@ -454,7 +454,7 @@ lists render similarly.
The
.Nm
utility was written by
-.An Kristaps Dzonsons Aq kristaps@kth.se .
+.An Kristaps Dzonsons Aq kristaps@bsd.lv .
.Sh CAVEATS
The
.Fl T Ns Cm html
diff --git a/usr.bin/mandoc/manuals.7 b/usr.bin/mandoc/manuals.7
index 7fb6b53223f..3fbb3c9486a 100644
--- a/usr.bin/mandoc/manuals.7
+++ b/usr.bin/mandoc/manuals.7
@@ -1,6 +1,6 @@
-.\" $Id: manuals.7,v 1.5 2009/08/22 16:32:22 schwarze Exp $
+.\" $Id: manuals.7,v 1.6 2010/05/14 01:54:37 schwarze Exp $
.\"
-.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
+.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
@@ -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: August 22 2009 $
+.Dd $Mdocdate: May 14 2010 $
.Dt MANUALS 7
.Os
.\" SECTION
@@ -134,7 +134,7 @@ or
to version-control your work. If you wish the last check-in to effect
your document's date, use the following RCS tag for the date macro:
.Pp
-.Dl \&.Dd $Mdocdate: August 22 2009 $
+.Dl \&.Dd $Mdocdate: May 14 2010 $
.\" SUBSECTION
.Ss Viewing
mdoc documents may be paged to your terminal with
diff --git a/usr.bin/mandoc/mdoc.7 b/usr.bin/mandoc/mdoc.7
index 329aa572db4..bdf763a4a62 100644
--- a/usr.bin/mandoc/mdoc.7
+++ b/usr.bin/mandoc/mdoc.7
@@ -1,6 +1,6 @@
-.\" $Id: mdoc.7,v 1.25 2010/04/07 23:15:05 schwarze Exp $
+.\" $Id: mdoc.7,v 1.26 2010/05/14 01:54:37 schwarze Exp $
.\"
-.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
+.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
@@ -14,16 +14,12 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: April 7 2010 $
+.Dd $Mdocdate: May 14 2010 $
.Dt MDOC 7
.Os
-.
-.
.Sh NAME
.Nm mdoc
.Nd mdoc language reference
-.
-.
.Sh DESCRIPTION
The
.Nm mdoc
@@ -31,13 +27,9 @@ language is used to format
.Bx
.Ux
manuals. In this reference document, we describe its syntax, structure,
-and usage. Our reference implementation is
-.Xr mandoc 1 .
-The
+and usage. Our reference implementation is mandoc; the
.Sx COMPATIBILITY
-section describes compatibility with
-.Xr groff 1 .
-.
+section describes compatibility with other troff \-mdoc implementations.
.Pp
An
.Nm
@@ -50,8 +42,6 @@ prior macros:
\&.Sh Macro lines change control state.
Other lines are interpreted within the current state.
.Ed
-.
-.
.Sh LANGUAGE SYNTAX
.Nm
documents may contain only graphable 7-bit ASCII characters, the space
@@ -59,8 +49,6 @@ character, and, in certain circumstances, the tab character. All
manuals must have
.Ux
line terminators.
-.
-.
.Ss Comments
Text following a
.Sq \e" ,
@@ -69,8 +57,6 @@ 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
whitespace are stripped from input.
-.
-.
.Ss Reserved Characters
Within a macro line, the following characters are reserved:
.Pp
@@ -98,7 +84,6 @@ Within a macro line, the following characters are reserved:
.It \&|
.Pq vertical bar
.El
-.
.Pp
Use of reserved characters is described in
.Sx MACRO SYNTAX .
@@ -106,8 +91,6 @@ For general use in macro lines, these characters must either be escaped
with a non-breaking space
.Pq Sq \e&
or, if applicable, an appropriate escape sequence used.
-.
-.
.Ss Special Characters
Special characters may occur in both macro and free-form lines.
Sequences begin with the escape character
@@ -126,8 +109,6 @@ for a complete list. Examples include
and
.Sq \ee
.Pq back-slash .
-.
-.
.Ss Text Decoration
Terms may be text-decorated using the
.Sq \ef
@@ -175,8 +156,6 @@ Note these forms are
recommended for
.Nm ,
which encourages semantic annotation.
-.
-.
.Ss Predefined Strings
Historically,
.Xr groff 1
@@ -201,37 +180,21 @@ for a complete list. Examples include
and
.Sq \e*(Ba
.Pq vertical bar .
-.
-.
.Ss Whitespace
-In non-literal free-form lines, consecutive blocks of whitespace are
-pruned from input and added later in the output filter, if applicable:
-.Bd -literal -offset indent
-These spaces are pruned from input.
-\&.Bd \-literal
-These are not.
-\&.Ed
-.Ed
-.
+Whitespace consists of the space character.
+In free-form lines, whitespace is preserved within a line; un-escaped
+trailing spaces are stripped from input (unless in a literal context).
+Blank free-form lines, which may include whitespace, are only permitted
+within literal contexts.
.Pp
In macro lines, whitespace delimits arguments and is discarded. If
arguments are quoted, whitespace within the quotes is retained.
-.
-.Pp
-Blank lines are only permitted within literal contexts, as are lines
-containing only whitespace. Tab characters are only acceptable when
-delimiting
-.Sq \&Bl \-column
-or when in a literal context.
-.
-.
.Ss Quotation
Macro arguments may be quoted with a double-quote to group
space-delimited terms or to retain blocks of whitespace. A quoted
argument begins with a double-quote preceded by whitespace. The next
double-quote not pair-wise adjacent to another double-quote terminates
the literal, regardless of surrounding whitespace.
-.
.Pp
This produces tokens
.Sq a" ,
@@ -245,10 +208,8 @@ considered literal text. Thus, the following produces
.Bd -literal -offset indent
\&.Em "Em a"
.Ed
-.
.Pp
In free-form mode, quotes are regarded as opaque text.
-.
.Ss Dates
There are several macros in
.Nm
@@ -275,14 +236,12 @@ Some examples of valid dates follow:
.D1 "May, 2009" Pq reduced form
.D1 "2009" Pq reduced form
.D1 "May 20, 2009" Pq canonical form
-.
.Ss Scaling Widths
Many macros support scaled widths for their arguments, such as
stipulating a two-inch list indentation with the following:
.Bd -literal -offset indent
\&.Bl -tag -width 2i
.Ed
-.
.Pp
The syntax for scaled widths is
.Sq Li [+-]?[0-9]*.[0-9]*[:unit:] ,
@@ -328,8 +287,6 @@ or
.Sq v
is necessarily non-portable across output media. See
.Sx COMPATIBILITY .
-.
-.
.Sh MANUAL STRUCTURE
A well-formed
.Nm
@@ -424,7 +381,6 @@ See
.Sx \&Nm
and
.Sx \&Nd .
-.
.It Em LIBRARY
The name of the library containing the documented material, which is
assumed to be a function in a section 2 or 3 manual. The syntax for
@@ -435,7 +391,6 @@ this is as follows:
.Pp
See
.Sx \&Lb .
-.
.It Em SYNOPSIS
Documents the utility invocation syntax, function call syntax, or device
configuration.
@@ -479,7 +434,6 @@ See
.Sx \&Ft ,
and
.Sx \&Vt .
-.
.It Em DESCRIPTION
This expands upon the brief, one-line description in
.Em NAME .
@@ -494,12 +448,10 @@ Print verbose information.
.Ed
.Pp
Manuals not documenting a command won't include the above fragment.
-.
.It Em IMPLEMENTATION NOTES
Implementation-specific notes should be kept here. This is useful when
implementing standard functions that may have side effects or notable
algorithmic implications.
-.
.It Em EXIT STATUS
Command exit status for section 1, 6, and 8 manuals. This section is
the dual of
@@ -511,7 +463,6 @@ a practise that is now discouraged.
.Pp
See
.Sx \&Ex .
-.
.It Em RETURN VALUES
This section is the dual of
.Em EXIT STATUS ,
@@ -520,26 +471,22 @@ in sections 2, 3, and 9.
.Pp
See
.Sx \&Rv .
-.
.It Em ENVIRONMENT
Documents any usages of environment variables, e.g.,
.Xr environ 7 .
.Pp
See
.Sx \&Ev .
-.
.It Em FILES
Documents files used. It's helpful to document both the file and a
short description of how the file is used (created, modified, etc.).
.Pp
See
.Sx \&Pa .
-.
.It Em EXAMPLES
Example usages. This often contains snippets of well-formed,
well-tested invocations. Make doubly sure that your examples work
properly!
-.
.It Em DIAGNOSTICS
Documents error conditions. This is most useful in section 4 manuals.
Historically, this section was used in place of
@@ -550,13 +497,11 @@ discouraged.
See
.Sx \&Bl
.Fl diag .
-.
.It Em ERRORS
Documents error handling in sections 2, 3, and 9.
.Pp
See
.Sx \&Er .
-.
.It Em SEE ALSO
References other manuals with related topics. This section should exist
for most manuals. Cross-references should conventionally be ordered
@@ -564,7 +509,6 @@ first by section, then alphabetically.
.Pp
See
.Sx \&Xr .
-.
.It Em STANDARDS
References any standards implemented or used. If not adhering to any
standards, the
@@ -573,32 +517,24 @@ section should be used instead.
.Pp
See
.Sx \&St .
-.
.It Em HISTORY
The history of any manual without a
.Em STANDARDS
section should be described in this section.
-.
.It Em AUTHORS
Credits to authors, if applicable, should appear in this section.
Authors should generally be noted by both name and an e-mail address.
.Pp
See
.Sx \&An .
-.
.It Em CAVEATS
Explanations of common misuses and misunderstandings should be explained
in this section.
-.
.It Em BUGS
Extant bugs should be described in this section.
-.
.It Em SECURITY CONSIDERATIONS
Documents any security precautions that operators should consider.
-.
.El
-.
-.
.Sh MACRO SYNTAX
Macros are one to three three characters in length and begin with a
control character ,
@@ -610,7 +546,6 @@ following are equivalent:
\&.Pp
\&.\ \ \ \&Pp
.Ed
-.
.Pp
The syntax of a macro depends on its classification. In this section,
.Sq \-arg
@@ -621,7 +556,6 @@ parameters;
opens the scope of a macro; and if specified,
.Sq \&Yc
closes it out.
-.
.Pp
The
.Em Callable
@@ -631,20 +565,16 @@ initial line macro is interpreted as opaque text, such that
.Sq \&.Fl \&Sh
produces
.Sq Fl \&Sh .
-.
.Pp
The
.Em Parsable
column indicates whether the macro may be followed by further
(ostensibly callable) macros. If a macro is not parsable, subsequent
macro invocations on the line will be interpreted as opaque text.
-.
.Pp
The
.Em Scope
column, if applicable, describes closure rules.
-.
-.
.Ss Block full-explicit
Multi-line scope closed by an explicit closing macro. All macros
contains bodies; only
@@ -655,7 +585,6 @@ contains a head.
\(lBbody...\(rB
\&.Yc
.Ed
-.
.Pp
.Bl -column -compact -offset indent "MacroX" "CallableX" "ParsableX" "closed by XXX"
.It Em Macro Ta Em Callable Ta Em Parsable Ta Em Scope
@@ -668,8 +597,6 @@ contains a head.
.It Sx \&Ek Ta \&No Ta \&No Ta opened by Sx \&Bk
.It Sx \&El Ta \&No Ta \&No Ta opened by Sx \&Bl
.El
-.
-.
.Ss Block full-implicit
Multi-line scope closed by end-of-file or implicitly by another macro.
All macros have bodies; some
@@ -689,7 +616,6 @@ has multiple heads.
\&.Yo \(lB\-arg \(lBparm...\(rB\(rB \(lBhead... \(lBTa head...\(rB\(rB
\(lBbody...\(rB
.Ed
-.
.Pp
.Bl -column -compact -offset indent "MacroX" "CallableX" "ParsableX" "closed by XXXXXXXXXXX"
.It Em Macro Ta Em Callable Ta Em Parsable Ta Em Scope
@@ -698,8 +624,6 @@ has multiple heads.
.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
.El
-.
-.
.Ss Block partial-explicit
Like block full-explicit, but also with single-line scope. Each
has at least a body and, in limited circumstances, a head
@@ -717,7 +641,6 @@ and/or tail
\&.Yo \(lB\-arg \(lBparm...\(rB\(rB \(lBhead...\(rB \
\(lBbody...\(rB \&Yc \(lBtail...\(rB
.Ed
-.
.Pp
.Bl -column "MacroX" "CallableX" "ParsableX" "closed by XXXX" -compact -offset indent
.It Em Macro Ta Em Callable Ta Em Parsable Ta Em Scope
@@ -746,8 +669,6 @@ and/or tail
.It Sx \&Xc Ta Yes Ta Yes Ta opened by Sx \&Xo
.It Sx \&Xo Ta Yes Ta Yes Ta closed by Sx \&Xc
.El
-.
-.
.Ss Block partial-implicit
Like block full-implicit, but with single-line scope closed by
.Sx Reserved Characters
@@ -755,7 +676,6 @@ or end of line.
.Bd -literal -offset indent
\&.Yo \(lB\-arg \(lBval...\(rB\(rB \(lBbody...\(rB \(lBres...\(rB
.Ed
-.
.Pp
.Bl -column "MacroX" "CallableX" "ParsableX" -compact -offset indent
.It Em Macro Ta Em Callable Ta Em Parsable
@@ -780,8 +700,6 @@ macro is a
only when invoked as the first macro
in a SYNOPSIS section line, else it is
.Sx In-line .
-.
-.
.Ss In-line
Closed by
.Sx Reserved Characters ,
@@ -797,7 +715,6 @@ then the macro accepts an arbitrary number of arguments.
\&.Yo \(lB\-arg \(lBval...\(rB\(rB arg0 arg1 argN
.Ed
-.
.Pp
.Bl -column "MacroX" "CallableX" "ParsableX" "Arguments" -compact -offset indent
.It Em Macro Ta Em Callable Ta Em Parsable Ta Em Arguments
@@ -876,13 +793,10 @@ then the macro accepts an arbitrary number of arguments.
.It Sx \&br Ta \&No Ta \&No Ta 0
.It Sx \&sp Ta \&No Ta \&No Ta 1
.El
-.
-.
.Sh REFERENCE
This section is a canonical reference of all macros, arranged
alphabetically. For the scoping of individual macros, see
.Sx MACRO SYNTAX .
-.
.Ss \&%A
Author name of an
.Sx \&Rs
@@ -890,13 +804,11 @@ block. Multiple authors should each be accorded their own
.Sx \%%A
line. Author names should be ordered with full or abbreviated
forename(s) first, then full surname.
-.
.Ss \&%B
Book title of an
.Sx \&Rs
block. This macro may also be used in a non-bibliographic context when
referring to book titles.
-.
.Ss \&%C
Publication city or location of an
.Sx \&Rs
@@ -905,70 +817,57 @@ block.
.Em Remarks :
this macro is not implemented in
.Xr groff 1 .
-.
.Ss \&%D
Publication date of an
.Sx \&Rs
block. This should follow the reduced or canonical form syntax
described in
.Sx Dates .
-.
.Ss \&%I
Publisher or issuer name of an
.Sx \&Rs
block.
-.
.Ss \&%J
Journal name of an
.Sx \&Rs
block.
-.
.Ss \&%N
Issue number (usually for journals) of an
.Sx \&Rs
block.
-.
.Ss \&%O
Optional information of an
.Sx \&Rs
block.
-.
.Ss \&%P
Book or journal page number of an
.Sx \&Rs
block.
-.
.Ss \&%Q
Institutional author (school, government, etc.) of an
.Sx \&Rs
block. Multiple institutional authors should each be accorded their own
.Sx \&%Q
line.
-.
.Ss \&%R
Technical report name of an
.Sx \&Rs
block.
-.
.Ss \&%T
Article title of an
.Sx \&Rs
block. This macro may also be used in a non-bibliographical context
when referring to article titles.
-.
.Ss \&%U
URI of reference document.
-.
.Ss \&%V
Volume number of an
.Sx \&Rs
block.
-.
.Ss \&Ac
Closes an
.Sx \&Ao
block. Does not have any tail arguments.
-.
.Ss \&Ad
Address construct: usually in the context of an computational address in
memory, not a physical (post) address.
@@ -976,7 +875,6 @@ memory, not a physical (post) address.
Examples:
.D1 \&.Ad [0,$]
.D1 \&.Ad 0x00000000
-.
.Ss \&An
Author name. This macro may alternatively accepts the following
arguments, although these may not be specified along with a parameter:
@@ -1008,7 +906,6 @@ are re-set when entering the AUTHORS section, so if one specifies
.Sx \&An Fl nosplit
in the general document body, it must be re-specified in the AUTHORS
section.
-.
.Ss \&Ao
Begins a block enclosed by angled brackets. Does not have any head
arguments.
@@ -1018,7 +915,6 @@ Examples:
.Pp
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 form of
@@ -1026,7 +922,6 @@ a function:
.Bd -literal -offset indent
\&.Fn execve Ap d
.Ed
-.
.Ss \&Aq
Encloses its arguments in angled brackets.
.Pp
@@ -1045,7 +940,6 @@ statements, which should use
.Pp
See also
.Sx \&Ao .
-.
.Ss \&Ar
Command arguments. If an argument is not provided, the string
.Dq file ...
@@ -1055,7 +949,6 @@ Examples:
.D1 \&.Fl o \&Ns \&Ar file1
.D1 \&.Ar
.D1 \&.Ar arg1 , arg2 .
-.
.Ss \&At
Formats an AT&T version. Accepts at most one parameter:
.Bl -tag -width 12n -offset indent
@@ -1082,12 +975,10 @@ See also
.Sx \&Ox ,
and
.Sx \&Ux .
-.
.Ss \&Bc
Closes a
.Sx \&Bo
block. Does not have any tail arguments.
-.
.Ss \&Bd
Begins a display block. A display is collection of macros or text which
may be collectively offset or justified in a manner different from that
@@ -1166,7 +1057,6 @@ See also
.Sx \&D1
and
.Sx \&Dl .
-.
.Ss \&Bf
.Ss \&Bk
.Ss \&Bl
@@ -1236,7 +1126,6 @@ Examples:
.Pp
See also
.Sx \&Bq .
-.
.Ss \&Bq
Encloses its arguments in square brackets.
.Pp
@@ -1253,12 +1142,10 @@ and
.Pp
See also
.Sx \&Bo .
-.
.Ss \&Brc
Closes a
.Sx \&Bro
block. Does not have any tail arguments.
-.
.Ss \&Bro
Begins a block enclosed by curly braces. Does not have any head
arguments.
@@ -1271,7 +1158,6 @@ Examples:
.Pp
See also
.Sx \&Brq .
-.
.Ss \&Brq
Encloses its arguments in curly braces.
.Pp
@@ -1280,7 +1166,6 @@ Examples:
.Pp
See also
.Sx \&Bro .
-.
.Ss \&Bsx
Format the BSD/OS version provided as an argument, or a default value if
no argument is provided.
@@ -1298,11 +1183,9 @@ See also
.Sx \&Ox ,
and
.Sx \&Ux .
-.
.Ss \&Bt
Prints
.Dq is currently in beta test.
-.
.Ss \&Bx
Format the BSD version provided as an argument, or a default value if no
argument is provided.
@@ -1320,10 +1203,8 @@ See also
.Sx \&Ox ,
and
.Sx \&Ux .
-.
.Ss \&Cd
-Configuration declaration (suggested for use only in section four
-manuals). This denotes strings accepted by
+Configuration declaration. This denotes strings accepted by
.Xr config 8 .
.Pp
Examples:
@@ -1334,7 +1215,6 @@ this macro is commonly abused by using quoted literals to retain
white-space and align consecutive
.Sx \&Cd
declarations. This practise is discouraged.
-.
.Ss \&Cm
Command modifiers. Useful when specifying configuration options or
keys.
@@ -1345,7 +1225,6 @@ Examples:
.Pp
See also
.Sx \&Fl .
-.
.Ss \&D1
One-line indented display. This is formatted by the default rules and
is useful for simple indented statements. It is followed by a newline.
@@ -1357,13 +1236,11 @@ See also
.Sx \&Bd
and
.Sx \&Dl .
-.
.Ss \&Db
.Ss \&Dc
Closes a
.Sx \&Do
block. Does not have any tail arguments.
-.
.Ss \&Dd
Document date. This is the mandatory first macro of any
.Nm
@@ -1390,7 +1267,6 @@ See also
.Sx \&Dt
and
.Sx \&Os .
-.
.Ss \&Dl
One-line intended display. This is formatted as literal text and is
useful for commands and invocations. It is followed by a newline.
@@ -1402,7 +1278,6 @@ See also
.Sx \&Bd
and
.Sx \&D1 .
-.
.Ss \&Do
Begins a block enclosed by double quotes. Does not have any head
arguments.
@@ -1412,7 +1287,6 @@ Examples:
.Pp
See also
.Sx \&Dq .
-.
.Ss \&Dq
Encloses its arguments in double quotes.
.Pp
@@ -1424,7 +1298,6 @@ Examples:
.Pp
See also
.Sx \&Do .
-.
.Ss \&Dt
Document title. This is the mandatory second macro of any
.Nm
@@ -1548,7 +1421,6 @@ See also
.Sx \&Dd
and
.Sx \&Os .
-.
.Ss \&Dv
Defined variables such as preprocessor constants.
.Pp
@@ -1558,7 +1430,6 @@ Examples:
.Pp
See also
.Sx \&Er .
-.
.Ss \&Dx
Format the DragonFly BSD version provided as an argument, or a default
value if no argument is provided.
@@ -1576,13 +1447,11 @@ See also
.Sx \&Ox ,
and
.Sx \&Ux .
-.
.Ss \&Ec
.Ss \&Ed
.Ss \&Ef
.Ss \&Ek
.Ss \&El
-.
.Ss \&Em
Denotes text that should be emphasised. Note that this is a
presentation term and should not be used for stylistically decorating
@@ -1591,7 +1460,6 @@ technical terms.
Examples:
.D1 \&.Em Warnings!
.D1 \&.Em Remarks :
-.
.Ss \&En
.Ss \&Eo
.Ss \&Er
@@ -1603,9 +1471,7 @@ Examples:
.Pp
See also
.Sx \&Dv .
-.
.Ss \&Es
-.
.Ss \&Ev
Environmental variables such as those specified in
.Xr environ 7 .
@@ -1613,7 +1479,6 @@ Environmental variables such as those specified in
Examples:
.D1 \&.Ev DISPLAY
.D1 \&.Ev PATH
-.
.Ss \&Ex
Inserts text regarding a utility's exit values. This macro must have
first the
@@ -1644,7 +1509,6 @@ Examples:
.Pp
See also
.Sx \&Cm .
-.
.Ss \&Fn
.Ss \&Fo
.Ss \&Fr
@@ -1666,7 +1530,6 @@ See also
.Sx \&Ox ,
and
.Sx \&Ux .
-.
.Ss \&Hf
.Ss \&Ic
.Ss \&In
@@ -1684,7 +1547,6 @@ Examples:
.Pp
See also
.Sx \&Mt .
-.
.Ss \&Lp
.Ss \&Ms
.Ss \&Mt
@@ -1709,7 +1571,6 @@ See also
.Sx \&Ox ,
and
.Sx \&Ux .
-.
.Ss \&Oc
.Ss \&Oo
.Ss \&Op
@@ -1736,13 +1597,11 @@ See also
.Sx \&Dd
and
.Sx \&Dt .
-.
.Ss \&Ot
Unknown usage.
.Pp
.Em Remarks :
this macro has been deprecated.
-.
.Ss \&Ox
Format the OpenBSD version provided as an argument, or a default value
if no argument is provided.
@@ -1760,7 +1619,6 @@ See also
.Sx \&Nx ,
and
.Sx \&Ux .
-.
.Ss \&Pa
.Ss \&Pc
.Ss \&Pf
@@ -1771,12 +1629,10 @@ and
.Ss \&Ql
.Ss \&Qo
.Ss \&Qq
-.
.Ss \&Re
Closes a
.Sx \&Rs
block. Does not have any tail arguments.
-.
.Ss \&Rs
Begins a bibliographic
.Pq Dq reference
@@ -1815,7 +1671,6 @@ If an
block is used within a SEE ALSO section, a vertical space is asserted
before the rendered output, else the block continues on the current
line.
-.
.Ss \&Rv
.Ss \&Sc
.Ss \&Sh
@@ -1843,7 +1698,6 @@ See also
.Sx \&Nx ,
and
.Sx \&Ox .
-.
.Ss \&Va
.Ss \&Vt
A variable type. This is also used for indicating global variables in the
@@ -1867,16 +1721,13 @@ See also
.Sx \&Ft
and
.Sx \&Va .
-.
.Ss \&Xc
Close a scope opened by
.Sx \&Xo .
-.
.Ss \&Xo
Open an extension scope. This macro originally existed to extend the
9-argument limit of troff; since this limit has been lifted, the macro
has been deprecated.
-.
.Ss \&Xr
Link to another manual
.Pq Qq cross-reference .
@@ -1900,22 +1751,21 @@ Examples:
.D1 \&.Xr mandoc 1
.D1 \&.Xr mandoc 1 ;
.D1 \&.Xr mandoc 1 \&Ns s behaviour
-.
.Ss \&br
.Ss \&sp
-.
-.
.Sh COMPATIBILITY
-This section documents compatibility with other roff implementations, at
-this time limited to
-.Xr groff 1 .
+This section documents compatibility between mandoc and other other
+troff implementations, at this time limited to GNU troff
+.Pq Qq groff .
The term
.Qq historic groff
-refers to those versions before the
+refers to groff versions before the
.Pa doc.tmac
file re-write
.Pq somewhere between 1.15 and 1.19 .
-.
+.Pp
+Heirloom troff, the other significant troff implementation accepting
+\-mdoc, is similar to historic groff.
.Pp
.Bl -dash -compact
.It
@@ -1923,36 +1773,28 @@ The comment syntax
.Sq \e."
is no longer accepted.
.It
-In
-.Xr groff 1 ,
-the
+In groff, the
.Sx \&Pa
macro does not format its arguments when used in the FILES section under
-certain list types. This irregular behaviour has been discontinued.
+certain list types. mandoc does.
.It
-Historic
-.Xr groff 1
-does not print a dash for empty
+Historic groff does not print a dash for empty
.Sx \&Fl
-arguments. This behaviour has been discontinued.
+arguments. mandoc and newer groff implementations do.
.It
-.Xr groff 1
-behaves strangely (even between versions) when specifying
+groff behaves irregularly when specifying
.Sq \ef
-escapes within line-macro scopes. These aberrations have been
-normalised.
+.Sx Text Decoration
+within line-macro scopes. mandoc follows a consistent system.
.It
-Negative scaling units are now truncated to zero instead of creating
-interesting conditions, such as with
-.Sx \&sp
-.Fl 1i .
-Furthermore, the
+In mandoc, negative scaling units are truncated to zero; groff would
+move to prior lines. Furthermore, the
.Sq f
scaling unit, while accepted, is rendered as the default unit.
.It
In quoted literals, groff allowed pair-wise double-quotes to produce a
standalone double-quote in formatted output. This idiosyncratic
-behaviour is no longer applicable.
+behaviour is not applicable in mandoc.
.It
Display types
.Sx \&Bd
@@ -1960,10 +1802,11 @@ Display types
and
.Fl right
are aliases for
-.Fl left .
-The
+.Fl left
+in manodc. Furthermore, the
.Fl file Ar file
-argument is ignored. Since text is not right-justified,
+argument is ignored. Lastly, since text is not right-justified in
+mandoc (or even groff),
.Fl ragged
and
.Fl filled
@@ -1972,22 +1815,16 @@ are aliases, as are
and
.Fl unfilled .
.It
-Blocks of whitespace are stripped from both macro and free-form text
-lines (except when in literal mode), while groff would retain whitespace
-in free-form text lines.
-.It
Historic groff has many un-callable macros. Most of these (excluding
-some block-level macros) are now callable, conforming to the
-non-historic groff version.
+some block-level macros) are now callable.
.It
The vertical bar
.Sq \(ba
made historic groff
.Qq go orbital
-but is a proper delimiter in this implementation.
+but has been a proper delimiter since then.
.It
-.Sx \&It
-.Fl nested
+.Sx \&It Fl nested
is assumed for all lists (it wasn't in historic groff): any list may be
nested and
.Fl enum
@@ -1996,24 +1833,29 @@ lists will restart the sequence only for the sub-list.
Some manuals use
.Sx \&Li
incorrectly by following it with a reserved character and expecting the
-delimiter to render. This is not supported.
+delimiter to render. This is not supported in mandoc.
.It
In groff, the
.Sx \&Fo
-macro only produces the first parameter. This is no longer the case.
+macro only produces the first parameter. This is not the case in
+mandoc.
+.It
+In groff, the
+.Sx \&Cd ,
+.Sx \&Er ,
+and
+.Sx \&Ex
+macros were stipulated only to occur in certain manual sections. mandoc
+does not have these restrictions.
.El
-.
-.
.Sh SEE ALSO
.Xr mandoc 1 ,
.Xr mandoc_char 7
-.
-.
.Sh AUTHORS
The
.Nm
reference was written by
-.An Kristaps Dzonsons Aq kristaps@kth.se .
+.An Kristaps Dzonsons Aq kristaps@bsd.lv .
.\"
.\" XXX: this really isn't the place for these caveats.
.\" .
diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c
index 9f913fd85bc..3005fe85738 100644
--- a/usr.bin/mandoc/mdoc.c
+++ b/usr.bin/mandoc/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.45 2010/05/08 01:57:33 schwarze Exp $ */
+/* $Id: mdoc.c,v 1.46 2010/05/14 01:54:37 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -150,8 +150,7 @@ static int node_append(struct mdoc *,
static int mdoc_ptext(struct mdoc *, int, char *);
static int mdoc_pmacro(struct mdoc *, int, char *);
static int macrowarn(struct mdoc *, int, const char *);
-static int pstring(struct mdoc *, int, int,
- const char *, size_t);
+
const struct mdoc_node *
mdoc_node(const struct mdoc *m)
@@ -345,15 +344,16 @@ int
mdoc_macro(struct mdoc *m, enum mdoct tok,
int ln, int pp, int *pos, char *buf)
{
-
assert(tok < MDOC_MAX);
- /*
- * If we're in the prologue, deny "body" macros. Similarly, if
- * we're in the body, deny prologue calls.
- */
+
+ /* If we're in the body, deny prologue calls. */
+
if (MDOC_PROLOGUE & mdoc_macros[tok].flags &&
MDOC_PBODY & m->flags)
return(mdoc_perr(m, ln, pp, EPROLBODY));
+
+ /* If we're in the prologue, deny "body" macros. */
+
if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) &&
! (MDOC_PBODY & m->flags)) {
if ( ! mdoc_pwarn(m, ln, pp, EBODYPROL))
@@ -530,13 +530,15 @@ mdoc_elem_alloc(struct mdoc *m, int line, int pos,
}
-static int
-pstring(struct mdoc *m, int line, int pos, const char *p, size_t len)
+int
+mdoc_word_alloc(struct mdoc *m, int line, int pos, const char *p)
{
struct mdoc_node *n;
- size_t sv;
+ size_t sv, len;
+
+ len = strlen(p);
- n = node_alloc(m, line, pos, -1, MDOC_TEXT);
+ n = node_alloc(m, line, pos, MDOC_MAX, MDOC_TEXT);
n->string = mandoc_malloc(len + 1);
sv = strlcpy(n->string, p, len + 1);
@@ -545,19 +547,12 @@ pstring(struct mdoc *m, int line, int pos, const char *p, size_t len)
if ( ! node_append(m, n))
return(0);
+
m->next = MDOC_NEXT_SIBLING;
return(1);
}
-int
-mdoc_word_alloc(struct mdoc *m, int line, int pos, const char *p)
-{
-
- return(pstring(m, line, pos, p, strlen(p)));
-}
-
-
void
mdoc_node_free(struct mdoc_node *p)
{
@@ -628,86 +623,68 @@ mdoc_node_delete(struct mdoc *m, struct mdoc_node *p)
static int
mdoc_ptext(struct mdoc *m, int line, char *buf)
{
- int i, j;
- char sv;
+ int i;
/* Ignore bogus comments. */
if ('\\' == buf[0] && '.' == buf[1] && '\"' == buf[2])
return(mdoc_pwarn(m, line, 0, EBADCOMMENT));
+ /* No text before an initial macro. */
+
if (SEC_NONE == m->lastnamed)
return(mdoc_perr(m, line, 0, ETEXTPROL));
-
- /*
- * If in literal mode, then pass the buffer directly to the
- * back-end, as it should be preserved as a single term.
- */
+ /* Literal just gets pulled in as-is. */
+
if (MDOC_LITERAL & m->flags)
return(mdoc_word_alloc(m, line, 0, buf));
- /* Disallow blank/white-space lines in non-literal mode. */
+ /* Check for a blank line, which may also consist of spaces. */
for (i = 0; ' ' == buf[i]; i++)
- /* Skip leading whitespace. */ ;
+ /* Skip to first non-space. */ ;
if ('\0' == buf[i]) {
if ( ! mdoc_pwarn(m, line, 0, ENOBLANK))
return(0);
+
/*
- * Assume that a `Pp' should be inserted in the case of
- * a blank line. Technically, blank lines aren't
- * allowed, but enough manuals assume this behaviour
- * that we want to work around it.
+ * Insert a `Pp' in the case of a blank line. Technically,
+ * blank lines aren't allowed, but enough manuals assume this
+ * behaviour that we want to work around it.
*/
if ( ! mdoc_elem_alloc(m, line, 0, MDOC_Pp, NULL))
return(0);
+
m->next = MDOC_NEXT_SIBLING;
return(1);
}
- /*
- * Break apart a free-form line into tokens. Spaces are
- * stripped out of the input.
+ /*
+ * Warn if the last un-escaped character is whitespace. Then
+ * strip away the remaining spaces (tabs stay!).
*/
- for (j = i; buf[i]; i++) {
- if (' ' != buf[i])
- continue;
-
- /* Escaped whitespace. */
- if (i && ' ' == buf[i] && '\\' == buf[i - 1])
- continue;
-
- sv = buf[i];
- buf[i++] = '\0';
-
- if ( ! pstring(m, line, j, &buf[j], (size_t)(i - j)))
- return(0);
-
- /* Trailing whitespace? Check at overwritten byte. */
+ i = (int)strlen(buf);
+ assert(i);
- if (' ' == sv && '\0' == buf[i])
+ if (' ' == buf[i - 1] || '\t' == buf[i - 1]) {
+ if (i > 1 && '\\' != buf[i - 2])
if ( ! mdoc_pwarn(m, line, i - 1, ETAILWS))
return(0);
- for ( ; ' ' == buf[i]; i++)
- /* Skip trailing whitespace. */ ;
-
- j = i;
+ for (--i; i && ' ' == buf[i]; i--)
+ /* Spin back to non-space. */ ;
- /* Trailing whitespace? */
-
- if (' ' == buf[i - 1] && '\0' == buf[i])
- if ( ! mdoc_pwarn(m, line, i - 1, ETAILWS))
- return(0);
+ /* Jump ahead of escaped whitespace. */
+ i += '\\' == buf[i] ? 2 : 1;
- if ('\0' == buf[i])
- break;
+ buf[i] = '\0';
}
- if (j != i && ! pstring(m, line, j, &buf[j], (size_t)(i - j)))
+ /* Allocate the whole word. */
+ if ( ! mdoc_word_alloc(m, line, 0, buf))
return(0);
/*
@@ -725,13 +702,11 @@ mdoc_ptext(struct mdoc *m, int line, char *buf)
}
-
static int
macrowarn(struct mdoc *m, int ln, const char *buf)
{
if ( ! (MDOC_IGN_MACRO & m->pflags))
- return(mdoc_verr(m, ln, 0,
- "unknown macro: %s%s",
+ return(mdoc_verr(m, ln, 0, "unknown macro: %s%s",
buf, strlen(buf) > 3 ? "..." : ""));
return(mdoc_vwarn(m, ln, 0, "unknown macro: %s%s",
buf, strlen(buf) > 3 ? "..." : ""));
@@ -745,8 +720,9 @@ macrowarn(struct mdoc *m, int ln, const char *buf)
int
mdoc_pmacro(struct mdoc *m, int ln, char *buf)
{
- int i, j, c;
- char mac[5];
+ enum mdoct tok;
+ int i, j;
+ char mac[5];
struct mdoc_node *n;
char *t;
@@ -790,7 +766,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf)
return(1);
}
- if (MDOC_MAX == (c = mdoc_hash_find(mac))) {
+ if (MDOC_MAX == (tok = mdoc_hash_find(mac))) {
if ( ! macrowarn(m, ln, mac))
goto err;
return(1);
@@ -801,7 +777,10 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf)
while (buf[i] && ' ' == buf[i])
i++;
- /* Trailing whitespace? */
+ /*
+ * Trailing whitespace. Note that tabs are allowed to be passed
+ * into the parser as "text", so we only warn about spaces here.
+ */
if ('\0' == buf[i] && ' ' == buf[i - 1])
if ( ! mdoc_pwarn(m, ln, i - 1, ETAILWS))
@@ -811,7 +790,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf)
* Begin recursive parse sequence. Since we're at the start of
* the line, we don't need to do callable/parseable checks.
*/
- if ( ! mdoc_macro(m, c, ln, 1, &i, buf))
+ if ( ! mdoc_macro(m, tok, ln, 1, &i, buf))
goto err;
/*
diff --git a/usr.bin/mandoc/mdoc_action.c b/usr.bin/mandoc/mdoc_action.c
index 9c00b2ac66d..8c0b356d28a 100644
--- a/usr.bin/mandoc/mdoc_action.c
+++ b/usr.bin/mandoc/mdoc_action.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_action.c,v 1.30 2010/04/07 23:15:05 schwarze Exp $ */
+/* $Id: mdoc_action.c,v 1.31 2010/05/14 01:54:37 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -40,7 +40,7 @@ struct actions {
static int concat(struct mdoc *, char *,
const struct mdoc_node *, size_t);
-static inline int order_rs(int);
+static inline int order_rs(enum mdoct);
static int post_ar(POST_ARGS);
static int post_at(POST_ARGS);
@@ -193,7 +193,7 @@ static const struct actions mdoc_actions[MDOC_MAX] = {
#define RSORD_MAX 14
-static const int rsord[RSORD_MAX] = {
+static const enum mdoct rsord[RSORD_MAX] = {
MDOC__A,
MDOC__T,
MDOC__B,
@@ -942,11 +942,11 @@ post_display(POST_ARGS)
static inline int
-order_rs(int t)
+order_rs(enum mdoct t)
{
int i;
- for (i = 0; i < RSORD_MAX; i++)
+ for (i = 0; i < (int)RSORD_MAX; i++)
if (rsord[i] == t)
return(i);
diff --git a/usr.bin/mandoc/mdoc_argv.c b/usr.bin/mandoc/mdoc_argv.c
index f181dcbe897..19877837017 100644
--- a/usr.bin/mandoc/mdoc_argv.c
+++ b/usr.bin/mandoc/mdoc_argv.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_argv.c,v 1.23 2010/04/03 16:30:42 schwarze Exp $ */
+/* $Id: mdoc_argv.c,v 1.24 2010/05/14 01:54:37 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -41,7 +41,7 @@
#define MULTI_STEP 5
static int argv_a2arg(enum mdoct, const char *);
-static int args(struct mdoc *, int, int *,
+static enum margserr args(struct mdoc *, int, int *,
char *, int, char **);
static int argv(struct mdoc *, int,
struct mdoc_argv *, int *, char *);
@@ -214,7 +214,7 @@ static int mdoc_argflags[MDOC_MAX] = {
* [value0...], which may either have a single mandatory value, at least
* one mandatory value, an optional single value, or no value.
*/
-int
+enum margverr
mdoc_argv(struct mdoc *m, int line, enum mdoct tok,
struct mdoc_arg **v, int *pos, char *buf)
{
@@ -297,7 +297,7 @@ mdoc_argv_free(struct mdoc_arg *p)
}
assert(p->argc);
- for (i = p->argc - 1; i >= 0; i--)
+ for (i = (int)p->argc - 1; i >= 0; i--)
mdoc_argn_free(p, i);
free(p->argv);
@@ -312,7 +312,7 @@ mdoc_argn_free(struct mdoc_arg *p, int iarg)
int j;
if (arg->sz && arg->value) {
- for (j = arg->sz - 1; j >= 0; j--)
+ for (j = (int)arg->sz - 1; j >= 0; j--)
free(arg->value[j]);
free(arg->value);
}
@@ -322,7 +322,7 @@ mdoc_argn_free(struct mdoc_arg *p, int iarg)
}
-int
+enum margserr
mdoc_zargs(struct mdoc *m, int line, int *pos,
char *buf, int flags, char **v)
{
@@ -331,7 +331,7 @@ mdoc_zargs(struct mdoc *m, int line, int *pos,
}
-int
+enum margserr
mdoc_args(struct mdoc *m, int line, int *pos,
char *buf, enum mdoct tok, char **v)
{
@@ -369,12 +369,13 @@ mdoc_args(struct mdoc *m, int line, int *pos,
}
-static int
+static enum margserr
args(struct mdoc *m, int line, int *pos,
char *buf, int fl, char **v)
{
int i;
char *p, *pp;
+ enum margserr rc;
/*
* Parse out the terms (like `val' in `.Xx -arg val' or simply
@@ -394,7 +395,7 @@ args(struct mdoc *m, int line, int *pos,
assert(*pos);
assert(' ' != buf[*pos]);
- if (0 == buf[*pos])
+ if ('\0' == buf[*pos])
return(ARGS_EOLN);
/*
@@ -450,14 +451,19 @@ args(struct mdoc *m, int line, int *pos,
break;
}
+ /* By default, assume a phrase. */
+ rc = ARGS_PHRASE;
+
/*
* Adjust new-buffer position to be beyond delimiter
* mark (e.g., Ta -> end + 2).
*/
if (p && pp) {
*pos += pp < p ? 2 : 1;
+ rc = pp < p ? ARGS_PHRASE : ARGS_PPHRASE;
p = pp < p ? pp : p;
} else if (p && ! pp) {
+ rc = ARGS_PPHRASE;
*pos += 1;
} else if (pp && ! p) {
p = pp;
@@ -485,7 +491,7 @@ args(struct mdoc *m, int line, int *pos,
for (pp = &buf[*pos]; ' ' == *pp; pp++, (*pos)++)
/* Skip ahead. */ ;
- return(ARGS_PHRASE);
+ return(rc);
}
/*
@@ -657,16 +663,16 @@ static int
argv_multi(struct mdoc *m, int line,
struct mdoc_argv *v, int *pos, char *buf)
{
- int c;
+ enum margserr ac;
char *p;
for (v->sz = 0; ; v->sz++) {
if ('-' == buf[*pos])
break;
- c = args(m, line, pos, buf, 0, &p);
- if (ARGS_ERROR == c)
+ ac = args(m, line, pos, buf, 0, &p);
+ if (ARGS_ERROR == ac)
return(0);
- else if (ARGS_EOLN == c)
+ else if (ARGS_EOLN == ac)
break;
if (0 == v->sz % MULTI_STEP)
@@ -684,16 +690,16 @@ static int
argv_opt_single(struct mdoc *m, int line,
struct mdoc_argv *v, int *pos, char *buf)
{
- int c;
+ enum margserr ac;
char *p;
if ('-' == buf[*pos])
return(1);
- c = args(m, line, pos, buf, 0, &p);
- if (ARGS_ERROR == c)
+ ac = args(m, line, pos, buf, 0, &p);
+ if (ARGS_ERROR == ac)
return(0);
- if (ARGS_EOLN == c)
+ if (ARGS_EOLN == ac)
return(1);
v->sz = 1;
@@ -711,15 +717,16 @@ static int
argv_single(struct mdoc *m, int line,
struct mdoc_argv *v, int *pos, char *buf)
{
- int c, ppos;
+ int ppos;
+ enum margserr ac;
char *p;
ppos = *pos;
- c = args(m, line, pos, buf, 0, &p);
- if (ARGS_ERROR == c)
+ ac = args(m, line, pos, buf, 0, &p);
+ if (ARGS_ERROR == ac)
return(0);
- if (ARGS_EOLN == c)
+ if (ARGS_EOLN == ac)
return(mdoc_perr(m, line, ppos, EARGVAL));
v->sz = 1;
diff --git a/usr.bin/mandoc/mdoc_hash.c b/usr.bin/mandoc/mdoc_hash.c
index 3b1535a4451..313c74182bd 100644
--- a/usr.bin/mandoc/mdoc_hash.c
+++ b/usr.bin/mandoc/mdoc_hash.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_hash.c,v 1.8 2010/04/02 12:39:47 schwarze Exp $ */
+/* $Id: mdoc_hash.c,v 1.9 2010/05/14 01:54:37 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -39,7 +39,7 @@ mdoc_hash_init(void)
memset(table, UCHAR_MAX, sizeof(table));
- for (i = 0; i < MDOC_MAX; i++) {
+ for (i = 0; i < (int)MDOC_MAX; i++) {
p = mdoc_macronames[i];
if (isalpha((u_char)p[1]))
diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c
index 2cef1cc635c..db2081c0e20 100644
--- a/usr.bin/mandoc/mdoc_macro.c
+++ b/usr.bin/mandoc/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_macro.c,v 1.35 2010/04/07 23:15:05 schwarze Exp $ */
+/* $Id: mdoc_macro.c,v 1.36 2010/05/14 01:54:37 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -29,33 +29,33 @@ enum rew {
REWIND_HALT
};
-static int ctx_synopsis(MACRO_PROT_ARGS);
-static int obsolete(MACRO_PROT_ARGS);
-static int blk_part_exp(MACRO_PROT_ARGS);
-static int in_line_eoln(MACRO_PROT_ARGS);
-static int in_line_argn(MACRO_PROT_ARGS);
-static int in_line(MACRO_PROT_ARGS);
-static int blk_full(MACRO_PROT_ARGS);
-static int blk_exp_close(MACRO_PROT_ARGS);
-static int blk_part_imp(MACRO_PROT_ARGS);
-
-static int phrase(struct mdoc *, int, int, char *);
-static enum rew rew_dohalt(enum mdoct, enum mdoc_type,
- const struct mdoc_node *);
-static enum mdoct rew_alt(enum mdoct);
-static int rew_dobreak(enum mdoct, const struct mdoc_node *);
-static int rew_elem(struct mdoc *, enum mdoct);
-static int rew_sub(enum mdoc_type, struct mdoc *,
- enum mdoct, int, int);
-static int rew_last(struct mdoc *,
- const struct mdoc_node *);
-static int append_delims(struct mdoc *, int, int *, char *);
-static int lookup(int, const char *);
-static int lookup_raw(const char *);
-static int swarn(struct mdoc *, enum mdoc_type, int, int,
- const struct mdoc_node *);
-
-/* Central table of library: who gets parsed how. */
+static int blk_full(MACRO_PROT_ARGS);
+static int blk_exp_close(MACRO_PROT_ARGS);
+static int blk_part_exp(MACRO_PROT_ARGS);
+static int blk_part_imp(MACRO_PROT_ARGS);
+static int ctx_synopsis(MACRO_PROT_ARGS);
+static int in_line_eoln(MACRO_PROT_ARGS);
+static int in_line_argn(MACRO_PROT_ARGS);
+static int in_line(MACRO_PROT_ARGS);
+static int obsolete(MACRO_PROT_ARGS);
+
+static int append_delims(struct mdoc *,
+ int, int *, char *);
+static enum mdoct lookup(enum mdoct, const char *);
+static enum mdoct lookup_raw(const char *);
+static int phrase(struct mdoc *, int, int, char *);
+static enum mdoct rew_alt(enum mdoct);
+static int rew_dobreak(enum mdoct,
+ const struct mdoc_node *);
+static enum rew rew_dohalt(enum mdoct, enum mdoc_type,
+ const struct mdoc_node *);
+static int rew_elem(struct mdoc *, enum mdoct);
+static int rew_last(struct mdoc *,
+ const struct mdoc_node *);
+static int rew_sub(enum mdoc_type, struct mdoc *,
+ enum mdoct, int, int);
+static int swarn(struct mdoc *, enum mdoc_type, int,
+ int, const struct mdoc_node *);
const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
{ in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* Ap */
@@ -263,8 +263,8 @@ mdoc_macroend(struct mdoc *m)
/*
* Look up a macro from within a subsequent context.
*/
-static int
-lookup(int from, const char *p)
+static enum mdoct
+lookup(enum mdoct from, const char *p)
{
/* FIXME: make -diag lists be un-PARSED. */
@@ -277,10 +277,10 @@ lookup(int from, const char *p)
/*
* Lookup a macro following the initial line macro.
*/
-static int
+static enum mdoct
lookup_raw(const char *p)
{
- int res;
+ enum mdoct res;
if (MDOC_MAX == (res = mdoc_hash_find(p)))
return(MDOC_MAX);
@@ -616,7 +616,8 @@ rew_sub(enum mdoc_type t, struct mdoc *m,
static int
append_delims(struct mdoc *mdoc, int line, int *pos, char *buf)
{
- int c, lastarg;
+ int lastarg;
+ enum margserr ac;
char *p;
if (0 == buf[*pos])
@@ -624,12 +625,11 @@ append_delims(struct mdoc *mdoc, int line, int *pos, char *buf)
for (;;) {
lastarg = *pos;
- c = mdoc_zargs(mdoc, line, pos, buf, ARGS_NOWARN, &p);
- assert(ARGS_PHRASE != c);
+ ac = mdoc_zargs(mdoc, line, pos, buf, ARGS_NOWARN, &p);
- if (ARGS_ERROR == c)
+ if (ARGS_ERROR == ac)
return(0);
- else if (ARGS_EOLN == c)
+ else if (ARGS_EOLN == ac)
break;
assert(mdoc_isdelim(p));
if ( ! mdoc_word_alloc(mdoc, line, lastarg, p))
@@ -646,7 +646,9 @@ append_delims(struct mdoc *mdoc, int line, int *pos, char *buf)
static int
blk_exp_close(MACRO_PROT_ARGS)
{
- int j, c, lastarg, maxargs, flushed;
+ int j, lastarg, maxargs, flushed;
+ enum margserr ac;
+ enum mdoct ntok;
char *p;
switch (tok) {
@@ -684,28 +686,31 @@ blk_exp_close(MACRO_PROT_ARGS)
flushed = 1;
}
- c = mdoc_args(m, line, pos, buf, tok, &p);
+ ac = mdoc_args(m, line, pos, buf, tok, &p);
- if (ARGS_ERROR == c)
+ if (ARGS_ERROR == ac)
return(0);
- if (ARGS_PUNCT == c)
+ if (ARGS_PUNCT == ac)
break;
- if (ARGS_EOLN == c)
+ if (ARGS_EOLN == ac)
break;
- if (MDOC_MAX != (c = lookup(tok, p))) {
- if ( ! flushed) {
- if ( ! rew_sub(MDOC_BLOCK, m, tok, line, ppos))
- return(0);
- flushed = 1;
- }
- if ( ! mdoc_macro(m, c, line, lastarg, pos, buf))
+ ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p);
+
+ if (MDOC_MAX == ntok) {
+ if ( ! mdoc_word_alloc(m, line, lastarg, p))
return(0);
- break;
- }
+ continue;
+ }
- if ( ! mdoc_word_alloc(m, line, lastarg, p))
+ if ( ! flushed) {
+ if ( ! rew_sub(MDOC_BLOCK, m, tok, line, ppos))
+ return(0);
+ flushed = 1;
+ }
+ if ( ! mdoc_macro(m, ntok, line, lastarg, pos, buf))
return(0);
+ break;
}
if ( ! flushed && ! rew_sub(MDOC_BLOCK, m, tok, line, ppos))
@@ -720,9 +725,12 @@ blk_exp_close(MACRO_PROT_ARGS)
static int
in_line(MACRO_PROT_ARGS)
{
- int la, lastpunct, c, w, cnt, d, nc;
- struct mdoc_arg *arg;
- char *p;
+ int la, lastpunct, cnt, d, nc;
+ enum margverr av;
+ enum mdoct ntok;
+ enum margserr ac;
+ struct mdoc_arg *arg;
+ char *p;
/*
* Whether we allow ignored elements (those without content,
@@ -750,15 +758,15 @@ in_line(MACRO_PROT_ARGS)
for (arg = NULL;; ) {
la = *pos;
- c = mdoc_argv(m, line, tok, &arg, pos, buf);
+ av = mdoc_argv(m, line, tok, &arg, pos, buf);
- if (ARGV_WORD == c) {
+ if (ARGV_WORD == av) {
*pos = la;
break;
}
- if (ARGV_EOLN == c)
+ if (ARGV_EOLN == av)
break;
- if (ARGV_ARG == c)
+ if (ARGV_ARG == av)
continue;
mdoc_argv_free(arg);
@@ -767,18 +775,16 @@ in_line(MACRO_PROT_ARGS)
for (cnt = 0, lastpunct = 1;; ) {
la = *pos;
- w = mdoc_args(m, line, pos, buf, tok, &p);
+ ac = mdoc_args(m, line, pos, buf, tok, &p);
- if (ARGS_ERROR == w)
+ if (ARGS_ERROR == ac)
return(0);
- if (ARGS_EOLN == w)
+ if (ARGS_EOLN == ac)
break;
- if (ARGS_PUNCT == w)
+ if (ARGS_PUNCT == ac)
break;
- /* Quoted words shouldn't be looked-up. */
-
- c = ARGS_QWORD == w ? MDOC_MAX : lookup(tok, p);
+ ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p);
/*
* In this case, we've located a submacro and must
@@ -787,7 +793,7 @@ in_line(MACRO_PROT_ARGS)
* or raise a warning.
*/
- if (MDOC_MAX != c) {
+ if (MDOC_MAX != ntok) {
if (0 == lastpunct && ! rew_elem(m, tok))
return(0);
if (nc && 0 == cnt) {
@@ -800,8 +806,7 @@ in_line(MACRO_PROT_ARGS)
if ( ! mdoc_pwarn(m, line, ppos, EIGNE))
return(0);
}
- c = mdoc_macro(m, c, line, la, pos, buf);
- if (0 == c)
+ if ( ! mdoc_macro(m, ntok, line, la, pos, buf))
return(0);
if (ppos > 1)
return(1);
@@ -814,9 +819,9 @@ in_line(MACRO_PROT_ARGS)
* the word.
*/
- d = ARGS_QWORD == w ? 0 : mdoc_isdelim(p);
+ d = ARGS_QWORD == ac ? 0 : mdoc_isdelim(p);
- if (ARGS_QWORD != w && d) {
+ if (ARGS_QWORD != ac && d) {
if (0 == lastpunct && ! rew_elem(m, tok))
return(0);
lastpunct = 1;
@@ -872,11 +877,14 @@ in_line(MACRO_PROT_ARGS)
static int
blk_full(MACRO_PROT_ARGS)
{
- int c, la;
+ int la;
struct mdoc_arg *arg;
struct mdoc_node *head; /* save of head macro */
struct mdoc_node *body; /* save of body macro */
struct mdoc_node *n;
+ enum mdoct ntok;
+ enum margserr ac;
+ enum margverr av;
char *p;
/* Close out prior implicit scope. */
@@ -899,16 +907,16 @@ blk_full(MACRO_PROT_ARGS)
for (arg = NULL;; ) {
la = *pos;
- c = mdoc_argv(m, line, tok, &arg, pos, buf);
+ av = mdoc_argv(m, line, tok, &arg, pos, buf);
- if (ARGV_WORD == c) {
+ if (ARGV_WORD == av) {
*pos = la;
break;
}
- if (ARGV_EOLN == c)
+ if (ARGV_EOLN == av)
break;
- if (ARGV_ARG == c)
+ if (ARGV_ARG == av)
continue;
mdoc_argv_free(arg);
@@ -938,11 +946,11 @@ blk_full(MACRO_PROT_ARGS)
for (;;) {
la = *pos;
- c = mdoc_args(m, line, pos, buf, tok, &p);
+ ac = mdoc_args(m, line, pos, buf, tok, &p);
- if (ARGS_ERROR == c)
+ if (ARGS_ERROR == ac)
return(0);
- if (ARGS_EOLN == c)
+ if (ARGS_EOLN == ac)
break;
/*
@@ -952,8 +960,9 @@ blk_full(MACRO_PROT_ARGS)
#if 0
/* Don't emit leading punct. for phrases. */
- if (NULL == head && ARGS_PHRASE != c &&
- ARGS_QWORD != c &&
+ if (NULL == head && ARGS_PHRASE != ac &&
+ ARGS_PPHRASE != ac &&
+ ARGS_QWORD != ac &&
1 == mdoc_isdelim(p)) {
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
@@ -963,13 +972,14 @@ blk_full(MACRO_PROT_ARGS)
/* Always re-open head for phrases. */
- if (NULL == head || ARGS_PHRASE == c) {
+ if (NULL == head || ARGS_PHRASE == ac ||
+ ARGS_PPHRASE == ac) {
if ( ! mdoc_head_alloc(m, line, ppos, tok))
return(0);
head = m->last;
}
- if (ARGS_PHRASE == c) {
+ if (ARGS_PHRASE == ac || ARGS_PPHRASE == ac) {
if ( ! phrase(m, line, la, buf))
return(0);
if ( ! rew_sub(MDOC_HEAD, m, tok, line, ppos))
@@ -977,15 +987,17 @@ blk_full(MACRO_PROT_ARGS)
continue;
}
- c = lookup(tok, p);
- if (MDOC_MAX != c) {
- if ( ! mdoc_macro(m, c, line, la, pos, buf))
+ ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p);
+
+ if (MDOC_MAX == ntok) {
+ if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
- break;
+ continue;
}
- if ( ! mdoc_word_alloc(m, line, la, p))
- return(0);
+ if ( ! mdoc_macro(m, ntok, line, la, pos, buf))
+ return(0);
+ break;
}
if (NULL == head) {
@@ -1031,7 +1043,9 @@ blk_full(MACRO_PROT_ARGS)
static int
blk_part_imp(MACRO_PROT_ARGS)
{
- int la, c;
+ int la;
+ enum mdoct ntok;
+ enum margserr ac;
char *p;
struct mdoc_node *blk; /* saved block context */
struct mdoc_node *body; /* saved body context */
@@ -1064,15 +1078,13 @@ blk_part_imp(MACRO_PROT_ARGS)
for (body = NULL; ; ) {
la = *pos;
- c = mdoc_args(m, line, pos, buf, tok, &p);
+ ac = mdoc_args(m, line, pos, buf, tok, &p);
- assert(ARGS_PHRASE != c);
-
- if (ARGS_ERROR == c)
+ if (ARGS_ERROR == ac)
return(0);
- if (ARGS_EOLN == c)
+ if (ARGS_EOLN == ac)
break;
- if (ARGS_PUNCT == c)
+ if (ARGS_PUNCT == ac)
break;
/*
@@ -1080,7 +1092,7 @@ blk_part_imp(MACRO_PROT_ARGS)
* We must investigate the fallout before enabling this.
*/
#if 0
- if (NULL == body && ARGS_QWORD != c &&
+ if (NULL == body && ARGS_QWORD != ac &&
1 == mdoc_isdelim(p)) {
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
@@ -1094,14 +1106,17 @@ blk_part_imp(MACRO_PROT_ARGS)
body = m->last;
}
- if (MDOC_MAX != (c = lookup(tok, p))) {
- if ( ! mdoc_macro(m, c, line, la, pos, buf))
+ ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p);
+
+ if (MDOC_MAX == ntok) {
+ if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
- break;
- }
+ continue;
+ }
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! mdoc_macro(m, ntok, line, la, pos, buf))
return(0);
+ break;
}
/* Clean-ups to leave in a consistent state. */
@@ -1145,10 +1160,12 @@ blk_part_imp(MACRO_PROT_ARGS)
static int
blk_part_exp(MACRO_PROT_ARGS)
{
- int la, c;
+ int la;
+ enum margserr ac;
struct mdoc_node *head; /* keep track of head */
struct mdoc_node *body; /* keep track of body */
char *p;
+ enum mdoct ntok;
/*
* The opening of an explicit macro having zero or more leading
@@ -1161,17 +1178,15 @@ blk_part_exp(MACRO_PROT_ARGS)
for (head = body = NULL; ; ) {
la = *pos;
- c = mdoc_args(m, line, pos, buf, tok, &p);
+ ac = mdoc_args(m, line, pos, buf, tok, &p);
- if (ARGS_ERROR == c)
+ if (ARGS_ERROR == ac)
return(0);
- if (ARGS_PUNCT == c)
+ if (ARGS_PUNCT == ac)
break;
- if (ARGS_EOLN == c)
+ if (ARGS_EOLN == ac)
break;
- assert(ARGS_PHRASE != c);
-
/*
* XXX Temporarily disable the handling of leading punctuation.
* We must investigate the fallout before enabling this.
@@ -1179,7 +1194,7 @@ blk_part_exp(MACRO_PROT_ARGS)
#if 0
/* Flush out leading punctuation. */
- if (NULL == head && ARGS_QWORD != c &&
+ if (NULL == head && ARGS_QWORD != ac &&
1 == mdoc_isdelim(p)) {
assert(NULL == body);
if ( ! mdoc_word_alloc(m, line, la, p))
@@ -1219,14 +1234,17 @@ blk_part_exp(MACRO_PROT_ARGS)
assert(NULL != head && NULL != body);
- if (MDOC_MAX != (c = lookup(tok, p))) {
- if ( ! mdoc_macro(m, c, line, la, pos, buf))
+ ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p);
+
+ if (MDOC_MAX == ntok) {
+ if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
- break;
+ continue;
}
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! mdoc_macro(m, ntok, line, la, pos, buf))
return(0);
+ break;
}
/* Clean-up to leave in a consistent state. */
@@ -1257,9 +1275,12 @@ blk_part_exp(MACRO_PROT_ARGS)
static int
in_line_argn(MACRO_PROT_ARGS)
{
- int la, flushed, j, c, maxargs;
- struct mdoc_arg *arg;
- char *p;
+ int la, flushed, j, maxargs;
+ enum margserr ac;
+ enum margverr av;
+ struct mdoc_arg *arg;
+ char *p;
+ enum mdoct ntok;
/*
* A line macro that has a fixed number of arguments (maxargs).
@@ -1289,16 +1310,16 @@ in_line_argn(MACRO_PROT_ARGS)
for (arg = NULL; ; ) {
la = *pos;
- c = mdoc_argv(m, line, tok, &arg, pos, buf);
+ av = mdoc_argv(m, line, tok, &arg, pos, buf);
- if (ARGV_WORD == c) {
+ if (ARGV_WORD == av) {
*pos = la;
break;
}
- if (ARGV_EOLN == c)
+ if (ARGV_EOLN == av)
break;
- if (ARGV_ARG == c)
+ if (ARGV_ARG == av)
continue;
mdoc_argv_free(arg);
@@ -1307,13 +1328,13 @@ in_line_argn(MACRO_PROT_ARGS)
for (flushed = j = 0; ; ) {
la = *pos;
- c = mdoc_args(m, line, pos, buf, tok, &p);
+ ac = mdoc_args(m, line, pos, buf, tok, &p);
- if (ARGS_ERROR == c)
+ if (ARGS_ERROR == ac)
return(0);
- if (ARGS_PUNCT == c)
+ if (ARGS_PUNCT == ac)
break;
- if (ARGS_EOLN == c)
+ if (ARGS_EOLN == ac)
break;
/*
@@ -1322,7 +1343,7 @@ in_line_argn(MACRO_PROT_ARGS)
*/
#if 0
if ( ! (MDOC_IGNDELIM & mdoc_macros[tok].flags) &&
- ARGS_QWORD != c &&
+ ARGS_QWORD != ac &&
0 == j && 1 == mdoc_isdelim(p)) {
if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
@@ -1339,18 +1360,20 @@ in_line_argn(MACRO_PROT_ARGS)
flushed = 1;
}
- if (MDOC_MAX != (c = lookup(tok, p))) {
+ ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p);
+
+ if (MDOC_MAX != ntok) {
if ( ! flushed && ! rew_elem(m, tok))
return(0);
flushed = 1;
- if ( ! mdoc_macro(m, c, line, la, pos, buf))
+ if ( ! mdoc_macro(m, ntok, line, la, pos, buf))
return(0);
j++;
break;
}
if ( ! (MDOC_IGNDELIM & mdoc_macros[tok].flags) &&
- ARGS_QWORD != c &&
+ ARGS_QWORD != ac &&
! flushed && mdoc_isdelim(p)) {
if ( ! rew_elem(m, tok))
return(0);
@@ -1392,9 +1415,12 @@ in_line_argn(MACRO_PROT_ARGS)
static int
in_line_eoln(MACRO_PROT_ARGS)
{
- int c, w, la;
- struct mdoc_arg *arg;
- char *p;
+ int la;
+ enum margserr ac;
+ enum margverr av;
+ struct mdoc_arg *arg;
+ char *p;
+ enum mdoct ntok;
assert( ! (MDOC_PARSED & mdoc_macros[tok].flags));
@@ -1402,15 +1428,15 @@ in_line_eoln(MACRO_PROT_ARGS)
for (arg = NULL; ; ) {
la = *pos;
- c = mdoc_argv(m, line, tok, &arg, pos, buf);
+ av = mdoc_argv(m, line, tok, &arg, pos, buf);
- if (ARGV_WORD == c) {
+ if (ARGV_WORD == av) {
*pos = la;
break;
}
- if (ARGV_EOLN == c)
+ if (ARGV_EOLN == av)
break;
- if (ARGV_ARG == c)
+ if (ARGV_ARG == av)
continue;
mdoc_argv_free(arg);
@@ -1426,23 +1452,24 @@ in_line_eoln(MACRO_PROT_ARGS)
for (;;) {
la = *pos;
- w = mdoc_args(m, line, pos, buf, tok, &p);
+ ac = mdoc_args(m, line, pos, buf, tok, &p);
- if (ARGS_ERROR == w)
+ if (ARGS_ERROR == ac)
return(0);
- if (ARGS_EOLN == w)
+ if (ARGS_EOLN == ac)
break;
- c = ARGS_QWORD == w ? MDOC_MAX : lookup(tok, p);
+ ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup(tok, p);
- if (MDOC_MAX != c) {
- if ( ! rew_elem(m, tok))
+ if (MDOC_MAX == ntok) {
+ if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
- return(mdoc_macro(m, c, line, la, pos, buf));
- }
+ continue;
+ }
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! rew_elem(m, tok))
return(0);
+ return(mdoc_macro(m, ntok, line, la, pos, buf));
}
/* Close out (no delimiters). */
@@ -1491,30 +1518,33 @@ obsolete(MACRO_PROT_ARGS)
static int
phrase(struct mdoc *m, int line, int ppos, char *buf)
{
- int c, w, la, pos;
- char *p;
+ int la, pos;
+ enum margserr ac;
+ enum mdoct ntok;
+ char *p;
for (pos = ppos; ; ) {
la = pos;
/* Note: no calling context! */
- w = mdoc_zargs(m, line, &pos, buf, 0, &p);
+ ac = mdoc_zargs(m, line, &pos, buf, 0, &p);
- if (ARGS_ERROR == w)
+ if (ARGS_ERROR == ac)
return(0);
- if (ARGS_EOLN == w)
+ if (ARGS_EOLN == ac)
break;
- c = ARGS_QWORD == w ? MDOC_MAX : lookup_raw(p);
+ ntok = ARGS_QWORD == ac ? MDOC_MAX : lookup_raw(p);
- if (MDOC_MAX != c) {
- if ( ! mdoc_macro(m, c, line, la, &pos, buf))
+ if (MDOC_MAX == ntok) {
+ if ( ! mdoc_word_alloc(m, line, la, p))
return(0);
- return(append_delims(m, line, &pos, buf));
- }
+ continue;
+ }
- if ( ! mdoc_word_alloc(m, line, la, p))
+ if ( ! mdoc_macro(m, ntok, line, la, &pos, buf))
return(0);
+ return(append_delims(m, line, &pos, buf));
}
return(1);
diff --git a/usr.bin/mandoc/mdoc_strings.c b/usr.bin/mandoc/mdoc_strings.c
index e65b648dfba..0110cc440ee 100644
--- a/usr.bin/mandoc/mdoc_strings.c
+++ b/usr.bin/mandoc/mdoc_strings.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_strings.c,v 1.13 2010/03/02 00:13:57 schwarze Exp $ */
+/* $Id: mdoc_strings.c,v 1.14 2010/05/14 01:54:37 schwarze Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -57,12 +57,16 @@ static const struct mdoc_secname secnames[SECNAME_MAX] = {
};
+/*
+ * FIXME: this is repeated in print_text() (html.c) and term_word()
+ * (term.c).
+ */
int
mdoc_iscdelim(char p)
{
switch (p) {
- case('|'):
+ case('|'): /* FIXME! */
/* FALLTHROUGH */
case('('):
/* FALLTHROUGH */
@@ -119,7 +123,7 @@ mdoc_atosec(const char *p)
/* FIXME: move this into an editable .in file. */
size_t
-mdoc_macro2len(int macro)
+mdoc_macro2len(enum mdoct macro)
{
switch (macro) {
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 308a52b2adb..2ac6cc82fff 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.49 2010/05/13 20:34:29 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.50 2010/05/14 01:54:37 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -93,7 +93,6 @@ static int post_vt(POST_ARGS);
static int pre_an(PRE_ARGS);
static int pre_bd(PRE_ARGS);
static int pre_bl(PRE_ARGS);
-static int pre_cd(PRE_ARGS);
static int pre_dd(PRE_ARGS);
static int pre_display(PRE_ARGS);
static int pre_dt(PRE_ARGS);
@@ -132,7 +131,6 @@ static v_post posts_xr[] = { ewarn_ge1, NULL };
static v_pre pres_an[] = { pre_an, NULL };
static v_pre pres_bd[] = { pre_display, pre_bd, NULL };
static v_pre pres_bl[] = { pre_bl, NULL };
-static v_pre pres_cd[] = { pre_cd, NULL };
static v_pre pres_d1[] = { pre_display, NULL };
static v_pre pres_dd[] = { pre_dd, NULL };
static v_pre pres_dt[] = { pre_dt, NULL };
@@ -164,7 +162,7 @@ const struct valids mdoc_valids[MDOC_MAX] = {
{ NULL, posts_text }, /* Ad */
{ pres_an, posts_an }, /* An */
{ NULL, NULL }, /* Ar */
- { pres_cd, posts_text }, /* Cd */
+ { NULL, posts_text }, /* Cd */
{ NULL, NULL }, /* Cm */
{ NULL, NULL }, /* Dv */
{ pres_er, posts_text }, /* Er */
@@ -735,7 +733,7 @@ pre_sh(PRE_ARGS)
if (MDOC_BLOCK != n->type)
return(1);
- return(check_parent(mdoc, n, -1, MDOC_ROOT));
+ return(check_parent(mdoc, n, MDOC_MAX, MDOC_ROOT));
}
@@ -772,8 +770,6 @@ static int
pre_rv(PRE_ARGS)
{
- if ( ! check_msec(mdoc, n, 2, 3, 0))
- return(0);
return(check_stdarg(mdoc, n));
}
@@ -789,14 +785,6 @@ pre_ex(PRE_ARGS)
static int
-pre_cd(PRE_ARGS)
-{
-
- return(check_msec(mdoc, n, 4, 0));
-}
-
-
-static int
pre_dt(PRE_ARGS)
{