Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/mixer/mixer.c
Show All 24 Lines | |||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <mixer.h> | #include <mixer.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#define C_VOL 0 | enum { | ||||
#define C_MUT 1 | C_VOL = 0, | ||||
#define C_SRC 2 | C_MUT, | ||||
C_SRC, | |||||
}; | |||||
static void usage(void) __dead2; | static void usage(void) __dead2; | ||||
static void initctls(struct mixer *); | static void initctls(struct mixer *); | ||||
static void printall(struct mixer *, int); | static void printall(struct mixer *, int); | ||||
static void printminfo(struct mixer *, int); | static void printminfo(struct mixer *, int); | ||||
static void printdev(struct mixer *, int); | static void printdev(struct mixer *, int); | ||||
static void printrecsrc(struct mixer *, int); /* XXX: change name */ | static void printrecsrc(struct mixer *, int); /* XXX: change name */ | ||||
/* Control handlers */ | /* Control handlers */ | ||||
Show All 15 Lines | |||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
struct mixer *m; | struct mixer *m; | ||||
mix_ctl_t *cp; | mix_ctl_t *cp; | ||||
char *name = NULL, buf[NAME_MAX]; | char *name = NULL, buf[NAME_MAX]; | ||||
char *p, *q, *devstr, *ctlstr, *valstr = NULL; | char *p, *q, *devstr, *ctlstr, *valstr = NULL; | ||||
int dunit, i, n, pall = 1; | int dunit, i, n, pall = 1, shorthand = 0; | ||||
int aflag = 0, dflag = 0, oflag = 0, sflag = 0; | int aflag = 0, dflag = 0, oflag = 0, sflag = 0; | ||||
int ch; | int ch; | ||||
while ((ch = getopt(argc, argv, "ad:f:hos")) != -1) { | while ((ch = getopt(argc, argv, "ad:f:hos")) != -1) { | ||||
switch (ch) { | switch (ch) { | ||||
case 'a': | case 'a': | ||||
aflag = 1; | aflag = 1; | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | if (sflag) { | ||||
printrecsrc(m, oflag); | printrecsrc(m, oflag); | ||||
(void)mixer_close(m); | (void)mixer_close(m); | ||||
return (0); | return (0); | ||||
} | } | ||||
parse: | parse: | ||||
while (argc > 0) { | while (argc > 0) { | ||||
if ((p = strdup(*argv)) == NULL) | if ((p = strdup(*argv)) == NULL) | ||||
err(1, "strdup(%s)", *argv); | err(1, "strdup(%s)", *argv); | ||||
hselasky: Can you put it like this:
```
bool shorthand;
/* Check if we're using the shorthand syntax… | |||||
/* Check if we're using the shorthand syntax for volume setting. */ | |||||
for (q = p; *q != '\0'; q++) { | |||||
if (*q == '=') | |||||
shorthand = 1; | |||||
else if (*q == '.' && shorthand) | |||||
shorthand = 0; | |||||
} | |||||
Done Inline ActionsDon't you need to set shorthand to zero for every loop? hselasky: Don't you need to set shorthand to zero for every loop? | |||||
/* Split the string into device, control and value. */ | /* Split the string into device, control and value. */ | ||||
devstr = strsep(&p, ".="); | devstr = strsep(&p, ".="); | ||||
if ((m->dev = mixer_get_dev_byname(m, devstr)) == NULL) { | if ((m->dev = mixer_get_dev_byname(m, devstr)) == NULL) { | ||||
warnx("%s: no such device", devstr); | warnx("%s: no such device", devstr); | ||||
goto next; | goto next; | ||||
} | } | ||||
/* Input: `dev`. */ | /* Input: `dev`. */ | ||||
if (p == NULL) { | if (p == NULL) { | ||||
printdev(m, 1); | printdev(m, 1); | ||||
pall = 0; | pall = 0; | ||||
goto next; | goto next; | ||||
} else { | } else if (shorthand) { | ||||
for (q = p; (*q >= '0' && *q <= '9') || *q == '.'; q++) | /* | ||||
; /* nothing */ | * Input: `dev=N` -> shorthand for `dev.volume=N`. | ||||
/* Input: `dev=N` -> shorthand for `dev.volume=N`. */ | * | ||||
if (*q == '\0') { | * We don't care what the rest of the string contains as | ||||
* long as we're sure the very beginning is right, | |||||
* mod_volume() will take care of parsing it properly. | |||||
*/ | |||||
if (*p == '+' || *p == '-' || *p == '.' || | |||||
(*p >= '0' && *p <= '9')) { | |||||
cp = mixer_get_ctl(m->dev, C_VOL); | cp = mixer_get_ctl(m->dev, C_VOL); | ||||
cp->mod(cp->parent_dev, p); | cp->mod(cp->parent_dev, p); | ||||
goto next; | goto next; | ||||
} | } | ||||
} | } | ||||
ctlstr = strsep(&p, "="); | ctlstr = strsep(&p, "="); | ||||
if ((cp = mixer_get_ctl_byname(m->dev, ctlstr)) == NULL) { | if ((cp = mixer_get_ctl_byname(m->dev, ctlstr)) == NULL) { | ||||
warnx("%s.%s: no such control", devstr, ctlstr); | warnx("%s.%s: no such control", devstr, ctlstr); | ||||
goto next; | goto next; | ||||
} | } | ||||
/* Input: `dev.control`. */ | /* Input: `dev.control`. */ | ||||
if (p == NULL) { | if (p == NULL) { | ||||
(void)cp->print(cp->parent_dev, cp->name); | (void)cp->print(cp->parent_dev, cp->name); | ||||
pall = 0; | pall = 0; | ||||
goto next; | goto next; | ||||
} | } | ||||
valstr = p; | valstr = p; | ||||
/* Input: `dev.control=val`. */ | /* Input: `dev.control=val`. */ | ||||
▲ Show 20 Lines • Show All 325 Lines • Show Last 20 Lines |
Can you put it like this: