=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/audioctl/audioctl.c,v retrieving revision 1.10 retrieving revision 1.11 diff -c -r1.10 -r1.11 *** src/usr.bin/audioctl/audioctl.c 2003/06/21 01:39:07 1.10 --- src/usr.bin/audioctl/audioctl.c 2004/07/06 02:46:06 1.11 *************** *** 1,4 **** ! /* $OpenBSD: audioctl.c,v 1.10 2003/06/21 01:39:07 deraadt Exp $ */ /* $NetBSD: audioctl.c,v 1.14 1998/04/27 16:55:23 augustss Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: audioctl.c,v 1.11 2004/07/06 02:46:06 vincent Exp $ */ /* $NetBSD: audioctl.c,v 1.14 1998/04/27 16:55:23 augustss Exp $ */ /* *************** *** 324,330 **** fprintf(stderr, "usage: %s [-f file] [-n] -a\n" " %s [-f file] [-n] name [...]\n" ! " %s [-f file] [-n] -w name=value [...]\n", __progname, __progname, __progname); exit(1); --- 324,330 ---- fprintf(stderr, "usage: %s [-f file] [-n] -a\n" " %s [-f file] [-n] name [...]\n" ! " %s [-f file] [-n] name=value [...]\n", __progname, __progname, __progname); exit(1); *************** *** 334,341 **** main(int argc, char **argv) { int fd, i, ch; ! int aflag = 0, wflag = 0; struct stat dstat, ostat; char *file; char *sep = "="; --- 334,342 ---- main(int argc, char **argv) { int fd, i, ch; ! int aflag = 0, canwrite, writeinfo = 0; struct stat dstat, ostat; + struct field *p; char *file; char *sep = "="; *************** *** 348,354 **** aflag++; break; case 'w': ! wflag++; break; case 'n': sep = 0; --- 349,355 ---- aflag++; break; case 'w': ! /* backward compatibility */ break; case 'n': sep = 0; *************** *** 356,372 **** case 'f': file = optarg; break; - case '?': default: usage(); } } argc -= optind; argv += optind; - if ((fd = open(file, wflag ? O_RDWR : O_RDONLY)) < 0) - err(1, "%s", file); - /* Check if stdout is the same device as the audio device. */ if (fstat(fd, &dstat) < 0) err(1, "fstat au"); --- 357,376 ---- case 'f': file = optarg; break; default: usage(); } } argc -= optind; argv += optind; + + if ((fd = open(file, O_RDWR)) < 0) { + if ((fd = open(file, O_RDONLY)) < 0) + err(1, "%s", file); + canwrite = 0; + } else + canwrite = 1; /* Check if stdout is the same device as the audio device. */ if (fstat(fd, &dstat) < 0) err(1, "fstat au"); *************** *** 378,447 **** /* We can't write to stdout so use stderr */ out = stderr; ! if (!wflag) ! getinfo(fd); ! if (!argc && aflag && !wflag) { ! for(i = 0; fields[i].name; i++) { if (!(fields[i].flags & ALIAS)) { prfield(&fields[i], sep); fprintf(out, "\n"); } } ! } else if (argc > 0 && !aflag) { ! struct field *p; ! if (wflag) { ! AUDIO_INITINFO(&info); ! while(argc--) { ! char *q; ! if ((q = strchr(*argv, '='))) { ! *q++ = 0; ! p = findfield(*argv); ! if (p == 0) ! warnx("field `%s' does not exist", *argv); else { ! if (p->flags & READONLY) ! warnx("`%s' is read only", *argv); ! else { ! rdfield(p, q); ! if (p->valp == &fullduplex) ! if (ioctl(fd, AUDIO_SETFD, &fullduplex) < 0) ! err(1, "set failed"); ! } } ! } else ! warnx("No `=' in %s", *argv); ! argv++; ! } ! if (ioctl(fd, AUDIO_SETINFO, &info) < 0) ! err(1, "set failed"); ! if (sep) { ! getinfo(fd); ! for(i = 0; fields[i].name; i++) { ! if (fields[i].flags & SET) { ! fprintf(out, "%s: -> ", fields[i].name); ! prfield(&fields[i], 0); ! fprintf(out, "\n"); ! } } ! } ! } else { ! while(argc--) { p = findfield(*argv); ! if (p == 0) { ! if (strchr(*argv, '=')) ! warnx("field %s does not exist (use -w to set a variable)", *argv); ! else ! warnx("field %s does not exist", *argv); ! } else { prfield(p, sep); fprintf(out, "\n"); } - argv++; } } ! } else ! usage(); exit(0); } --- 382,446 ---- /* We can't write to stdout so use stderr */ out = stderr; ! if (!argc && !aflag) ! usage(); ! getinfo(fd); ! ! if (aflag) { ! for (i = 0; fields[i].name; i++) { if (!(fields[i].flags & ALIAS)) { prfield(&fields[i], sep); fprintf(out, "\n"); } } ! } else { ! while (argc--) { ! char *q; ! if ((q = strchr(*argv, '=')) != NULL) { ! *q++ = 0; ! p = findfield(*argv); ! if (p == 0) ! warnx("field `%s' does not exist", *argv); ! else { ! if (!canwrite) ! errx(1, "%s: permission denied", ! *argv); ! if (p->flags & READONLY) ! warnx("`%s' is read only", *argv); else { ! rdfield(p, q); ! if (p->valp == &fullduplex) ! if (ioctl(fd, AUDIO_SETFD, ! &fullduplex) < 0) ! err(1, "set failed"); } ! writeinfo = 1; } ! } else { p = findfield(*argv); ! if (p == 0) ! warnx("field %s does not exist", *argv); ! else { prfield(p, sep); fprintf(out, "\n"); } } + argv++; } ! if (writeinfo && ioctl(fd, AUDIO_SETINFO, &info) < 0) ! err(1, "set failed"); ! if (sep) { ! getinfo(fd); ! for (i = 0; fields[i].name; i++) { ! if (fields[i].flags & SET) { ! fprintf(out, "%s: -> ", fields[i].name); ! prfield(&fields[i], 0); ! fprintf(out, "\n"); ! } ! } ! } ! } exit(0); }