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