mixer(8): Allow full PCM device names as input for the -d option

The -d option is a wrapper around hw.snd.default_unit. Currently
mixer(8) expects the option argument to be just the unit's number (e.g
pcm0 -> 0). To avoid confusion, allow full device names of the form
"pcmN" as well.

While here, improve the -d option's description in the man page.

Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Reviewed by:	dev_submerge.ch, imp
Differential Revision:	https://reviews.freebsd.org/D43794
This commit is contained in:
Christos Margiolis
2024-02-12 12:59:02 +02:00
parent 09ba07011a
commit 75be886e58
2 changed files with 18 additions and 11 deletions
+14 -9
View File
@@ -19,7 +19,7 @@
.\" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
.\" THE SOFTWARE.
.\"
.Dd January 12, 2024
.Dd February 8, 2024
.Dt MIXER 8
.Os
.Sh NAME
@@ -28,12 +28,11 @@
.Sh SYNOPSIS
.Nm
.Op Fl f Ar device
.Op Fl d Ar unit
.Op Fl d Ar pcmN | N
.Op Fl os
.Op Ar dev Ns Op Cm \&. Ns Ar control Ns Op Cm \&= Ns Ar value
.Ar ...
.Nm
.Op Fl d Ar unit
.Op Fl os
.Fl a
.Nm
@@ -44,16 +43,17 @@ The
utility is used to set and display soundcard mixer device controls.
.Pp
The options are as follows:
.Bl -tag -width "-f device"
.Bl -tag -width "-d pcmN | N"
.It Fl a
Print the values for all mixer devices available in the system
.Pq see Sx FILES .
.It Fl d Ar unit
.It Fl d Ar pcmN | N
Change the default audio card to
.Ar unit .
The unit has to be an integer value.
To see what unit values are available, look at the number each mixer device has by running
.Nm .
.Ar pcmN ,
where N is the unit number (e.g for pcm0, the unit number is 0).
See
.Sx EXAMPLES
on how to list all available audio devices in the system.
.It Fl f Ar device
Open
.Ar device
@@ -218,6 +218,11 @@ opens when the
option has not been specified.
.El
.Sh EXAMPLES
List all available audio devices in the system:
.Bd -literal -offset indent
$ mixer -a | grep ^pcm
.Ed
.Pp
Increase the volume for the
.Cm vol
device of the first mixer found by 5%:
+4 -2
View File
@@ -66,6 +66,8 @@ main(int argc, char *argv[])
aflag = 1;
break;
case 'd':
if (strncmp(optarg, "pcm", 3) == 0)
optarg += 3;
errno = 0;
dunit = strtol(optarg, NULL, 10);
if (errno == EINVAL || errno == ERANGE)
@@ -194,8 +196,8 @@ main(int argc, char *argv[])
static void __dead2
usage(void)
{
fprintf(stderr, "usage: %1$s [-f device] [-d unit] [-os] [dev[.control[=value]]] ...\n"
" %1$s [-d unit] [-os] -a\n"
fprintf(stderr, "usage: %1$s [-f device] [-d pcmN | N] [-os] [dev[.control[=value]]] ...\n"
" %1$s [-os] -a\n"
" %1$s -h\n", getprogname());
exit(1);
}