70 lines
1.7 KiB
Plaintext
70 lines
1.7 KiB
Plaintext
'\"macro stdmacro
|
|
.if n .pH g3g.bufsplit @(#)bufsplit 40.9 of 5/22/91
|
|
.\" Copyright 1991 UNIX System Laboratories, Inc.
|
|
.\" Copyright 1989, 1990 AT&T
|
|
.nr X
|
|
.if \nX=0 .ds x} bufsplit 3G "Enhanced Programming Library" "\&"
|
|
.if \nX=1 .ds x} bufsplit 3G "Enhanced Programming Library"
|
|
.if \nX=2 .ds x} bufsplit 3G "" "\&"
|
|
.if \nX=3 .ds x} bufsplit "" "" "\&"
|
|
.TH \*(x}
|
|
.SH NAME
|
|
\f4bufsplit\f1 \- split buffer into fields
|
|
.SH SYNOPSIS
|
|
\f4cc\f1
|
|
[\f2flag\fP \|.\|.\|.] \f2file\fP \|.\|.\|.
|
|
\f4\-lgen\f1
|
|
[\f2library\fP \|.\|.\|.]
|
|
.PP
|
|
\f4#include <libgen.h>\f1
|
|
.PP
|
|
\f4size_t bufsplit (char \(**buf, size_t n, char \(**\(**a);\f1
|
|
.SH DESCRIPTION
|
|
\f4bufsplit\fP
|
|
examines the buffer, \f2buf\f1, and assigns values to the pointer array,
|
|
\f2a\f1, so that the pointers point to the first
|
|
.I n
|
|
fields in \f2buf\f1 that are delimited by tabs or new-lines.
|
|
.PP
|
|
To change the characters used to separate fields, call
|
|
\f4bufsplit\fP
|
|
with
|
|
.I buf
|
|
pointing to the string of characters, and
|
|
.I n
|
|
and
|
|
.I a
|
|
set to zero. For example, to use '\f4:\fP', '\f4.\fP', and '\f4,\fP' as
|
|
separators along with tab
|
|
and new-line:
|
|
.PP
|
|
.RS
|
|
.ft 4
|
|
bufsplit (":.,\et\en", 0, (char\(**\(**)0 );
|
|
.ft 1
|
|
.RE
|
|
.SH "RETURN VALUE"
|
|
The number of fields assigned in the array
|
|
.IR a .
|
|
If
|
|
.I buf
|
|
is zero, the return value is zero and the array is unchanged. Otherwise the value is
|
|
at least one. The remainder of the elements in the array are assigned the address
|
|
of the null byte at the end of the buffer.
|
|
.SH EXAMPLES
|
|
.ft 4
|
|
.nf
|
|
/\(**
|
|
\(** set a[0] = "This", a[1] = "is", a[2] = "a",
|
|
\(** a[3] = "test"
|
|
\(**/
|
|
bufsplit("This\\tis\\ta\\ttest\\n", 4, a);
|
|
.fi
|
|
.ft 1
|
|
.SH NOTES
|
|
\f4bufsplit\fP
|
|
changes the delimiters to null bytes in
|
|
.IR buf .
|
|
.\" @(#)bufsplit.3g 1 of 8/25/88
|
|
.Ee
|