2009-10-21 05:07:44 +04:00
|
|
|
.\" $NetBSD: fparseln.3,v 1.4 2009/10/21 01:07:45 snj Exp $
|
1997-11-17 01:15:54 +03:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 1997 Christos Zoulas. All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
.\"
|
2002-11-30 06:04:44 +03:00
|
|
|
.Dd November 30, 2002
|
1997-11-17 01:15:54 +03:00
|
|
|
.Dt FPARSELN 3
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm fparseln
|
|
|
|
.Nd return the next logical line from a stream
|
1998-02-05 21:45:17 +03:00
|
|
|
.Sh LIBRARY
|
2002-11-30 06:04:44 +03:00
|
|
|
.Lb libc
|
1997-11-17 01:15:54 +03:00
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In stdio.h
|
1997-12-01 05:58:40 +03:00
|
|
|
.Ft "char *"
|
|
|
|
.Fo "fparseln"
|
|
|
|
.Fa "FILE *stream" "size_t *len" "size_t *lineno"
|
|
|
|
.Fa "const char delim[3]" "int flags"
|
|
|
|
.Fc
|
1997-11-17 01:15:54 +03:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Fn fparseln
|
|
|
|
function
|
|
|
|
returns a pointer to the next logical line from the stream referenced by
|
|
|
|
.Fa stream .
|
1999-07-02 19:46:05 +04:00
|
|
|
This string is
|
1997-11-17 01:15:54 +03:00
|
|
|
.Dv NUL
|
2002-10-02 14:48:26 +04:00
|
|
|
terminated and it is dynamically allocated on each invocation.
|
2002-10-01 23:36:30 +04:00
|
|
|
It is the responsibility of the caller to free the pointer.
|
1997-11-23 07:07:32 +03:00
|
|
|
.Pp
|
2001-08-20 16:00:46 +04:00
|
|
|
By default, if a character is escaped, both it and the preceding escape
|
1997-12-01 05:58:40 +03:00
|
|
|
character will be present in the returned string.
|
|
|
|
Various
|
|
|
|
.Fa flags
|
|
|
|
alter this behaviour.
|
|
|
|
.Pp
|
|
|
|
The meaning of the arguments is as follows:
|
1997-11-23 07:07:32 +03:00
|
|
|
.Bl -tag -width "lineno"
|
1997-12-01 05:58:40 +03:00
|
|
|
.It Fa stream
|
|
|
|
The stream to read from.
|
1997-11-23 07:07:32 +03:00
|
|
|
.It Fa len
|
|
|
|
If not
|
1997-11-17 01:15:54 +03:00
|
|
|
.Dv NULL ,
|
|
|
|
the length of the string is stored in the memory location to which it
|
|
|
|
points.
|
1997-11-23 07:07:32 +03:00
|
|
|
.It Fa lineno
|
|
|
|
If not
|
1997-11-17 01:15:54 +03:00
|
|
|
.Dv NULL ,
|
|
|
|
the value of the memory location to which is pointed to, is incremented
|
|
|
|
by the number of lines actually read from the file.
|
1997-11-23 07:07:32 +03:00
|
|
|
.It Fa delim
|
|
|
|
Contains the escape, continuation, and comment characters.
|
1997-11-17 01:15:54 +03:00
|
|
|
If a character is
|
|
|
|
.Dv NUL
|
|
|
|
then processing for that character is disabled.
|
1999-07-02 19:46:05 +04:00
|
|
|
If
|
1997-11-23 07:07:32 +03:00
|
|
|
.Dv NULL ,
|
1997-11-17 01:15:54 +03:00
|
|
|
all characters default to values specified below.
|
1997-11-23 07:07:32 +03:00
|
|
|
The contents of
|
|
|
|
.Fa delim
|
|
|
|
is as follows:
|
|
|
|
.Bl -tag -width "delim[0]"
|
|
|
|
.It Fa delim[0]
|
1997-11-17 01:15:54 +03:00
|
|
|
The escape character, which defaults to
|
1997-11-23 07:07:32 +03:00
|
|
|
.Cm \e ,
|
1997-11-17 01:15:54 +03:00
|
|
|
is used to remove any special meaning from the next character.
|
1997-11-23 07:07:32 +03:00
|
|
|
.It Fa delim[1]
|
1997-11-17 01:15:54 +03:00
|
|
|
The continuation character, which defaults to
|
1997-11-23 07:07:32 +03:00
|
|
|
.Cm \e ,
|
1997-11-17 01:15:54 +03:00
|
|
|
is used to indicate that the next line should be concatenated with the
|
|
|
|
current one if this character is the last character on the current line
|
|
|
|
and is not escaped.
|
1997-11-23 07:07:32 +03:00
|
|
|
.It Fa delim[2]
|
1997-11-17 01:15:54 +03:00
|
|
|
The comment character, which defaults to
|
1997-11-23 07:07:32 +03:00
|
|
|
.Cm # ,
|
1997-11-17 01:15:54 +03:00
|
|
|
if not escaped indicates the beginning of a comment that extends until the
|
|
|
|
end of the current line.
|
1997-11-23 07:07:32 +03:00
|
|
|
.El
|
1997-12-01 05:58:40 +03:00
|
|
|
.It Fa flags
|
|
|
|
If non-zero, alter the operation of
|
|
|
|
.Fn fparseln .
|
|
|
|
The various flags, which may be
|
|
|
|
.Em or Ns -ed
|
|
|
|
together, are:
|
|
|
|
.Bl -tag -width "FPARSELN_UNESCCOMM"
|
|
|
|
.It Dv FPARSELN_UNESCCOMM
|
2001-08-20 16:00:46 +04:00
|
|
|
Remove escape preceding an escaped comment.
|
1997-12-01 05:58:40 +03:00
|
|
|
.It Dv FPARSELN_UNESCCONT
|
2001-08-20 16:00:46 +04:00
|
|
|
Remove escape preceding an escaped continuation.
|
1997-12-01 05:58:40 +03:00
|
|
|
.It Dv FPARSELN_UNESCESC
|
2001-08-20 16:00:46 +04:00
|
|
|
Remove escape preceding an escaped escape.
|
1997-12-01 05:58:40 +03:00
|
|
|
.It Dv FPARSELN_UNESCREST
|
2001-08-20 16:00:46 +04:00
|
|
|
Remove escape preceding any other character.
|
1997-12-01 05:58:40 +03:00
|
|
|
.It Dv FPARSELN_UNESCALL
|
|
|
|
All of the above.
|
|
|
|
.El
|
1997-11-23 07:07:32 +03:00
|
|
|
.Pp
|
|
|
|
.El
|
1997-11-17 01:15:54 +03:00
|
|
|
.Sh RETURN VALUES
|
1997-11-23 07:07:32 +03:00
|
|
|
Upon successful completion a pointer to the parsed line is returned;
|
1997-11-17 01:15:54 +03:00
|
|
|
otherwise,
|
|
|
|
.Dv NULL
|
|
|
|
is returned.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn fparseln
|
|
|
|
function uses internally
|
|
|
|
.Xr fgetln 3 ,
|
1999-07-02 19:46:05 +04:00
|
|
|
so all error conditions that apply to
|
1997-11-17 01:15:54 +03:00
|
|
|
.Xr fgetln 3 ,
|
1999-07-02 19:46:05 +04:00
|
|
|
apply to
|
1997-11-17 01:15:54 +03:00
|
|
|
.Fn fparseln .
|
|
|
|
In addition
|
|
|
|
.Fn fparseln
|
|
|
|
may set
|
1999-02-16 22:36:52 +03:00
|
|
|
.Va errno
|
1997-11-17 01:15:54 +03:00
|
|
|
to
|
1999-07-02 19:46:05 +04:00
|
|
|
.Bq Er ENOMEM
|
|
|
|
and return
|
1997-11-17 01:15:54 +03:00
|
|
|
.Dv NULL
|
|
|
|
if it runs out of memory.
|
|
|
|
.Sh SEE ALSO
|
1999-07-02 19:46:05 +04:00
|
|
|
.Xr fgetln 3
|
1997-11-17 01:15:54 +03:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Fn fparseln
|
1999-07-02 19:46:05 +04:00
|
|
|
function first appeared in
|
1997-11-24 09:28:50 +03:00
|
|
|
.Nx 1.4 .
|