version 1.36, 2010/01/07 19:10:09 |
version 1.37, 2010/02/17 19:22:01 |
|
|
.\" $Id$ |
.\" $Id$ |
.\" |
.\" |
.\" Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se> |
.\" Copyright (c) 2009-2010 Kristaps Dzonsons <kristaps@bsd.lv> |
.\" |
.\" |
.\" 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 |
Line 92 Both functions (see |
|
Line 92 Both functions (see |
|
and variables (see |
and variables (see |
.Sx Variables ) |
.Sx Variables ) |
may use the following types: |
may use the following types: |
.Bl -ohang -offset "XXXX" |
.Bl -ohang |
.\" LIST-ITEM |
.\" LIST-ITEM |
.It Vt struct mdoc |
.It Vt struct mdoc |
An opaque type defined in |
An opaque type defined in |
|
|
.\" SUBSECTION |
.\" SUBSECTION |
.Ss Functions |
.Ss Functions |
Function descriptions follow: |
Function descriptions follow: |
.Bl -ohang -offset "XXXX" |
.Bl -ohang |
.\" LIST-ITEM |
.\" LIST-ITEM |
.It Fn mdoc_alloc |
.It Fn mdoc_alloc |
Allocates a parsing structure. The |
Allocates a parsing structure. The |
Line 168 return 0, the data will be incomplete. |
|
Line 168 return 0, the data will be incomplete. |
|
.\" SUBSECTION |
.\" SUBSECTION |
.Ss Variables |
.Ss Variables |
The following variables are also defined: |
The following variables are also defined: |
.Bl -ohang -offset "XXXX" |
.Bl -ohang |
.\" LIST-ITEM |
.\" LIST-ITEM |
.It Va mdoc_macronames |
.It Va mdoc_macronames |
An array of string-ified token names. |
An array of string-ified token names. |
Line 225 fields) and some type-specific data. |
|
Line 225 fields) and some type-specific data. |
|
The tree itself is arranged according to the following normal form, |
The tree itself is arranged according to the following normal form, |
where capitalised non-terminals represent nodes. |
where capitalised non-terminals represent nodes. |
.Pp |
.Pp |
.Bl -tag -width "ELEMENTXX" -compact -offset "XXXX" |
.Bl -tag -width "ELEMENTXX" -compact |
.\" LIST-ITEM |
.\" LIST-ITEM |
.It ROOT |
.It ROOT |
\(<- mnode+ |
\(<- mnode+ |
Line 259 an empty line will produce a zero-length string. |
|
Line 259 an empty line will produce a zero-length string. |
|
The following example reads lines from stdin and parses them, operating |
The following example reads lines from stdin and parses them, operating |
on the finished parse tree with |
on the finished parse tree with |
.Fn parsed . |
.Fn parsed . |
Note that, if the last line of the file isn't newline-terminated, this |
This example does not error-check nor free memory upon failure. |
will truncate the file's last character (see |
.Bd -literal -offset indent |
.Xr fgetln 3 ) . |
|
Further, this example does not error-check nor free memory upon failure. |
|
.Bd -literal -offset "XXXX" |
|
struct mdoc *mdoc; |
struct mdoc *mdoc; |
const struct mdoc_node *node; |
const struct mdoc_node *node; |
char *buf; |
char *buf; |
|
|
|
|
line = 1; |
line = 1; |
mdoc = mdoc_alloc(NULL, 0, NULL); |
mdoc = mdoc_alloc(NULL, 0, NULL); |
|
buf = NULL; |
|
alloc_len = 0; |
|
|
while ((buf = fgetln(fp, &len))) { |
while ((len = getline(&buf, &alloc_len, stdin)) >= 0) { |
buf[len - 1] = '\e0'; |
if (len && buflen[len - 1] = '\en') |
if ( ! mdoc_parseln(mdoc, line, buf)) |
buf[len - 1] = '\e0'; |
errx(1, "mdoc_parseln"); |
if ( ! mdoc_parseln(mdoc, line, buf)) |
line++; |
errx(1, "mdoc_parseln"); |
|
line++; |
} |
} |
|
|
if ( ! mdoc_endparse(mdoc)) |
if ( ! mdoc_endparse(mdoc)) |
errx(1, "mdoc_endparse"); |
errx(1, "mdoc_endparse"); |
if (NULL == (node = mdoc_node(mdoc))) |
if (NULL == (node = mdoc_node(mdoc))) |
errx(1, "mdoc_node"); |
errx(1, "mdoc_node"); |
|
|
parsed(mdoc, node); |
parsed(mdoc, node); |
mdoc_free(mdoc); |
mdoc_free(mdoc); |
Line 297 mdoc_free(mdoc); |
|
Line 297 mdoc_free(mdoc); |
|
The |
The |
.Nm |
.Nm |
utility was written by |
utility was written by |
.An Kristaps Dzonsons Aq kristaps@kth.se . |
.An Kristaps Dzonsons Aq kristaps@bsd.lv . |
.\" SECTION |
.\" SECTION |
.Sh CAVEATS |
.Sh CAVEATS |
.Bl -dash -compact |
.Bl -dash -compact |