diff options
author | jkim <jkim@FreeBSD.org> | 2008-03-15 01:20:05 +0000 |
---|---|---|
committer | jkim <jkim@FreeBSD.org> | 2008-03-15 01:20:05 +0000 |
commit | a277d9b4820fc8b15fdaa3b1b44f112c2b636cca (patch) | |
tree | b00d4de547cf3619f47a2c908037d0f10e04adac /usr.sbin | |
parent | dd20f0a338fa59b8db17e16426683917977298c2 (diff) | |
download | FreeBSD-src-a277d9b4820fc8b15fdaa3b1b44f112c2b636cca.zip FreeBSD-src-a277d9b4820fc8b15fdaa3b1b44f112c2b636cca.tar.gz |
Clean up code and fix style(9) nits.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/mixer/mixer.c | 202 |
1 files changed, 102 insertions, 100 deletions
diff --git a/usr.sbin/mixer/mixer.c b/usr.sbin/mixer/mixer.c index 5b9423d..3a88ddd 100644 --- a/usr.sbin/mixer/mixer.c +++ b/usr.sbin/mixer/mixer.c @@ -24,20 +24,20 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include <sys/soundcard.h> -const char *names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; +const char *names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; -void usage(int devmask, int recmask); -int res_name(const char *name, int mask); -void print_recsrc(int recsrc, int recmask, int shortflag); +static void usage(int devmask, int recmask); +static int res_name(const char *name, int mask); +static void print_recsrc(int recsrc, int recmask, int sflag); -void +static void usage(int devmask, int recmask) { - int i, n; + int i, n; printf("usage: mixer [-f device] [-s | -S] [dev [+|-][voll[:[+|-]volr]] ...\n" - " mixer [-f device] [-s | -S] recsrc ...\n" - " mixer [-f device] [-s | -S] {^|+|-|=}rec rdev ... \n"); + " mixer [-f device] [-s | -S] recsrc ...\n" + " mixer [-f device] [-s | -S] {^|+|-|=}rec rdev ...\n"); if (devmask != 0) { printf(" devices: "); for (i = 0, n = 0; i < SOUND_MIXER_NRDEVICES; i++) @@ -45,7 +45,7 @@ usage(int devmask, int recmask) if (n) printf(", "); printf("%s", names[i]); - n = 1; + n++; } } if (recmask != 0) { @@ -55,64 +55,59 @@ usage(int devmask, int recmask) if (n) printf(", "); printf("%s", names[i]); - n = 1; + n++; } } printf("\n"); exit(1); } -int +static int res_name(const char *name, int mask) { - int foo; + int foo; for (foo = 0; foo < SOUND_MIXER_NRDEVICES; foo++) - if ((1 << foo) & mask && !strcmp(names[foo], name)) + if ((1 << foo) & mask && strcmp(names[foo], name) == 0) break; - return foo == SOUND_MIXER_NRDEVICES ? -1 : foo; + return (foo == SOUND_MIXER_NRDEVICES ? -1 : foo); } -void -print_recsrc(int recsrc, int recmask, int shortflag) +static void +print_recsrc(int recsrc, int recmask, int sflag) { - int i, n = 0; + int i, n; if (recmask == 0) return; - if (!shortflag) + if (!sflag) printf("Recording source: "); - for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) + for (i = 0, n = 0; i < SOUND_MIXER_NRDEVICES; i++) if ((1 << i) & recsrc) { - if (shortflag) { - if (n) - printf(" +rec "); - else - printf("=rec "); - } else if (n) + if (sflag) + printf("%srec ", n ? " +" : "="); + else if (n) printf(", "); printf("%s", names[i]); - n = 1; + n++; } - if (!shortflag) + if (!sflag) printf("\n"); } int main(int argc, char *argv[]) { - char mixer[PATH_MAX] = "/dev/mixer"; - char *name, *eptr; - int foo, bar, baz, dev; - int devmask = 0, recmask = 0, recsrc = 0, orecsrc; - int dusage = 0, drecsrc = 0, shortflag = 0, Shortflag = 0; - int l = 0, r = 0, t = 0; - char lstr[5], rstr[5]; - int n, lrel = 0, rrel = 0; - char ch; + char mixer[PATH_MAX] = "/dev/mixer"; + char lstr[5], rstr[5]; + char *name, *eptr; + int devmask = 0, recmask = 0, recsrc = 0, orecsrc; + int dusage = 0, drecsrc = 0, sflag = 0, Sflag = 0; + int l, r, lrel, rrel; + int ch, foo, bar, baz, dev, m, n, t; if ((name = strdup(basename(argv[0]))) == NULL) err(1, "strdup()"); @@ -138,17 +133,17 @@ main(int argc, char *argv[]) name = argv[n + 1]; n += 2; } else if (ch == 's') { - shortflag = 1; + sflag = 1; n++; } else if (ch == 'S') { - Shortflag = 1; + Sflag = 1; n++; } else { dusage = 1; break; } } - if (shortflag && Shortflag) + if (sflag && Sflag) dusage = 1; argc -= n - 1; @@ -164,38 +159,41 @@ main(int argc, char *argv[]) err(1, "SOUND_MIXER_READ_RECSRC"); orecsrc = recsrc; - if ((argc == 1) && (dusage == 0)) { - for (foo = 0; foo < SOUND_MIXER_NRDEVICES; foo++) { - if (!((1 << foo) & devmask)) + if (argc == 1 && dusage == 0) { + for (foo = 0, n = 0; foo < SOUND_MIXER_NRDEVICES; foo++) { + if (!((1 << foo) & devmask)) continue; - if (ioctl(baz, MIXER_READ(foo),&bar)== -1) { + if (ioctl(baz, MIXER_READ(foo),&bar) == -1) { warn("MIXER_READ"); continue; } - if (Shortflag) - printf("%s:%d:%d ", names[foo], bar & 0x7f, - (bar >> 8) & 0x7f); - else if (shortflag) - printf("%s %d:%d ", names[foo], bar & 0x7f, - (bar >> 8) & 0x7f); - else - printf("Mixer %-8s is currently set to %3d:%d\n", - names[foo], bar & 0x7f, (bar >> 8) & 0x7f); + if (Sflag || sflag) { + printf("%s%s%c%d:%d", n ? " " : "", + names[foo], Sflag ? ':' : ' ', + bar & 0x7f, (bar >> 8) & 0x7f); + n++; + } else + printf("Mixer %-8s is currently set to " + "%3d:%d\n", names[foo], bar & 0x7f, + (bar >> 8) & 0x7f); } - if (ioctl(baz, SOUND_MIXER_READ_RECSRC, &recsrc) == -1) - err(1, "SOUND_MIXER_READ_RECSRC"); - print_recsrc(recsrc, recmask, shortflag || Shortflag); - return(0); + if (n && recmask) + printf(" "); + print_recsrc(recsrc, recmask, Sflag | sflag); + return (0); } - argc--; argv++; + argc--; + argv++; - while ((argc > 0) && (dusage == 0)) { - if (!strcmp("recsrc", *argv)) { + n = 0; + while (argc > 0 && dusage == 0) { + if (strcmp("recsrc", *argv) == 0) { drecsrc = 1; - argc--; argv++; + argc--; + argv++; continue; - } else if (argc > 1 && !strcmp("rec", *argv + 1)) { + } else if (argc > 1 && strcmp("rec", *argv + 1) == 0) { if (**argv != '+' && **argv != '-' && **argv != '=' && **argv != '^') { warnx("unknown modifier: %c", **argv); @@ -207,7 +205,7 @@ main(int argc, char *argv[]) dusage = 1; break; } - switch(**argv) { + switch (**argv) { case '+': recsrc |= (1 << dev); break; @@ -222,61 +220,63 @@ main(int argc, char *argv[]) break; } drecsrc = 1; - argc -= 2; argv += 2; + argc -= 2; + argv += 2; continue; } - if ((t = sscanf(*argv, "%d:%d", &l, &r)) > 0) { + if ((t = sscanf(*argv, "%d:%d", &l, &r)) > 0) dev = 0; - } - else if((dev = res_name(*argv, devmask)) == -1) { + else if ((dev = res_name(*argv, devmask)) == -1) { warnx("unknown device: %s", *argv); dusage = 1; break; } -#define issign(c) (((c) == '+') || ((c) == '-')) - + lrel = rrel = 0; if (argc > 1) { - n = sscanf(argv[1], "%7[^:]:%7s", lstr, rstr); - if (n > 0) { - if (issign(lstr[0])) + m = sscanf(argv[1], "%7[^:]:%7s", lstr, rstr); + if (m > 0) { + if (*lstr == '+' || *lstr == '-') lrel = rrel = 1; - l = atoi(lstr); + l = strtol(lstr, NULL, 10); } - if (n > 1) { - rrel = 0; - if (issign(rstr[0])) + if (m > 1) { + if (*rstr == '+' || *rstr == '-') rrel = 1; - r = atoi(rstr); + r = strtol(rstr, NULL, 10); } } - switch(argc > 1 ? n : t) { + switch (argc > 1 ? m : t) { case 0: - if (ioctl(baz, MIXER_READ(dev),&bar)== -1) { + if (ioctl(baz, MIXER_READ(dev), &bar) == -1) { warn("MIXER_READ"); - argc--; argv++; + argc--; + argv++; continue; } - if (Shortflag) - printf("%s:%d:%d ", names[dev], bar & 0x7f, - (bar >> 8) & 0x7f); - else if (shortflag) - printf("%s %d:%d ", names[dev], bar & 0x7f, - (bar >> 8) & 0x7f); - else - printf("Mixer %-8s is currently set to %3d:%d\n", - names[dev], bar & 0x7f, (bar >> 8) & 0x7f); - - argc--; argv++; + if (Sflag || sflag) { + printf("%s%s%c%d:%d", n ? " " : "", + names[dev], Sflag ? ':' : ' ', + bar & 0x7f, (bar >> 8) & 0x7f); + n++; + } else + printf("Mixer %-8s is currently set to " + "%3d:%d\n", names[dev], bar & 0x7f, + (bar >> 8) & 0x7f); + + argc--; + argv++; break; case 1: r = l; + /* FALLTHROUGH */ case 2: - if (ioctl(baz, MIXER_READ(dev),&bar)== -1) { + if (ioctl(baz, MIXER_READ(dev), &bar) == -1) { warn("MIXER_READ"); - argc--; argv++; + argc--; + argv++; continue; } @@ -294,15 +294,17 @@ main(int argc, char *argv[]) else if (r > 100) r = 100; - if (!Shortflag) - printf("Setting the mixer %s from %d:%d to %d:%d.\n", - names[dev], bar & 0x7f, (bar >> 8) & 0x7f, l, r); + if (!Sflag) + printf("Setting the mixer %s from %d:%d to " + "%d:%d.\n", names[dev], bar & 0x7f, + (bar >> 8) & 0x7f, l, r); l |= r << 8; if (ioctl(baz, MIXER_WRITE(dev), &l) == -1) warn("WRITE_MIXER"); - argc -= 2; argv += 2; + argc -= 2; + argv += 2; break; } } @@ -310,7 +312,7 @@ main(int argc, char *argv[]) if (dusage) { close(baz); usage(devmask, recmask); - /* Not reached */ + /* NOTREACHED */ } if (orecsrc != recsrc) { @@ -319,11 +321,11 @@ main(int argc, char *argv[]) if (ioctl(baz, SOUND_MIXER_READ_RECSRC, &recsrc) == -1) err(1, "SOUND_MIXER_READ_RECSRC"); } - + if (drecsrc) - print_recsrc(recsrc, recmask, shortflag || Shortflag); + print_recsrc(recsrc, recmask, Sflag || sflag); close(baz); - exit(0); + return (0); } |