xref: /openbsd/lib/libutil/fparseln.3 (revision 3cab2bb3)
1.\"	$OpenBSD: fparseln.3,v 1.10 2015/09/14 15:14:55 schwarze 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: September 14 2015 $
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.In stdio.h
39.In 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 NUL then processing for that character is disabled.
79If
80.Dv NULL ,
81all characters default to values specified below.
82The contents of
83.Fa delim
84is as follows:
85.Bl -tag -width "delim[0]"
86.It Fa delim[0]
87The escape character, which defaults to
88.Ql \e ,
89is used to remove any special meaning from the next character.
90.It Fa delim[1]
91The continuation character, which defaults to
92.Ql \e ,
93is used to indicate that the next line should be concatenated with the
94current one if this character is the last character on the current line
95and is not escaped.
96.It Fa delim[2]
97The comment character, which defaults to
98.Ql # ,
99if not escaped indicates the beginning of a comment that extends until the
100end of the current line.
101.El
102.It Fa flags
103If non-zero, alter the operation of
104.Fn fparseln .
105The various flags, which may be OR'ed together, are:
106.Bl -tag -width "FPARSELN_UNESCCOMM"
107.It Dv FPARSELN_UNESCCOMM
108Remove escape preceding an escaped comment.
109.It Dv FPARSELN_UNESCCONT
110Remove escape preceding an escaped continuation.
111.It Dv FPARSELN_UNESCESC
112Remove escape preceding an escaped escape.
113.It Dv FPARSELN_UNESCREST
114Remove escape preceding any other character.
115.It Dv FPARSELN_UNESCALL
116All of the above.
117.El
118.El
119.Sh RETURN VALUES
120Upon successful completion a pointer to the parsed line is returned;
121otherwise,
122.Dv NULL
123is returned.
124.Pp
125Internally, the
126.Fn fparseln
127function uses
128.Xr fgetln 3 ,
129so all error conditions that apply to
130.Xr fgetln 3
131apply to
132.Fn fparseln
133as well.
134In addition
135.Fn fparseln
136may set
137.Va errno
138to
139.Er ENOMEM
140and return
141.Dv NULL
142if it runs out of memory.
143.Sh SEE ALSO
144.Xr fgetln 3
145