xref: /openbsd-src/lib/libutil/fparseln.3 (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1.\"	$OpenBSD: fparseln.3,v 1.4 2000/01/05 18:51:11 deraadt 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 December 1, 1997
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 and dynamically allocated on each
52invocation. It is the responsibility of the caller to free the pointer.
53.Pp
54By default, if a character is escaped, both it and the preceding escape
55character will be present in the returned string.
56Various
57.Fa flags
58alter this behaviour.
59.Pp
60The meaning of the arguments is as follows:
61.Bl -tag -width "lineno"
62.It Fa stream
63The stream to read from.
64.It Fa len
65If not
66.Dv NULL ,
67the length of the string is stored in the memory location referenced by
68.Fa len .
69.It Fa lineno
70If not
71.Dv NULL ,
72the value of the memory location to which
73.Fa lineno
74references is incremented by the number of lines actually read from the file.
75.It Fa delim
76Contains the escape, continuation, and comment characters.
77If a character is
78.Tn NUL
79then processing for that character is disabled.
80If
81.Dv NULL ,
82all characters default to values specified below.
83The contents of
84.Fa delim
85is as follows:
86.Bl -tag -width "delim[0]"
87.It Fa delim[0]
88The escape character, which defaults to
89.Ql \e ,
90is used to remove any special meaning from the next character.
91.It Fa delim[1]
92The continuation character, which defaults to
93.Ql \e ,
94is used to indicate that the next line should be concatenated with the
95current one if this character is the last character on the current line
96and is not escaped.
97.It Fa delim[2]
98The comment character, which defaults to
99.Ql # ,
100if not escaped indicates the beginning of a comment that extends until the
101end of the current line.
102.El
103.It Fa flags
104If non-zero, alter the operation of
105.Fn fparseln .
106The various flags, which may be
107.Tn OR Ns 'ed
108together, are:
109.Bl -tag -width "FPARSELN_UNESCCOMM"
110.It Dv FPARSELN_UNESCCOMM
111Remove escape preceding an escaped comment.
112.It Dv FPARSELN_UNESCCONT
113Remove escape preceding an escaped continuation.
114.It Dv FPARSELN_UNESCESC
115Remove escape preceding an escaped escape.
116.It Dv FPARSELN_UNESCREST
117Remove escape preceding any other character.
118.It Dv FPARSELN_UNESCALL
119All of the above.
120.El
121.El
122.Sh RETURN VALUES
123Upon successful completion a pointer to the parsed line is returned;
124otherwise,
125.Dv NULL
126is returned.
127.Pp
128Internally, the
129.Fn fparseln
130function uses
131.Xr fgetln 3 ,
132so all error conditions that apply to
133.Xr fgetln 3
134apply to
135.Fn fparseln
136as well.
137In addition
138.Fn fparseln
139may set
140.Va errno
141to
142.Er ENOMEM
143and return
144.Dv NULL
145if it runs out of memory.
146.Sh SEE ALSO
147.Xr fgetln 3
148