From 47e28c8d77f2c5329bd6869db1dfeeab0e846525 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Wed, 17 Feb 2010 19:22:01 +0000 Subject: Removed offsets from most parts (no reason for indentation). Using POSIX2008 idioms for examples (thanks Joerg Sonnenberger). Removed references to fgetln(). --- man.3 | 42 ++++++++++++++++++++++-------------------- mdoc.3 | 40 ++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/man.3 b/man.3 index 33f35bed..174e85b5 100644 --- a/man.3 +++ b/man.3 @@ -1,6 +1,6 @@ -.\" $Id: man.3,v 1.11 2010/01/07 19:10:09 kristaps Exp $ +.\" $Id: man.3,v 1.12 2010/02/17 19:22:01 kristaps Exp $ .\" -.\" Copyright (c) 2009 Kristaps Dzonsons +.\" Copyright (c) 2009-2010 Kristaps Dzonsons .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 7 2010 $ +.Dd $Mdocdate: February 17 2010 $ .Dt MAN 3 .Os .\" SECTION @@ -91,7 +91,7 @@ Both functions (see and variables (see .Sx Variables ) may use the following types: -.Bl -ohang -offset "XXXX" +.Bl -ohang .\" LIST-ITEM .It Vt struct man An opaque type defined in @@ -112,7 +112,7 @@ for details. .\" SUBSECTION .Ss Functions Function descriptions follow: -.Bl -ohang -offset "XXXX" +.Bl -ohang .\" LIST-ITEM .It Fn man_alloc Allocates a parsing structure. The @@ -166,7 +166,7 @@ return 0, the data will be incomplete. .\" SUBSECTION .Ss Variables The following variables are also defined: -.Bl -ohang -offset "XXXX" +.Bl -ohang .\" LIST-ITEM .It Va man_macronames An array of string-ified token names. @@ -215,7 +215,7 @@ fields) and some type-specific data. The tree itself is arranged according to the following normal form, where capitalised non-terminals represent nodes. .Pp -.Bl -tag -width "ELEMENTXX" -compact -offset "XXXX" +.Bl -tag -width "ELEMENTXX" -compact .\" LIST-ITEM .It ROOT \(<- mnode+ @@ -242,11 +242,8 @@ next-lint scope as documented in The following example reads lines from stdin and parses them, operating on the finished parse tree with .Fn parsed . -Note that, if the last line of the file isn't newline-terminated, this -will truncate the file's last character (see -.Xr fgetln 3 ) . -Further, this example does not error-check nor free memory upon failure. -.Bd -literal -offset "XXXX" +This example does not error-check nor free memory upon failure. +.Bd -literal -offset indent struct man *man; struct man_node *node; char *buf; @@ -255,18 +252,23 @@ int line; line = 1; man = man_alloc(NULL, 0, NULL); +buf = NULL; +alloc_len = 0; -while ((buf = fgetln(fp, &len))) { - buf[len - 1] = '\e0'; - if ( ! man_parseln(man, line, buf)) - errx(1, "man_parseln"); - line++; +while ((len = getline(&buf, &alloc_len, stdin)) >= 0) { + if (len && buflen[len - 1] = '\en') + buf[len - 1] = '\e0'; + if ( ! man_parseln(man, line, buf)) + errx(1, "man_parseln"); + line++; } +free(buf); + if ( ! man_endparse(man)) - errx(1, "man_endparse"); + errx(1, "man_endparse"); if (NULL == (node = man_node(man))) - errx(1, "man_node"); + errx(1, "man_node"); parsed(man, node); man_free(man); @@ -280,4 +282,4 @@ man_free(man); The .Nm utility was written by -.An Kristaps Dzonsons Aq kristaps@kth.se . +.An Kristaps Dzonsons Aq kristaps@bsd.lv . diff --git a/mdoc.3 b/mdoc.3 index 35b13f6e..22087afb 100644 --- a/mdoc.3 +++ b/mdoc.3 @@ -1,6 +1,6 @@ -.\" $Id: mdoc.3,v 1.36 2010/01/07 19:10:09 kristaps Exp $ +.\" $Id: mdoc.3,v 1.37 2010/02/17 19:22:01 kristaps Exp $ .\" -.\" Copyright (c) 2009 Kristaps Dzonsons +.\" Copyright (c) 2009-2010 Kristaps Dzonsons .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 7 2010 $ +.Dd $Mdocdate: February 17 2010 $ .Dt MDOC 3 .Os .\" SECTION @@ -92,7 +92,7 @@ Both functions (see and variables (see .Sx Variables ) may use the following types: -.Bl -ohang -offset "XXXX" +.Bl -ohang .\" LIST-ITEM .It Vt struct mdoc An opaque type defined in @@ -113,7 +113,7 @@ for details. .\" SUBSECTION .Ss Functions Function descriptions follow: -.Bl -ohang -offset "XXXX" +.Bl -ohang .\" LIST-ITEM .It Fn mdoc_alloc Allocates a parsing structure. The @@ -168,7 +168,7 @@ return 0, the data will be incomplete. .\" SUBSECTION .Ss Variables The following variables are also defined: -.Bl -ohang -offset "XXXX" +.Bl -ohang .\" LIST-ITEM .It Va mdoc_macronames An array of string-ified token names. @@ -225,7 +225,7 @@ fields) and some type-specific data. The tree itself is arranged according to the following normal form, where capitalised non-terminals represent nodes. .Pp -.Bl -tag -width "ELEMENTXX" -compact -offset "XXXX" +.Bl -tag -width "ELEMENTXX" -compact .\" LIST-ITEM .It ROOT \(<- mnode+ @@ -259,11 +259,8 @@ an empty line will produce a zero-length string. The following example reads lines from stdin and parses them, operating on the finished parse tree with .Fn parsed . -Note that, if the last line of the file isn't newline-terminated, this -will truncate the file's last character (see -.Xr fgetln 3 ) . -Further, this example does not error-check nor free memory upon failure. -.Bd -literal -offset "XXXX" +This example does not error-check nor free memory upon failure. +.Bd -literal -offset indent struct mdoc *mdoc; const struct mdoc_node *node; char *buf; @@ -272,18 +269,21 @@ int line; line = 1; mdoc = mdoc_alloc(NULL, 0, NULL); +buf = NULL; +alloc_len = 0; -while ((buf = fgetln(fp, &len))) { - buf[len - 1] = '\e0'; - if ( ! mdoc_parseln(mdoc, line, buf)) - errx(1, "mdoc_parseln"); - line++; +while ((len = getline(&buf, &alloc_len, stdin)) >= 0) { + if (len && buflen[len - 1] = '\en') + buf[len - 1] = '\e0'; + if ( ! mdoc_parseln(mdoc, line, buf)) + errx(1, "mdoc_parseln"); + line++; } if ( ! mdoc_endparse(mdoc)) - errx(1, "mdoc_endparse"); + errx(1, "mdoc_endparse"); if (NULL == (node = mdoc_node(mdoc))) - errx(1, "mdoc_node"); + errx(1, "mdoc_node"); parsed(mdoc, node); mdoc_free(mdoc); @@ -297,7 +297,7 @@ mdoc_free(mdoc); The .Nm utility was written by -.An Kristaps Dzonsons Aq kristaps@kth.se . +.An Kristaps Dzonsons Aq kristaps@bsd.lv . .\" SECTION .Sh CAVEATS .Bl -dash -compact -- cgit v1.2.3-56-ge451