aboutsummaryrefslogtreecommitdiff
path: root/man/man3/acme.3
blob: d2f116ae691aa1564e4c783bcba1ba06cb6732d8 (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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
.TH ACME 3
.SH NAME
Event, Win,
eventfmt,
newwin,
pipetowin,
pipewinto,
sysrun,
winaddr,
winclosefiles,
winctl,
windel,
windeleteall,
windows,
wineventchan,
winfd,
winfree,
winmread,
winname,
winopenfd,
winprint,
winread,
winreadaddr,
winreadevent,
winseek,
winwrite,
winwriteevent \- acme client library
.SH SYNOPSIS
.ft L
.nf
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <9pclient.h>
#include <acme.h>
.fi
.PP
.ft L
.ta +\w'\fLxxxx'u +\w'\fLxxxxx'u
.nf
struct Event
{
	int	c1;
	int	c2;
	int	q0;
	int	q1;
	int	oq0;
	int	oq1;
	int	flag;
	int	nb;
	int	nr;
	char	text[];
	char	arg[];
	char	loc[];
};
.PP
.ta +\w'\fLxxxxxxxxxx'u
.B
int	eventfmt(Fmt *fmt)
.PP
.B
Win*	newwin(void)
.PP
.B
Win*	openwin(int id, CFid *ctlfid)
.PP
.B
int	pipetowin(Win *w, char *file, int fderr, char *fmt, ...)
.PP
.B
int	pipewinto(Win *w, char *file, int fdout, char *fmt, ...)
.PP
.B
char*	sysrun(char *fmt, ...)
.PP
.B
int	winaddr(Win *w, char *fmt, ...)
.PP
.B
void	winclosefiles(Win *w)
.PP
.B
int	winctl(Win *w, char *fmt, ...)
.PP
.B
int	windel(Win *w, int sure)
.PP
.B
void	windeleteall(void)
.PP
.B
Channel*	wineventchan(Win *w)
.PP
.B
int	winfd(Win *w, char *name, int mode)
.PP
.B
void	winfree(Win *w)
.PP
.B
char*	winmread(Win *w, char *file)
.PP
.B
int	winname(Win *w, char *fmt, ...)
.PP
.B
int	winopenfd(Win *w, char *name, int mode)
.PP
.B
int	winprint(Win *w, char *file, char *fmt, ...)
.PP
.B
int	winread(Win *w, char *file, void *a, int n)
.PP
.B
int	winreadaddr(Win *w, uint *q1)
.PP
.B
int	winreadevent(Win *w, Event *e)
.PP
.B
int	winseek(Win *w, char *file, int off, int type)
.PP
.B
int	winwrite(Win *w, char *file, void *a, int n)
.PP
.B
int	winwriteevent(Win *w, Event *e)
.PP
.B
void*	emalloc(uint n)
.PP
.B
void*	erealloc(void *v, uint n)
.PP
.B
char*	estrdup(char *s)
.PP
.B
char*	evsmprint(char *fmt, va_list arg)
.SH DESCRIPTION
.I Libacme
provides a simple C interface for interacting with
.IM acme (1)
windows.
.PP
A
.B Win
structure represents a single window and its control files.
The contents of the structure should not be accessed directly.
.I Newwin
creates a new window and returns a structure corresponding to that window.
.I Openwin
allocates a structure corresponding to the existing window with the given
.IR id .
If
.I ctlfid
is non-nil, 
.I openwin
assumes it is a file descriptor open for writing to the window's
.B ctl
file.
Ownership of
.I ctlfid
passes to the library.
.PP
Most of the library routines access files in the window's
.I acme
directory.
See
.IM acme (4)
for details.
Many library routines take a format string
.I fmt
followed by a variable list of arguments.
In the discussion below, the notation
.I fmt\fR, \fP...
denotes the result of formatting the string and arguments
using
.I smprint
(see
.IM print (3) ).
.PP
.I Pipetowin
runs the
.IM rc (1)
command line
.I fmt\fR, \fP...
with 
.B /dev/null
on standard input and the window's
.I file
on standard output.
If
.I fderr
is non-zero (sic), 
it is used as standard error.
Otherwise the command inherits the caller's standard error.
.PP
.I Pipewinto
runs the 
.IM rc (1)
command line
.I fmt\fR, \fP...
with the window's
.I file
on standard input.
The command runs with
.I fdout 
as its standard output and standard error.
.PP
.I Sysrun
runs the
.I rc
command line
.I fmt\fR, \fP...
and returns a pointer to the first kilobyte of output, NUL-terminated.
The buffer holding the output is reused on each call.
.PP
.I Winaddr
writes
.I fmt\fR, \fP...
to the window's
.B addr
file.
.PP
.I Winclosefiles
closes all the open file descriptors associated with the window.
(These file descriptors are maintained from the library and 
cached across calls to 
.IR winctl ,
.IR etc .)
.PP
.I Winctl
writes
.I fmt\fR, \fP...
to the window's
.B ctl
file.
.PP
.I Windel
deletes the window,
writing
.B del
(or, if
.I sure
is set,
.B delete)
to the window's
.B ctl
file.
.PP
.I Winfd
returns a file descriptor for the window's
.I file
opened for
.IR mode .
The caller is responsible for closing the file descriptor.
.PP
.I Winmread
reads the contents of the window's
.I file
into a dynamically allocated buffer
and returns it.
The caller is responsible for freeing the buffer.
.PP
.I Winname
sets the name of the window to
.I fmt\fR, \fP...
by writing to the
.B ctl
file.
.PP
.I Winprint
prints
.I fmt\fR, \fP...
to the window's
.IR file .
.PP
.I Winread
reads at most 
.I n
bytes from the window's
.IR file
into the buffer pointed at by
.IR a .
.PP
.I Winreadaddr
reads the window's
.B addr
file, which contains two integers.
It returns the first and stores the second in 
.BI * q1 \fR.
.PP
.I Winseek
seeks the file descriptor for the window's
.I file
to position
.I off
relative to
.I type
(see
.IM seek (3) ).
.PP
.I Winwrite
writes the
.I n
bytes pointed at by
.I a
to the window's
.IR file .
.PP
An
.B Event
structure represents an event originating in a particular window.
The fields correspond to the fields in
.IR acme 's
event messages.
See 
.IM acme (4)
for detailed explanations.
The fields are:
.TP
.BR c1 ", " c2
The two event characters, indicating origin and type of action.
.TP
.BR q0 ", " q1
The character addresses of the action.
If the original event had an empty selection
.RB ( q0 = q1 )
and was accompanied by an expansion
(the 2 bit is set in the flag), then 
.B q0
and
.B q1
will indicate the expansion rather than original event.
.TP
.BR oq0 ", " oq1
The 
.B q0
and
.B q1
of the original event, even if it was expanded.
If there was no expansion,
.BR oq0 = q0
and
.BR oq1 = q1 .
.TP
.B flag
The flag.
.TP
.B nr
The number of characters (UTF sequences) included in the optional text.
.TP
.B text
The optional text itself, encoded in UTF.
.TP
.B nb
The number of bytes included in the optional text.
.TP
.B arg
The chorded argument, if present
(the 8 bit is set in the flag).
.TP
.B loc
The chorded location, if present
(the 8 bit is set in the flag).
.PD
.PP
.I Winreadevent
reads the next event (q.v.)
from the window's
.B event
file.
.PP
.I Winwriteevent
writes an event back to the window's 
.B event
file, indicating to
.I acme
that it should be handled internally.
.PP
.I Wineventchan
returns a pointer to a
.B Channel
(see
.IM thread (3) )
on which event structures (not pointers) can be read.
The first call to
.I wineventchan
allocates a channel and
starts a new thread that loops calling
.I winreadevent
and copying the events into the channel.
Subsequent calls return the same channel.
Clients should not call
.I winreadevent
after calling
.IR wineventchan .
.PP
.IR Emalloc ,
.IR erealloc ,
.IR estrdup ,
and
.I evsmprint
are like
.IM malloc (3) ,
.IR realloc ,
.IR strdup
(see
.IM strcat (3) ),
and
.IR vsmprint
(see
.IM print (3) ),
but they call
.IM sysfatal (3)
on error rather than returning nil.
.SH SOURCE
.B \*9/src/libacme
.SH SEE ALSO
.IM acme (1) ,
.IM acme (4)