diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2009-08-22 23:17:41 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2009-08-22 23:17:41 +0000 |
commit | 89e6167dec9df85ef505dfdeb8631c121ab08c2c (patch) | |
tree | 3a2abb37fcd97ba5d1aecdbe5cb2e11a7a5daa51 /usr.bin | |
parent | 304f11e8dec2909a45d6ad823965f6869118448b (diff) |
another large chunk of -man updates,
among others regarding .DT, .HP, .RS, .RE, .SH, .SS, and scoping,
now in sync vith release 1.9.1
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mandoc/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/libman.h | 9 | ||||
-rw-r--r-- | usr.bin/mandoc/man.7 | 487 | ||||
-rw-r--r-- | usr.bin/mandoc/man.c | 143 | ||||
-rw-r--r-- | usr.bin/mandoc/man.h | 7 | ||||
-rw-r--r-- | usr.bin/mandoc/man_action.c | 52 | ||||
-rw-r--r-- | usr.bin/mandoc/man_hash.c | 16 | ||||
-rw-r--r-- | usr.bin/mandoc/man_macro.c | 144 | ||||
-rw-r--r-- | usr.bin/mandoc/man_term.c | 114 | ||||
-rw-r--r-- | usr.bin/mandoc/man_validate.c | 51 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.1 | 143 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc.7 | 773 |
12 files changed, 1195 insertions, 748 deletions
diff --git a/usr.bin/mandoc/Makefile b/usr.bin/mandoc/Makefile index e6cf2ef04a7..5b382e66442 100644 --- a/usr.bin/mandoc/Makefile +++ b/usr.bin/mandoc/Makefile @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile,v 1.16 2009/08/22 20:14:37 schwarze Exp $ +# $OpenBSD: Makefile,v 1.17 2009/08/22 23:17:39 schwarze Exp $ .include <bsd.own.mk> -VERSION=1.9.0 +VERSION=1.9.1 CFLAGS+=-DVERSION=\"${VERSION}\" CFLAGS+=-W -Wall -Wstrict-prototypes .if ${USE_GCC3:L} != "no" diff --git a/usr.bin/mandoc/libman.h b/usr.bin/mandoc/libman.h index 2f23ca70323..70c1e8e4edf 100644 --- a/usr.bin/mandoc/libman.h +++ b/usr.bin/mandoc/libman.h @@ -1,4 +1,4 @@ -/* $Id: libman.h,v 1.7 2009/08/22 20:14:37 schwarze Exp $ */ +/* $Id: libman.h,v 1.8 2009/08/22 23:17:39 schwarze Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -33,6 +33,7 @@ struct man { #define MAN_HALT (1 << 0) #define MAN_ELINE (1 << 1) /* Next-line element scope. */ #define MAN_BLINE (1 << 2) /* Next-line block scope. */ +#define MAN_LITERAL (1 << 3) /* Literal input. */ enum man_next next; struct man_node *last; struct man_node *first; @@ -57,6 +58,9 @@ enum merr { WMACRO, WMACROFORM, WEXITSCOPE, + WNOSCOPE, + WOLITERAL, + WNLITERAL, WERRMAX }; @@ -67,6 +71,8 @@ struct man_macro { int (*fp)(MACRO_PROT_ARGS); int flags; #define MAN_SCOPED (1 << 0) +#define MAN_EXPLICIT (1 << 1) /* See blk_imp(). */ +#define MAN_FSCOPED (1 << 2) /* See blk_imp(). */ }; extern const struct man_macro *const man_macros; @@ -104,6 +110,7 @@ int man_verr(struct man *, int, int, const char *, ...); int man_valid_post(struct man *); int man_valid_pre(struct man *, const struct man_node *); int man_action_post(struct man *); +int man_action_pre(struct man *, struct man_node *); int man_unscope(struct man *, const struct man_node *); __END_DECLS diff --git a/usr.bin/mandoc/man.7 b/usr.bin/mandoc/man.7 index ab7ebca76c4..cc32b12bdbc 100644 --- a/usr.bin/mandoc/man.7 +++ b/usr.bin/mandoc/man.7 @@ -1,4 +1,4 @@ -.\" $Id: man.7,v 1.9 2009/08/22 20:14:37 schwarze Exp $ +.\" $Id: man.7,v 1.10 2009/08/22 23:17:39 schwarze Exp $ .\" .\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> .\" @@ -20,132 +20,146 @@ . . .Sh NAME -. Nm man -. Nd man language reference +.Nm man +.Nd man language reference . . .Sh DESCRIPTION The -. Nm man +.Nm man language was historically used to format -. Ux +.Ux manuals. This reference document describes its syntax, structure, and usage. -. Pp -. Bf -emphasis +. +.Pp +.Bf -emphasis Do not use -. Nm +.Nm to write your manuals. -. Ef +.Ef Use the -. Xr mdoc 7 +.Xr mdoc 7 language, instead. -. Pp +. +.Pp An -. Nm +.Nm document follows simple rules: lines beginning with the control character -. Sq \&. +.Sq \&. are parsed for macros. Other lines are interpreted within the scope of prior macros: -. Bd -literal -offset indent +.Bd -literal -offset indent \&.SH Macro lines change control state. Other lines are interpreted within the current state. -. Ed +.Ed . . .Sh INPUT ENCODING -. Nm +.Nm documents may contain only graphable 7-bit ASCII characters, the space character, and the tabs character. All manuals must have -. Ux +.Ux line termination. -. Pp +. +.Pp Blank lines are acceptable; where found, the output will assert a vertical space. -. Pp +. +.Pp The -. Sq \ec +.Sq \ec escape is common in historical -. Nm +.Nm documents; if encountered at the end of a word, it ensures that the subsequent word isn't off-set by whitespace. . . -. Ss Comments +.Ss Comments Text following a -. Sq \e\*" , +.Sq \e\*" , 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" , +.Sq \&.\e" , is also ignored. Macro lines with only a control charater and optionally whitespace are stripped from input. . . -. Ss Special Characters +.Ss Special Characters Special characters may occur in both macro and free-form lines. Sequences begin with the escape character -. Sq \e +.Sq \e followed by either an open-parenthesis -. Sq \&( +.Sq \&( for two-character sequences; an open-bracket -. Sq \&[ +.Sq \&[ for n-character sequences (terminated at a close-bracket -. Sq \&] ) ; +.Sq \&] ) ; or a single one-character sequence. See -. Xr mandoc_char 7 +.Xr mandoc_char 7 for a complete list. Examples include -. Sq \e(em -. Pq em-dash +.Sq \e(em +.Pq em-dash and -. Sq \ee -. Pq back-slash . +.Sq \ee +.Pq back-slash . . . -. Ss Text Decoration +.Ss Text Decoration Terms may be text-decorated using the -. Sq \ef +.Sq \ef escape followed by an indicator: B (bold), I, (italic), or P and R (Roman, or reset). . . -. Ss Whitespace +.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 . +.Xr mandoc 1 . . . .Sh MANUAL STRUCTURE Each -. Nm +.Nm document must contain contains at least the -. Sq \&TH +.Sq TH macro describing the document's section and title. It may occur anywhere in the document, although conventionally, it appears as the first macro. -. Pp +. +.Pp Beyond -. Sq \&TH , +.Sq TH , at least one macro or text node must appear in the document. Documents are generally structured as follows: -. Bd -literal -offset indent +.Bd -literal -offset indent \&.TH FOO 1 "13 Aug 2009" \&. \&.SH NAME -foo \e- a description goes here +\efBfoo\efR \e(en a description goes here +\&.\e\*q The next is for sections 2 & 3 only. +\&.\e\*q .SH LIBRARY \&. \&.SH SYNOPSIS \efBfoo\efR [\efB\e-options\efR] arguments... \&. \&.SH DESCRIPTION -The \efBfoo\efR utility does... +The \efBfoo\efR utility processes files... \&. +\&.\e\*q .SH IMPLEMENTATION NOTES +\&.\e\*q The next is for sections 1 & 8 only. +\&.\e\*q .SH EXIT STATUS +\&.\e\*q The next is for sections 2, 3, & 9 only. \&.\e\*q .SH RETURN VALUES +\&.\e\*q The next is for sections 1, 6, 7, & 8 only. \&.\e\*q .SH ENVIRONMENT \&.\e\*q .SH FILES \&.\e\*q .SH EXAMPLES +\&.\e\*q The next is for sections 1, 4, 6, 7, & 8 only. \&.\e\*q .SH DIAGNOSTICS +\&.\e\*q The next is for sections 2, 3, & 9 only. \&.\e\*q .SH ERRORS \&.\e\*q .SH SEE ALSO \&.\e\*q \efBbar\efR(1) @@ -154,314 +168,371 @@ The \efBfoo\efR utility does... \&.\e\*q .SH AUTHORS \&.\e\*q .SH CAVEATS \&.\e\*q .SH BUGS -. Ed +\&.\e\*q .SH SECURITY CONSIDERATIONS +.Ed . . .Sh MACRO SYNTAX Macros are one to three three characters in length and begin with a control character , -. Sq \&. , +.Sq \&. , at the beginning of the line. An arbitrary amount of whitespace may sit between the control character and the macro name. Thus, -. Sq \&.PP +.Sq .PP and -. Sq \&.\ \ \ \&PP +.Sq \&.\ \ \ PP are equivalent. -. Pp +. +.Pp The -. Nm -macros are classified by scope: line scope or block scope. Line-scoped +.Nm +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 scoped to the current line, with the body consisting of -zero or more arguments. If a macro is next-line scoped and the line -arguments are empty, the next line is used instead. Thus: -. Bd -literal -offset indent -\&.RI +.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 +line and the line arguments are empty, the next line is used instead, +else the general syntax is used. Thus: +.Bd -literal -offset indent +\&.I foo -. Ed -. Pp +.Ed +. +.Pp is equivalent to -. Sq \&.RI foo . -.\" PARAGRAPH -Consecutive next-line invocations are disallowed. -. Bd -literal -offset indent +.Sq \&.I foo . +If next-line macros are invoked consecutively, only the last is used. +If a next-line macro is proceded by a block macro, it is ignored. +.Bd -literal -offset indent \&.YO \(lBbody...\(rB \(lBbody...\(rB -. Ed -. Pp -. Bl -column -compact -offset indent "MacroX" "ArgumentsX" "ScopeXXXXX" -. It Em Macro Ta Em Arguments Ta Em Scope -. It \&B Ta n Ta next-line -. It \&BI Ta n Ta current -. It \&BR Ta n Ta current -. It \&I Ta n Ta next-line -. It \&IB Ta n Ta current -. It \&IR Ta n Ta current -. It \&R Ta n Ta next-line -. It \&RB Ta n Ta current -. It \&RI Ta n Ta current -. It \&SB Ta n Ta next-line -. It \&SM Ta n Ta next-line -. It \&TH Ta >1, <6 Ta current -. It \&br Ta 0 Ta current -. It \&fi Ta 0 Ta current -. It \&i Ta n Ta current -. It \&na Ta 0 Ta current -. It \&nf Ta 0 Ta current -. It \&r Ta 0 Ta current -. It \&sp Ta 1 Ta current -. El -. Pp -The lower-case -. Sq \&br , -. Sq \&fi , -. Sq \&i , -. Sq \&na , -. Sq \&nf , -. Sq \&r , +.Ed +. +.Pp +.Bl -column -compact -offset indent "MacroX" "ArgumentsX" "ScopeXXXXX" +.It Em Macro Ta Em Arguments Ta Em Scope +.It B Ta n Ta next-line +.It BI Ta n Ta current +.It BR Ta n Ta current +.It DT Ta 0 Ta current +.It I Ta n Ta next-line +.It IB Ta n Ta current +.It IR Ta n Ta current +.It R Ta n Ta next-line +.It RB Ta n Ta current +.It RI Ta n Ta current +.It SB Ta n Ta next-line +.It SM Ta n Ta next-line +.It TH Ta >1, <6 Ta current +.It br Ta 0 Ta current +.It fi Ta 0 Ta current +.It i Ta n Ta current +.It na Ta 0 Ta current +.It nf Ta 0 Ta current +.It r Ta 0 Ta current +.It sp Ta 1 Ta current +.El +. +.Pp +The +.Sq RS , +.Sq RE , +.Sq br , +.Sq fi , +.Sq i , +.Sq na , +.Sq nf , +.Sq r , and -. Sq \&sp +.Sq sp macros aren't historically part of -. Nm +.Nm and should not be used. They're included for compatibility. . . -. Ss Block Macros -Block macros are comprised of a head and body. The head is scoped to -the current line and, in one circumstance, the next line; the body is -scoped to subsequent lines and is closed out by a subsequent block macro -invocation. -. Bd -literal -offset indent +.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 +next line; the body is scoped to subsequent lines and is closed out by a +subsequent block macro invocation. +.Bd -literal -offset indent \&.YO \(lBhead...\(rB \(lBhead...\(rB \(lBbody...\(rB -. Ed -. Pp +.Ed +. +.Pp +The closure of body scope may be to the section, where a macro is closed +by +.Sq SH ; +sub-section, closed by a section or +.Sq SS ; +part, closed by a section, sub-section, or +.Sq RE ; +or paragraph, closed by a section, sub-section, part, +.Sq HP , +.Sq IP , +.Sq LP , +.Sq P , +.Sq PP , +or +.Sq TP . +No closure refers to an explicit block closing macro. +. +.Pp +.Bl -column "MacroX" "ArgumentsX" "Head ScopeX" "sub-sectionX" -compact -offset indent +.It Em Macro Ta Em Arguments Ta Em Head Scope Ta Em Body Scope +.It HP Ta <2 Ta current Ta paragraph +.It IP Ta <3 Ta current Ta paragraph +.It LP Ta 0 Ta current Ta paragraph +.It P Ta 0 Ta current Ta paragraph +.It PP Ta 0 Ta current Ta paragraph +.It RE Ta 0 Ta current Ta none +.It RS Ta 1 Ta current Ta part +.It SH Ta >0 Ta next-line Ta section +.It SS Ta >0 Ta next-line Ta sub-section +.It TP Ta n Ta next-line Ta paragraph +.El +. +.Pp If a block macro is next-line scoped, it may only be followed by in-line macros (excluding -. Sq br , -. Sq na , -. Sq sp , -. Sq nf , -. Sq fi , +.Sq DT , +.Sq TH , +.Sq br , +.Sq na , +.Sq sp , +.Sq nf , and -. Sq TH ) . -. Pp -. Bl -column "MacroX" "Arguments" "ScopeXXXX" -compact -offset indent -. It Em Macro Ta Em Arguments Ta Em Scope -. It \&HP Ta <2 Ta current -. It \&IP Ta <3 Ta current -. It \&LP Ta 0 Ta current -. It \&P Ta 0 Ta current -. It \&PP Ta 0 Ta current -. It \&SH Ta >0 Ta current -. It \&SS Ta >0 Ta current -. It \&TP Ta n Ta next-line -. El +.Sq fi ) . . . .Sh REFERENCE This section is a canonical reference to all macros, arranged alphabetically. For the scoping of individual macros, see -. Sx MACRO SYNTAX . +.Sx MACRO SYNTAX . . . -. Ss Terms +.Ss Definitions In this reference, a numerical width may be either a standalone natural number (such as 3, 4, 10, etc.) or a natural number followed by a width multiplier -. Qq n , +.Qq n , corresponding to the width of the formatted letter n, or -. Qq m , +.Qq m , corresponding to the width of the formatted letter m. The latter is the default, if unspecified. Thus, -. Bd -literal -offset indent +.Bd -literal -offset indent \&.HP 12n -. Ed -. Pp +.Ed +. +.Pp indicates an offset of 12 -. Qq n -. Ns -sized +.Qq n +.Ns -sized letters. . . -. Ss Macro Reference -. Bl -tag -width Ds -. It \&B +.Ss Macro Reference +.Bl -tag -width Ds +.It B Text is rendered in bold face. -. It \&BI +.It BI Text is rendered alternately in bold face and italic. Thus, -. Sq \&.BI this word and that +.Sq .BI this word and that causes -. Sq this +.Sq this and -. Sq and +.Sq and to render in bold face, while -. Sq word +.Sq word and -. Sq that +.Sq that render in italics. Whitespace between arguments is omitted in output. -. It \&BR +.It BR Text is rendered alternately in bold face and roman (the default font). Whitespace between arguments is omitted in output. -. It \&HP +.It DT +Re-set the tab spacing to 0.5 inches. +.It HP Begin a paragraph whose initial output line is left-justified, but subsequent output lines are indented, with the following syntax: -. Bd -literal -offset indent +.Bd -literal -offset indent \&.HP [width] -. Ed -. Pp +.Ed +. +.Pp If -. Va width +.Va width is specified, it's saved for later paragraph left-margins; if unspecified, the saved or default width is used. -. It \&I +.It I Text is rendered in italics. -. It \&IB +.It IB Text is rendered alternately in italics and bold face. Whitespace between arguments is omitted in output. -. It \&IP +.It IP Begin a paragraph with the following syntax: -. Bd -literal -offset indent +.Bd -literal -offset indent \&.IP [head [width]] -. Ed -. Pp +.Ed +. +.Pp This follows the behaviour of the -. Sq \&TP +.Sq TP except for the macro syntax (all arguments on the line, instead of having next-line scope). If -. Va width +.Va width is specified, it's saved for later paragraph left-margins; if unspecified, the saved or default width is used. -. It \&IR +.It IR Text is rendered alternately in italics and roman (the default font). Whitespace between arguments is omitted in output. -. It \&LP, \&P, \&PP +.It LP, P, PP Begin an undecorated paragraph. The scope of a paragraph is closed by a subsequent paragraph, sub-section, section, or end of file. The saved paragraph left-margin width is re-set to the default. -. It \&R +.It R Text is rendered in roman (the default font). -. It \&RB +.It RB Text is rendered alternately in roman (the default font) and bold face. Whitespace between arguments is omitted in output. -. It \&RI +.It RE +Explicitly close out the scope of a prior +.Sq RS . +.It RI Text is rendered alternately in roman (the default font) and italics. Whitespace between arguments is omitted in output. -. It \&SB +.It RS +Begin a part setting the left margin. The left margin controls the +offset, following an initial indentation, to un-indented text such as +that of +.Sq PP . +The width may be specified as following: +.Bd -literal -offset indent +\&.RS [width] +.Ed +. +.Pp +If +.Va width +is not specified, the saved or default width is used. +.It SB Text is rendered in small size (one point smaller than the default font) bold face. -. It \&SH +.It 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. -. It \&SM +.It SM Text is rendered in small size (one point smaller than the default font). -. It \&SS +.It 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. -. It \&TH +.It TH Sets the title of the manual page with the following syntax: -. Bd -literal -offset indent -\&.TH title section date source volume -. Ed -. Pp +.Bd -literal -offset indent +\&.TH title section [date [source [volume]]] +.Ed +. +.Pp At least the -. Va title +.Va title and -. Va section +.Va section arguments must be provided. The -. Va date +.Va date argument should be formatted as -. Qq %b [%d] %Y +.Qq %b [%d] %Y format, described in -. Xr strptime 3 . +.Xr strptime 3 . The -. Va source +.Va source string specifies the organisation providing the utility. The -. Va volume +.Va volume replaces the default rendered volume as dictated by the manual section. -. It \&TP +.It 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 buffer to the indentation width. Subsequent output lines are indented. -. Pp +. +.Pp The indentation width may be set as follows: -. Bd -literal -offset indent +.Bd -literal -offset indent \&.TP [width] -. Ed -. Pp +.Ed +. +.Pp Where -. Va width +.Va width must be a properly-formed numeric width. If -. Va width +.Va width is specified, it's saved for later paragraph left-margins; if unspecified, the saved or default width is used. -. It \&br +.It br Breaks the current line. Consecutive invocations have no further effect. -. It \&fi +.It fi End literal mode begun by -. Sq \&nf . -. It \&i +.Sq nf . +.It i Italicise arguments. If no arguments are specified, all subsequent text is italicised. -. It \&na -No alignment to the right margin. -. It \&nf +.It na +Don't alignment the right margin. +.It nf Begin literal mode: all subsequent free-form lines have their end of line boundaries preserved. May be ended by -. Sq \&fi . -. It \&r +.Sq fi . +.It r Fonts and styles (bold face, italics) reset to roman (default font). -. It \&sp +.It sp Insert n spaces, where n is the macro's positive numeric argument. If 0, this is equivalent to the -. Sq br +.Sq br macro. -. El +.El . . .Sh COMPATIBILITY This section documents compatibility with other roff implementations, at this time limited to -. Xr groff 1 . -. Bl -hyphen -. It +.Xr groff 1 . +.Bl -hyphen +.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. -. It +.It The -. Sq \&sp +.Sq sp macro does not accept negative numbers. -. It +.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. -. El +.El . . .Sh SEE ALSO -. Xr mandoc 1 , -. Xr mandoc_char 7 +.Xr mandoc 1 , +.Xr mandoc_char 7 . . .Sh AUTHORS The -. Nm +.Nm reference was written by -. An Kristaps Dzonsons Aq kristaps@kth.se . +.An Kristaps Dzonsons Aq kristaps@kth.se . . . .Sh CAVEATS Do not use this language. Use -. Xr mdoc 7 , +.Xr mdoc 7 , instead. . diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c index a35d914b6d4..009a25ef413 100644 --- a/usr.bin/mandoc/man.c +++ b/usr.bin/mandoc/man.c @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.9 2009/08/22 20:14:37 schwarze Exp $ */ +/* $Id: man.c,v 1.10 2009/08/22 23:17:39 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -40,7 +40,10 @@ const char *const __man_merrnames[WERRMAX] = { "expected empty block head", /* WNHEADARGS */ "unknown macro", /* WMACRO */ "ill-formed macro", /* WMACROFORM */ - "scope open on exit" /* WEXITSCOPE */ + "scope open on exit", /* WEXITSCOPE */ + "no scope context", /* WNOSCOPE */ + "literal context already open", /* WOLITERAL */ + "no literal context open" /* WNLITERAL */ }; const char *const __man_macronames[MAN_MAX] = { @@ -50,7 +53,8 @@ const char *const __man_macronames[MAN_MAX] = { "BI", "IB", "BR", "RB", "R", "B", "I", "IR", "RI", "na", "i", "sp", - "nf", "fi", "r" + "nf", "fi", "r", "RE", + "RS", "DT" }; const char * const *man_macronames = __man_macronames; @@ -63,6 +67,8 @@ static int man_ptext(struct man *, int, char *); static int man_pmacro(struct man *, int, char *); static void man_free1(struct man *); static int man_alloc1(struct man *); +static int pstring(struct man *, int, int, + const char *, size_t); const struct man_node * @@ -257,14 +263,17 @@ man_node_alloc(int line, int pos, enum man_type type, int tok) int -man_elem_alloc(struct man *man, int line, int pos, int tok) +man_elem_alloc(struct man *m, int line, int pos, int tok) { struct man_node *p; p = man_node_alloc(line, pos, MAN_ELEM, tok); if (NULL == p) return(0); - return(man_node_append(man, p)); + if ( ! man_node_append(m, p)) + return(0); + m->next = MAN_NEXT_CHILD; + return(1); } @@ -313,18 +322,40 @@ man_block_alloc(struct man *m, int line, int pos, int tok) } -int -man_word_alloc(struct man *man, - int line, int pos, const char *word) +static int +pstring(struct man *m, int line, int pos, + const char *p, size_t len) { - struct man_node *p; + struct man_node *n; + size_t sv; - p = man_node_alloc(line, pos, MAN_TEXT, -1); - if (NULL == p) + n = man_node_alloc(line, pos, MAN_TEXT, -1); + if (NULL == n) + return(0); + + n->string = malloc(len + 1); + if (NULL == n->string) { + free(n); return(0); - if (NULL == (p->string = strdup(word))) + } + + sv = strlcpy(n->string, p, len + 1); + + /* Prohibit truncation. */ + assert(sv < len + 1); + + if ( ! man_node_append(m, n)) return(0); - return(man_node_append(man, p)); + 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))); } @@ -343,26 +374,65 @@ man_node_free(struct man_node *p) void man_node_freelist(struct man_node *p) { + struct man_node *n; if (p->child) man_node_freelist(p->child); - if (p->next) - man_node_freelist(p->next); - assert(0 == p->nchild); + n = p->next; man_node_free(p); + if (n) + man_node_freelist(n); } static int man_ptext(struct man *m, int line, char *buf) { + int i, j; + + /* Literal free-form text whitespace is preserved. */ + + if (MAN_LITERAL & m->flags) { + if ( ! man_word_alloc(m, line, 0, buf)) + return(0); + goto descope; + } + + /* First de-chunk and allocate words. */ + + for (i = 0; ' ' == buf[i]; i++) + /* Skip leading whitespace. */ ; + if (0 == buf[i]) { + if ( ! pstring(m, line, 0, &buf[i], 0)) + return(0); + goto descope; + } - /* First allocate word. */ + for (j = i; buf[i]; i++) { + if (' ' != buf[i]) + continue; + + /* Escaped whitespace. */ + if (i && ' ' == buf[i] && '\\' == buf[i - 1]) + continue; + + buf[i++] = 0; + if ( ! pstring(m, line, j, &buf[j], (size_t)(i - j))) + return(0); + + for ( ; ' ' == buf[i]; i++) + /* Skip trailing whitespace. */ ; + + j = i; + if (0 == buf[i]) + break; + } - if ( ! man_word_alloc(m, line, 0, buf)) + if (j != i && ! pstring(m, line, j, &buf[j], (size_t)(i - j))) return(0); - m->next = MAN_NEXT_SIBLING; + +descope: /* * Co-ordinate what happens with having a next-line scope open: @@ -370,8 +440,6 @@ man_ptext(struct man *m, int line, char *buf) * out the block scope (also if applicable). */ - /* XXX - this should be in man_action.c. */ - if (MAN_ELINE & m->flags) { m->flags &= ~MAN_ELINE; if ( ! man_unscope(m, m->last->parent)) @@ -391,8 +459,9 @@ man_ptext(struct man *m, int line, char *buf) int man_pmacro(struct man *m, int ln, char *buf) { - int i, j, c, ppos, fl; - char mac[5]; + int i, j, c, ppos, fl; + char mac[5]; + struct man_node *n; /* Comments and empties are quickly ignored. */ @@ -449,6 +518,32 @@ man_pmacro(struct man *m, int ln, char *buf) while (buf[i] && ' ' == buf[i]) i++; + /* Remove prior ELINE macro, if applicable. */ + + if (m->flags & MAN_ELINE) { + n = m->last; + assert(NULL == n->child); + assert(0 == n->nchild); + if ( ! man_nwarn(m, n, WLNSCOPE)) + return(0); + + if (n->prev) { + assert(n != n->parent->child); + assert(n == n->prev->next); + n->prev->next = NULL; + m->last = n->prev; + m->next = MAN_NEXT_SIBLING; + } else { + assert(n == n->parent->child); + n->parent->child = NULL; + m->last = n->parent; + m->next = MAN_NEXT_CHILD; + } + + man_node_free(n); + m->flags &= ~MAN_ELINE; + } + /* Begin recursive parse sequence. */ assert(man_macros[c].fp); @@ -470,8 +565,6 @@ out: /* Close out the block scope opened in the prior line. */ - /* XXX - this should be in man_action.c. */ - assert(MAN_BLINE & m->flags); m->flags &= ~MAN_BLINE; diff --git a/usr.bin/mandoc/man.h b/usr.bin/mandoc/man.h index fd49874369a..1ddeef9f981 100644 --- a/usr.bin/mandoc/man.h +++ b/usr.bin/mandoc/man.h @@ -1,4 +1,4 @@ -/* $Id: man.h,v 1.7 2009/08/22 20:14:37 schwarze Exp $ */ +/* $Id: man.h,v 1.8 2009/08/22 23:17:40 schwarze Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -46,7 +46,10 @@ #define MAN_nf 24 #define MAN_fi 25 #define MAN_r 26 -#define MAN_MAX 27 +#define MAN_RE 27 +#define MAN_RS 28 +#define MAN_DT 29 +#define MAN_MAX 30 enum man_type { MAN_TEXT, diff --git a/usr.bin/mandoc/man_action.c b/usr.bin/mandoc/man_action.c index ec612f39b06..c296042276c 100644 --- a/usr.bin/mandoc/man_action.c +++ b/usr.bin/mandoc/man_action.c @@ -1,4 +1,4 @@ -/* $Id: man_action.c,v 1.6 2009/08/22 20:14:37 schwarze Exp $ */ +/* $Id: man_action.c,v 1.7 2009/08/22 23:17:40 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -27,9 +27,9 @@ struct actions { int (*post)(struct man *); }; - static int post_TH(struct man *); -static time_t man_atotime(const char *); +static int post_fi(struct man *); +static int post_nf(struct man *); const struct actions man_actions[MAN_MAX] = { { NULL }, /* br */ @@ -56,11 +56,16 @@ const struct actions man_actions[MAN_MAX] = { { NULL }, /* na */ { NULL }, /* i */ { NULL }, /* sp */ - { NULL }, /* nf */ - { NULL }, /* fi */ - { NULL }, /* r*/ + { post_nf }, /* nf */ + { post_fi }, /* fi */ + { NULL }, /* r */ + { NULL }, /* RE */ + { NULL }, /* RS */ + { NULL }, /* DT */ }; +static time_t man_atotime(const char *); + int man_action_post(struct man *m) @@ -72,14 +77,39 @@ man_action_post(struct man *m) switch (m->last->type) { case (MAN_TEXT): - break; + /* FALLTHROUGH */ case (MAN_ROOT): - break; + return(1); default: - if (NULL == man_actions[m->last->tok].post) - break; - return((*man_actions[m->last->tok].post)(m)); + break; } + + if (NULL == man_actions[m->last->tok].post) + return(1); + return((*man_actions[m->last->tok].post)(m)); +} + + +static int +post_fi(struct man *m) +{ + + if ( ! (MAN_LITERAL & m->flags)) + if ( ! man_nwarn(m, m->last, WNLITERAL)) + return(0); + m->flags &= ~MAN_LITERAL; + return(1); +} + + +static int +post_nf(struct man *m) +{ + + if (MAN_LITERAL & m->flags) + if ( ! man_nwarn(m, m->last, WOLITERAL)) + return(0); + m->flags |= MAN_LITERAL; return(1); } diff --git a/usr.bin/mandoc/man_hash.c b/usr.bin/mandoc/man_hash.c index ba2e1094ddc..2b83f0f56b3 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.4 2009/06/23 22:43:30 schwarze Exp $ */ +/* $Id: man_hash.c,v 1.5 2009/08/22 23:17:40 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -39,10 +39,10 @@ man_hash_alloc(void) /* Initialised to -1. */ - htab = malloc(26 * 5 * sizeof(int)); + htab = malloc(26 * 6 * sizeof(int)); if (NULL == htab) return(NULL); - for (i = 0; i < 26 * 5; i++) + for (i = 0; i < 26 * 6; i++) htab[i] = -1; for (i = 0; i < MAN_MAX; i++) { @@ -52,15 +52,15 @@ man_hash_alloc(void) (x >= 97 && x <= 122)); x -= (x <= 90) ? 65 : 97; - x *= 5; + x *= 6; - for (j = 0; j < 5; j++) + for (j = 0; j < 6; j++) if (-1 == htab[x + j]) { htab[x + j] = i; break; } - assert(j < 5); + assert(j < 6); } return((void *)htab); @@ -81,9 +81,9 @@ man_hash_find(const void *arg, const char *tmp) return(MAN_MAX); x -= (x <= 90) ? 65 : 97; - x *= 5; + x *= 6; - for (i = 0; i < 5; i++) { + for (i = 0; i < 6; i++) { if (-1 == (tok = htab[x + i])) return(MAN_MAX); if (0 == strcmp(tmp, man_macronames[tok])) diff --git a/usr.bin/mandoc/man_macro.c b/usr.bin/mandoc/man_macro.c index 12d1d45ef74..1bdc4c2563a 100644 --- a/usr.bin/mandoc/man_macro.c +++ b/usr.bin/mandoc/man_macro.c @@ -1,4 +1,4 @@ -/* $Id: man_macro.c,v 1.6 2009/08/22 20:14:37 schwarze Exp $ */ +/* $Id: man_macro.c,v 1.7 2009/08/22 23:17:40 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -27,17 +27,20 @@ static int in_line_eoln(MACRO_PROT_ARGS); static int blk_imp(MACRO_PROT_ARGS); +static int blk_close(MACRO_PROT_ARGS); static int rew_scope(enum man_type, struct man *, int); static int rew_dohalt(int, enum man_type, const struct man_node *); +static int rew_block(int, enum man_type, + const struct man_node *); const struct man_macro __man_macros[MAN_MAX] = { { in_line_eoln, 0 }, /* br */ { in_line_eoln, 0 }, /* TH */ - { blk_imp, 0 }, /* SH */ - { blk_imp, 0 }, /* SS */ - { blk_imp, MAN_SCOPED }, /* TP */ + { blk_imp, MAN_SCOPED }, /* SH */ + { blk_imp, MAN_SCOPED }, /* SS */ + { blk_imp, MAN_SCOPED | MAN_FSCOPED }, /* TP */ { blk_imp, 0 }, /* LP */ { blk_imp, 0 }, /* PP */ { blk_imp, 0 }, /* P */ @@ -60,6 +63,9 @@ const struct man_macro __man_macros[MAN_MAX] = { { in_line_eoln, 0 }, /* nf */ { in_line_eoln, 0 }, /* fi */ { in_line_eoln, 0 }, /* r */ + { blk_close, 0 }, /* RE */ + { blk_imp, MAN_EXPLICIT }, /* RS */ + { in_line_eoln, 0 }, /* DT */ }; const struct man_macro * const man_macros = __man_macros; @@ -88,6 +94,17 @@ man_unscope(struct man *m, const struct man_node *n) } +static int +rew_block(int ntok, enum man_type type, const struct man_node *n) +{ + + if (MAN_BLOCK == type && ntok == n->parent->tok && + MAN_BODY == n->parent->type) + return(REW_REWIND); + return(ntok == n->tok ? REW_HALT : REW_NOHALT); +} + + /* * There are three scope levels: scoped to the root (all), scoped to the * section (all less sections), and scoped to subsections (all less @@ -96,6 +113,7 @@ man_unscope(struct man *m, const struct man_node *n) static int rew_dohalt(int tok, enum man_type type, const struct man_node *n) { + int c; if (MAN_ROOT == n->type) return(REW_HALT); @@ -105,42 +123,36 @@ rew_dohalt(int tok, enum man_type type, const struct man_node *n) if (MAN_VALID & n->flags) return(REW_NOHALT); + /* Rewind to ourselves, first. */ + if (type == n->type && tok == n->tok) + return(REW_REWIND); + switch (tok) { case (MAN_SH): - /* Rewind to ourselves. */ - if (type == n->type && tok == n->tok) - return(REW_REWIND); break; case (MAN_SS): - /* Rewind to ourselves. */ - if (type == n->type && tok == n->tok) - return(REW_REWIND); /* Rewind to a section, if a block. */ - if (MAN_BLOCK == type && MAN_SH == n->parent->tok && - MAN_BODY == n->parent->type) - return(REW_REWIND); - /* Don't go beyond a section. */ - if (MAN_SH == n->tok) - return(REW_HALT); + if (REW_NOHALT != (c = rew_block(MAN_SH, type, n))) + return(c); + break; + case (MAN_RS): + /* Rewind to a subsection, if a block. */ + if (REW_NOHALT != (c = rew_block(MAN_SS, type, n))) + return(c); + /* Rewind to a section, if a block. */ + if (REW_NOHALT != (c = rew_block(MAN_SH, type, n))) + return(c); break; default: - /* Rewind to ourselves. */ - if (type == n->type && tok == n->tok) - return(REW_REWIND); + /* Rewind to an offsetter, if a block. */ + if (REW_NOHALT != (c = rew_block(MAN_RS, type, n))) + return(c); /* Rewind to a subsection, if a block. */ - if (MAN_BLOCK == type && MAN_SS == n->parent->tok && - MAN_BODY == n->parent->type) - return(REW_REWIND); - /* Don't go beyond a subsection. */ - if (MAN_SS == n->tok) - return(REW_HALT); + if (REW_NOHALT != (c = rew_block(MAN_SS, type, n))) + return(c); /* Rewind to a section, if a block. */ - if (MAN_BLOCK == type && MAN_SH == n->parent->tok && - MAN_BODY == n->parent->type) - return(REW_REWIND); - /* Don't go beyond a section. */ - if (MAN_SH == n->tok) - return(REW_HALT); + if (REW_NOHALT != (c = rew_block(MAN_SH, type, n))) + return(c); break; } @@ -180,6 +192,39 @@ rew_scope(enum man_type type, struct man *m, int tok) } +/* ARGSUSED */ +int +blk_close(MACRO_PROT_ARGS) +{ + int ntok; + const struct man_node *nn; + + switch (tok) { + case (MAN_RE): + ntok = MAN_RS; + break; + default: + abort(); + /* NOTREACHED */ + } + + for (nn = m->last->parent; nn; nn = nn->parent) + if (ntok == nn->tok) + break; + + if (NULL == nn) + if ( ! man_pwarn(m, line, ppos, WNOSCOPE)) + return(0); + + if ( ! rew_scope(MAN_BODY, m, ntok)) + return(0); + if ( ! rew_scope(MAN_BLOCK, m, ntok)) + return(0); + m->next = MAN_NEXT_SIBLING; + return(1); +} + + /* * Parse an implicit-block macro. These contain a MAN_HEAD and a * MAN_BODY contained within a MAN_BLOCK. Rules for closing out other @@ -191,6 +236,7 @@ blk_imp(MACRO_PROT_ARGS) { int w, la; char *p; + struct man_node *n; /* Close out prior scopes. */ @@ -206,6 +252,8 @@ blk_imp(MACRO_PROT_ARGS) if ( ! man_head_alloc(m, line, ppos, tok)) return(0); + n = m->last; + /* Add line arguments. */ for (;;) { @@ -219,15 +267,22 @@ blk_imp(MACRO_PROT_ARGS) if ( ! man_word_alloc(m, line, la, p)) return(0); - m->next = MAN_NEXT_SIBLING; } /* Close out head and open body (unless MAN_SCOPE). */ if (MAN_SCOPED & man_macros[tok].flags) { - m->flags |= MAN_BLINE; - return(1); - } else if ( ! rew_scope(MAN_HEAD, m, tok)) + /* If we're forcing scope (`TP'), keep it open. */ + if (MAN_FSCOPED & man_macros[tok].flags) { + m->flags |= MAN_BLINE; + return(1); + } else if (n == m->last) { + m->flags |= MAN_BLINE; + return(1); + } + } + + if ( ! rew_scope(MAN_HEAD, m, tok)) return(0); return(man_body_alloc(m, line, ppos, tok)); @@ -245,7 +300,6 @@ in_line_eoln(MACRO_PROT_ARGS) return(0); n = m->last; - m->next = MAN_NEXT_CHILD; for (;;) { la = *pos; @@ -258,10 +312,9 @@ in_line_eoln(MACRO_PROT_ARGS) if ( ! man_word_alloc(m, line, la, p)) return(0); - m->next = MAN_NEXT_SIBLING; } - if (n == m->last && (MAN_SCOPED & man_macros[tok].flags)) { + if (n == m->last && MAN_SCOPED & man_macros[tok].flags) { m->flags |= MAN_ELINE; return(1); } @@ -271,8 +324,6 @@ in_line_eoln(MACRO_PROT_ARGS) * make sure that we don't clobber as its sibling. */ - /* FIXME: clean this to use man_unscope(). */ - for ( ; m->last; m->last = m->last->parent) { if (m->last == n) break; @@ -304,6 +355,19 @@ in_line_eoln(MACRO_PROT_ARGS) int man_macroend(struct man *m) { + struct man_node *n; + + n = MAN_VALID & m->last->flags ? + m->last->parent : m->last; + + for ( ; n; n = n->parent) { + if (MAN_BLOCK != n->type) + continue; + if ( ! (MAN_EXPLICIT & man_macros[n->tok].flags)) + continue; + if ( ! man_nwarn(m, n, WEXITSCOPE)) + return(0); + } return(man_unscope(m, m->first)); } diff --git a/usr.bin/mandoc/man_term.c b/usr.bin/mandoc/man_term.c index a4f1fb2139f..9995a9ed377 100644 --- a/usr.bin/mandoc/man_term.c +++ b/usr.bin/mandoc/man_term.c @@ -1,4 +1,4 @@ -/* $Id: man_term.c,v 1.12 2009/08/22 20:19:24 schwarze Exp $ */ +/* $Id: man_term.c,v 1.13 2009/08/22 23:17:40 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -14,6 +14,8 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <sys/types.h> + #include <assert.h> #include <ctype.h> #include <err.h> @@ -30,7 +32,21 @@ struct mtermp { int fl; #define MANT_LITERAL (1 << 0) - int lmargin; + /* + * Default amount to indent the left margin after leading text + * has been printed (e.g., `HP' left-indent, `TP' and `IP' body + * indent). This needs to be saved because `HP' and so on, if + * not having a specified value, must default. + * + * Note that this is the indentation AFTER the left offset, so + * the total offset is usually offset + lmargin. + */ + size_t lmargin; + /* + * The default offset, i.e., the amount between any text and the + * page boundary. + */ + size_t offset; }; #define DECL_ARGS struct termp *p, \ @@ -54,6 +70,7 @@ static int pre_IR(DECL_ARGS); static int pre_PP(DECL_ARGS); static int pre_RB(DECL_ARGS); static int pre_RI(DECL_ARGS); +static int pre_RS(DECL_ARGS); static int pre_SH(DECL_ARGS); static int pre_SS(DECL_ARGS); static int pre_TP(DECL_ARGS); @@ -67,6 +84,7 @@ static void post_B(DECL_ARGS); static void post_I(DECL_ARGS); static void post_IP(DECL_ARGS); static void post_HP(DECL_ARGS); +static void post_RS(DECL_ARGS); static void post_SH(DECL_ARGS); static void post_SS(DECL_ARGS); static void post_TP(DECL_ARGS); @@ -94,12 +112,15 @@ static const struct termact termacts[MAN_MAX] = { { pre_I, post_I }, /* I */ { pre_IR, NULL }, /* IR */ { pre_RI, NULL }, /* RI */ - { NULL, NULL }, /* na */ /* TODO: document that has no effect */ + { NULL, NULL }, /* na */ { pre_I, post_i }, /* i */ { pre_sp, NULL }, /* sp */ { pre_nf, NULL }, /* nf */ { pre_fi, NULL }, /* fi */ { pre_r, NULL }, /* r */ + { NULL, NULL }, /* RE */ + { pre_RS, post_RS }, /* RS */ + { NULL, NULL }, /* DT */ }; static void print_head(struct termp *, @@ -125,6 +146,7 @@ man_run(struct termp *p, const struct man *m) mt.fl = 0; mt.lmargin = INDENT; + mt.offset = INDENT; if (man_node(m)->child) print_body(p, &mt, man_node(m)->child, man_meta(m)); @@ -426,7 +448,7 @@ pre_HP(DECL_ARGS) return(0); } - len = (size_t)mt->lmargin; + len = mt->lmargin; ival = -1; /* Calculate offset. */ @@ -438,11 +460,11 @@ pre_HP(DECL_ARGS) if (0 == len) len = 1; - p->offset = INDENT; - p->rmargin = INDENT + len; + p->offset = mt->offset; + p->rmargin = mt->offset + len; if (ival >= 0) - mt->lmargin = ival; + mt->lmargin = (size_t)ival; return(1); } @@ -461,7 +483,7 @@ post_HP(DECL_ARGS) term_flushln(p); p->flags &= ~TERMP_NOBREAK; p->flags &= ~TERMP_TWOSPACE; - p->offset = INDENT; + p->offset = mt->offset; p->rmargin = p->maxrmargin; break; default: @@ -481,7 +503,7 @@ pre_PP(DECL_ARGS) fmt_block_vspace(p, n); break; default: - p->offset = INDENT; + p->offset = mt->offset; break; } @@ -513,7 +535,7 @@ pre_IP(DECL_ARGS) return(1); } - len = (size_t)mt->lmargin; + len = mt->lmargin; ival = -1; /* Calculate offset. */ @@ -532,20 +554,20 @@ pre_IP(DECL_ARGS) if (0 == len) len = 1; - p->offset = INDENT; - p->rmargin = INDENT + len; + p->offset = mt->offset; + p->rmargin = mt->offset + len; if (ival < 0) break; /* Set the saved left-margin. */ - mt->lmargin = ival; + mt->lmargin = (size_t)ival; /* Don't print the length value. */ for (nn = n->child; nn->next; nn = nn->next) print_node(p, mt, nn, m); return(0); case (MAN_BODY): - p->offset = INDENT + len; + p->offset = mt->offset + len; p->rmargin = p->maxrmargin; break; default: @@ -618,8 +640,8 @@ pre_TP(DECL_ARGS) if (0 == len) len = 1; - p->offset = INDENT; - p->rmargin = INDENT + len; + p->offset = mt->offset; + p->rmargin = mt->offset + len; /* Don't print same-line elements. */ for (nn = n->child; nn; nn = nn->next) @@ -627,11 +649,11 @@ pre_TP(DECL_ARGS) print_node(p, mt, nn, m); if (ival >= 0) - mt->lmargin = ival; + mt->lmargin = (size_t)ival; return(0); case (MAN_BODY): - p->offset = INDENT + len; + p->offset = mt->offset + len; p->rmargin = p->maxrmargin; break; default: @@ -672,6 +694,7 @@ pre_SS(DECL_ARGS) switch (n->type) { case (MAN_BLOCK): mt->lmargin = INDENT; + mt->offset = INDENT; /* If following a prior empty `SS', no vspace. */ if (n->prev && MAN_SS == n->prev->tok) if (NULL == n->prev->body->child) @@ -685,7 +708,7 @@ pre_SS(DECL_ARGS) p->offset = HALFINDENT; break; case (MAN_BODY): - p->offset = INDENT; + p->offset = mt->offset; break; default: break; @@ -722,6 +745,7 @@ pre_SH(DECL_ARGS) switch (n->type) { case (MAN_BLOCK): mt->lmargin = INDENT; + mt->offset = INDENT; /* If following a prior empty `SH', no vspace. */ if (n->prev && MAN_SH == n->prev->tok) if (NULL == n->prev->body->child) @@ -733,7 +757,7 @@ pre_SH(DECL_ARGS) p->offset = 0; break; case (MAN_BODY): - p->offset = INDENT; + p->offset = mt->offset; break; default: break; @@ -762,6 +786,56 @@ post_SH(DECL_ARGS) } +/* ARGSUSED */ +static int +pre_RS(DECL_ARGS) +{ + const struct man_node *nn; + int ival; + + switch (n->type) { + case (MAN_BLOCK): + term_newln(p); + return(1); + case (MAN_HEAD): + return(0); + default: + break; + } + + if (NULL == (nn = n->parent->head->child)) { + mt->offset = mt->lmargin + INDENT; + p->offset = mt->offset; + return(1); + } + + if ((ival = arg_width(nn)) < 0) + return(1); + + mt->offset = INDENT + (size_t)ival; + p->offset = mt->offset; + + return(1); +} + + +/* ARGSUSED */ +static void +post_RS(DECL_ARGS) +{ + + switch (n->type) { + case (MAN_BLOCK): + mt->offset = mt->lmargin = INDENT; + break; + default: + term_newln(p); + p->offset = INDENT; + break; + } +} + + static void print_node(DECL_ARGS) { diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c index 0b015a2e552..cb07087c74d 100644 --- a/usr.bin/mandoc/man_validate.c +++ b/usr.bin/mandoc/man_validate.c @@ -1,4 +1,4 @@ -/* $Id: man_validate.c,v 1.7 2009/08/22 20:14:37 schwarze Exp $ */ +/* $Id: man_validate.c,v 1.8 2009/08/22 23:17:40 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -36,12 +36,12 @@ struct man_valid { }; static int check_bline(CHKARGS); -static int check_eline(CHKARGS); static int check_eq0(CHKARGS); static int check_eq1(CHKARGS); static int check_ge2(CHKARGS); static int check_le5(CHKARGS); static int check_par(CHKARGS); +static int check_part(CHKARGS); static int check_root(CHKARGS); static int check_sec(CHKARGS); static int check_sp(CHKARGS); @@ -50,9 +50,9 @@ static int check_text(CHKARGS); static v_check posts_eq0[] = { check_eq0, NULL }; static v_check posts_ge2_le5[] = { check_ge2, check_le5, NULL }; static v_check posts_par[] = { check_par, NULL }; +static v_check posts_part[] = { check_part, NULL }; static v_check posts_sec[] = { check_sec, NULL }; static v_check posts_sp[] = { check_sp, NULL }; -static v_check pres_eline[] = { check_eline, NULL }; static v_check pres_bline[] = { check_bline, NULL }; static const struct man_valid man_valids[MAN_MAX] = { @@ -66,15 +66,15 @@ static const struct man_valid man_valids[MAN_MAX] = { { pres_bline, posts_par }, /* P */ { pres_bline, posts_par }, /* IP */ { pres_bline, posts_par }, /* HP */ - { pres_eline, NULL }, /* SM */ - { pres_eline, NULL }, /* SB */ + { NULL, NULL }, /* SM */ + { NULL, NULL }, /* SB */ { NULL, NULL }, /* BI */ { NULL, NULL }, /* IB */ { NULL, NULL }, /* BR */ { NULL, NULL }, /* RB */ - { pres_eline, NULL }, /* R */ - { pres_eline, NULL }, /* B */ - { pres_eline, NULL }, /* I */ + { NULL, NULL }, /* R */ + { NULL, NULL }, /* B */ + { NULL, NULL }, /* I */ { NULL, NULL }, /* IR */ { NULL, NULL }, /* RI */ { pres_bline, posts_eq0 }, /* na */ @@ -83,6 +83,9 @@ static const struct man_valid man_valids[MAN_MAX] = { { pres_bline, posts_eq0 }, /* nf */ { pres_bline, posts_eq0 }, /* fi */ { NULL, NULL }, /* r */ + { NULL, NULL }, /* RE */ + { NULL, posts_part }, /* RS */ + { NULL, NULL }, /* DT */ }; @@ -137,12 +140,13 @@ static int check_root(CHKARGS) { - /* XXX - make this into a warning? */ if (MAN_BLINE & m->flags) - return(man_nerr(m, n, WEXITSCOPE)); - /* XXX - make this into a warning? */ + return(man_nwarn(m, n, WEXITSCOPE)); if (MAN_ELINE & m->flags) - return(man_nerr(m, n, WEXITSCOPE)); + return(man_nwarn(m, n, WEXITSCOPE)); + + m->flags &= ~MAN_BLINE; + m->flags &= ~MAN_ELINE; if (NULL == m->first->child) return(man_nerr(m, n, WNODATA)); @@ -248,6 +252,16 @@ check_sec(CHKARGS) static int +check_part(CHKARGS) +{ + + if (MAN_BODY == n->type && 0 == n->nchild) + return(man_nwarn(m, n, WBODYARGS)); + return(1); +} + + +static int check_par(CHKARGS) { @@ -286,23 +300,12 @@ check_par(CHKARGS) static int -check_eline(CHKARGS) -{ - - if (MAN_ELINE & m->flags) - return(man_nerr(m, n, WLNSCOPE)); - return(1); -} - - -static int check_bline(CHKARGS) { + assert( ! (MAN_ELINE & m->flags)); if (MAN_BLINE & m->flags) return(man_nerr(m, n, WLNSCOPE)); - if (MAN_ELINE & m->flags) - return(man_nerr(m, n, WLNSCOPE)); return(1); } diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index 8ba31bbf930..38b2e413ba3 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,4 +1,4 @@ -.\" $Id: mandoc.1,v 1.13 2009/08/22 16:03:14 schwarze Exp $ +.\" $Id: mandoc.1,v 1.14 2009/08/22 23:17:40 schwarze Exp $ .\" .\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> .\" @@ -17,11 +17,13 @@ .Dd $Mdocdate: August 22 2009 $ .Dt MANDOC 1 .Os -.\" SECTION +. +. .Sh NAME .Nm mandoc .Nd format and display UNIX manuals -.\" SECTION +. +. .Sh SYNOPSIS .Nm mandoc .Op Fl V @@ -30,35 +32,36 @@ .Op Fl W Ns Ar err... .Op Fl T Ns Ar output .Op Ar infile... -.\" SECTION +. +. .Sh DESCRIPTION The .Nm utility formats .Ux manual pages for display. The arguments are as follows: +. .Bl -tag -width Ds -.\" ITEM .It Fl f Ns Ar option... Override default compiler behaviour. See .Sx Compiler Options for details. -.\" ITEM +. .It Fl m Ns Ar format Input format. See .Sx Input Formats for available formats. Defaults to .Fl m Ns Ar andoc . -.\" ITEM +. .It Fl T Ns Ar output Output format. See .Sx Output Formats for available formats. Defaults to .Fl T Ns Ar ascii . -.\" ITEM +. .It Fl V Print version and exit. -.\" ITEM +. .It Fl W Ns Ar err... Configure warning messages. Use .Fl W Ns Ar all @@ -69,7 +72,7 @@ termination. Multiple .Fl W arguments may be comma-separated, such as .Fl W Ns Ar error,all . -.\" ITEM +. .It Ar infile... Read input from zero or more .Ar infile . @@ -77,7 +80,7 @@ If unspecified, reads from stdin. If multiple files are specified, .Nm will halt with the first failed parse. .El -.\" PARAGRAPH +. .Pp By default, .Nm @@ -90,10 +93,11 @@ text from stdin, implying and prints 78-column backspace-encoded output to stdout as if .Fl T Ns Ar ascii were provided. -.\" PARAGRAPH +. .Pp .Ex -std mandoc -.\" SUB-SECTION +. +. .Ss Punctuation and Spacing If punctuation is set apart from words, such as in the phrase .Dq to be \&, or not to be , @@ -120,20 +124,21 @@ and .Sq \&} .Pc is not preceded by whitespace. +. .Pp If the input is .Xr mdoc 7 , these rules are also applied to macro arguments when appropriate. +. .Pp White-space, in non-literal (normal) mode, is stripped from input and -replaced on output by a single space. Thus, if you wish to preserve -multiple spaces, they must be space-escaped -.Sq \e\ -or used in a literal display mode, e.g., +replaced on output by a single space. Thus, if you wish to preserve multiple +spaces, they must be space-escaped or used in a literal display mode, e.g., .Sq \&Bd \-literal in .Xr mdoc 7 . -.\" SUB-SECTION +. +. .Ss Input Formats The .Nm @@ -152,6 +157,7 @@ format is recommended; .Xr man 7 should only be used for legacy manuals. +. .Pp A third option, .Fl m Ns Ar andoc , @@ -165,6 +171,7 @@ the parser is used; otherwise, the .Xr man 7 parser is used. +. .Pp If multiple files are specified with @@ -175,64 +182,65 @@ specified and or .Fl m Ns Ar an is specified, then this format is used exclusively. -.\" .Pp -.\" The following escape sequences are recognised, although the per-format -.\" compiler may not allow certain sequences. -.\" .Bl -tag -width Ds -offset XXXX -.\" .It \efX -.\" sets the font mode to X (B, I, R or P, where P resets the font) -.\" .It \eX, \e(XX, \e[XN] -.\" queries the special-character table for a corresponding symbol -.\" .It \e*X, \e*(XX, \e*[XN] -.\" deprecated special-character format -.\" .El -.\" SUB-SECTION +. +. .Ss Output Formats The .Nm utility accepts the following .Fl T arguments: +. .Bl -tag -width Ds .It Fl T Ns Ar ascii Produce 7-bit ASCII output, backspace-encoded for bold and underline styles. This is the default. +. .It Fl T Ns Ar tree Produce an indented parse tree. +. .It Fl T Ns Ar lint Parse only: produce no output. .El +. .Pp If multiple input files are specified, these will be processed by the corresponding filter in-order. -.\" SUB-SECTION +. +. .Ss Compiler Options Default compiler behaviour may be overriden with the .Fl f flag. +. .Bl -tag -width Ds .It Fl f Ns Ar ign-scope When rewinding the scope of a block macro, forces the compiler to ignore scope violations. This can seriously mangle the resulting tree. .Pq mdoc only +. .It Fl f Ns Ar no-ign-escape Don't ignore invalid escape sequences. +. .It Fl f Ns Ar no-ign-macro Do not ignore unknown macros at the start of input lines. +. .It Fl f Ns Ar no-ign-chars Do not ignore disallowed characters. +. .It Fl f Ns Ar strict Implies .Fl f Ns Ar no-ign-escape , .Fl f Ns Ar no-ign-macro and .Fl f Ns Ar no-ign-chars . +. .It Fl f Ns Ar ign-errors Don't halt when encountering parse errors. Useful with .Fl T Ns Ar lint over a large set of manuals passed on the command line. .El -.\" PARAGRAPH +. .Pp As with the .Fl W @@ -242,49 +250,90 @@ options may be grouped and delimited with a comma. Using .Fl f Ns Ar ign-scope,no-ign-escape , for example, will try to ignore scope and not ignore character-escape errors. -.\" SECTION +. +. .Sh EXAMPLES To page manuals to the terminal: -.\" PARAGRAPH +. .Pp .D1 % mandoc \-Wall,error \-fstrict mandoc.1 2>&1 | less .D1 % mandoc mandoc.1 mdoc.3 mdoc.7 | less -.\" PARAGRAPH +. .Pp To check over a large set of manuals: -.\" PARAGRAPH +. .Pp .Dl % mandoc \-Tlint \-fign-errors `find /usr/src -name \e*\e.[1-9]` -.\" SECTION +. +. .Sh COMPATIBILITY This section summarises .Nm compatibility with .Xr groff 1 . -.Pp +Each input and output format is separately noted. +. +. +.Ss ASCII output .Bl -bullet -compact -.\" LIST-ITEM .It The .Sq \e~ -special character doesn't produce expected behaviour. -.\" LIST-ITEM +special character doesn't produce expected behaviour in +.Fl T Ns Ar ascii . +. +.It +The +.Sq \&Bd \-literal +and +.Sq \&Bd \-unfilled +macros of +.Xr mdoc 7 +in +.Fl T Ns Ar ascii +are synonyms, as are \-filled and \-ragged. +. +.It +In +.Xr groff 1 , +the +.Sq \&Pa +.Xr mdoc 7 +macro does not underline when scoped under an +.Sq \&It +in the FILES section. This behaves correctly in +.Nm . +. .It A list or display following .Sq \&Ss +.Xr mdoc 7 +macro in +.Fl T Ns Ar ascii does not assert a prior vertical break, just as it doesn't with .Sq \&Sh . +. .It -The \-literal and \-unfilled -.Sq \&Bd -displays types are synonyms, as are \-filled and \-ragged. -.\" LIST-ITEM +The +.Sq \&na +and +.Sq \&Dt +.Xr man 7 +macros in +.Fl T Ns Ar ascii +have no effect. +. .It Words aren't hyphenated. -.\" LIST-ITEM +. .It In normal mode (not a literal block), blocks of spaces aren't preserved, -so double spaces following sentence closure are reduced to a single space. +so double spaces following sentence closure are reduced to a single space; +.Xr groff 1 +retains spaces. +. +.It +Sentences are unilaterally monospaced. .El .\" SECTION .Sh SEE ALSO diff --git a/usr.bin/mandoc/mdoc.7 b/usr.bin/mandoc/mdoc.7 index dbf795c673d..5ede57b2990 100644 --- a/usr.bin/mandoc/mdoc.7 +++ b/usr.bin/mandoc/mdoc.7 @@ -1,4 +1,4 @@ -.\" $Id: mdoc.7,v 1.14 2009/08/22 19:45:39 schwarze Exp $ +.\" $Id: mdoc.7,v 1.15 2009/08/22 23:17:40 schwarze Exp $ .\" .\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> .\" @@ -20,209 +20,251 @@ . . .Sh NAME -. Nm mdoc -. Nd mdoc language reference +.Nm mdoc +.Nd mdoc language reference . . .Sh DESCRIPTION The -. Nm mdoc +.Nm mdoc language is used to format -. Bx -. Ux +.Bx +.Ux manuals. In this reference document, we describe its syntax, structure, and usage. Our reference implementation is -. Xr mandoc 1 . +.Xr mandoc 1 . The -. Sx COMPATIBILITY +.Sx COMPATIBILITY section describes compatibility with -. Xr groff 1 . -. Pp +.Xr groff 1 . +. +.Pp An -. Nm +.Nm document follows simple rules: lines beginning with the control character -. Sq \. +.Sq \. are parsed for macros. Other lines are interpreted within the scope of prior macros: -. Bd -literal -offset indent +.Bd -literal -offset indent \&.Sh Macro lines change control state. Other lines are interpreted within the current state. -. Ed +.Ed . . .Sh LANGUAGE SYNTAX -. Nm +.Nm documents may contain only graphable 7-bit ASCII characters, the space character, and, in certain circumstances, the tab character. All manuals must have -. Ux +.Ux line terminators. . . -. Ss Comments +.Ss Comments Text following a -. Sq \e" , +.Sq \e" , 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. +.Sq \&.\e" , +is also ignored. Macro lines with only a control charater and optionally +whitespace are stripped from input. . . -. Ss Reserved Characters +.Ss Reserved Characters Within a macro line, the following characters are reserved: -. Bl -tag -width Ds -offset indent -compact -. It \&. -. Pq period -. It \&, -. Pq comma -. It \&: -. Pq colon -. It \&; -. Pq semicolon -. It \&( -. Pq left-parenthesis -. It \&) -. Pq right-parenthesis -. It \&[ -. Pq left-bracket -. It \&] -. Pq right-bracket -. It \&? -. Pq question -. It \&! -. Pq exclamation -. It \&| -. Pq vertical bar -. El -. Pp +.Bl -tag -width Ds -offset indent -compact +.It \&. +.Pq period +.It \&, +.Pq comma +.It \&: +.Pq colon +.It \&; +.Pq semicolon +.It \&( +.Pq left-parenthesis +.It \&) +.Pq right-parenthesis +.It \&[ +.Pq left-bracket +.It \&] +.Pq right-bracket +.It \&? +.Pq question +.It \&! +.Pq exclamation +.It \&| +.Pq vertical bar +.El +. +.Pp Use of reserved characters is described in -. Sx MACRO SYNTAX . +.Sx MACRO SYNTAX . For general use in macro lines, these characters must either be escaped with a non-breaking space -. Pq Sq \e& +.Pq Sq \e& or, if applicable, an appropriate escape sequence used. . . -. Ss Special Characters +.Ss Special Characters Special characters may occur in both macro and free-form lines. Sequences begin with the escape character -. Sq \e +.Sq \e followed by either an open-parenthesis -. Sq \&( +.Sq \&( for two-character sequences; an open-bracket -. Sq \&[ +.Sq \&[ for n-character sequences (terminated at a close-bracket -. Sq \&] ) ; +.Sq \&] ) ; or a single one-character sequence. See -. Xr mandoc_char 7 +.Xr mandoc_char 7 for a complete list. Examples include -. Sq \e(em -. Pq em-dash +.Sq \e(em +.Pq em-dash and -. Sq \ee -. Pq back-slash . +.Sq \ee +.Pq back-slash . . . -. Ss Text Decoration +.Ss Text Decoration Terms may be text-decorated using the -. Sq \ef +.Sq \ef escape followed by an indicator: B (bold), I, (italic), or P and R (Roman, or reset). This form is not recommended for -. Nm , +.Nm , which encourages semantic, not presentation, annotation. . . -. Ss Predefined Strings +.Ss Predefined Strings Historically, -. Xr groff 1 +.Xr groff 1 also defined a set of package-specific -. Dq predefined strings , +.Dq predefined strings , which, like -. Sx Special Characters , +.Sx Special Characters , demark special output characters and strings by way of input codes. Predefined strings are escaped with the slash-asterisk, -. Sq \e* : +.Sq \e* : single-character -. Sq \e*X , +.Sq \e*X , two-character -. Sq \e*(XX , +.Sq \e*(XX , and N-character -. Sq \e*[N] . +.Sq \e*[N] . See -. Xr mandoc_char 7 +.Xr mandoc_char 7 for a complete list. Examples include -. Sq \e*(Am -. Pq ampersand +.Sq \e*(Am +.Pq ampersand and -. Sq \e*(Ba -. Pq vertical bar . +.Sq \e*(Ba +.Pq vertical bar . . . -. Ss Whitespace +.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 +.Bd -literal -offset indent These spaces are pruned from input. \&.Bd \-literal These are not. \&.Ed -. Ed -. Pp +.Ed +. +.Pp In macro lines, whitespace delimits arguments and is discarded. If arguments are quoted, whitespace within the quotes is retained. -. Pp +. +.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 +.Sq \&Bl \-column or when in a literal context. . . -. Ss Quotation +.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 +. +.Pp This produces tokens -. Sq a" , -. Sq b c , -. Sq de , +.Sq a" , +.Sq b c , +.Sq de , and -. Sq fg" . +.Sq fg" . Note that any quoted term, be it argument or macro, is indiscriminately considered literal text. Thus, the following produces -. Sq \&Em a : -. Bd -literal -offset indent +.Sq \&Em a : +.Bd -literal -offset indent \&.Em "Em a" -. Ed -. Pp +.Ed +. +.Pp In free-form mode, quotes are regarded as opaque text. . . .Sh MANUAL STRUCTURE Each -. Nm +.Nm document must begin with a document prologue, containing, in order, -. Sq \&Dd , -. Sq \&Dt , +.Sq \&Dd , +.Sq \&Dt , and -. Sq \&Os , +.Sq \&Os , then the NAME section containing at least one -. Sq \&Nm +.Sq \&Nm followed by -. Sq \&Nd : -. Bd -literal -offset indent +.Sq \&Nd : +.Bd -literal -offset indent \&.Dd $\&Mdocdate$ \&.Dt mdoc 7 \&.Os +\&. \&.Sh NAME -\&.Nm mdoc -\&.Nd mdoc language reference -. Ed -. Pp +\&.Nm foo +\&.Nd a description goes here +\&.\e\*q The next is for sections 2 & 3 only. +\&.\e\*q .Sh LIBRARY +\&. +\&.Sh SYNOPSIS +\&.Nm foo +\&.Op Fl options +\&.Ar +\&. +\&.Sh DESCRIPTION +The +\&.Nm +utility processes files ... +\&.\e\*q .Sh IMPLEMENTATION NOTES +\&.\e\*q The next is for sections 1 & 8 only. +\&.\e\*q .Sh EXIT STATUS +\&.\e\*q The next is for sections 2, 3, & 9 only. +\&.\e\*q .Sh RETURN VALUES +\&.\e\*q The next is for sections 1, 6, 7, & 8 only. +\&.\e\*q .Sh ENVIRONMENT +\&.\e\*q .Sh FILES +\&.\e\*q .Sh EXAMPLES +\&.\e\*q The next is for sections 1, 4, 6, 7, & 8 only. +\&.\e\*q .Sh DIAGNOSTICS +\&.\e\*q The next is for sections 2, 3, & 9 only. +\&.\e\*q .Sh ERRORS +\&.\e\*q .Sh SEE ALSO +\&.\e\*q .Xr foobar 1 +\&.\e\*q .Sh STANDARDS +\&.\e\*q .Sh HISTORY +\&.\e\*q .Sh AUTHORS +\&.\e\*q .Sh CAVEATS +\&.\e\*q .Sh BUGS +\&.\e\*q .Sh SECURITY CONSIDERATIONS +.Ed +. +.Pp Subsequent SYNOPSIS and DESCRIPTION sections are strongly encouraged, but non-compulsory. . @@ -230,397 +272,408 @@ but non-compulsory. .Sh MACRO SYNTAX Macros are one to three three characters in length and begin with a control character , -. Sq \&. , +.Sq \&. , at the beginning of the line. An arbitrary amount of whitespace may sit between the control character and the macro name. Thus, -. Sq \&.Pp +.Sq \&.Pp and -. Sq \&.\ \ \ \&Pp +.Sq \&.\ \ \ \&Pp are equivalent. Macro names are two or three characters in length. -. Pp +. +.Pp The syntax of a macro depends on its classification. In this section, -. Sq \-arg +.Sq \-arg refers to macro arguments, which may be followed by zero or more -. Sq parm +.Sq parm parameters; -. Sq \&Yo +.Sq \&Yo opens the scope of a macro; and if specified, -. Sq \&Yc +.Sq \&Yc closes it out. -. Pp +. +.Pp The -. Em Callable +.Em Callable column indicates that the macro may be called subsequent to the initial line-macro. If a macro is not callable, then its invocation after the initial line macro is interpreted as opaque text, such that -. Sq \&.Fl Sh +.Sq \&.Fl Sh produces -. Sq Fl Sh . -. Pp +.Sq Fl Sh . +. +.Pp The -. Em Parsable +.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 +. +.Pp The -. Em Scope +.Em Scope column, if applicable, describes closure rules. . . -. Ss Block full-explicit +.Ss Block full-explicit Multi-line scope closed by an explicit closing macro. All macros contains bodies; only -. Pq Sq \&Bf +.Pq Sq \&Bf contains a head. -. Bd -literal -offset indent +.Bd -literal -offset indent \&.Yo \(lB\-arg \(lBparm...\(rB\(rB \(lBhead...\(rB \(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 -. It \&Bd Ta \&No Ta \&No Ta closed by \&Ed -. It \&Bf Ta \&No Ta \&No Ta closed by \&Ef -. It \&Bk Ta \&No Ta \&No Ta closed by \&Ek -. It \&Bl Ta \&No Ta \&No Ta closed by \&El -. It \&Ed Ta \&No Ta \&No Ta opened by \&Bd -. It \&Ef Ta \&No Ta \&No Ta opened by \&Bf -. It \&Ek Ta \&No Ta \&No Ta opened by \&Bk -. It \&El Ta \&No Ta \&No Ta opened by \&Bl -. El -. -. -. Ss Block full-implicit +.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 +.It \&Bd Ta \&No Ta \&No Ta closed by \&Ed +.It \&Bf Ta \&No Ta \&No Ta closed by \&Ef +.It \&Bk Ta \&No Ta \&No Ta closed by \&Ek +.It \&Bl Ta \&No Ta \&No Ta closed by \&El +.It \&Ed Ta \&No Ta \&No Ta opened by \&Bd +.It \&Ef Ta \&No Ta \&No Ta opened by \&Bf +.It \&Ek Ta \&No Ta \&No Ta opened by \&Bk +.It \&El Ta \&No Ta \&No Ta opened by \&Bl +.El +. +. +.Ss Block full-implicit Multi-line scope closed by end-of-file or implicitly by another macro. All macros have bodies; some -. Po -. Sq \&It \-bullet , -. Sq \-hyphen , -. Sq \-dash , -. Sq \-enum , -. Sq \-item -. Pc +.Po +.Sq \&It \-bullet , +.Sq \-hyphen , +.Sq \-dash , +.Sq \-enum , +.Sq \-item +.Pc don't have heads, while -. Sq \&It \-column +.Sq \&It \-column may have multiple heads. -. Bd -literal -offset indent +.Bd -literal -offset indent \&.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 -. It \&It Ta \&No Ta Yes Ta closed by \&It, \&El -. It \&Nd Ta \&No Ta \&No Ta closed by \&Sh -. It \&Sh Ta \&No Ta \&No Ta closed by \&Sh -. It \&Ss Ta \&No Ta \&No Ta closed by \&Sh, \&Ss -. El -. -. -. Ss Block partial-explicit +.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 +.It \&It Ta \&No Ta Yes Ta closed by \&It, \&El +.It \&Nd Ta \&No Ta \&No Ta closed by \&Sh +.It \&Sh Ta \&No Ta \&No Ta closed by \&Sh +.It \&Ss Ta \&No Ta \&No Ta closed by \&Sh, \&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 -. Pq So \&Fo Sc , So \&Eo Sc +.Pq So \&Fo Sc , So \&Eo Sc and/or tail -. Pq So \&Ec Sc . -. Bd -literal -offset indent +.Pq So \&Ec Sc . +.Bd -literal -offset indent \&.Yo \(lB\-arg \(lBparm...\(rB\(rB \(lBhead...\(rB \(lBbody...\(rB \&.Yc \(lBtail...\(rB \&.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 -. It \&Ac Ta Yes Ta Yes Ta opened by \&Ao -. It \&Ao Ta Yes Ta Yes Ta closed by \&Ac -. It \&Bc Ta Yes Ta Yes Ta closed by \&Bo -. It \&Bo Ta Yes Ta Yes Ta opened by \&Bc -. It \&Brc Ta Yes Ta Yes Ta opened by \&Bro -. It \&Bro Ta Yes Ta Yes Ta closed by \&Brc -. It \&Dc Ta Yes Ta Yes Ta opened by \&Do -. It \&Do Ta Yes Ta Yes Ta closed by \&Dc -. It \&Ec Ta Yes Ta Yes Ta opened by \&Eo -. It \&Eo Ta Yes Ta Yes Ta closed by \&Ec -. It \&Fc Ta Yes Ta Yes Ta opened by \&Fo -. It \&Fo Ta \&No Ta \&No Ta closed by \&Fc -. It \&Oc Ta Yes Ta Yes Ta closed by \&Oo -. It \&Oo Ta Yes Ta Yes Ta opened by \&Oc -. It \&Pc Ta Yes Ta Yes Ta closed by \&Po -. It \&Po Ta Yes Ta Yes Ta opened by \&Pc -. It \&Qc Ta Yes Ta Yes Ta opened by \&Oo -. It \&Qo Ta Yes Ta Yes Ta closed by \&Oc -. It \&Re Ta \&No Ta \&No Ta opened by \&Rs -. It \&Rs Ta \&No Ta \&No Ta closed by \&Re -. It \&Sc Ta Yes Ta Yes Ta opened by \&So -. It \&So Ta Yes Ta Yes Ta closed by \&Sc -. It \&Xc Ta Yes Ta Yes Ta opened by \&Xo -. It \&Xo Ta Yes Ta Yes Ta closed by \&Xc -. El -. -. -. Ss Block partial-implicit +.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 +.It \&Ac Ta Yes Ta Yes Ta opened by \&Ao +.It \&Ao Ta Yes Ta Yes Ta closed by \&Ac +.It \&Bc Ta Yes Ta Yes Ta closed by \&Bo +.It \&Bo Ta Yes Ta Yes Ta opened by \&Bc +.It \&Brc Ta Yes Ta Yes Ta opened by \&Bro +.It \&Bro Ta Yes Ta Yes Ta closed by \&Brc +.It \&Dc Ta Yes Ta Yes Ta opened by \&Do +.It \&Do Ta Yes Ta Yes Ta closed by \&Dc +.It \&Ec Ta Yes Ta Yes Ta opened by \&Eo +.It \&Eo Ta Yes Ta Yes Ta closed by \&Ec +.It \&Fc Ta Yes Ta Yes Ta opened by \&Fo +.It \&Fo Ta \&No Ta \&No Ta closed by \&Fc +.It \&Oc Ta Yes Ta Yes Ta closed by \&Oo +.It \&Oo Ta Yes Ta Yes Ta opened by \&Oc +.It \&Pc Ta Yes Ta Yes Ta closed by \&Po +.It \&Po Ta Yes Ta Yes Ta opened by \&Pc +.It \&Qc Ta Yes Ta Yes Ta opened by \&Oo +.It \&Qo Ta Yes Ta Yes Ta closed by \&Oc +.It \&Re Ta \&No Ta \&No Ta opened by \&Rs +.It \&Rs Ta \&No Ta \&No Ta closed by \&Re +.It \&Sc Ta Yes Ta Yes Ta opened by \&So +.It \&So Ta Yes Ta Yes Ta closed by \&Sc +.It \&Xc Ta Yes Ta Yes Ta opened by \&Xo +.It \&Xo Ta Yes Ta Yes Ta closed by \&Xc +.El +. +. +.Ss Block partial-implicit Like block full-implicit, but with single-line scope closed by -. Sx Reserved Characters +.Sx Reserved Characters or end of line. -. Bd -literal -offset indent +.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 -. It \&Aq Ta Yes Ta Yes -. It \&Bq Ta Yes Ta Yes -. It \&Brq Ta Yes Ta Yes -. It \&D1 Ta \&No Ta \&Yes -. It \&Dl Ta \&No Ta Yes -. It \&Dq Ta Yes Ta Yes -. It \&Op Ta Yes Ta Yes -. It \&Pq Ta Yes Ta Yes -. It \&Ql Ta Yes Ta Yes -. It \&Qq Ta Yes Ta Yes -. It \&Sq Ta Yes Ta Yes -. El -. -. -. Ss In-line +.Ed +. +.Pp +.Bl -column "MacroX" "CallableX" "ParsableX" -compact -offset indent +.It Em Macro Ta Em Callable Ta Em Parsable +.It \&Aq Ta Yes Ta Yes +.It \&Bq Ta Yes Ta Yes +.It \&Brq Ta Yes Ta Yes +.It \&D1 Ta \&No Ta \&Yes +.It \&Dl Ta \&No Ta Yes +.It \&Dq Ta Yes Ta Yes +.It \&Op Ta Yes Ta Yes +.It \&Pq Ta Yes Ta Yes +.It \&Ql Ta Yes Ta Yes +.It \&Qq Ta Yes Ta Yes +.It \&Sq Ta Yes Ta Yes +.El +. +. +.Ss In-line Closed by -. Sx Reserved Characters , +.Sx Reserved Characters , end of line, fixed argument lengths, and/or subsequent macros. In-line macros have only text children. If a number (or inequality) of arguments is -. Pq n , +.Pq n , then the macro accepts an arbitrary number of arguments. -. Bd -literal -offset indent +.Bd -literal -offset indent \&.Yo \(lB\-arg \(lBval...\(rB\(rB \(lBargs...\(rB \(lbres...\(rb \&.Yo \(lB\-arg \(lBval...\(rB\(rB \(lBargs...\(rB Yc... \&.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 -. It \&%A Ta \&No Ta \&No Ta >0 -. It \&%B Ta \&No Ta \&No Ta >0 -. It \&%C Ta \&No Ta \&No Ta >0 -. It \&%D Ta \&No Ta \&No Ta >0 -. It \&%I Ta \&No Ta \&No Ta >0 -. It \&%J Ta \&No Ta \&No Ta >0 -. It \&%N Ta \&No Ta \&No Ta >0 -. It \&%O Ta \&No Ta \&No Ta >0 -. It \&%P Ta \&No Ta \&No Ta >0 -. It \&%R Ta \&No Ta \&No Ta >0 -. It \&%T Ta \&No Ta \&No Ta >0 -. It \&%V Ta \&No Ta \&No Ta >0 -. It \&Ad Ta Yes Ta Yes Ta n -. It \&An Ta Yes Ta Yes Ta n -. It \&Ap Ta Yes Ta Yes Ta 0 -. It \&Ar Ta Yes Ta Yes Ta n -. It \&At Ta Yes Ta Yes Ta 1 -. It \&Bsx Ta Yes Ta Yes Ta n -. It \&Bt Ta \&No Ta \&No Ta 0 -. It \&Bx Ta Yes Ta Yes Ta n -. It \&Cd Ta Yes Ta Yes Ta >0 -. It \&Cm Ta Yes Ta Yes Ta n -. It \&Db Ta \&No Ta \&No Ta 1 -. It \&Dd Ta \&No Ta \&No Ta >0 -. It \&Dt Ta \&No Ta \&No Ta n -. It \&Dv Ta Yes Ta Yes Ta n -. It \&Dx Ta Yes Ta Yes Ta n -. It \&Em Ta Yes Ta Yes Ta >0 -. It \&En Ta \&No Ta \&No Ta 0 -. It \&Er Ta Yes Ta Yes Ta >0 -. It \&Es Ta \&No Ta \&No Ta 0 -. It \&Ev Ta Yes Ta Yes Ta n -. It \&Ex Ta \&No Ta \&No Ta 0 -. It \&Fa Ta Yes Ta Yes Ta n -. It \&Fd Ta \&No Ta \&No Ta >0 -. It \&Fl Ta Yes Ta Yes Ta n -. It \&Fn Ta Yes Ta Yes Ta >0 -. It \&Fr Ta \&No Ta \&No Ta n -. It \&Ft Ta Yes Ta Yes Ta n -. It \&Fx Ta Yes Ta Yes Ta n -. It \&Hf Ta \&No Ta \&No Ta n -. It \&Ic Ta Yes Ta Yes Ta >0 -. It \&In Ta \&No Ta \&No Ta n -. It \&Lb Ta \&No Ta \&No Ta 1 -. It \&Li Ta Yes Ta Yes Ta n -. It \&Lk Ta Yes Ta Yes Ta n -. It \&Lp Ta \&No Ta \&No Ta 0 -. It \&Ms Ta Yes Ta Yes Ta >0 -. It \&Mt Ta Yes Ta Yes Ta >0 -. It \&Nm Ta Yes Ta Yes Ta n -. It \&No Ta Yes Ta Yes Ta 0 -. It \&Ns Ta Yes Ta Yes Ta 0 -. It \&Nx Ta Yes Ta Yes Ta n -. It \&Os Ta \&No Ta \&No Ta n -. It \&Ot Ta \&No Ta \&No Ta n -. It \&Ox Ta Yes Ta Yes Ta n -. It \&Pa Ta Yes Ta Yes Ta n -. It \&Pf Ta \&No Ta Yes Ta 1 -. It \&Pp Ta \&No Ta \&No Ta 0 -. It \&Rv Ta \&No Ta \&No Ta 0 -. It \&Sm Ta \&No Ta \&No Ta 1 -. It \&St Ta \&No Ta Yes Ta 1 -. It \&Sx Ta Yes Ta Yes Ta >0 -. It \&Sy Ta Yes Ta Yes Ta >0 -. It \&Tn Ta Yes Ta Yes Ta >0 -. It \&Ud Ta \&No Ta \&No Ta 0 -. It \&Ux Ta Yes Ta Yes Ta n -. It \&Va Ta Yes Ta Yes Ta n -. It \&Vt Ta Yes Ta Yes Ta >0 -. It \&Xr Ta Yes Ta Yes Ta >0, <3 -. It \&br Ta \&No Ta \&No Ta 0 -. It \&sp Ta \&No Ta \&No Ta 1 -. El +.Ed +. +.Pp +.Bl -column "MacroX" "CallableX" "ParsableX" "Arguments" -compact -offset indent +.It Em Macro Ta Em Callable Ta Em Parsable Ta Em Arguments +.It \&%A Ta \&No Ta \&No Ta >0 +.It \&%B Ta \&No Ta \&No Ta >0 +.It \&%C Ta \&No Ta \&No Ta >0 +.It \&%D Ta \&No Ta \&No Ta >0 +.It \&%I Ta \&No Ta \&No Ta >0 +.It \&%J Ta \&No Ta \&No Ta >0 +.It \&%N Ta \&No Ta \&No Ta >0 +.It \&%O Ta \&No Ta \&No Ta >0 +.It \&%P Ta \&No Ta \&No Ta >0 +.It \&%R Ta \&No Ta \&No Ta >0 +.It \&%T Ta \&No Ta \&No Ta >0 +.It \&%V Ta \&No Ta \&No Ta >0 +.It \&Ad Ta Yes Ta Yes Ta n +.It \&An Ta Yes Ta Yes Ta n +.It \&Ap Ta Yes Ta Yes Ta 0 +.It \&Ar Ta Yes Ta Yes Ta n +.It \&At Ta Yes Ta Yes Ta 1 +.It \&Bsx Ta Yes Ta Yes Ta n +.It \&Bt Ta \&No Ta \&No Ta 0 +.It \&Bx Ta Yes Ta Yes Ta n +.It \&Cd Ta Yes Ta Yes Ta >0 +.It \&Cm Ta Yes Ta Yes Ta n +.It \&Db Ta \&No Ta \&No Ta 1 +.It \&Dd Ta \&No Ta \&No Ta >0 +.It \&Dt Ta \&No Ta \&No Ta n +.It \&Dv Ta Yes Ta Yes Ta n +.It \&Dx Ta Yes Ta Yes Ta n +.It \&Em Ta Yes Ta Yes Ta >0 +.It \&En Ta \&No Ta \&No Ta 0 +.It \&Er Ta Yes Ta Yes Ta >0 +.It \&Es Ta \&No Ta \&No Ta 0 +.It \&Ev Ta Yes Ta Yes Ta n +.It \&Ex Ta \&No Ta \&No Ta n +.It \&Fa Ta Yes Ta Yes Ta n +.It \&Fd Ta \&No Ta \&No Ta >0 +.It \&Fl Ta Yes Ta Yes Ta n +.It \&Fn Ta Yes Ta Yes Ta >0 +.It \&Fr Ta \&No Ta \&No Ta n +.It \&Ft Ta Yes Ta Yes Ta n +.It \&Fx Ta Yes Ta Yes Ta n +.It \&Hf Ta \&No Ta \&No Ta n +.It \&Ic Ta Yes Ta Yes Ta >0 +.It \&In Ta \&No Ta \&No Ta n +.It \&Lb Ta \&No Ta \&No Ta 1 +.It \&Li Ta Yes Ta Yes Ta n +.It \&Lk Ta Yes Ta Yes Ta n +.It \&Lp Ta \&No Ta \&No Ta 0 +.It \&Ms Ta Yes Ta Yes Ta >0 +.It \&Mt Ta Yes Ta Yes Ta >0 +.It \&Nm Ta Yes Ta Yes Ta n +.It \&No Ta Yes Ta Yes Ta 0 +.It \&Ns Ta Yes Ta Yes Ta 0 +.It \&Nx Ta Yes Ta Yes Ta n +.It \&Os Ta \&No Ta \&No Ta n +.It \&Ot Ta \&No Ta \&No Ta n +.It \&Ox Ta Yes Ta Yes Ta n +.It \&Pa Ta Yes Ta Yes Ta n +.It \&Pf Ta \&No Ta Yes Ta 1 +.It \&Pp Ta \&No Ta \&No Ta 0 +.It \&Rv Ta \&No Ta \&No Ta n +.It \&Sm Ta \&No Ta \&No Ta 1 +.It \&St Ta \&No Ta Yes Ta 1 +.It \&Sx Ta Yes Ta Yes Ta >0 +.It \&Sy Ta Yes Ta Yes Ta >0 +.It \&Tn Ta Yes Ta Yes Ta >0 +.It \&Ud Ta \&No Ta \&No Ta 0 +.It \&Ux Ta Yes Ta Yes Ta n +.It \&Va Ta Yes Ta Yes Ta n +.It \&Vt Ta Yes Ta Yes Ta >0 +.It \&Xr Ta Yes Ta Yes Ta >0, <3 +.It \&br Ta \&No Ta \&No Ta 0 +.It \&sp Ta \&No Ta \&No Ta 1 +.El . . .Sh COMPATIBILITY This section documents compatibility with other roff implementations, at this time limited to -. Xr groff 1 . +.Xr groff 1 . The term -. Qq historic groff +.Qq historic groff refers to those versions before the -. Pa doc.tmac +.Pa doc.tmac file re-write -. Pq somewhere between 1.15 and 1.19 . -. Pp -. Bl -dash -compact -. It +.Pq somewhere between 1.15 and 1.19 . +. +.Pp +.Bl -dash -compact +.It The -. Sq \-split +.Sq \-split or -. Sq \-nosplit +.Sq \-nosplit argument to -. Sq \&An +.Sq \&An applies to the whole document, not just to the current section as it does in groff. -. It +.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. -. It +.It The -. Sq \&sp +.Sq \&sp macro does not accept negative numbers. -. It +.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 +.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. -. It +.It The vertical bar -. Sq \(ba +.Sq \(ba made historic groff -. Qq go orbital +.Qq go orbital but is a proper delimiter in this implementation. -. It -. Sq \&It \-nested +.It +.Sq \&It \-nested is assumed for all lists (it wasn't in historic groff): any list may be nested and -. Sq \-enum +.Sq \-enum lists will restart the sequence only for the sub-list. -. It -. Sq \&It \-column +.It +.Sq \&It \-column syntax where column widths may be preceded by other arguments (instead of proceeded) is not supported. -. It +.It The -. Sq \&At +.Sq \&At macro only accepts a single parameter. -. It +.It Some manuals use -. Sq \&Li +.Sq \&Li incorrectly by following it with a reserved character and expecting the delimiter to render. This is not supported. -. It +.It In groff, the -. Sq \&Fo +.Sq \&Fo macro only produces the first parameter. This is no longer the case. -. El +.El . . .Sh SEE ALSO -. Xr mandoc 1 , -. Xr mandoc_char 7 +.Xr mandoc 1 , +.Xr mandoc_char 7 . . .Sh AUTHORS The -. Nm +.Nm reference was written by -. An Kristaps Dzonsons Aq kristaps@kth.se . +.An Kristaps Dzonsons Aq kristaps@kth.se . . . .Sh CAVEATS There are many ambiguous parts of mdoc. -. Pp -. Bl -dash -compact -. It -. Sq \&Fa +. +.Pp +.Bl -dash -compact +.It +.Sq \&Fa should be -. Sq \&Va +.Sq \&Va as function arguments are variables. -. It -. Sq \&Ft +.It +.Sq \&Ft should be -. Sq \&Vt +.Sq \&Vt as function return types are still types. Furthermore, the -. Sq \&Ft +.Sq \&Ft should be removed and -. Sq \&Fo , +.Sq \&Fo , which ostensibly follows it, should follow the same convention as -. Sq \&Va . -. It -. Sq \&Va +.Sq \&Va . +.It +.Sq \&Va should formalise that only one or two arguments are acceptable: a variable name and optional, preceding type. -. It -. Sq \&Fd +.It +.Sq \&Fd is ambiguous. It's commonly used to indicate an include file in the synopsis section. -. Sq \&In +.Sq \&In should be used, instead. -. It +.It Only the -. Sq \-literal +.Sq \-literal argument to -. Sq \&Bd +.Sq \&Bd makes sense. The remaining ones should be removed. -. It +.It The -. Sq \&Xo +.Sq \&Xo and -. Sq \&Xc +.Sq \&Xc macros should be deprecated. -. It +.It The -. Sq \&Dt +.Sq \&Dt macro lacks clarity. It should be absolutely clear which title will render when formatting the manual page. -. It +.It A -. Sq \&Lx +.Sq \&Lx should be provided for Linux (\(`a la -. Sq \&Ox , -. Sq \&Nx +.Sq \&Ox , +.Sq \&Nx etc.). -. It +.It There's no way to refer to references in -. Sq \&Rs/Re +.Sq \&Rs/Re blocks. -. It +.It The \-split and \-nosplit dictates via -. Sq \&An +.Sq \&An are re-set when entering and leaving the AUTHORS section. -. El +.El . |