xref: /openbsd-src/lib/libutil/fparseln.3 (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1.\"	$OpenBSD: fparseln.3,v 1.7 2007/05/31 19:19:38 jmc Exp $
2.\"	$NetBSD: fparseln.3,v 1.7 1999/07/02 15:49:12 simonb Exp $
3.\"
4.\" Copyright (c) 1997 Christos Zoulas.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by Christos Zoulas.
17.\" 4. The name of the author may not be used to endorse or promote products
18.\"    derived from this software without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30.\"
31.Dd $Mdocdate: May 31 2007 $
32.Dt FPARSELN 3
33.Os
34.Sh NAME
35.Nm fparseln
36.Nd return the next logical line from a stream
37.Sh SYNOPSIS
38.Fd #include <stdio.h>
39.Fd #include <util.h>
40.Ft "char *"
41.Fo "fparseln"
42.Fa "FILE *stream" "size_t *len" "size_t *lineno"
43.Fa "const char delim[3]" "int flags"
44.Fc
45.Sh DESCRIPTION
46The
47.Fn fparseln
48function
49returns a pointer to the next logical line from the stream referenced by
50.Fa stream .
51This string is null terminated, contains no trailing newline,
52and is dynamically allocated on each invocation.
53It is the responsibility of the caller to free the pointer.
54.Pp
55By default, if a character is escaped, both it and the preceding escape
56character will be present in the returned string.
57Various
58.Fa flags
59alter this behaviour.
60.Pp
61The meaning of the arguments is as follows:
62.Bl -tag -width "lineno"
63.It Fa stream
64The stream to read from.
65.It Fa len
66If not
67.Dv NULL ,
68the length of the string is stored in the memory location referenced by
69.Fa len .
70.It Fa lineno
71If not
72.Dv NULL ,
73the value of the memory location to which
74.Fa lineno
75references is incremented by the number of lines actually read from the file.
76.It Fa delim
77Contains the escape, continuation, and comment characters.
78If a character is
79.Tn NUL
80then processing for that character is disabled.
81If
82.Dv NULL ,
83all characters default to values specified below.
84The contents of
85.Fa delim
86is as follows:
87.Bl -tag -width "delim[0]"
88.It Fa delim[0]
89The escape character, which defaults to
90.Ql \e ,
91is used to remove any special meaning from the next character.
92.It Fa delim[1]
93The continuation character, which defaults to
94.Ql \e ,
95is used to indicate that the next line should be concatenated with the
96current one if this character is the last character on the current line
97and is not escaped.
98.It Fa delim[2]
99The comment character, which defaults to
100.Ql # ,
101if not escaped indicates the beginning of a comment that extends until the
102end of the current line.
103.El
104.It Fa flags
105If non-zero, alter the operation of
106.Fn fparseln .
107The various flags, which may be
108.Tn OR Ns 'ed
109together, are:
110.Bl -tag -width "FPARSELN_UNESCCOMM"
111.It Dv FPARSELN_UNESCCOMM
112Remove escape preceding an escaped comment.
113.It Dv FPARSELN_UNESCCONT
114Remove escape preceding an escaped continuation.
115.It Dv FPARSELN_UNESCESC
116Remove escape preceding an escaped escape.
117.It Dv FPARSELN_UNESCREST
118Remove escape preceding any other character.
119.It Dv FPARSELN_UNESCALL
120All of the above.
121.El
122.El
123.Sh RETURN VALUES
124Upon successful completion a pointer to the parsed line is returned;
125otherwise,
126.Dv NULL
127is returned.
128.Pp
129Internally, the
130.Fn fparseln
131function uses
132.Xr fgetln 3 ,
133so all error conditions that apply to
134.Xr fgetln 3
135apply to
136.Fn fparseln
137as well.
138In addition
139.Fn fparseln
140may set
141.Va errno
142to
143.Er ENOMEM
144and return
145.Dv NULL
146if it runs out of memory.
147.Sh SEE ALSO
148.Xr fgetln 3
149