xref: /freebsd/lib/libutil/fparseln.3 (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1.\"	$NetBSD: fparseln.3,v 1.4 2009/10/21 01:07:45 snj 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.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24.\"
25.Dd December 1, 1997
26.Dt FPARSELN 3
27.Os
28.Sh NAME
29.Nm fparseln
30.Nd return the next logical line from a stream
31.Sh LIBRARY
32.Lb libutil
33.Sh SYNOPSIS
34.In stdio.h
35.In libutil.h
36.Ft "char *"
37.Fo fparseln
38.Fa "FILE *stream" "size_t *len" "size_t *lineno"
39.Fa "const char delim[3]" "int flags"
40.Fc
41.Sh DESCRIPTION
42The
43.Fn fparseln
44function
45returns a pointer to the next logical line from the stream referenced by
46.Fa stream .
47This string is
48.Dv NUL
49terminated and it is dynamically allocated on each invocation.
50It is the responsibility of the caller to free the pointer.
51.Pp
52By default, if a character is escaped, both it and the preceding escape
53character will be present in the returned string.
54Various
55.Fa flags
56alter this behaviour.
57.Pp
58The meaning of the arguments is as follows:
59.Bl -tag -width "lineno"
60.It Fa stream
61The stream to read from.
62.It Fa len
63If not
64.Dv NULL ,
65the length of the string is stored in the memory location to which it
66points.
67.It Fa lineno
68If not
69.Dv NULL ,
70the value of the memory location to which is pointed to, is incremented
71by the number of lines actually read from the file.
72.It Fa delim
73Contains the escape, continuation, and comment characters.
74If a character is
75.Dv NUL
76then processing for that character is disabled.
77If
78.Dv NULL ,
79all characters default to values specified below.
80The contents of
81.Fa delim
82is as follows:
83.Bl -tag -width "delim[0]"
84.It Fa delim[0]
85The escape character, which defaults to
86.Cm \e ,
87is used to remove any special meaning from the next character.
88.It Fa delim[1]
89The continuation character, which defaults to
90.Cm \e ,
91is used to indicate that the next line should be concatenated with the
92current one if this character is the last character on the current line
93and is not escaped.
94.It Fa delim[2]
95The comment character, which defaults to
96.Cm # ,
97if not escaped indicates the beginning of a comment that extends until the
98end of the current line.
99.El
100.It Fa flags
101If non-zero, alter the operation of
102.Fn fparseln .
103The various flags, which may be
104.Em or Ns -ed
105together, 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
125The
126.Fn fparseln
127function uses internally
128.Xr fgetln 3 ,
129so all error conditions that apply to
130.Xr fgetln 3 ,
131apply to
132.Fn fparseln .
133In addition
134.Fn fparseln
135may set
136.Va errno
137to
138.Er ENOMEM
139and return
140.Dv NULL
141if it runs out of memory.
142.Sh SEE ALSO
143.Xr fgetln 3
144.Sh HISTORY
145The
146.Fn fparseln
147function first appeared in
148.Nx 1.4
149and
150.Fx 4.0 .
151