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