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