blob: feaf10d85197c0cf870abfa7271e7192f157ed01 [file] [log] [blame]
rsccfa37a72004-04-10 18:53:55 +00001.TH GETFIELDS 3
2.SH NAME
3getfields, 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
11int getfields(char *str, char **args, int maxargs, int multiflag,
12.br
13.B
14 char *delims)
15.PP
16.B
17int gettokens(char *str, char **args, int maxargs, char *delims)
18.PP
19.B
20int tokenize(char *str, char **args, int maxargs)
21.SH DESCRIPTION
22.I Getfields
23places into the array
24.I args
25pointers to the first
26.I maxargs
27fields of the null terminated
28.SM UTF
29string
30.IR str .
31Delimiters between these fields are set to null.
32.PP
33Fields are substrings of
34.I str
35whose definition depends on the value of
36.IR multiflag.
37If
38.I multiflag
39is zero,
40adjacent fields are separated by exactly one delimiter.
41For example
42.EX
43
44 getfields("#alice#bob##charles###", arg, 3, 0, "#");
45
46.EE
47yields three substrings:
48null-string ,
49.BR "alice" ,
50and
51.BR "bob##charles###" .
52If the
53.I multiflag
54argument is not zero,
55a field is a non-empty string of non-delimiters.
56For example
57.EX
58
59 getfields("#alice#bob##charles###", arg, 3, 1, "#");
60
61.EE
62yields the three substrings:
63.BR "alice" ,
64.BR "bob" ,
65and
66.BR "charles###" .
67.PP
68Getfields returns the number of fields pointed to.
69.PP
70.I Gettokens
71is the same as
72.I getfields
73with
74.I multiflag
75non-zero,
76except that fields may be quoted using single quotes, in the manner
77of
78.IR rc (1).
79See
rscbf8a59f2004-04-11 03:42:27 +000080.IR quote (3)
rsccfa37a72004-04-10 18:53:55 +000081for related quote-handling software.
82.PP
83.I Tokenize
84is
85.I gettokens
86with
87.I delims
88set to \f5"\et\er\en "\fP.
89.SH SOURCE
rscc3674de2005-01-11 17:37:33 +000090.B \*9/src/lib9/tokenize.c
rsccfa37a72004-04-10 18:53:55 +000091.SH SEE ALSO
92.I strtok
93in
rscbf8a59f2004-04-11 03:42:27 +000094.IR strcat (3),
95.IR quote (3).