On Thu, 22 Oct 2009 21:41:45 +0000 Jacob Meuser <[email protected]> wrote:
> On Thu, Oct 22, 2009 at 11:02:37PM +0200, Pawlowski Marcin Piotr > wrote: > > On Thu, 22 Oct 2009 22:33:23 +0200 > > Pawlowski Marcin Piotr <[email protected]> wrote: > > > > > Hi, > > > I was playing with audioctl and found that: > > > - fullduplex and full_duplex are the same so one of them is > > > redundant > > so? did you consider that scripts may use one form and not > the other? did you look at the commit history? I did looked at commit history but didn't found any info about why. I will look at scripts and try to find any references of that. > > > - output is different from other *ctl tools > > $ sudo sysctl -n kern.usermount=1 > 1 > $ audioctl -n play.rate=44100 > $ mixerctl -n outputs.master=200 > outputs.master: 200,200 -> 200,200 > > imo, that is a much more "important" inconsistency. > Done. --- audioctl.c.orig Sun Oct 18 12:13:07 2009 +++ audioctl.c Fri Oct 23 00:25:05 2009 @@ -284,6 +284,30 @@ p->flags |= SET; } +cpfield(struct field *p, struct field *q) +{ + int i; + u_int u; + + /* Copy only what is necessary */ + + p->format = q->format; + p->flags = q->flags; + + switch (p->format) { + case ENC: + case UINT: + case XINT: + memcpy(p->valp, q->valp, sizeof(unsigned int)); + break; + case UCHAR: + memcpy(p->valp, q->valp, sizeof(u_char)); + break; + default: + errx(1, "Invalid copy format."); + } +} + void getinfo(int fd) { @@ -335,7 +359,7 @@ int fd, i, ch; int aflag = 0, canwrite, writeinfo = 0; struct stat dstat, ostat; - struct field *p; + struct field *p, old; const char *file; const char *sep = "="; @@ -399,26 +423,42 @@ } 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); + 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); + warnx("`%s' is read only", + *argv); else { + cpfield(&old, p); rdfield(p, q); if (p->valp == &fullduplex) - if (ioctl(fd, AUDIO_SETFD, + if (ioctl(fd, + AUDIO_SETFD, &fullduplex) < 0) - err(1, "set failed"); + err(1, + "set failed"); } - writeinfo = 1; + if (ioctl(fd, AUDIO_SETINFO, &info) < 0) + err(1, "set failed"); + getinfo(fd); + if (sep == 0) { + prfield(p, 0); + fprintf(out, "\n"); + } else if (p->flags & SET) { + fprintf(out, "%s: ", p->name); + prfield(&old, 0); + fprintf(out, " -> "); + prfield(p, 0); + fprintf(out, "\n"); + } } } else { p = findfield(*argv); @@ -430,18 +470,6 @@ } } 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); --- mixerctl.c.orig Fri Oct 23 00:17:36 2009 +++ mixerctl.c Fri Oct 23 00:40:45 2009 @@ -50,7 +50,7 @@ void adjlevel(char **, u_char *, int); void catstr(char *, char *, char *); void prfield(struct field *, char *, int); -void rdfield(int, struct field *, char *, int); +void rdfield(int, struct field *, char *, int, char *); __dead void usage(void); #define FIELD_NAME_MAX 64 @@ -163,7 +163,7 @@ } void -rdfield(int fd, struct field *p, char *q, int quiet) +rdfield(int fd, struct field *p, char *q, int quiet, char *sep) { mixer_ctrl_t *m, oldval; int i, mask; @@ -227,14 +227,19 @@ if (ioctl(fd, AUDIO_MIXER_WRITE, p->valp) < 0) { warn("AUDIO_MIXER_WRITE"); } else if (!quiet) { - *p->valp = oldval; - prfield(p, ": ", 0); - if (ioctl(fd, AUDIO_MIXER_READ, p->valp) < 0) { - warn("AUDIO_MIXER_READ"); - } else { - printf(" -> "); + if (!sep) { prfield(p, NULL, 0); printf("\n"); + } else { + *p->valp = oldval; + prfield(p, ": ", 0); + if (ioctl(fd, AUDIO_MIXER_READ, p->valp) < 0) { + warn("AUDIO_MIXER_READ"); + } else { + printf(" -> "); + prfield(p, NULL, 0); + printf("\n"); + } } } } @@ -375,7 +380,7 @@ } else if (ch || tflag) { if (tflag && q == NULL) q = "toggle"; - rdfield(fd, p, q, qflag); + rdfield(fd, p, q, qflag, sep); } else { prfield(p, sep, vflag); printf("\n");
