aboutsummaryrefslogtreecommitdiff
path: root/man/man3/getfields.3
blob: feaf10d85197c0cf870abfa7271e7192f157ed01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
.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
.IR rc (1).
See
.IR 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
.IR strcat (3),
.IR quote (3).