Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / libutil / fparseln.3
1 .\"     $NetBSD: fparseln.3,v 1.7 1999/07/02 15:49:12 simonb Exp $
2 .\" $FreeBSD: src/lib/libutil/fparseln.3,v 1.5.2.4 2001/12/17 10:08:32 ru Exp $
3 .\" $DragonFly: src/lib/libutil/fparseln.3,v 1.2 2003/06/17 04:26:51 dillon Exp $
4 .\"
5 .\" Copyright (c) 1997 Christos Zoulas.  All rights reserved.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgement:
17 .\"     This product includes software developed by Christos Zoulas.
18 .\" 4. The name of the author may not be used to endorse or promote products
19 .\"    derived from this software without specific prior written permission.
20 .\"
21 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 .\"
32 .Dd December 1, 1997
33 .Dt FPARSELN 3
34 .Os
35 .Sh NAME
36 .Nm fparseln
37 .Nd return the next logical line from a stream
38 .Sh LIBRARY
39 .Lb libutil
40 .Sh SYNOPSIS
41 .In stdio.h
42 .In libutil.h
43 .Ft "char *"
44 .Fo fparseln
45 .Fa "FILE *stream" "size_t *len" "size_t *lineno"
46 .Fa "const char delim[3]" "int flags"
47 .Fc
48 .Sh DESCRIPTION
49 The
50 .Fn fparseln
51 function
52 returns a pointer to the next logical line from the stream referenced by
53 .Fa stream .
54 This string is
55 .Dv NUL
56 terminated and it is dynamically allocated on each invocation.
57 It is the
58 responsibility of the caller to free the pointer.
59 .Pp
60 By default, if a character is escaped, both it and the preceding escape
61 character will be present in the returned string.
62 Various
63 .Fa flags
64 alter this behaviour.
65 .Pp
66 The meaning of the arguments is as follows:
67 .Bl -tag -width "lineno"
68 .It Fa stream
69 The stream to read from.
70 .It Fa len
71 If not
72 .Dv NULL ,
73 the length of the string is stored in the memory location to which it
74 points.
75 .It Fa lineno
76 If not
77 .Dv NULL ,
78 the value of the memory location to which is pointed to, is incremented
79 by the number of lines actually read from the file.
80 .It Fa delim
81 Contains the escape, continuation, and comment characters.
82 If a character is
83 .Dv NUL
84 then processing for that character is disabled.
85 If
86 .Dv NULL ,
87 all characters default to values specified below.
88 The contents of
89 .Fa delim
90 is as follows:
91 .Bl -tag -width "delim[0]"
92 .It Fa delim[0]
93 The escape character, which defaults to
94 .Cm \e ,
95 is used to remove any special meaning from the next character.
96 .It Fa delim[1]
97 The continuation character, which defaults to
98 .Cm \e ,
99 is used to indicate that the next line should be concatenated with the
100 current one if this character is the last character on the current line
101 and is not escaped.
102 .It Fa delim[2]
103 The comment character, which defaults to
104 .Cm # ,
105 if not escaped indicates the beginning of a comment that extends until the
106 end of the current line.
107 .El
108 .It Fa flags
109 If non-zero, alter the operation of
110 .Fn fparseln .
111 The various flags, which may be
112 .Em or Ns -ed
113 together, are:
114 .Bl -tag -width "FPARSELN_UNESCCOMM"
115 .It Dv FPARSELN_UNESCCOMM
116 Remove escape preceding an escaped comment.
117 .It Dv FPARSELN_UNESCCONT
118 Remove escape preceding an escaped continuation.
119 .It Dv FPARSELN_UNESCESC
120 Remove escape preceding an escaped escape.
121 .It Dv FPARSELN_UNESCREST
122 Remove escape preceding any other character.
123 .It Dv FPARSELN_UNESCALL
124 All of the above.
125 .El
126 .Pp
127 .El
128 .Sh RETURN VALUES
129 Upon successful completion a pointer to the parsed line is returned;
130 otherwise,
131 .Dv NULL
132 is returned.
133 .Pp
134 The
135 .Fn fparseln
136 function uses internally
137 .Xr fgetln 3 ,
138 so all error conditions that apply to
139 .Xr fgetln 3 ,
140 apply to
141 .Fn fparseln .
142 In addition
143 .Fn fparseln
144 may set
145 .Va errno
146 to
147 .Er ENOMEM
148 and return
149 .Dv NULL
150 if it runs out of memory.
151 .Sh SEE ALSO
152 .Xr fgetln 3
153 .Sh HISTORY
154 The
155 .Fn fparseln
156 function first appeared in
157 .Nx 1.4 .