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