From nobody Sun Mar 20 16:33:49 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id CD3211A30C5A; Sun, 20 Mar 2022 16:33:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KM3Gj521zz3rtf; Sun, 20 Mar 2022 16:33:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647794029; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EiA2xb9c9oQ7L8MWohkpQ1SlYVhpSPN5y6cPgvOnz7U=; b=DAWBlkiO2Vy6TaVutNQwEgcS220FOrnwhCd8BSCul8n6JJKzer0TokPJhCFHmiZkplgopE nvPrKsMU+KUqcxsmuERKBEIpMpZ7+9cogjzETwDX4pEUBkhz9/IMyEMh9COavU+5Y7+Dzk mzm9L2aa/9rSxkMiqf2x5Pd0wIk6veqGMK/VmzSNVF3lpcbXiqR5OVDUsVc15/bthaYB1+ 1KUanPBBL+orQdmbOoFWc5emQM+MxkbwcyQ7DoArcP0rtmKV5e+xPS/Job/MipQ46GnPOd ITGAAu3hwibB2kJbjeDg8vDiI2u6EO4rS7yTzgnfcJWj3G8mhpVeu8KXDcpGZw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8701E2A8E; Sun, 20 Mar 2022 16:33:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 22KGXnAh034812; Sun, 20 Mar 2022 16:33:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22KGXnVa034811; Sun, 20 Mar 2022 16:33:49 GMT (envelope-from git) Date: Sun, 20 Mar 2022 16:33:49 GMT Message-Id: <202203201633.22KGXnVa034811@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Hans Petter Selasky Subject: git: da3d4469ef84 - main - mixer(8): Add shorthand syntax for setting the volume. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: hselasky X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: da3d4469ef841be44ac4b346a6b51668d608ed49 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647794029; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EiA2xb9c9oQ7L8MWohkpQ1SlYVhpSPN5y6cPgvOnz7U=; b=VNMGmV+CK6J+Ph1mgT/JNzs2I6uuqHu5pxPhnBhGXypi4NKNIcKmaBx5b9yyFzwG0wlyy0 ZPmpk5jvQ4onE7NtR95FIXxlxfzDrUMQBKJ+y7oJI4DksYiKPVDd4b+4PAGTxkSuoL6GtI QtD94bWpnkb2dpGYIEWTqRxOHQdAVINiWFSe0HyMC4W077DZzCjkULNdP+ZcGV6nNp7p9A go8lcxyzxcQpUVzKBVBKySddW95bJ8Lb8zHkDdmd5DlU3XTX1BfbfXD4vR/OOiNRntYcyZ kGOQpVaIzRyh+Mrh7ru9pof1kWyHZL5Yr/Ke9YBcPn0P07D6iHN7wv3etAiXDg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647794029; a=rsa-sha256; cv=none; b=dQ1DCpnmQv9oK08vwA9GwKlXB0AoJieE2Z7kYD6+UacDoqtLKroUPZ4EK4XZYc4TNB7k1r SQ+7F8lr3wdJkbHwoHIhGEy6pZ/9BFe4LZsh+otiq8kZZjkNzItbHx7JSDRQ4hDMOzJYzD 8LjVH3tcwOwHWZTiGkkv0GZ0GB1ghvel/m1ajXYDqsFYs8+zdY7vqyR3daUmcd73Hn/p/Z 4oS/asz2vpscZphy1awCq29wocP5DMclUoCMcB6VhCQSjiXduhLQetI8iuY33pzCEmOYAa /DxNSWeKFNEa/hcgmXMay5SQzkCMTcIqQKg1JK+LwSAc9qiXVmZXLth7rruknA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=da3d4469ef841be44ac4b346a6b51668d608ed49 commit da3d4469ef841be44ac4b346a6b51668d608ed49 Author: Hans Petter Selasky AuthorDate: 2022-03-20 16:28:08 +0000 Commit: Hans Petter Selasky CommitDate: 2022-03-20 16:32:46 +0000 mixer(8): Add shorthand syntax for setting the volume. dev.volume=X[.X] can now also be written as dev=X[.X] . Requested by: hselasky@ and bsduck (FreeBSD forums) Submitted by: christos@ Differential Revision: https://reviews.freebsd.org/D34612 Sponsored by: NVIDIA Networking --- usr.sbin/mixer/mixer.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/usr.sbin/mixer/mixer.c b/usr.sbin/mixer/mixer.c index a6f48f85ae43..f3a8d9aaa92a 100644 --- a/usr.sbin/mixer/mixer.c +++ b/usr.sbin/mixer/mixer.c @@ -24,12 +24,15 @@ #include #include +#include #include #include #include #include -#include +#define C_VOL 0 +#define C_MUT 1 +#define C_SRC 2 static void usage(void) __dead2; static void initctls(struct mixer *); @@ -60,7 +63,7 @@ main(int argc, char *argv[]) struct mixer *m; mix_ctl_t *cp; char *name = NULL, buf[NAME_MAX]; - char *p, *bufp, *devstr, *ctlstr, *valstr = NULL; + char *p, *q, *devstr, *ctlstr, *valstr = NULL; int dunit, i, n, pall = 1; int aflag = 0, dflag = 0, oflag = 0, sflag = 0; int ch; @@ -85,7 +88,7 @@ main(int argc, char *argv[]) case 's': sflag = 1; break; - case 'h': /* FALLTROUGH */ + case 'h': /* FALLTHROUGH */ case '?': default: usage(); @@ -130,10 +133,10 @@ main(int argc, char *argv[]) parse: while (argc > 0) { - if ((p = bufp = strdup(*argv)) == NULL) + if ((p = strdup(*argv)) == NULL) err(1, "strdup(%s)", *argv); /* Split the string into device, control and value. */ - devstr = strsep(&p, "."); + devstr = strsep(&p, ".="); if ((m->dev = mixer_get_dev_byname(m, devstr)) == NULL) { warnx("%s: no such device", devstr); goto next; @@ -143,6 +146,15 @@ parse: printdev(m, 1); pall = 0; goto next; + } else { + for (q = p; (*q >= '0' && *q <= '9') || *q == '.'; q++) + ; /* nothing */ + /* Input: `dev=N` -> shorthand for `dev.volume=N`. */ + if (*q == '\0') { + cp = mixer_get_ctl(m->dev, C_VOL); + cp->mod(cp->parent_dev, p); + goto next; + } } ctlstr = strsep(&p, "="); if ((cp = mixer_get_ctl_byname(m->dev, ctlstr)) == NULL) { @@ -187,9 +199,6 @@ initctls(struct mixer *m) struct mix_dev *dp; int rc = 0; -#define C_VOL 0 -#define C_MUT 1 -#define C_SRC 2 TAILQ_FOREACH(dp, &m->devs, devs) { rc += mixer_add_ctl(dp, C_VOL, "volume", mod_volume, print_volume); rc += mixer_add_ctl(dp, C_MUT, "mute", mod_mute, print_mute); @@ -284,8 +293,7 @@ printrecsrc(struct mixer *m, int oflag) printf("%s", dp->name); if (oflag) printf(".%s=+%s", - mixer_get_ctl(dp, C_SRC)->name, - n ? " " : ""); + mixer_get_ctl(dp, C_SRC)->name, n ? " " : ""); } } printf("\n");