xref: /freebsd/lib/libutil/fparseln.3 (revision c6ff3a1bf74d96278726113478b2c66884aab584)
1.\"	$NetBSD: fparseln.3,v 1.7 1999/07/02 15:49:12 simonb Exp $
2.\" $FreeBSD$
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 LIBRARY
38.Lb libutil
39.Sh SYNOPSIS
40.Fd #include <stdio.h>
41.Fd #include <libutil.h>
42.Ft "char *"
43.Fo fparseln
44.Fa "FILE *stream" "size_t *len" "size_t *lineno"
45.Fa "const char delim[3]" "int flags"
46.Fc
47.Pp
48Link with
49.Va -lutil
50on the
51.Xr cc 1
52command line.
53.Sh DESCRIPTION
54The
55.Fn fparseln
56function
57returns a pointer to the next logical line from the stream referenced by
58.Fa stream .
59This string is
60.Dv NUL
61terminated and it is dynamicaly allocated on each invocation.
62It is the
63responsibility of the caller to free the pointer.
64.Pp
65By default, if a character is escaped, both it and the preceeding escape
66character will be present in the returned string.
67Various
68.Fa flags
69alter this behaviour.
70.Pp
71The meaning of the arguments is as follows:
72.Bl -tag -width "lineno"
73.It Fa stream
74The stream to read from.
75.It Fa len
76If not
77.Dv NULL ,
78the length of the string is stored in the memory location to which it
79points.
80.It Fa lineno
81If not
82.Dv NULL ,
83the value of the memory location to which is pointed to, is incremented
84by the number of lines actually read from the file.
85.It Fa delim
86Contains the escape, continuation, and comment characters.
87If a character is
88.Dv NUL
89then processing for that character is disabled.
90If
91.Dv NULL ,
92all characters default to values specified below.
93The contents of
94.Fa delim
95is as follows:
96.Bl -tag -width "delim[0]"
97.It Fa delim[0]
98The escape character, which defaults to
99.Cm \e ,
100is used to remove any special meaning from the next character.
101.It Fa delim[1]
102The continuation character, which defaults to
103.Cm \e ,
104is used to indicate that the next line should be concatenated with the
105current one if this character is the last character on the current line
106and is not escaped.
107.It Fa delim[2]
108The comment character, which defaults to
109.Cm # ,
110if not escaped indicates the beginning of a comment that extends until the
111end of the current line.
112.El
113.It Fa flags
114If non-zero, alter the operation of
115.Fn fparseln .
116The various flags, which may be
117.Em or Ns -ed
118together, are:
119.Bl -tag -width "FPARSELN_UNESCCOMM"
120.It Dv FPARSELN_UNESCCOMM
121Remove escape preceeding an escaped comment.
122.It Dv FPARSELN_UNESCCONT
123Remove escape preceeding an escaped continuation.
124.It Dv FPARSELN_UNESCESC
125Remove escape preceeding an escaped escape.
126.It Dv FPARSELN_UNESCREST
127Remove escape preceeding any other character.
128.It Dv FPARSELN_UNESCALL
129All of the above.
130.El
131.Pp
132.El
133.Sh RETURN VALUES
134Upon successful completion a pointer to the parsed line is returned;
135otherwise,
136.Dv NULL
137is returned.
138.Pp
139The
140.Fn fparseln
141function uses internally
142.Xr fgetln 3 ,
143so all error conditions that apply to
144.Xr fgetln 3 ,
145apply to
146.Fn fparseln .
147In addition
148.Fn fparseln
149may set
150.Va errno
151to
152.Bq Er ENOMEM
153and return
154.Dv NULL
155if it runs out of memory.
156.Sh SEE ALSO
157.Xr fgetln 3
158.Sh HISTORY
159The
160.Fn fparseln
161function first appeared in
162.Nx 1.4 .
163