summaryrefslogtreecommitdiff
path: root/src/lib/libast/man/tok.3
blob: 46fbff95035b5b4d356a32f9bce6296f4b475fcf (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
.fp 5 CW
.de Af
.ds ;G \\*(;G\\f\\$1\\$3\\f\\$2
.if !\\$4 .Af \\$2 \\$1 "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
..
.de aF
.ie \\$3 .ft \\$1
.el \{\
.ds ;G \&
.nr ;G \\n(.f
.Af "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
\\*(;G
.ft \\n(;G \}
..
.de L
.aF 5 \\n(.f "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de LR
.aF 5 1 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de RL
.aF 1 5 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de EX		\" start example
.ta 1i 2i 3i 4i 5i 6i
.PP
.RS 
.PD 0
.ft 5
.nf
..
.de EE		\" end example
.fi
.ft
.PD
.RE
.PP
..
.TH TOK 3
.SH NAME
tok \- space separated token stream routines
.SH SYNOPSIS
.L "#include <ast.h>"
.sp
.L "void* tokopen(char* string)"
.L "char* tokread(void* tok)"
.L "void tokclose(void* tok)"
.sp
.L "int tokscan(char* string, char** next, const char* format, ...);"
.sp
.L "Sfio_t* tokline(const char* input, int flags, int* line);"
.SH DESCRIPTION
.L tokopen
returns a pointer to a space separated token stream on the 0 terminated
string
.LR string .
.L tokread
returns a pointer to the next
space separated token in the token stream
.L tok
as returned by
.LR tokopen .
0 is returned when no tokens remain.
.L tokread
temporarily modifies
.L string
by inserting 0's to terminate each token.
.L tokclose
closes the token stream and restores
.L string
to its original state.
.PP
.L tokscan
scans the string
.L string
for tokens specified in
.LR format .
It is a more forgiving
.IR sscanf (3).
If
.L "next != 0"
then it will point to the next unread character in
.L string
on return.
The number of scanned tokens is returned.
.L \-1
is returned if 
.L string
was not empty and
.L format
failed to match and tokens.
.PP
.I space
in
.L format
matches 0 or more
.I space
or
.I tab
characters.
.I newline
in format eats the remainder of the current line in
.LR string .
"...", '...' and \e\fIcharacter\fP quotes are interpreted.
A quoted
.I carriage-return
is converted to
.IR newline .
.I newline
in
.L string
is equivalent to end of string except when quoted.
.I \enewline
is a line splice.
.PP
.L %
in
.L format
prefixes format conversion characters; each conversion character 
corresponds to a
.L tokscan
argument following the
.L format
argument.
The format conversions are:
.TP
.L %c
A single 
.LR char .
.TP
.L "%hd %d %ld"
[short, int, long] base 10 integer.
.TP
.L "%hn %n %ln"
[short, int, long] C-style base integer.
.TP
.L "%ho %o %lo"
[short, int, long] base 8 integer.
.TP
.L %s
String.
.TP
.L "%hu %u %lu"
[short, int, long] C-style base unsigned integer.
.TP
.L %v
The next two arguments are a pointer to a
.L char**
argument vector and the maximum number of elements in the vector.
.TP
.L "%hx %x %lx"
[short, int, long] base 16 integer.
.PP
.L %s
and
.L %v
data may also be counted length strings of the form
\f5(\fIcount\fP:\fIdata\fP)\fR
where
.I count
is the number of characters in
.I data
and the terminating
.L )
may also be a
.IR tab ,
or the data may be
.L (null)
which represents the
.L NULL
string.
.PP
.L tokline
returns an
.IR sfio (3)
stream to a file or string that splices
.I \enewline
into single lines,
allows "..." and '...' to quotes to span
.I newlines
(done by translating quoted
.I newline
to
.IR carriage-return ;
.L tokscan
above converts quoted
.I carriage-return
back to 
.IR newline ),
and deletes
.I "# ... newline"
comments.
This is done by pushing an
.I sfio
discipline onto a string or file stream.
Seeks are disabled on the resulting stream.
If
.L "flags == SF_READ"
then
.L input
is a file name;
If
.L "flags == SF_STRING"
then
.L input
is a 0 terminated string;
otherwise
.L input
is an open 
.L Sfio_t*
stream.
If
.L "line != 0"
then it points to a line count that is initialized to 0
and is incremented for each input line.
.SH "SEE ALSO"
sfio(3)