From nobody Sun Mar 20 19:21:46 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 0733B1A17011; Sun, 20 Mar 2022 19:21:47 +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 4KM70V6nBRz4rYd; Sun, 20 Mar 2022 19:21:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647804107; 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=pxo7z3hC7fOrbRSQjdvVrIf91ps5e8K/772BsZJ/jGw=; b=HfSBhiAJm8S5UN4rcgX+D4tHtZpeVOOk0wPLjKYVMHXevfC5N2q0OkXBXIWaBMnscl9gxQ mPy1QN0HzCIlIQm4EeIpFyI5K24dYbEJFViPWYx3a3Jx8UlR/embsAdj5M8/y+c+stXjHK DOwa9xk4dSGi9g6FlvRDfI02GzegmXimcBpL2G1V3HgKl+JV7lW8/4IETf7qXiMdsYksWi lTsFwTtsJhvI+q2oNw1KGm2QXf33/CdNyV/k3WIjXOa/acjZKkjSAERUbZvBQ9fWabHyYF jEC5fxqIaiLmFFPiSPcKDeb9yP969fwEuy6mOFSQ1aGtfeOLLHz1YNOIHdHYZQ== 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 C8BB85201; Sun, 20 Mar 2022 19:21:46 +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 22KJLkAu060520; Sun, 20 Mar 2022 19:21:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22KJLkoW060519; Sun, 20 Mar 2022 19:21:46 GMT (envelope-from git) Date: Sun, 20 Mar 2022 19:21:46 GMT Message-Id: <202203201921.22KJLkoW060519@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: f250ff5ff309 - main - mixer(8): Improve shorthand volume parsing. 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: f250ff5ff3094abd5570df61fbe4d2c37e3624a9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647804107; 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=pxo7z3hC7fOrbRSQjdvVrIf91ps5e8K/772BsZJ/jGw=; b=ZX6Y7onhikU+GTnhG8ICCyMvsg5pBWb8KShWln0Qzcs4looUMyKuRbgSUepVqazhXKf6VM 8hOn6sIMd6KYrXteN54FXJxJDUuA47V1PzlNVPqxRZatSx8YFv4Om/MdsAMAcRKEP5t5Cq CI2+Y/nQIpkP0YmXqGZ9HrH/08dlgVNdUy6NhGZikCbCxaZsDRCLhJ45mS6I74z8JdG3b8 UohO8juPtawCr+gbfxRk34c+WXVhsE4eB/TcwSXiiduKh7S2vgFmEHH8AWl1Y1N0H74rBT WQJ7Mu3d0CYBRIkfVfgopzhKw4lF5Pvhdd76mfgdlBLmEcz0/Ouzki8CVcSzsQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647804107; a=rsa-sha256; cv=none; b=Ixa+/1+SAM7yx7h0upX0ON7OtC+ynT1+CSnvaKHfZJRrpL5Pf9GgRlrBOeKpAk4R4eomDZ OtjHtIdyGeAfYCds55965J75Dvdo5DLMsYJJXBlbKvTkxNXRhnZdLpRM6+uD+tynFkrxjr DH+7GHbqpZbC4BArlBHZapOAEvUVtrya60s+41Nfv2qNae+vpIMWbNf89zJpmWWSJZVEmT G54P3QbQWOwmvYnq95BfHNZyr9K8kI5VqLGe3ZgFPc4aEIuj1YzVAU6kbj1F20tD1yz93x iOFJhuRqiaX29r8aVwJyDa3CiukDyID7OlRGoBnzr8d8v+t5piQSf0gIv8gYjw== 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=f250ff5ff3094abd5570df61fbe4d2c37e3624a9 commit f250ff5ff3094abd5570df61fbe4d2c37e3624a9 Author: Hans Petter Selasky AuthorDate: 2022-03-20 19:08:13 +0000 Commit: Hans Petter Selasky CommitDate: 2022-03-20 19:19:16 +0000 mixer(8): Improve shorthand volume parsing. The initial patch had a bug where the full volume syntax, floating point values, :, + and -, wasn't accepted. While at it move some defines to enum's. Fixes: da3d4469ef841be44ac4b346a6b51668d608ed49 Submitted by: christos@ Differential Revision: https://reviews.freebsd.org/D34617 Sponsored by: NVIDIA Networking --- usr.sbin/mixer/mixer.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/usr.sbin/mixer/mixer.c b/usr.sbin/mixer/mixer.c index f3a8d9aaa92a..c0a9ec25c6fa 100644 --- a/usr.sbin/mixer/mixer.c +++ b/usr.sbin/mixer/mixer.c @@ -30,9 +30,11 @@ #include #include -#define C_VOL 0 -#define C_MUT 1 -#define C_SRC 2 +enum { + C_VOL = 0, + C_MUT, + C_SRC, +}; static void usage(void) __dead2; static void initctls(struct mixer *); @@ -64,7 +66,7 @@ main(int argc, char *argv[]) mix_ctl_t *cp; char *name = NULL, buf[NAME_MAX]; char *p, *q, *devstr, *ctlstr, *valstr = NULL; - int dunit, i, n, pall = 1; + int dunit, i, n, pall = 1, shorthand; int aflag = 0, dflag = 0, oflag = 0, sflag = 0; int ch; @@ -135,6 +137,19 @@ parse: while (argc > 0) { if ((p = strdup(*argv)) == NULL) err(1, "strdup(%s)", *argv); + + /* Check if we're using the shorthand syntax for volume setting. */ + shorthand = 0; + for (q = p; *q != '\0'; q++) { + if (*q == '=') { + q++; + shorthand = ((*q >= '0' && *q <= '9') || + *q == '+' || *q == '-' || *q == '.'); + break; + } else if (*q == '.') + break; + } + /* Split the string into device, control and value. */ devstr = strsep(&p, ".="); if ((m->dev = mixer_get_dev_byname(m, devstr)) == NULL) { @@ -146,22 +161,23 @@ 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; - } + } else if (shorthand) { + /* + * Input: `dev=N` -> shorthand for `dev.volume=N`. + * + * 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. + */ + 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) { warnx("%s.%s: no such control", devstr, ctlstr); goto next; } - /* Input: `dev.control`. */ if (p == NULL) { (void)cp->print(cp->parent_dev, cp->name);