1*0a6a1f1dSLionel Sambuc.\" $NetBSD: fparseln.3,v 1.5 2014/01/07 13:34:11 njoly Exp $ 22fe8fb19SBen Gras.\" 32fe8fb19SBen Gras.\" Copyright (c) 1997 Christos Zoulas. All rights reserved. 42fe8fb19SBen Gras.\" 52fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without 62fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions 72fe8fb19SBen Gras.\" are met: 82fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright 92fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer. 102fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright 112fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer in the 122fe8fb19SBen Gras.\" documentation and/or other materials provided with the distribution. 132fe8fb19SBen Gras.\" 142fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 152fe8fb19SBen Gras.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 162fe8fb19SBen Gras.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 172fe8fb19SBen Gras.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 182fe8fb19SBen Gras.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 192fe8fb19SBen Gras.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 202fe8fb19SBen Gras.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 212fe8fb19SBen Gras.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 222fe8fb19SBen Gras.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 232fe8fb19SBen Gras.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 242fe8fb19SBen Gras.\" 252fe8fb19SBen Gras.Dd November 30, 2002 262fe8fb19SBen Gras.Dt FPARSELN 3 272fe8fb19SBen Gras.Os 282fe8fb19SBen Gras.Sh NAME 292fe8fb19SBen Gras.Nm fparseln 302fe8fb19SBen Gras.Nd return the next logical line from a stream 312fe8fb19SBen Gras.Sh LIBRARY 322fe8fb19SBen Gras.Lb libc 332fe8fb19SBen Gras.Sh SYNOPSIS 342fe8fb19SBen Gras.In stdio.h 352fe8fb19SBen Gras.Ft "char *" 362fe8fb19SBen Gras.Fo "fparseln" 372fe8fb19SBen Gras.Fa "FILE *stream" "size_t *len" "size_t *lineno" 382fe8fb19SBen Gras.Fa "const char delim[3]" "int flags" 392fe8fb19SBen Gras.Fc 402fe8fb19SBen Gras.Sh DESCRIPTION 412fe8fb19SBen GrasThe 422fe8fb19SBen Gras.Fn fparseln 432fe8fb19SBen Grasfunction 442fe8fb19SBen Grasreturns a pointer to the next logical line from the stream referenced by 452fe8fb19SBen Gras.Fa stream . 462fe8fb19SBen GrasThis string is 472fe8fb19SBen Gras.Dv NUL 482fe8fb19SBen Grasterminated and it is dynamically allocated on each invocation. 492fe8fb19SBen GrasIt is the responsibility of the caller to free the pointer. 502fe8fb19SBen Gras.Pp 512fe8fb19SBen GrasBy default, if a character is escaped, both it and the preceding escape 522fe8fb19SBen Grascharacter will be present in the returned string. 532fe8fb19SBen GrasVarious 542fe8fb19SBen Gras.Fa flags 552fe8fb19SBen Grasalter this behaviour. 562fe8fb19SBen Gras.Pp 572fe8fb19SBen GrasThe meaning of the arguments is as follows: 582fe8fb19SBen Gras.Bl -tag -width "lineno" 592fe8fb19SBen Gras.It Fa stream 602fe8fb19SBen GrasThe stream to read from. 612fe8fb19SBen Gras.It Fa len 622fe8fb19SBen GrasIf not 632fe8fb19SBen Gras.Dv NULL , 642fe8fb19SBen Grasthe length of the string is stored in the memory location to which it 652fe8fb19SBen Graspoints. 662fe8fb19SBen Gras.It Fa lineno 672fe8fb19SBen GrasIf not 682fe8fb19SBen Gras.Dv NULL , 692fe8fb19SBen Grasthe value of the memory location to which is pointed to, is incremented 702fe8fb19SBen Grasby the number of lines actually read from the file. 712fe8fb19SBen Gras.It Fa delim 722fe8fb19SBen GrasContains the escape, continuation, and comment characters. 732fe8fb19SBen GrasIf a character is 742fe8fb19SBen Gras.Dv NUL 752fe8fb19SBen Grasthen processing for that character is disabled. 762fe8fb19SBen GrasIf 772fe8fb19SBen Gras.Dv NULL , 782fe8fb19SBen Grasall characters default to values specified below. 792fe8fb19SBen GrasThe contents of 802fe8fb19SBen Gras.Fa delim 812fe8fb19SBen Grasis as follows: 822fe8fb19SBen Gras.Bl -tag -width "delim[0]" 832fe8fb19SBen Gras.It Fa delim[0] 842fe8fb19SBen GrasThe escape character, which defaults to 852fe8fb19SBen Gras.Cm \e , 862fe8fb19SBen Grasis used to remove any special meaning from the next character. 872fe8fb19SBen Gras.It Fa delim[1] 882fe8fb19SBen GrasThe continuation character, which defaults to 892fe8fb19SBen Gras.Cm \e , 902fe8fb19SBen Grasis used to indicate that the next line should be concatenated with the 912fe8fb19SBen Grascurrent one if this character is the last character on the current line 922fe8fb19SBen Grasand is not escaped. 932fe8fb19SBen Gras.It Fa delim[2] 942fe8fb19SBen GrasThe comment character, which defaults to 952fe8fb19SBen Gras.Cm # , 962fe8fb19SBen Grasif not escaped indicates the beginning of a comment that extends until the 972fe8fb19SBen Grasend of the current line. 982fe8fb19SBen Gras.El 992fe8fb19SBen Gras.It Fa flags 1002fe8fb19SBen GrasIf non-zero, alter the operation of 1012fe8fb19SBen Gras.Fn fparseln . 1022fe8fb19SBen GrasThe various flags, which may be 1032fe8fb19SBen Gras.Em or Ns -ed 1042fe8fb19SBen Grastogether, are: 1052fe8fb19SBen Gras.Bl -tag -width "FPARSELN_UNESCCOMM" 1062fe8fb19SBen Gras.It Dv FPARSELN_UNESCCOMM 1072fe8fb19SBen GrasRemove escape preceding an escaped comment. 1082fe8fb19SBen Gras.It Dv FPARSELN_UNESCCONT 1092fe8fb19SBen GrasRemove escape preceding an escaped continuation. 1102fe8fb19SBen Gras.It Dv FPARSELN_UNESCESC 1112fe8fb19SBen GrasRemove escape preceding an escaped escape. 1122fe8fb19SBen Gras.It Dv FPARSELN_UNESCREST 1132fe8fb19SBen GrasRemove escape preceding any other character. 1142fe8fb19SBen Gras.It Dv FPARSELN_UNESCALL 1152fe8fb19SBen GrasAll of the above. 1162fe8fb19SBen Gras.El 1172fe8fb19SBen Gras.El 1182fe8fb19SBen Gras.Sh RETURN VALUES 1192fe8fb19SBen GrasUpon successful completion a pointer to the parsed line is returned; 1202fe8fb19SBen Grasotherwise, 1212fe8fb19SBen Gras.Dv NULL 1222fe8fb19SBen Grasis returned. 1232fe8fb19SBen Gras.Pp 1242fe8fb19SBen GrasThe 1252fe8fb19SBen Gras.Fn fparseln 1262fe8fb19SBen Grasfunction uses internally 1272fe8fb19SBen Gras.Xr fgetln 3 , 1282fe8fb19SBen Grasso all error conditions that apply to 1292fe8fb19SBen Gras.Xr fgetln 3 , 1302fe8fb19SBen Grasapply to 1312fe8fb19SBen Gras.Fn fparseln . 1322fe8fb19SBen GrasIn addition 1332fe8fb19SBen Gras.Fn fparseln 1342fe8fb19SBen Grasmay set 1352fe8fb19SBen Gras.Va errno 1362fe8fb19SBen Grasto 1372fe8fb19SBen Gras.Bq Er ENOMEM 1382fe8fb19SBen Grasand return 1392fe8fb19SBen Gras.Dv NULL 1402fe8fb19SBen Grasif it runs out of memory. 1412fe8fb19SBen Gras.Sh SEE ALSO 1422fe8fb19SBen Gras.Xr fgetln 3 1432fe8fb19SBen Gras.Sh HISTORY 1442fe8fb19SBen GrasThe 1452fe8fb19SBen Gras.Fn fparseln 1462fe8fb19SBen Grasfunction first appeared in 1472fe8fb19SBen Gras.Nx 1.4 . 148