Files
plan9port/man/man3/getfields.3
Dmitri Vereshchagin 10564b1175 tmac/tmac.an: define .MR in a groff compatible way
groff 1.23.0 added .MR to its -man macro package.  The NEWS file states
that the inclusion of the macro "was prompted by its introduction to
Plan 9 from User Space's troff in August 2020."  From d32deab it seems
that the name for Plan 9 from User Space's implementation was suggested
by groff maintainer G. Brandon Robinson.

Not sure if the intention was to make these definitions compatible, but
it would be nice if they were.

Currently, Plan 9 from User Space's .MR expects its second argument to
be parenthesized.  groff's .MR does not.  This results in extra
parentheses appearing in manual references when viewing Plan 9 from User
Space's manual pages on a system using groff.
2025-07-27 09:58:50 -04:00

96 lines
1.6 KiB
Groff

.TH GETFIELDS 3
.SH NAME
getfields, gettokens, tokenize \- break a string into fields
.SH SYNOPSIS
.B #include <u.h>
.br
.B #include <libc.h>
.PP
.ta \w'\fLchar* \fP'u
.B
int getfields(char *str, char **args, int maxargs, int multiflag,
.br
.B
char *delims)
.PP
.B
int gettokens(char *str, char **args, int maxargs, char *delims)
.PP
.B
int tokenize(char *str, char **args, int maxargs)
.SH DESCRIPTION
.I Getfields
places into the array
.I args
pointers to the first
.I maxargs
fields of the null terminated
.SM UTF
string
.IR str .
Delimiters between these fields are set to null.
.PP
Fields are substrings of
.I str
whose definition depends on the value of
.IR multiflag.
If
.I multiflag
is zero,
adjacent fields are separated by exactly one delimiter.
For example
.EX
getfields("#alice#bob##charles###", arg, 3, 0, "#");
.EE
yields three substrings:
null-string ,
.BR "alice" ,
and
.BR "bob##charles###" .
If the
.I multiflag
argument is not zero,
a field is a non-empty string of non-delimiters.
For example
.EX
getfields("#alice#bob##charles###", arg, 3, 1, "#");
.EE
yields the three substrings:
.BR "alice" ,
.BR "bob" ,
and
.BR "charles###" .
.PP
Getfields returns the number of fields pointed to.
.PP
.I Gettokens
is the same as
.I getfields
with
.I multiflag
non-zero,
except that fields may be quoted using single quotes, in the manner
of
.MR rc 1 .
See
.MR quote 3
for related quote-handling software.
.PP
.I Tokenize
is
.I gettokens
with
.I delims
set to \f5"\et\er\en "\fP.
.SH SOURCE
.B \*9/src/lib9/tokenize.c
.SH SEE ALSO
.I strtok
in
.MR strcat 3 ,
.MR quote 3 .