ctl.c revision 1.21 1 1.21 augustss /* $NetBSD: ctl.c,v 1.21 1998/11/25 22:17:08 augustss Exp $ */
2 1.1 augustss
3 1.1 augustss /*
4 1.1 augustss * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 1.1 augustss * All rights reserved.
6 1.1 augustss *
7 1.21 augustss * This code is derived from software contributed to The NetBSD Foundation
8 1.21 augustss * by Lennart Augustsson (augustss (at) netbsd.org).
9 1.1 augustss *
10 1.1 augustss * Redistribution and use in source and binary forms, with or without
11 1.1 augustss * modification, are permitted provided that the following conditions
12 1.1 augustss * are met:
13 1.1 augustss * 1. Redistributions of source code must retain the above copyright
14 1.1 augustss * notice, this list of conditions and the following disclaimer.
15 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 augustss * notice, this list of conditions and the following disclaimer in the
17 1.1 augustss * documentation and/or other materials provided with the distribution.
18 1.1 augustss * 3. All advertising materials mentioning features or use of this software
19 1.1 augustss * must display the following acknowledgement:
20 1.1 augustss * This product includes software developed by the NetBSD
21 1.1 augustss * Foundation, Inc. and its contributors.
22 1.1 augustss * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 augustss * contributors may be used to endorse or promote products derived
24 1.1 augustss * from this software without specific prior written permission.
25 1.1 augustss *
26 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.10 jtc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.10 jtc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 augustss * POSSIBILITY OF SUCH DAMAGE.
37 1.1 augustss */
38 1.1 augustss
39 1.1 augustss #include <stdio.h>
40 1.13 augustss #include <stdlib.h>
41 1.1 augustss #include <fcntl.h>
42 1.1 augustss #include <err.h>
43 1.1 augustss #include <unistd.h>
44 1.1 augustss #include <string.h>
45 1.1 augustss #include <sys/types.h>
46 1.2 augustss #include <sys/stat.h>
47 1.1 augustss #include <sys/ioctl.h>
48 1.1 augustss #include <sys/audioio.h>
49 1.1 augustss
50 1.19 augustss #define AUDIOCTL "/dev/audioctl0"
51 1.19 augustss #define OLD_AUDIOCTL "/dev/audioctl"
52 1.19 augustss
53 1.9 augustss struct field *findfield __P((char *name));
54 1.9 augustss void prfield __P((struct field *p, char *sep));
55 1.9 augustss void rdfield __P((struct field *p, char *q));
56 1.9 augustss void getinfo __P((int fd));
57 1.9 augustss void usage __P((void));
58 1.9 augustss int main __P((int argc, char **argv));
59 1.9 augustss
60 1.1 augustss FILE *out = stdout;
61 1.1 augustss
62 1.1 augustss char *prog;
63 1.1 augustss
64 1.1 augustss audio_device_t adev;
65 1.1 augustss
66 1.1 augustss audio_info_t info;
67 1.1 augustss
68 1.1 augustss char encbuf[1000];
69 1.1 augustss
70 1.6 augustss int properties, fullduplex, rerror;
71 1.1 augustss
72 1.1 augustss struct field {
73 1.1 augustss char *name;
74 1.1 augustss void *valp;
75 1.1 augustss int format;
76 1.1 augustss #define STRING 1
77 1.1 augustss #define INT 2
78 1.1 augustss #define UINT 3
79 1.1 augustss #define P_R 4
80 1.18 mrg #define ULONG 5 /* XXX obsolete now */
81 1.1 augustss #define UCHAR 6
82 1.1 augustss #define ENC 7
83 1.6 augustss #define PROPS 8
84 1.12 augustss #define XINT 9
85 1.17 mycroft #define FORMAT 10
86 1.2 augustss char flags;
87 1.2 augustss #define READONLY 1
88 1.2 augustss #define ALIAS 2
89 1.2 augustss #define SET 4
90 1.1 augustss } fields[] = {
91 1.11 augustss { "name", &adev.name, STRING, READONLY },
92 1.11 augustss { "version", &adev.version, STRING, READONLY },
93 1.11 augustss { "config", &adev.config, STRING, READONLY },
94 1.11 augustss { "encodings", encbuf, STRING, READONLY },
95 1.11 augustss { "properties", &properties, PROPS, READONLY },
96 1.15 augustss { "full_duplex", &fullduplex, UINT, 0 },
97 1.15 augustss { "fullduplex", &fullduplex, UINT, 0 },
98 1.11 augustss { "blocksize", &info.blocksize, UINT, 0 },
99 1.11 augustss { "hiwat", &info.hiwat, UINT, 0 },
100 1.11 augustss { "lowat", &info.lowat, UINT, 0 },
101 1.12 augustss { "monitor_gain", &info.monitor_gain, UINT, 0 },
102 1.11 augustss { "mode", &info.mode, P_R, READONLY },
103 1.17 mycroft { "play", &info.play, FORMAT, ALIAS },
104 1.11 augustss { "play.rate", &info.play.sample_rate, UINT, 0 },
105 1.11 augustss { "play.sample_rate", &info.play.sample_rate, UINT, ALIAS },
106 1.11 augustss { "play.channels", &info.play.channels, UINT, 0 },
107 1.11 augustss { "play.precision", &info.play.precision, UINT, 0 },
108 1.11 augustss { "play.encoding", &info.play.encoding, ENC, 0 },
109 1.11 augustss { "play.gain", &info.play.gain, UINT, 0 },
110 1.12 augustss { "play.balance", &info.play.balance, UCHAR, 0 },
111 1.12 augustss { "play.port", &info.play.port, XINT, 0 },
112 1.12 augustss { "play.avail_ports", &info.play.avail_ports, XINT, 0 },
113 1.18 mrg { "play.seek", &info.play.seek, UINT, READONLY },
114 1.11 augustss { "play.samples", &info.play.samples, UINT, READONLY },
115 1.11 augustss { "play.eof", &info.play.eof, UINT, READONLY },
116 1.11 augustss { "play.pause", &info.play.pause, UCHAR, 0 },
117 1.11 augustss { "play.error", &info.play.error, UCHAR, READONLY },
118 1.11 augustss { "play.waiting", &info.play.waiting, UCHAR, READONLY },
119 1.11 augustss { "play.open", &info.play.open, UCHAR, READONLY },
120 1.11 augustss { "play.active", &info.play.active, UCHAR, READONLY },
121 1.12 augustss { "play.buffer_size", &info.play.buffer_size, UINT, 0 },
122 1.17 mycroft { "record", &info.record, FORMAT, ALIAS },
123 1.11 augustss { "record.rate", &info.record.sample_rate,UINT, 0 },
124 1.11 augustss { "record.sample_rate", &info.record.sample_rate,UINT, ALIAS },
125 1.11 augustss { "record.channels", &info.record.channels, UINT, 0 },
126 1.11 augustss { "record.precision", &info.record.precision, UINT, 0 },
127 1.11 augustss { "record.encoding", &info.record.encoding, ENC, 0 },
128 1.11 augustss { "record.gain", &info.record.gain, UINT, 0 },
129 1.12 augustss { "record.balance", &info.record.balance, UCHAR, 0 },
130 1.12 augustss { "record.port", &info.record.port, XINT, 0 },
131 1.12 augustss { "record.avail_ports", &info.record.avail_ports,XINT, 0 },
132 1.18 mrg { "record.seek", &info.record.seek, UINT, READONLY },
133 1.11 augustss { "record.samples", &info.record.samples, UINT, READONLY },
134 1.11 augustss { "record.eof", &info.record.eof, UINT, READONLY },
135 1.11 augustss { "record.pause", &info.record.pause, UCHAR, 0 },
136 1.11 augustss { "record.error", &info.record.error, UCHAR, READONLY },
137 1.11 augustss { "record.waiting", &info.record.waiting, UCHAR, READONLY },
138 1.11 augustss { "record.open", &info.record.open, UCHAR, READONLY },
139 1.11 augustss { "record.active", &info.record.active, UCHAR, READONLY },
140 1.12 augustss { "record.buffer_size", &info.record.buffer_size,UINT, 0 },
141 1.11 augustss { "record.errors", &rerror, INT, READONLY },
142 1.11 augustss { 0 }
143 1.1 augustss };
144 1.1 augustss
145 1.1 augustss struct {
146 1.1 augustss char *ename;
147 1.1 augustss int eno;
148 1.1 augustss } encs[] = {
149 1.12 augustss { AudioEmulaw, AUDIO_ENCODING_ULAW },
150 1.11 augustss { "ulaw", AUDIO_ENCODING_ULAW },
151 1.12 augustss { AudioEalaw, AUDIO_ENCODING_ALAW },
152 1.12 augustss { AudioEslinear, AUDIO_ENCODING_SLINEAR },
153 1.11 augustss { "linear", AUDIO_ENCODING_SLINEAR },
154 1.12 augustss { AudioEulinear, AUDIO_ENCODING_ULINEAR },
155 1.12 augustss { AudioEadpcm, AUDIO_ENCODING_ADPCM },
156 1.11 augustss { "ADPCM", AUDIO_ENCODING_ADPCM },
157 1.12 augustss { AudioEslinear_le, AUDIO_ENCODING_SLINEAR_LE },
158 1.11 augustss { "linear_le", AUDIO_ENCODING_SLINEAR_LE },
159 1.12 augustss { AudioEulinear_le, AUDIO_ENCODING_ULINEAR_LE },
160 1.12 augustss { AudioEslinear_be, AUDIO_ENCODING_SLINEAR_BE },
161 1.11 augustss { "linear_be", AUDIO_ENCODING_SLINEAR_BE },
162 1.12 augustss { AudioEulinear_be, AUDIO_ENCODING_ULINEAR_BE },
163 1.12 augustss { AudioEmpeg_l1_stream, AUDIO_ENCODING_MPEG_L1_STREAM },
164 1.12 augustss { AudioEmpeg_l1_packets,AUDIO_ENCODING_MPEG_L1_PACKETS },
165 1.12 augustss { AudioEmpeg_l1_system, AUDIO_ENCODING_MPEG_L1_SYSTEM },
166 1.12 augustss { AudioEmpeg_l2_stream, AUDIO_ENCODING_MPEG_L2_STREAM },
167 1.12 augustss { AudioEmpeg_l2_packets,AUDIO_ENCODING_MPEG_L2_PACKETS },
168 1.12 augustss { AudioEmpeg_l2_system, AUDIO_ENCODING_MPEG_L2_SYSTEM },
169 1.11 augustss { 0 }
170 1.11 augustss };
171 1.11 augustss
172 1.11 augustss static struct {
173 1.11 augustss char *name;
174 1.11 augustss u_int prop;
175 1.11 augustss } props[] = {
176 1.11 augustss { "full_duplex", AUDIO_PROP_FULLDUPLEX },
177 1.11 augustss { "mmap", AUDIO_PROP_MMAP },
178 1.11 augustss { "independent", AUDIO_PROP_INDEPENDENT },
179 1.11 augustss { 0 }
180 1.1 augustss };
181 1.1 augustss
182 1.1 augustss struct field *
183 1.9 augustss findfield(name)
184 1.11 augustss char *name;
185 1.1 augustss {
186 1.11 augustss int i;
187 1.11 augustss for(i = 0; fields[i].name; i++)
188 1.11 augustss if (strcmp(fields[i].name, name) == 0)
189 1.11 augustss return &fields[i];
190 1.11 augustss return 0;
191 1.1 augustss }
192 1.1 augustss
193 1.1 augustss void
194 1.9 augustss prfield(p, sep)
195 1.11 augustss struct field *p;
196 1.11 augustss char *sep;
197 1.1 augustss {
198 1.11 augustss u_int v;
199 1.11 augustss char *cm;
200 1.11 augustss int i;
201 1.11 augustss
202 1.11 augustss if (sep)
203 1.11 augustss fprintf(out, "%s%s", p->name, sep);
204 1.11 augustss switch(p->format) {
205 1.11 augustss case STRING:
206 1.11 augustss fprintf(out, "%s", (char*)p->valp);
207 1.11 augustss break;
208 1.11 augustss case INT:
209 1.11 augustss fprintf(out, "%d", *(int*)p->valp);
210 1.11 augustss break;
211 1.11 augustss case UINT:
212 1.11 augustss fprintf(out, "%u", *(u_int*)p->valp);
213 1.11 augustss break;
214 1.12 augustss case XINT:
215 1.12 augustss fprintf(out, "0x%x", *(u_int*)p->valp);
216 1.12 augustss break;
217 1.11 augustss case UCHAR:
218 1.11 augustss fprintf(out, "%u", *(u_char*)p->valp);
219 1.11 augustss break;
220 1.11 augustss case ULONG:
221 1.11 augustss fprintf(out, "%lu", *(u_long*)p->valp);
222 1.11 augustss break;
223 1.11 augustss case P_R:
224 1.11 augustss v = *(u_int*)p->valp;
225 1.11 augustss cm = "";
226 1.11 augustss if (v & AUMODE_PLAY) {
227 1.11 augustss if (v & AUMODE_PLAY_ALL)
228 1.11 augustss fprintf(out, "play");
229 1.11 augustss else
230 1.11 augustss fprintf(out, "playsync");
231 1.11 augustss cm = ",";
232 1.11 augustss }
233 1.11 augustss if (v & AUMODE_RECORD)
234 1.11 augustss fprintf(out, "%srecord", cm);
235 1.11 augustss break;
236 1.11 augustss case ENC:
237 1.11 augustss v = *(u_int*)p->valp;
238 1.11 augustss for(i = 0; encs[i].ename; i++)
239 1.11 augustss if (encs[i].eno == v)
240 1.11 augustss break;
241 1.11 augustss if (encs[i].ename)
242 1.11 augustss fprintf(out, "%s", encs[i].ename);
243 1.11 augustss else
244 1.11 augustss fprintf(out, "%u", v);
245 1.11 augustss break;
246 1.11 augustss case PROPS:
247 1.11 augustss v = *(u_int*)p->valp;
248 1.11 augustss for (cm = "", i = 0; props[i].name; i++) {
249 1.11 augustss if (v & props[i].prop) {
250 1.11 augustss fprintf(out, "%s%s", cm, props[i].name);
251 1.11 augustss cm = ",";
252 1.11 augustss }
253 1.11 augustss }
254 1.1 augustss break;
255 1.17 mycroft case FORMAT:
256 1.17 mycroft prfield(p + 1, 0);
257 1.17 mycroft fprintf(out, ",");
258 1.17 mycroft prfield(p + 3, 0);
259 1.17 mycroft fprintf(out, ",");
260 1.17 mycroft prfield(p + 4, 0);
261 1.17 mycroft fprintf(out, ",");
262 1.17 mycroft prfield(p + 5, 0);
263 1.17 mycroft break;
264 1.11 augustss default:
265 1.12 augustss errx(1, "Invalid print format.");
266 1.6 augustss }
267 1.2 augustss }
268 1.2 augustss
269 1.2 augustss void
270 1.9 augustss rdfield(p, q)
271 1.11 augustss struct field *p;
272 1.11 augustss char *q;
273 1.2 augustss {
274 1.11 augustss int i;
275 1.12 augustss u_int u;
276 1.17 mycroft char *s;
277 1.2 augustss
278 1.11 augustss switch(p->format) {
279 1.11 augustss case UINT:
280 1.11 augustss if (sscanf(q, "%u", (unsigned int *)p->valp) != 1)
281 1.17 mycroft errx(1, "Bad number: %s", q);
282 1.1 augustss break;
283 1.12 augustss case UCHAR:
284 1.12 augustss if (sscanf(q, "%u", &u) != 1)
285 1.17 mycroft errx(1, "Bad number: %s", q);
286 1.12 augustss else
287 1.12 augustss *(u_char *)p->valp = u;
288 1.12 augustss break;
289 1.12 augustss case XINT:
290 1.12 augustss if (sscanf(q, "0x%x", (unsigned int *)p->valp) != 1 &&
291 1.12 augustss sscanf(q, "%x", (unsigned int *)p->valp) != 1)
292 1.17 mycroft errx(1, "Bad number: %s", q);
293 1.12 augustss break;
294 1.11 augustss case ENC:
295 1.11 augustss for(i = 0; encs[i].ename; i++)
296 1.11 augustss if (strcmp(encs[i].ename, q) == 0)
297 1.11 augustss break;
298 1.11 augustss if (encs[i].ename)
299 1.11 augustss *(u_int*)p->valp = encs[i].eno;
300 1.11 augustss else
301 1.17 mycroft errx(1, "Unknown encoding: %s", q);
302 1.17 mycroft break;
303 1.17 mycroft case FORMAT:
304 1.17 mycroft s = strsep(&q, ",");
305 1.17 mycroft if (s)
306 1.17 mycroft rdfield(p + 1, s);
307 1.17 mycroft s = strsep(&q, ",");
308 1.17 mycroft if (s)
309 1.17 mycroft rdfield(p + 3, s);
310 1.17 mycroft s = strsep(&q, ",");
311 1.17 mycroft if (s)
312 1.17 mycroft rdfield(p + 4, s);
313 1.17 mycroft s = strsep(&q, ",");
314 1.17 mycroft if (s)
315 1.17 mycroft rdfield(p + 5, s);
316 1.17 mycroft if (!s || q)
317 1.17 mycroft errx(1, "Bad format");
318 1.11 augustss break;
319 1.11 augustss default:
320 1.12 augustss errx(1, "Invalid read format.");
321 1.11 augustss }
322 1.11 augustss p->flags |= SET;
323 1.1 augustss }
324 1.1 augustss
325 1.1 augustss void
326 1.9 augustss getinfo(fd)
327 1.11 augustss int fd;
328 1.1 augustss {
329 1.11 augustss int pos, i;
330 1.1 augustss
331 1.11 augustss if (ioctl(fd, AUDIO_GETDEV, &adev) < 0)
332 1.11 augustss err(1, "AUDIO_GETDEV");
333 1.16 mycroft for (pos = 0, i = 0; ; i++) {
334 1.11 augustss audio_encoding_t enc;
335 1.11 augustss enc.index = i;
336 1.11 augustss if (ioctl(fd, AUDIO_GETENC, &enc) < 0)
337 1.11 augustss break;
338 1.16 mycroft if (pos >= sizeof(encbuf)-1)
339 1.16 mycroft break;
340 1.11 augustss if (pos)
341 1.11 augustss encbuf[pos++] = ',';
342 1.16 mycroft if (pos >= sizeof(encbuf)-1)
343 1.16 mycroft break;
344 1.16 mycroft pos += snprintf(encbuf+pos, sizeof(encbuf)-pos, "%s:%d%s",
345 1.16 mycroft enc.name, enc.precision,
346 1.11 augustss enc.flags & AUDIO_ENCODINGFLAG_EMULATED ? "*" : "");
347 1.11 augustss }
348 1.11 augustss if (ioctl(fd, AUDIO_GETFD, &fullduplex) < 0)
349 1.11 augustss err(1, "AUDIO_GETFD");
350 1.11 augustss if (ioctl(fd, AUDIO_GETPROPS, &properties) < 0)
351 1.11 augustss err(1, "AUDIO_GETPROPS");
352 1.11 augustss if (ioctl(fd, AUDIO_RERROR, &rerror) < 0)
353 1.11 augustss err(1, "AUDIO_RERROR");
354 1.11 augustss if (ioctl(fd, AUDIO_GETINFO, &info) < 0)
355 1.11 augustss err(1, "AUDIO_GETINFO");
356 1.2 augustss }
357 1.2 augustss
358 1.2 augustss void
359 1.9 augustss usage()
360 1.2 augustss {
361 1.11 augustss fprintf(out, "%s [-f file] [-n] name ...\n", prog);
362 1.11 augustss fprintf(out, "%s [-f file] [-n] -w name=value ...\n", prog);
363 1.11 augustss fprintf(out, "%s [-f file] [-n] -a\n", prog);
364 1.11 augustss exit(1);
365 1.1 augustss }
366 1.1 augustss
367 1.9 augustss int
368 1.9 augustss main(argc, argv)
369 1.11 augustss int argc;
370 1.11 augustss char **argv;
371 1.1 augustss {
372 1.11 augustss int fd, i, ch;
373 1.11 augustss int aflag = 0, wflag = 0;
374 1.11 augustss struct stat dstat, ostat;
375 1.16 mycroft const char *file;
376 1.11 augustss char *sep = "=";
377 1.2 augustss
378 1.14 augustss file = getenv("AUDIOCTLDEVICE");
379 1.13 augustss if (file == 0)
380 1.19 augustss file = AUDIOCTL;
381 1.13 augustss
382 1.11 augustss prog = *argv;
383 1.2 augustss
384 1.11 augustss while ((ch = getopt(argc, argv, "af:nw")) != -1) {
385 1.11 augustss switch(ch) {
386 1.11 augustss case 'a':
387 1.11 augustss aflag++;
388 1.11 augustss break;
389 1.11 augustss case 'w':
390 1.11 augustss wflag++;
391 1.11 augustss break;
392 1.11 augustss case 'n':
393 1.11 augustss sep = 0;
394 1.11 augustss break;
395 1.11 augustss case 'f':
396 1.11 augustss file = optarg;
397 1.11 augustss break;
398 1.11 augustss case '?':
399 1.11 augustss default:
400 1.11 augustss usage();
401 1.11 augustss }
402 1.1 augustss }
403 1.11 augustss argc -= optind;
404 1.11 augustss argv += optind;
405 1.1 augustss
406 1.11 augustss fd = open(file, O_WRONLY);
407 1.11 augustss if (fd < 0)
408 1.11 augustss fd = open(file, O_RDONLY);
409 1.19 augustss #ifdef OLD_AUDIOCTL
410 1.19 augustss /* Allow the non-unit device to be used. */
411 1.20 augustss if (fd < 0 && file == AUDIOCTL) {
412 1.19 augustss file = OLD_AUDIOCTL;
413 1.19 augustss fd = open(file, O_WRONLY);
414 1.19 augustss if (fd < 0)
415 1.19 augustss fd = open(file, O_RDONLY);
416 1.19 augustss }
417 1.19 augustss #endif
418 1.11 augustss if (fd < 0)
419 1.11 augustss err(1, "%s", file);
420 1.2 augustss
421 1.11 augustss /* Check if stdout is the same device as the audio device. */
422 1.11 augustss if (fstat(fd, &dstat) < 0)
423 1.11 augustss err(1, "fstat au");
424 1.11 augustss if (fstat(STDOUT_FILENO, &ostat) < 0)
425 1.9 augustss err(1, "fstat stdout");
426 1.11 augustss if (S_ISCHR(dstat.st_mode) && S_ISCHR(ostat.st_mode) &&
427 1.11 augustss major(dstat.st_dev) == major(ostat.st_dev) &&
428 1.11 augustss minor(dstat.st_dev) == minor(ostat.st_dev))
429 1.11 augustss /* We can't write to stdout so use stderr */
430 1.11 augustss out = stderr;
431 1.11 augustss
432 1.11 augustss if (!wflag)
433 1.2 augustss getinfo(fd);
434 1.11 augustss
435 1.11 augustss if (argc == 0 && aflag && !wflag) {
436 1.1 augustss for(i = 0; fields[i].name; i++) {
437 1.11 augustss if (!(fields[i].flags & ALIAS)) {
438 1.11 augustss prfield(&fields[i], sep);
439 1.11 augustss fprintf(out, "\n");
440 1.11 augustss }
441 1.1 augustss }
442 1.11 augustss } else if (argc > 0 && !aflag) {
443 1.11 augustss struct field *p;
444 1.11 augustss if (wflag) {
445 1.11 augustss AUDIO_INITINFO(&info);
446 1.11 augustss while(argc--) {
447 1.11 augustss char *q;
448 1.11 augustss
449 1.11 augustss q = strchr(*argv, '=');
450 1.11 augustss if (q) {
451 1.11 augustss *q++ = 0;
452 1.11 augustss p = findfield(*argv);
453 1.11 augustss if (p == 0)
454 1.11 augustss warnx("field `%s' does not exist", *argv);
455 1.11 augustss else {
456 1.11 augustss if (p->flags & READONLY)
457 1.11 augustss warnx("`%s' is read only", *argv);
458 1.11 augustss else {
459 1.11 augustss rdfield(p, q);
460 1.11 augustss if (p->valp == &fullduplex)
461 1.11 augustss if (ioctl(fd, AUDIO_SETFD, &fullduplex) < 0)
462 1.11 augustss err(1, "set failed");
463 1.11 augustss }
464 1.11 augustss }
465 1.11 augustss } else
466 1.11 augustss warnx("No `=' in %s", *argv);
467 1.11 augustss argv++;
468 1.11 augustss }
469 1.11 augustss if (ioctl(fd, AUDIO_SETINFO, &info) < 0)
470 1.11 augustss err(1, "set failed");
471 1.11 augustss if (sep) {
472 1.11 augustss getinfo(fd);
473 1.11 augustss for(i = 0; fields[i].name; i++) {
474 1.11 augustss if (fields[i].flags & SET) {
475 1.11 augustss fprintf(out, "%s: -> ", fields[i].name);
476 1.11 augustss prfield(&fields[i], 0);
477 1.11 augustss fprintf(out, "\n");
478 1.11 augustss }
479 1.11 augustss }
480 1.11 augustss }
481 1.1 augustss } else {
482 1.11 augustss while(argc--) {
483 1.11 augustss p = findfield(*argv);
484 1.11 augustss if (p == 0) {
485 1.11 augustss if (strchr(*argv, '='))
486 1.11 augustss warnx("field %s does not exist (use -w to set a variable)", *argv);
487 1.11 augustss else
488 1.11 augustss warnx("field %s does not exist", *argv);
489 1.11 augustss } else {
490 1.11 augustss prfield(p, sep);
491 1.11 augustss fprintf(out, "\n");
492 1.11 augustss }
493 1.11 augustss argv++;
494 1.11 augustss }
495 1.1 augustss }
496 1.11 augustss } else
497 1.11 augustss usage();
498 1.11 augustss exit(0);
499 1.1 augustss }
500