xref: /netbsd/lib/libc/stdio/fparseln.3 (revision c4a72b64)
1.\"	$NetBSD: fparseln.3,v 1.1 2002/11/30 03:04:45 lukem Exp $
2.\"
3.\" Copyright (c) 1997 Christos Zoulas.  All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\" 3. All advertising materials mentioning features or use of this software
14.\"    must display the following acknowledgement:
15.\"	This product includes software developed by Christos Zoulas.
16.\" 4. The name of the author may not be used to endorse or promote products
17.\"    derived from this software without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd November 30, 2002
31.Dt FPARSELN 3
32.Os
33.Sh NAME
34.Nm fparseln
35.Nd return the next logical line from a stream
36.Sh LIBRARY
37.Lb libc
38.Sh SYNOPSIS
39.Fd #include \*[Lt]stdio.h\*[Gt]
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
52.Dv NUL
53terminated and it is dynamically allocated on each invocation.
54It is the responsibility of the caller to free the pointer.
55.Pp
56By default, if a character is escaped, both it and the preceding escape
57character will be present in the returned string.
58Various
59.Fa flags
60alter this behaviour.
61.Pp
62The meaning of the arguments is as follows:
63.Bl -tag -width "lineno"
64.It Fa stream
65The stream to read from.
66.It Fa len
67If not
68.Dv NULL ,
69the length of the string is stored in the memory location to which it
70points.
71.It Fa lineno
72If not
73.Dv NULL ,
74the value of the memory location to which is pointed to, is incremented
75by 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.Dv 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.Cm \e ,
91is used to remove any special meaning from the next character.
92.It Fa delim[1]
93The continuation character, which defaults to
94.Cm \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.Cm # ,
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.Em 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.Pp
123.El
124.Sh RETURN VALUES
125Upon successful completion a pointer to the parsed line is returned;
126otherwise,
127.Dv NULL
128is returned.
129.Pp
130The
131.Fn fparseln
132function uses internally
133.Xr fgetln 3 ,
134so all error conditions that apply to
135.Xr fgetln 3 ,
136apply to
137.Fn fparseln .
138In addition
139.Fn fparseln
140may set
141.Va errno
142to
143.Bq Er ENOMEM
144and return
145.Dv NULL
146if it runs out of memory.
147.Sh SEE ALSO
148.Xr fgetln 3
149.Sh HISTORY
150The
151.Fn fparseln
152function first appeared in
153.Nx 1.4 .
154