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