xref: /minix3/external/bsd/mdocml/dist/mandoc.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	Id: mandoc.3,v 1.22 2013/10/06 17:01:52 schwarze Exp
292395e9cSLionel Sambuc.\"
392395e9cSLionel Sambuc.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
492395e9cSLionel Sambuc.\" Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
592395e9cSLionel Sambuc.\"
692395e9cSLionel Sambuc.\" Permission to use, copy, modify, and distribute this software for any
792395e9cSLionel Sambuc.\" purpose with or without fee is hereby granted, provided that the above
892395e9cSLionel Sambuc.\" copyright notice and this permission notice appear in all copies.
992395e9cSLionel Sambuc.\"
1092395e9cSLionel Sambuc.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1192395e9cSLionel Sambuc.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1292395e9cSLionel Sambuc.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1392395e9cSLionel Sambuc.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1492395e9cSLionel Sambuc.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1592395e9cSLionel Sambuc.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1692395e9cSLionel Sambuc.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1792395e9cSLionel Sambuc.\"
18*0a6a1f1dSLionel Sambuc.Dd October 6, 2013
1992395e9cSLionel Sambuc.Dt MANDOC 3
2092395e9cSLionel Sambuc.Os
2192395e9cSLionel Sambuc.Sh NAME
2292395e9cSLionel Sambuc.Nm mandoc ,
2392395e9cSLionel Sambuc.Nm mandoc_escape ,
2492395e9cSLionel Sambuc.Nm man_meta ,
2592395e9cSLionel Sambuc.Nm man_mparse ,
2692395e9cSLionel Sambuc.Nm man_node ,
2792395e9cSLionel Sambuc.Nm mchars_alloc ,
2892395e9cSLionel Sambuc.Nm mchars_free ,
2992395e9cSLionel Sambuc.Nm mchars_num2char ,
3092395e9cSLionel Sambuc.Nm mchars_num2uc ,
3192395e9cSLionel Sambuc.Nm mchars_spec2cp ,
3292395e9cSLionel Sambuc.Nm mchars_spec2str ,
3392395e9cSLionel Sambuc.Nm mdoc_meta ,
3492395e9cSLionel Sambuc.Nm mdoc_node ,
3592395e9cSLionel Sambuc.Nm mparse_alloc ,
3692395e9cSLionel Sambuc.Nm mparse_free ,
3792395e9cSLionel Sambuc.Nm mparse_getkeep ,
3892395e9cSLionel Sambuc.Nm mparse_keep ,
3992395e9cSLionel Sambuc.Nm mparse_readfd ,
4092395e9cSLionel Sambuc.Nm mparse_reset ,
4192395e9cSLionel Sambuc.Nm mparse_result ,
4292395e9cSLionel Sambuc.Nm mparse_strerror ,
4392395e9cSLionel Sambuc.Nm mparse_strlevel
4492395e9cSLionel Sambuc.Nd mandoc macro compiler library
4592395e9cSLionel Sambuc.Sh LIBRARY
46*0a6a1f1dSLionel Sambuc.Lb libmandoc
4792395e9cSLionel Sambuc.Sh SYNOPSIS
4892395e9cSLionel Sambuc.In man.h
4992395e9cSLionel Sambuc.In mdoc.h
5092395e9cSLionel Sambuc.In mandoc.h
5192395e9cSLionel Sambuc.Ft "enum mandoc_esc"
5292395e9cSLionel Sambuc.Fo mandoc_escape
53*0a6a1f1dSLionel Sambuc.Fa "const char const **end"
54*0a6a1f1dSLionel Sambuc.Fa "const char const **start"
5592395e9cSLionel Sambuc.Fa "int *sz"
5692395e9cSLionel Sambuc.Fc
5792395e9cSLionel Sambuc.Ft "const struct man_meta *"
5892395e9cSLionel Sambuc.Fo man_meta
5992395e9cSLionel Sambuc.Fa "const struct man *man"
6092395e9cSLionel Sambuc.Fc
6192395e9cSLionel Sambuc.Ft "const struct mparse *"
6292395e9cSLionel Sambuc.Fo man_mparse
6392395e9cSLionel Sambuc.Fa "const struct man *man"
6492395e9cSLionel Sambuc.Fc
6592395e9cSLionel Sambuc.Ft "const struct man_node *"
6692395e9cSLionel Sambuc.Fo man_node
6792395e9cSLionel Sambuc.Fa "const struct man *man"
6892395e9cSLionel Sambuc.Fc
6992395e9cSLionel Sambuc.Ft "struct mchars *"
70*0a6a1f1dSLionel Sambuc.Fn mchars_alloc "void"
7192395e9cSLionel Sambuc.Ft void
7292395e9cSLionel Sambuc.Fn mchars_free "struct mchars *p"
7392395e9cSLionel Sambuc.Ft char
7492395e9cSLionel Sambuc.Fn mchars_num2char "const char *cp" "size_t sz"
7592395e9cSLionel Sambuc.Ft int
7692395e9cSLionel Sambuc.Fn mchars_num2uc "const char *cp" "size_t sz"
7792395e9cSLionel Sambuc.Ft "const char *"
7892395e9cSLionel Sambuc.Fo mchars_spec2str
7992395e9cSLionel Sambuc.Fa "const struct mchars *p"
8092395e9cSLionel Sambuc.Fa "const char *cp"
8192395e9cSLionel Sambuc.Fa "size_t sz"
8292395e9cSLionel Sambuc.Fa "size_t *rsz"
8392395e9cSLionel Sambuc.Fc
8492395e9cSLionel Sambuc.Ft int
8592395e9cSLionel Sambuc.Fo mchars_spec2cp
8692395e9cSLionel Sambuc.Fa "const struct mchars *p"
8792395e9cSLionel Sambuc.Fa "const char *cp"
8892395e9cSLionel Sambuc.Fa "size_t sz"
8992395e9cSLionel Sambuc.Fc
9092395e9cSLionel Sambuc.Ft "const struct mdoc_meta *"
9192395e9cSLionel Sambuc.Fo mdoc_meta
9292395e9cSLionel Sambuc.Fa "const struct mdoc *mdoc"
9392395e9cSLionel Sambuc.Fc
9492395e9cSLionel Sambuc.Ft "const struct mdoc_node *"
9592395e9cSLionel Sambuc.Fo mdoc_node
9692395e9cSLionel Sambuc.Fa "const struct mdoc *mdoc"
9792395e9cSLionel Sambuc.Fc
9892395e9cSLionel Sambuc.Ft void
9992395e9cSLionel Sambuc.Fo mparse_alloc
10092395e9cSLionel Sambuc.Fa "enum mparset type"
10192395e9cSLionel Sambuc.Fa "enum mandoclevel wlevel"
10292395e9cSLionel Sambuc.Fa "mandocmsg msg"
10392395e9cSLionel Sambuc.Fa "void *msgarg"
10492395e9cSLionel Sambuc.Fc
10592395e9cSLionel Sambuc.Ft void
10692395e9cSLionel Sambuc.Fo mparse_free
10792395e9cSLionel Sambuc.Fa "struct mparse *parse"
10892395e9cSLionel Sambuc.Fc
10992395e9cSLionel Sambuc.Ft void
11092395e9cSLionel Sambuc.Fo mparse_getkeep
11192395e9cSLionel Sambuc.Fa "const struct mparse *parse"
11292395e9cSLionel Sambuc.Fc
11392395e9cSLionel Sambuc.Ft void
11492395e9cSLionel Sambuc.Fo mparse_keep
11592395e9cSLionel Sambuc.Fa "struct mparse *parse"
11692395e9cSLionel Sambuc.Fc
11792395e9cSLionel Sambuc.Ft "enum mandoclevel"
11892395e9cSLionel Sambuc.Fo mparse_readfd
11992395e9cSLionel Sambuc.Fa "struct mparse *parse"
12092395e9cSLionel Sambuc.Fa "int fd"
12192395e9cSLionel Sambuc.Fa "const char *fname"
12292395e9cSLionel Sambuc.Fc
12392395e9cSLionel Sambuc.Ft void
12492395e9cSLionel Sambuc.Fo mparse_reset
12592395e9cSLionel Sambuc.Fa "struct mparse *parse"
12692395e9cSLionel Sambuc.Fc
12792395e9cSLionel Sambuc.Ft void
12892395e9cSLionel Sambuc.Fo mparse_result
12992395e9cSLionel Sambuc.Fa "struct mparse *parse"
13092395e9cSLionel Sambuc.Fa "struct mdoc **mdoc"
13192395e9cSLionel Sambuc.Fa "struct man **man"
13292395e9cSLionel Sambuc.Fc
13392395e9cSLionel Sambuc.Ft "const char *"
13492395e9cSLionel Sambuc.Fo mparse_strerror
13592395e9cSLionel Sambuc.Fa "enum mandocerr"
13692395e9cSLionel Sambuc.Fc
13792395e9cSLionel Sambuc.Ft "const char *"
13892395e9cSLionel Sambuc.Fo mparse_strlevel
13992395e9cSLionel Sambuc.Fa "enum mandoclevel"
14092395e9cSLionel Sambuc.Fc
14192395e9cSLionel Sambuc.Vt extern const char * const * man_macronames;
14292395e9cSLionel Sambuc.Vt extern const char * const * mdoc_argnames;
14392395e9cSLionel Sambuc.Vt extern const char * const * mdoc_macronames;
14492395e9cSLionel Sambuc.Fd "#define ASCII_NBRSP"
14592395e9cSLionel Sambuc.Fd "#define ASCII_HYPH"
14692395e9cSLionel Sambuc.Sh DESCRIPTION
14792395e9cSLionel SambucThe
14892395e9cSLionel Sambuc.Nm mandoc
14992395e9cSLionel Sambuclibrary parses a
15092395e9cSLionel Sambuc.Ux
15192395e9cSLionel Sambucmanual into an abstract syntax tree (AST).
15292395e9cSLionel Sambuc.Ux
15392395e9cSLionel Sambucmanuals are composed of
15492395e9cSLionel Sambuc.Xr mdoc 7
15592395e9cSLionel Sambucor
15692395e9cSLionel Sambuc.Xr man 7 ,
15792395e9cSLionel Sambucand may be mixed with
15892395e9cSLionel Sambuc.Xr roff 7 ,
15992395e9cSLionel Sambuc.Xr tbl 7 ,
16092395e9cSLionel Sambucand
16192395e9cSLionel Sambuc.Xr eqn 7
16292395e9cSLionel Sambucinvocations.
16392395e9cSLionel Sambuc.Pp
16492395e9cSLionel SambucThe following describes a general parse sequence:
16592395e9cSLionel Sambuc.Bl -enum
16692395e9cSLionel Sambuc.It
16792395e9cSLionel Sambucinitiate a parsing sequence with
16892395e9cSLionel Sambuc.Fn mparse_alloc ;
16992395e9cSLionel Sambuc.It
17092395e9cSLionel Sambucparse files or file descriptors with
17192395e9cSLionel Sambuc.Fn mparse_readfd ;
17292395e9cSLionel Sambuc.It
17392395e9cSLionel Sambucretrieve a parsed syntax tree, if the parse was successful, with
17492395e9cSLionel Sambuc.Fn mparse_result ;
17592395e9cSLionel Sambuc.It
17692395e9cSLionel Sambuciterate over parse nodes with
17792395e9cSLionel Sambuc.Fn mdoc_node
17892395e9cSLionel Sambucor
17992395e9cSLionel Sambuc.Fn man_node ;
18092395e9cSLionel Sambuc.It
18192395e9cSLionel Sambucfree all allocated memory with
18292395e9cSLionel Sambuc.Fn mparse_free ,
18392395e9cSLionel Sambucor invoke
18492395e9cSLionel Sambuc.Fn mparse_reset
18592395e9cSLionel Sambucand parse new files.
18692395e9cSLionel Sambuc.El
18792395e9cSLionel Sambuc.Pp
18892395e9cSLionel SambucThe
18992395e9cSLionel Sambuc.Nm
19092395e9cSLionel Sambuclibrary also contains routines for translating character strings into glyphs
19192395e9cSLionel Sambuc.Pq see Fn mchars_alloc
19292395e9cSLionel Sambucand parsing escape sequences from strings
19392395e9cSLionel Sambuc.Pq see Fn mandoc_escape .
19492395e9cSLionel Sambuc.Sh REFERENCE
19592395e9cSLionel SambucThis section documents the functions, types, and variables available
19692395e9cSLionel Sambucvia
19792395e9cSLionel Sambuc.In mandoc.h .
19892395e9cSLionel Sambuc.Ss Types
19992395e9cSLionel Sambuc.Bl -ohang
20092395e9cSLionel Sambuc.It Vt "enum mandoc_esc"
20192395e9cSLionel SambucAn escape sequence classification.
20292395e9cSLionel Sambuc.It Vt "enum mandocerr"
20392395e9cSLionel SambucA fatal error, error, or warning message during parsing.
20492395e9cSLionel Sambuc.It Vt "enum mandoclevel"
20592395e9cSLionel SambucA classification of an
20692395e9cSLionel Sambuc.Vt "enum mandoclevel"
20792395e9cSLionel Sambucas regards system operation.
20892395e9cSLionel Sambuc.It Vt "struct mchars"
20992395e9cSLionel SambucAn opaque pointer to an object allowing for translation between
21092395e9cSLionel Sambuccharacter strings and glyphs.
21192395e9cSLionel SambucSee
21292395e9cSLionel Sambuc.Fn mchars_alloc .
21392395e9cSLionel Sambuc.It Vt "enum mparset"
21492395e9cSLionel SambucThe type of parser when reading input.
21592395e9cSLionel SambucThis should usually be
21692395e9cSLionel Sambuc.Dv MPARSE_AUTO
21792395e9cSLionel Sambucfor auto-detection.
21892395e9cSLionel Sambuc.It Vt "struct mparse"
21992395e9cSLionel SambucAn opaque pointer to a running parse sequence.
22092395e9cSLionel SambucCreated with
22192395e9cSLionel Sambuc.Fn mparse_alloc
22292395e9cSLionel Sambucand freed with
22392395e9cSLionel Sambuc.Fn mparse_free .
22492395e9cSLionel SambucThis may be used across parsed input if
22592395e9cSLionel Sambuc.Fn mparse_reset
22692395e9cSLionel Sambucis called between parses.
22792395e9cSLionel Sambuc.It Vt "mandocmsg"
22892395e9cSLionel SambucA prototype for a function to handle fatal error, error, and warning
22992395e9cSLionel Sambucmessages emitted by the parser.
23092395e9cSLionel Sambuc.El
23192395e9cSLionel Sambuc.Ss Functions
23292395e9cSLionel Sambuc.Bl -ohang
23392395e9cSLionel Sambuc.It Fn mandoc_escape
23492395e9cSLionel SambucScan an escape sequence, i.e., a character string beginning with
23592395e9cSLionel Sambuc.Sq \e .
23692395e9cSLionel SambucPass a pointer to the character after the
23792395e9cSLionel Sambuc.Sq \e
23892395e9cSLionel Sambucas
23992395e9cSLionel Sambuc.Va end ;
24092395e9cSLionel Sambucit will be set to the supremum of the parsed escape sequence unless
24192395e9cSLionel Sambucreturning
24292395e9cSLionel Sambuc.Dv ESCAPE_ERROR ,
24392395e9cSLionel Sambucin which case the string is bogus and should be
24492395e9cSLionel Sambucthrown away.
24592395e9cSLionel SambucIf not
24692395e9cSLionel Sambuc.Dv ESCAPE_ERROR
24792395e9cSLionel Sambucor
24892395e9cSLionel Sambuc.Dv ESCAPE_IGNORE ,
24992395e9cSLionel Sambuc.Va start
25092395e9cSLionel Sambucis set to the first relevant character of the substring (font, glyph,
25192395e9cSLionel Sambucwhatever) of length
25292395e9cSLionel Sambuc.Va sz .
25392395e9cSLionel SambucBoth
25492395e9cSLionel Sambuc.Va start
25592395e9cSLionel Sambucand
25692395e9cSLionel Sambuc.Va sz
25792395e9cSLionel Sambucmay be
25892395e9cSLionel Sambuc.Dv NULL .
259*0a6a1f1dSLionel SambucDeclared in
260*0a6a1f1dSLionel Sambuc.In mandoc.h ,
261*0a6a1f1dSLionel Sambucimplemented in
262*0a6a1f1dSLionel Sambuc.Pa mandoc.c .
26392395e9cSLionel Sambuc.It Fn man_meta
26492395e9cSLionel SambucObtain the meta-data of a successful parse.
26592395e9cSLionel SambucThis may only be used on a pointer returned by
26692395e9cSLionel Sambuc.Fn mparse_result .
267*0a6a1f1dSLionel SambucDeclared in
268*0a6a1f1dSLionel Sambuc.In man.h ,
269*0a6a1f1dSLionel Sambucimplemented in
270*0a6a1f1dSLionel Sambuc.Pa man.c .
27192395e9cSLionel Sambuc.It Fn man_mparse
27292395e9cSLionel SambucGet the parser used for the current output.
273*0a6a1f1dSLionel SambucDeclared in
274*0a6a1f1dSLionel Sambuc.In man.h ,
275*0a6a1f1dSLionel Sambucimplemented in
276*0a6a1f1dSLionel Sambuc.Pa man.c .
27792395e9cSLionel Sambuc.It Fn man_node
27892395e9cSLionel SambucObtain the root node of a successful parse.
27992395e9cSLionel SambucThis may only be used on a pointer returned by
28092395e9cSLionel Sambuc.Fn mparse_result .
281*0a6a1f1dSLionel SambucDeclared in
282*0a6a1f1dSLionel Sambuc.In man.h ,
283*0a6a1f1dSLionel Sambucimplemented in
284*0a6a1f1dSLionel Sambuc.Pa man.c .
28592395e9cSLionel Sambuc.It Fn mchars_alloc
28692395e9cSLionel SambucAllocate an
28792395e9cSLionel Sambuc.Vt "struct mchars *"
28892395e9cSLionel Sambucobject for translating special characters into glyphs.
28992395e9cSLionel SambucSee
29092395e9cSLionel Sambuc.Xr mandoc_char 7
29192395e9cSLionel Sambucfor an overview of special characters.
29292395e9cSLionel SambucThe object must be freed with
29392395e9cSLionel Sambuc.Fn mchars_free .
294*0a6a1f1dSLionel SambucDeclared in
295*0a6a1f1dSLionel Sambuc.In mandoc.h ,
296*0a6a1f1dSLionel Sambucimplemented in
297*0a6a1f1dSLionel Sambuc.Pa chars.c .
29892395e9cSLionel Sambuc.It Fn mchars_free
29992395e9cSLionel SambucFree an object created with
30092395e9cSLionel Sambuc.Fn mchars_alloc .
301*0a6a1f1dSLionel SambucDeclared in
302*0a6a1f1dSLionel Sambuc.In mandoc.h ,
303*0a6a1f1dSLionel Sambucimplemented in
304*0a6a1f1dSLionel Sambuc.Pa chars.c .
30592395e9cSLionel Sambuc.It Fn mchars_num2char
30692395e9cSLionel SambucConvert a character index (e.g., the \eN\(aq\(aq escape) into a
30792395e9cSLionel Sambucprintable ASCII character.
30892395e9cSLionel SambucReturns \e0 (the nil character) if the input sequence is malformed.
309*0a6a1f1dSLionel SambucDeclared in
310*0a6a1f1dSLionel Sambuc.In mandoc.h ,
311*0a6a1f1dSLionel Sambucimplemented in
312*0a6a1f1dSLionel Sambuc.Pa chars.c .
31392395e9cSLionel Sambuc.It Fn mchars_num2uc
31492395e9cSLionel SambucConvert a hexadecimal character index (e.g., the \e[uNNNN] escape) into
31592395e9cSLionel Sambuca Unicode codepoint.
31692395e9cSLionel SambucReturns \e0 (the nil character) if the input sequence is malformed.
317*0a6a1f1dSLionel SambucDeclared in
318*0a6a1f1dSLionel Sambuc.In mandoc.h ,
319*0a6a1f1dSLionel Sambucimplemented in
320*0a6a1f1dSLionel Sambuc.Pa chars.c .
32192395e9cSLionel Sambuc.It Fn mchars_spec2cp
32292395e9cSLionel SambucConvert a special character into a valid Unicode codepoint.
32392395e9cSLionel SambucReturns \-1 on failure or a non-zero Unicode codepoint on success.
324*0a6a1f1dSLionel SambucDeclared in
325*0a6a1f1dSLionel Sambuc.In mandoc.h ,
326*0a6a1f1dSLionel Sambucimplemented in
327*0a6a1f1dSLionel Sambuc.Pa chars.c .
32892395e9cSLionel Sambuc.It Fn mchars_spec2str
32992395e9cSLionel SambucConvert a special character into an ASCII string.
33092395e9cSLionel SambucReturns
33192395e9cSLionel Sambuc.Dv NULL
33292395e9cSLionel Sambucon failure.
333*0a6a1f1dSLionel SambucDeclared in
334*0a6a1f1dSLionel Sambuc.In mandoc.h ,
335*0a6a1f1dSLionel Sambucimplemented in
336*0a6a1f1dSLionel Sambuc.Pa chars.c .
33792395e9cSLionel Sambuc.It Fn mdoc_meta
33892395e9cSLionel SambucObtain the meta-data of a successful parse.
33992395e9cSLionel SambucThis may only be used on a pointer returned by
34092395e9cSLionel Sambuc.Fn mparse_result .
341*0a6a1f1dSLionel SambucDeclared in
342*0a6a1f1dSLionel Sambuc.In mdoc.h ,
343*0a6a1f1dSLionel Sambucimplemented in
344*0a6a1f1dSLionel Sambuc.Pa mdoc.c .
34592395e9cSLionel Sambuc.It Fn mdoc_node
34692395e9cSLionel SambucObtain the root node of a successful parse.
34792395e9cSLionel SambucThis may only be used on a pointer returned by
34892395e9cSLionel Sambuc.Fn mparse_result .
349*0a6a1f1dSLionel SambucDeclared in
350*0a6a1f1dSLionel Sambuc.In mdoc.h ,
351*0a6a1f1dSLionel Sambucimplemented in
352*0a6a1f1dSLionel Sambuc.Pa mdoc.c .
35392395e9cSLionel Sambuc.It Fn mparse_alloc
35492395e9cSLionel SambucAllocate a parser.
35592395e9cSLionel SambucThe same parser may be used for multiple files so long as
35692395e9cSLionel Sambuc.Fn mparse_reset
35792395e9cSLionel Sambucis called between parses.
35892395e9cSLionel Sambuc.Fn mparse_free
35992395e9cSLionel Sambucmust be called to free the memory allocated by this function.
360*0a6a1f1dSLionel SambucDeclared in
361*0a6a1f1dSLionel Sambuc.In mandoc.h ,
362*0a6a1f1dSLionel Sambucimplemented in
363*0a6a1f1dSLionel Sambuc.Pa read.c .
36492395e9cSLionel Sambuc.It Fn mparse_free
36592395e9cSLionel SambucFree all memory allocated by
36692395e9cSLionel Sambuc.Fn mparse_alloc .
367*0a6a1f1dSLionel SambucDeclared in
368*0a6a1f1dSLionel Sambuc.In mandoc.h ,
369*0a6a1f1dSLionel Sambucimplemented in
370*0a6a1f1dSLionel Sambuc.Pa read.c .
37192395e9cSLionel Sambuc.It Fn mparse_getkeep
37292395e9cSLionel SambucAcquire the keep buffer.
37392395e9cSLionel SambucMust follow a call of
37492395e9cSLionel Sambuc.Fn mparse_keep .
375*0a6a1f1dSLionel SambucDeclared in
376*0a6a1f1dSLionel Sambuc.In mandoc.h ,
377*0a6a1f1dSLionel Sambucimplemented in
378*0a6a1f1dSLionel Sambuc.Pa read.c .
37992395e9cSLionel Sambuc.It Fn mparse_keep
38092395e9cSLionel SambucInstruct the parser to retain a copy of its parsed input.
38192395e9cSLionel SambucThis can be acquired with subsequent
38292395e9cSLionel Sambuc.Fn mparse_getkeep
38392395e9cSLionel Sambuccalls.
384*0a6a1f1dSLionel SambucDeclared in
385*0a6a1f1dSLionel Sambuc.In mandoc.h ,
386*0a6a1f1dSLionel Sambucimplemented in
387*0a6a1f1dSLionel Sambuc.Pa read.c .
38892395e9cSLionel Sambuc.It Fn mparse_readfd
38992395e9cSLionel SambucParse a file or file descriptor.
39092395e9cSLionel SambucIf
39192395e9cSLionel Sambuc.Va fd
39292395e9cSLionel Sambucis -1,
39392395e9cSLionel Sambuc.Va fname
39492395e9cSLionel Sambucis opened for reading.
39592395e9cSLionel SambucOtherwise,
39692395e9cSLionel Sambuc.Va fname
39792395e9cSLionel Sambucis assumed to be the name associated with
39892395e9cSLionel Sambuc.Va fd .
39992395e9cSLionel SambucThis may be called multiple times with different parameters; however,
40092395e9cSLionel Sambuc.Fn mparse_reset
40192395e9cSLionel Sambucshould be invoked between parses.
402*0a6a1f1dSLionel SambucDeclared in
403*0a6a1f1dSLionel Sambuc.In mandoc.h ,
404*0a6a1f1dSLionel Sambucimplemented in
405*0a6a1f1dSLionel Sambuc.Pa read.c .
40692395e9cSLionel Sambuc.It Fn mparse_reset
40792395e9cSLionel SambucReset a parser so that
40892395e9cSLionel Sambuc.Fn mparse_readfd
40992395e9cSLionel Sambucmay be used again.
410*0a6a1f1dSLionel SambucDeclared in
411*0a6a1f1dSLionel Sambuc.In mandoc.h ,
412*0a6a1f1dSLionel Sambucimplemented in
413*0a6a1f1dSLionel Sambuc.Pa read.c .
41492395e9cSLionel Sambuc.It Fn mparse_result
41592395e9cSLionel SambucObtain the result of a parse.
41692395e9cSLionel SambucOnly successful parses
41792395e9cSLionel Sambuc.Po
41892395e9cSLionel Sambuci.e., those where
41992395e9cSLionel Sambuc.Fn mparse_readfd
42092395e9cSLionel Sambucreturned less than MANDOCLEVEL_FATAL
42192395e9cSLionel Sambuc.Pc
42292395e9cSLionel Sambucshould invoke this function, in which case one of the two pointers will
42392395e9cSLionel Sambucbe filled in.
424*0a6a1f1dSLionel SambucDeclared in
425*0a6a1f1dSLionel Sambuc.In mandoc.h ,
426*0a6a1f1dSLionel Sambucimplemented in
427*0a6a1f1dSLionel Sambuc.Pa read.c .
42892395e9cSLionel Sambuc.It Fn mparse_strerror
42992395e9cSLionel SambucReturn a statically-allocated string representation of an error code.
430*0a6a1f1dSLionel SambucDeclared in
431*0a6a1f1dSLionel Sambuc.In mandoc.h ,
432*0a6a1f1dSLionel Sambucimplemented in
433*0a6a1f1dSLionel Sambuc.Pa read.c .
43492395e9cSLionel Sambuc.It Fn mparse_strlevel
43592395e9cSLionel SambucReturn a statically-allocated string representation of a level code.
436*0a6a1f1dSLionel SambucDeclared in
437*0a6a1f1dSLionel Sambuc.In mandoc.h ,
438*0a6a1f1dSLionel Sambucimplemented in
439*0a6a1f1dSLionel Sambuc.Pa read.c .
44092395e9cSLionel Sambuc.El
44192395e9cSLionel Sambuc.Ss Variables
44292395e9cSLionel Sambuc.Bl -ohang
44392395e9cSLionel Sambuc.It Va man_macronames
44492395e9cSLionel SambucThe string representation of a man macro as indexed by
44592395e9cSLionel Sambuc.Vt "enum mant" .
44692395e9cSLionel Sambuc.It Va mdoc_argnames
44792395e9cSLionel SambucThe string representation of a mdoc macro argument as indexed by
44892395e9cSLionel Sambuc.Vt "enum mdocargt" .
44992395e9cSLionel Sambuc.It Va mdoc_macronames
45092395e9cSLionel SambucThe string representation of a mdoc macro as indexed by
45192395e9cSLionel Sambuc.Vt "enum mdoct" .
45292395e9cSLionel Sambuc.El
45392395e9cSLionel Sambuc.Sh IMPLEMENTATION NOTES
45492395e9cSLionel SambucThis section consists of structural documentation for
45592395e9cSLionel Sambuc.Xr mdoc 7
45692395e9cSLionel Sambucand
45792395e9cSLionel Sambuc.Xr man 7
45892395e9cSLionel Sambucsyntax trees and strings.
45992395e9cSLionel Sambuc.Ss Man and Mdoc Strings
46092395e9cSLionel SambucStrings may be extracted from mdoc and man meta-data, or from text
46192395e9cSLionel Sambucnodes (MDOC_TEXT and MAN_TEXT, respectively).
46292395e9cSLionel SambucThese strings have special non-printing formatting cues embedded in the
46392395e9cSLionel Sambuctext itself, as well as
46492395e9cSLionel Sambuc.Xr roff 7
46592395e9cSLionel Sambucescapes preserved from input.
46692395e9cSLionel SambucImplementing systems will need to handle both situations to produce
46792395e9cSLionel Sambuchuman-readable text.
46892395e9cSLionel SambucIn general, strings may be assumed to consist of 7-bit ASCII characters.
46992395e9cSLionel Sambuc.Pp
47092395e9cSLionel SambucThe following non-printing characters may be embedded in text strings:
47192395e9cSLionel Sambuc.Bl -tag -width Ds
47292395e9cSLionel Sambuc.It Dv ASCII_NBRSP
47392395e9cSLionel SambucA non-breaking space character.
47492395e9cSLionel Sambuc.It Dv ASCII_HYPH
47592395e9cSLionel SambucA soft hyphen.
47692395e9cSLionel Sambuc.El
47792395e9cSLionel Sambuc.Pp
47892395e9cSLionel SambucEscape characters are also passed verbatim into text strings.
47992395e9cSLionel SambucAn escape character is a sequence of characters beginning with the
48092395e9cSLionel Sambucbackslash
48192395e9cSLionel Sambuc.Pq Sq \e .
48292395e9cSLionel SambucTo construct human-readable text, these should be intercepted with
48392395e9cSLionel Sambuc.Fn mandoc_escape
48492395e9cSLionel Sambucand converted with one of
48592395e9cSLionel Sambuc.Fn mchars_num2char ,
48692395e9cSLionel Sambuc.Fn mchars_spec2str ,
48792395e9cSLionel Sambucand so on.
48892395e9cSLionel Sambuc.Ss Man Abstract Syntax Tree
48992395e9cSLionel SambucThis AST is governed by the ontological rules dictated in
49092395e9cSLionel Sambuc.Xr man 7
49192395e9cSLionel Sambucand derives its terminology accordingly.
49292395e9cSLionel Sambuc.Pp
49392395e9cSLionel SambucThe AST is composed of
49492395e9cSLionel Sambuc.Vt struct man_node
49592395e9cSLionel Sambucnodes with element, root and text types as declared by the
49692395e9cSLionel Sambuc.Va type
49792395e9cSLionel Sambucfield.
49892395e9cSLionel SambucEach node also provides its parse point (the
49992395e9cSLionel Sambuc.Va line ,
50092395e9cSLionel Sambuc.Va sec ,
50192395e9cSLionel Sambucand
50292395e9cSLionel Sambuc.Va pos
50392395e9cSLionel Sambucfields), its position in the tree (the
50492395e9cSLionel Sambuc.Va parent ,
50592395e9cSLionel Sambuc.Va child ,
50692395e9cSLionel Sambuc.Va next
50792395e9cSLionel Sambucand
50892395e9cSLionel Sambuc.Va prev
50992395e9cSLionel Sambucfields) and some type-specific data.
51092395e9cSLionel Sambuc.Pp
51192395e9cSLionel SambucThe tree itself is arranged according to the following normal form,
51292395e9cSLionel Sambucwhere capitalised non-terminals represent nodes.
51392395e9cSLionel Sambuc.Pp
51492395e9cSLionel Sambuc.Bl -tag -width "ELEMENTXX" -compact
51592395e9cSLionel Sambuc.It ROOT
51692395e9cSLionel Sambuc\(<- mnode+
51792395e9cSLionel Sambuc.It mnode
51892395e9cSLionel Sambuc\(<- ELEMENT | TEXT | BLOCK
51992395e9cSLionel Sambuc.It BLOCK
52092395e9cSLionel Sambuc\(<- HEAD BODY
52192395e9cSLionel Sambuc.It HEAD
52292395e9cSLionel Sambuc\(<- mnode*
52392395e9cSLionel Sambuc.It BODY
52492395e9cSLionel Sambuc\(<- mnode*
52592395e9cSLionel Sambuc.It ELEMENT
52692395e9cSLionel Sambuc\(<- ELEMENT | TEXT*
52792395e9cSLionel Sambuc.It TEXT
52892395e9cSLionel Sambuc\(<- [[:ascii:]]*
52992395e9cSLionel Sambuc.El
53092395e9cSLionel Sambuc.Pp
53192395e9cSLionel SambucThe only elements capable of nesting other elements are those with
53292395e9cSLionel Sambucnext-lint scope as documented in
53392395e9cSLionel Sambuc.Xr man 7 .
53492395e9cSLionel Sambuc.Ss Mdoc Abstract Syntax Tree
53592395e9cSLionel SambucThis AST is governed by the ontological
53692395e9cSLionel Sambucrules dictated in
53792395e9cSLionel Sambuc.Xr mdoc 7
53892395e9cSLionel Sambucand derives its terminology accordingly.
53992395e9cSLionel Sambuc.Qq In-line
54092395e9cSLionel Sambucelements described in
54192395e9cSLionel Sambuc.Xr mdoc 7
54292395e9cSLionel Sambucare described simply as
54392395e9cSLionel Sambuc.Qq elements .
54492395e9cSLionel Sambuc.Pp
54592395e9cSLionel SambucThe AST is composed of
54692395e9cSLionel Sambuc.Vt struct mdoc_node
54792395e9cSLionel Sambucnodes with block, head, body, element, root and text types as declared
54892395e9cSLionel Sambucby the
54992395e9cSLionel Sambuc.Va type
55092395e9cSLionel Sambucfield.
55192395e9cSLionel SambucEach node also provides its parse point (the
55292395e9cSLionel Sambuc.Va line ,
55392395e9cSLionel Sambuc.Va sec ,
55492395e9cSLionel Sambucand
55592395e9cSLionel Sambuc.Va pos
55692395e9cSLionel Sambucfields), its position in the tree (the
55792395e9cSLionel Sambuc.Va parent ,
55892395e9cSLionel Sambuc.Va child ,
55992395e9cSLionel Sambuc.Va nchild ,
56092395e9cSLionel Sambuc.Va next
56192395e9cSLionel Sambucand
56292395e9cSLionel Sambuc.Va prev
56392395e9cSLionel Sambucfields) and some type-specific data, in particular, for nodes generated
56492395e9cSLionel Sambucfrom macros, the generating macro in the
56592395e9cSLionel Sambuc.Va tok
56692395e9cSLionel Sambucfield.
56792395e9cSLionel Sambuc.Pp
56892395e9cSLionel SambucThe tree itself is arranged according to the following normal form,
56992395e9cSLionel Sambucwhere capitalised non-terminals represent nodes.
57092395e9cSLionel Sambuc.Pp
57192395e9cSLionel Sambuc.Bl -tag -width "ELEMENTXX" -compact
57292395e9cSLionel Sambuc.It ROOT
57392395e9cSLionel Sambuc\(<- mnode+
57492395e9cSLionel Sambuc.It mnode
57592395e9cSLionel Sambuc\(<- BLOCK | ELEMENT | TEXT
57692395e9cSLionel Sambuc.It BLOCK
57792395e9cSLionel Sambuc\(<- HEAD [TEXT] (BODY [TEXT])+ [TAIL [TEXT]]
57892395e9cSLionel Sambuc.It ELEMENT
57992395e9cSLionel Sambuc\(<- TEXT*
58092395e9cSLionel Sambuc.It HEAD
58192395e9cSLionel Sambuc\(<- mnode*
58292395e9cSLionel Sambuc.It BODY
58392395e9cSLionel Sambuc\(<- mnode* [ENDBODY mnode*]
58492395e9cSLionel Sambuc.It TAIL
58592395e9cSLionel Sambuc\(<- mnode*
58692395e9cSLionel Sambuc.It TEXT
58792395e9cSLionel Sambuc\(<- [[:ascii:]]*
58892395e9cSLionel Sambuc.El
58992395e9cSLionel Sambuc.Pp
59092395e9cSLionel SambucOf note are the TEXT nodes following the HEAD, BODY and TAIL nodes of
59192395e9cSLionel Sambucthe BLOCK production: these refer to punctuation marks.
59292395e9cSLionel SambucFurthermore, although a TEXT node will generally have a non-zero-length
59392395e9cSLionel Sambucstring, in the specific case of
59492395e9cSLionel Sambuc.Sq \&.Bd \-literal ,
59592395e9cSLionel Sambucan empty line will produce a zero-length string.
59692395e9cSLionel SambucMultiple body parts are only found in invocations of
59792395e9cSLionel Sambuc.Sq \&Bl \-column ,
59892395e9cSLionel Sambucwhere a new body introduces a new phrase.
59992395e9cSLionel Sambuc.Pp
60092395e9cSLionel SambucThe
60192395e9cSLionel Sambuc.Xr mdoc 7
60292395e9cSLionel Sambucsyntax tree accommodates for broken block structures as well.
60392395e9cSLionel SambucThe ENDBODY node is available to end the formatting associated
60492395e9cSLionel Sambucwith a given block before the physical end of that block.
60592395e9cSLionel SambucIt has a non-null
60692395e9cSLionel Sambuc.Va end
60792395e9cSLionel Sambucfield, is of the BODY
60892395e9cSLionel Sambuc.Va type ,
60992395e9cSLionel Sambuchas the same
61092395e9cSLionel Sambuc.Va tok
61192395e9cSLionel Sambucas the BLOCK it is ending, and has a
61292395e9cSLionel Sambuc.Va pending
61392395e9cSLionel Sambucfield pointing to that BLOCK's BODY node.
61492395e9cSLionel SambucIt is an indirect child of that BODY node
61592395e9cSLionel Sambucand has no children of its own.
61692395e9cSLionel Sambuc.Pp
61792395e9cSLionel SambucAn ENDBODY node is generated when a block ends while one of its child
61892395e9cSLionel Sambucblocks is still open, like in the following example:
61992395e9cSLionel Sambuc.Bd -literal -offset indent
62092395e9cSLionel Sambuc\&.Ao ao
62192395e9cSLionel Sambuc\&.Bo bo ac
62292395e9cSLionel Sambuc\&.Ac bc
62392395e9cSLionel Sambuc\&.Bc end
62492395e9cSLionel Sambuc.Ed
62592395e9cSLionel Sambuc.Pp
62692395e9cSLionel SambucThis example results in the following block structure:
62792395e9cSLionel Sambuc.Bd -literal -offset indent
62892395e9cSLionel SambucBLOCK Ao
62992395e9cSLionel Sambuc    HEAD Ao
63092395e9cSLionel Sambuc    BODY Ao
63192395e9cSLionel Sambuc        TEXT ao
63292395e9cSLionel Sambuc        BLOCK Bo, pending -> Ao
63392395e9cSLionel Sambuc            HEAD Bo
63492395e9cSLionel Sambuc            BODY Bo
63592395e9cSLionel Sambuc                TEXT bo
63692395e9cSLionel Sambuc                TEXT ac
63792395e9cSLionel Sambuc                ENDBODY Ao, pending -> Ao
63892395e9cSLionel Sambuc                TEXT bc
63992395e9cSLionel SambucTEXT end
64092395e9cSLionel Sambuc.Ed
64192395e9cSLionel Sambuc.Pp
64292395e9cSLionel SambucHere, the formatting of the
64392395e9cSLionel Sambuc.Sq \&Ao
64492395e9cSLionel Sambucblock extends from TEXT ao to TEXT ac,
64592395e9cSLionel Sambucwhile the formatting of the
64692395e9cSLionel Sambuc.Sq \&Bo
64792395e9cSLionel Sambucblock extends from TEXT bo to TEXT bc.
64892395e9cSLionel SambucIt renders as follows in
64992395e9cSLionel Sambuc.Fl T Ns Cm ascii
65092395e9cSLionel Sambucmode:
65192395e9cSLionel Sambuc.Pp
65292395e9cSLionel Sambuc.Dl <ao [bo ac> bc] end
65392395e9cSLionel Sambuc.Pp
65492395e9cSLionel SambucSupport for badly-nested blocks is only provided for backward
65592395e9cSLionel Sambuccompatibility with some older
65692395e9cSLionel Sambuc.Xr mdoc 7
65792395e9cSLionel Sambucimplementations.
65892395e9cSLionel SambucUsing badly-nested blocks is
65992395e9cSLionel Sambuc.Em strongly discouraged ;
66092395e9cSLionel Sambucfor example, the
66192395e9cSLionel Sambuc.Fl T Ns Cm html
66292395e9cSLionel Sambucand
66392395e9cSLionel Sambuc.Fl T Ns Cm xhtml
66492395e9cSLionel Sambucfront-ends to
66592395e9cSLionel Sambuc.Xr mandoc 1
66692395e9cSLionel Sambucare unable to render them in any meaningful way.
66792395e9cSLionel SambucFurthermore, behaviour when encountering badly-nested blocks is not
66892395e9cSLionel Sambucconsistent across troff implementations, especially when using  multiple
66992395e9cSLionel Sambuclevels of badly-nested blocks.
67092395e9cSLionel Sambuc.Sh SEE ALSO
67192395e9cSLionel Sambuc.Xr mandoc 1 ,
67292395e9cSLionel Sambuc.Xr eqn 7 ,
67392395e9cSLionel Sambuc.Xr man 7 ,
67492395e9cSLionel Sambuc.Xr mandoc_char 7 ,
67592395e9cSLionel Sambuc.Xr mdoc 7 ,
67692395e9cSLionel Sambuc.Xr roff 7 ,
67792395e9cSLionel Sambuc.Xr tbl 7
67892395e9cSLionel Sambuc.Sh AUTHORS
67992395e9cSLionel SambucThe
68092395e9cSLionel Sambuc.Nm
68192395e9cSLionel Sambuclibrary was written by
682*0a6a1f1dSLionel Sambuc.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv .
683