Subversion Repositories planix.SVN

Rev

Rev 34 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
.TH GETFIELDS 2
2
.SH NAME
3
getfields, gettokens, tokenize \- break a string into fields
4
.SH SYNOPSIS
5
.B #include <u.h>
6
.br
7
.B #include <libc.h>
8
.PP
9
.ta \w'\fLchar* \fP'u
10
.B
11
int	getfields(char *str, char **args, int maxargs, int multiflag,
12
.br
13
.B
14
	    char *delims)
15
.PP
16
.B
17
int	gettokens(char *str, char **args, int maxargs, char *delims)
18
.PP
19
.B
20
int	tokenize(char *str, char **args, int maxargs)
21
.SH DESCRIPTION
22
.I Getfields
23
places into the array
24
.I args
25
pointers to the first
26
.I maxargs
27
fields of the null terminated
28
.SM UTF
29
string
30
.IR str .
31
Delimiters between these fields are set to
32
.SM NUL
33
bytes.
34
.PP
35
Fields are substrings of
36
.I str
37
whose definition depends on the value of
38
.IR multiflag.
39
If
40
.I multiflag
41
is zero,
42
adjacent fields are separated by exactly one delimiter.
43
For example
44
.EX
45
 
46
	getfields("#alice#bob##charles###", arg, 3, 0, "#");
47
 
48
.EE
49
yields three substrings:
50
null-string ,
51
.BR "alice" ,
52
and
53
.BR "bob##charles###" .
54
If the
55
.I multiflag
56
argument is not zero,
57
a field is a non-empty string of non-delimiters.
58
For example
59
.EX
60
 
61
	getfields("#alice#bob##charles###", arg, 3, 1, "#");
62
 
63
.EE
64
yields the three substrings:
65
.BR "alice" ,
66
.BR "bob" ,
67
and
68
.BR "charles###" .
69
.PP
70
Getfields returns the number of fields pointed to.
71
.PP
72
.I Gettokens
73
is the same as
74
.I getfields
75
with
76
.I multiflag
77
non-zero,
78
except that fields may be quoted using single quotes, in the manner
79
of
80
.IR rc (1).
81
Any such quotes remain in the resulting
82
.IR args .
83
See
84
.IR quote (2)
85
for related quote-handling software.
86
.PP
87
.I Tokenize
88
is similar to
89
.I gettokens
90
with 
91
.I delims
92
set to \f5"\et\er\en\ "\fP,
93
except that quotes are interpreted but do not appear in the resulting
94
.IR args .
95
.SH SOURCE
96
.B /sys/src/libc/port/tokenize.c
97
.SH SEE ALSO
98
.I strtok
99
in
100
.IR strcat (2),
101
.IR quote (2).