version 1.26, 2014/09/03 23:21:47 |
version 1.31, 2015/01/15 04:26:40 |
|
|
.\" $Id$ |
.\" $Id$ |
.\" |
.\" |
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
.\" Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> |
.\" Copyright (c) 2010, 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> |
.\" |
.\" |
.\" Permission to use, copy, modify, and distribute this software for any |
.\" Permission to use, copy, modify, and distribute this software for any |
.\" purpose with or without fee is hereby granted, provided that the above |
.\" purpose with or without fee is hereby granted, provided that the above |
|
|
.Nm mparse_strlevel |
.Nm mparse_strlevel |
.Nm mparse_wait , |
.Nm mparse_wait , |
.Nd mandoc macro compiler library |
.Nd mandoc macro compiler library |
.Sh LIBRARY |
|
.Lb libmandoc |
|
.Sh SYNOPSIS |
.Sh SYNOPSIS |
.In sys/types.h |
.In sys/types.h |
.In mandoc.h |
.In mandoc.h |
|
.Pp |
.Fd "#define ASCII_NBRSP" |
.Fd "#define ASCII_NBRSP" |
.Fd "#define ASCII_HYPH" |
.Fd "#define ASCII_HYPH" |
.Fd "#define ASCII_BREAK" |
.Fd "#define ASCII_BREAK" |
|
|
.Fa "int options" |
.Fa "int options" |
.Fa "enum mandoclevel wlevel" |
.Fa "enum mandoclevel wlevel" |
.Fa "mandocmsg mmsg" |
.Fa "mandocmsg mmsg" |
|
.Fa "const struct mchars *mchars" |
.Fa "char *defos" |
.Fa "char *defos" |
.Fc |
.Fc |
.Ft void |
.Ft void |
|
|
.Fa "struct mparse *parse" |
.Fa "struct mparse *parse" |
.Fa "int *fd" |
.Fa "int *fd" |
.Fa "const char *fname" |
.Fa "const char *fname" |
.Fa "pid_t *child_pid" |
|
.Fc |
.Fc |
.Ft "enum mandoclevel" |
.Ft "enum mandoclevel" |
.Fo mparse_readfd |
.Fo mparse_readfd |
|
|
.Ft "enum mandoclevel" |
.Ft "enum mandoclevel" |
.Fo mparse_wait |
.Fo mparse_wait |
.Fa "struct mparse *parse" |
.Fa "struct mparse *parse" |
.Fa "pid_t child_pid" |
|
.Fc |
.Fc |
.In sys/types.h |
.In sys/types.h |
.In mandoc.h |
.In mandoc.h |
Line 173 The following describes a general parse sequence: |
|
Line 171 The following describes a general parse sequence: |
|
.Bl -enum |
.Bl -enum |
.It |
.It |
initiate a parsing sequence with |
initiate a parsing sequence with |
|
.Xr mchars_alloc 3 |
|
and |
.Fn mparse_alloc ; |
.Fn mparse_alloc ; |
.It |
.It |
parse files or file descriptors with |
open a file with |
|
.Xr open 2 |
|
or |
|
.Fn mparse_open ; |
|
.It |
|
parse it with |
.Fn mparse_readfd ; |
.Fn mparse_readfd ; |
.It |
.It |
retrieve a parsed syntax tree, if the parse was successful, with |
retrieve the syntax tree with |
.Fn mparse_result ; |
.Fn mparse_result ; |
.It |
.It |
iterate over parse nodes with |
iterate over parse nodes with |
|
|
.Fn man_node ; |
.Fn man_node ; |
.It |
.It |
free all allocated memory with |
free all allocated memory with |
.Fn mparse_free , |
.Fn mparse_free |
|
and |
|
.Xr mchars_free 3 , |
or invoke |
or invoke |
.Fn mparse_reset |
.Fn mparse_reset |
and parse new files. |
and parse new files. |
|
|
.Ss Types |
.Ss Types |
.Bl -ohang |
.Bl -ohang |
.It Vt "enum mandocerr" |
.It Vt "enum mandocerr" |
A fatal error, error, or warning message during parsing. |
An error or warning message during parsing. |
.It Vt "enum mandoclevel" |
.It Vt "enum mandoclevel" |
A classification of an |
A classification of an |
.Vt "enum mandocerr" |
.Vt "enum mandocerr" |
as regards system operation. |
as regards system operation. |
|
.It Vt "struct mchars" |
|
An opaque pointer to a a character table. |
|
Created with |
|
.Xr mchars_alloc 3 |
|
and freed with |
|
.Xr mchars_free 3 . |
.It Vt "struct mparse" |
.It Vt "struct mparse" |
An opaque pointer to a running parse sequence. |
An opaque pointer to a running parse sequence. |
Created with |
Created with |
Line 218 This may be used across parsed input if |
|
Line 231 This may be used across parsed input if |
|
.Fn mparse_reset |
.Fn mparse_reset |
is called between parses. |
is called between parses. |
.It Vt "mandocmsg" |
.It Vt "mandocmsg" |
A prototype for a function to handle fatal error, error, and warning |
A prototype for a function to handle error and warning |
messages emitted by the parser. |
messages emitted by the parser. |
.El |
.El |
.Ss Functions |
.Ss Functions |
Line 322 This is for example useful in |
|
Line 335 This is for example useful in |
|
to quickly build minimal databases. |
to quickly build minimal databases. |
.It Ar wlevel |
.It Ar wlevel |
Can be set to |
Can be set to |
.Dv MANDOCLEVEL_FATAL , |
.Dv MANDOCLEVEL_BADARG , |
.Dv MANDOCLEVEL_ERROR , |
.Dv MANDOCLEVEL_ERROR , |
or |
or |
.Dv MANDOCLEVEL_WARNING . |
.Dv MANDOCLEVEL_WARNING . |
Line 332 A callback function to handle errors and warnings. |
|
Line 345 A callback function to handle errors and warnings. |
|
See |
See |
.Pa main.c |
.Pa main.c |
for an example. |
for an example. |
|
.It Ar mchars |
|
An opaque pointer to a a character table obtained from |
|
.Xr mchars_alloc 3 . |
.It Ar defos |
.It Ar defos |
A default string for the |
A default string for the |
.Xr mdoc 7 |
.Xr mdoc 7 |
|
|
.Xr gunzip 1 ; |
.Xr gunzip 1 ; |
otherwise, with |
otherwise, with |
.Xr open 2 . |
.Xr open 2 . |
|
If |
|
.Xr open 2 |
|
fails, append |
|
.Pa .gz |
|
and try with |
|
.Xr gunzip 1 . |
Return a file descriptor open for reading in |
Return a file descriptor open for reading in |
.Fa fd , |
.Fa fd , |
or -1 on failure. |
or -1 on failure. |
It can be passed to |
It can be passed to |
.Fn mparse_readfd |
.Fn mparse_readfd |
or used directly. |
or used directly. |
If applicable, return the |
|
.Xr gunzip 1 |
|
child process ID in |
|
.Fa child_pid , |
|
or otherwise 0. |
|
If non-zero, it should be passed to |
|
.Fn mparse_wait |
|
after completing the parse sequence. |
|
Declared in |
Declared in |
.In mandoc.h , |
.In mandoc.h , |
implemented in |
implemented in |
.Pa read.c . |
.Pa read.c . |
.It Fn mparse_readfd |
.It Fn mparse_readfd |
Parse a file or file descriptor. |
Parse a file descriptor opened with |
If |
.Xr open 2 |
.Va fd |
or |
is -1, |
.Fn mparse_open . |
.Va fname |
Pass the associated filename in |
is opened for reading. |
.Va fname . |
Otherwise, |
Calls |
.Va fname |
.Fn mparse_wait |
is assumed to be the name associated with |
before returning. |
.Va fd . |
This function may be called multiple times with different parameters; however, |
This may be called multiple times with different parameters; however, |
|
.Fn mparse_reset |
.Fn mparse_reset |
should be invoked between parses. |
should be invoked between parses. |
Declared in |
Declared in |
|
|
.Pa read.c . |
.Pa read.c . |
.It Fn mparse_result |
.It Fn mparse_result |
Obtain the result of a parse. |
Obtain the result of a parse. |
Only successful parses |
One of the three pointers will be filled in. |
.Po |
|
i.e., those where |
|
.Fn mparse_readfd |
|
returned less than MANDOCLEVEL_FATAL |
|
.Pc |
|
should invoke this function, in which case one of the three pointers will |
|
be filled in. |
|
Declared in |
Declared in |
.In mandoc.h , |
.In mandoc.h , |
implemented in |
implemented in |
|
|
.It Fn mparse_wait |
.It Fn mparse_wait |
Bury a |
Bury a |
.Xr gunzip 1 |
.Xr gunzip 1 |
child process |
child process that was spawned with |
.Fa child_pid |
|
that was spawned with |
|
.Fn mparse_open . |
.Fn mparse_open . |
To be called after the parse sequence is complete. |
To be called after the parse sequence is complete. |
|
Not needed after |
|
.Fn mparse_readfd , |
|
but does no harm in that case, either. |
Returns |
Returns |
.Dv MANDOCLEVEL_OK |
.Dv MANDOCLEVEL_OK |
on success and |
on success and |