From nobody Tue Jan 18 21:15:39 2022 X-Original-To: dev-commits-src-all@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 970321965734; Tue, 18 Jan 2022 21:15:39 +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 4JdhQ33tKzz3qg1; Tue, 18 Jan 2022 21:15:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642540539; 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=RcEeBbzcvJ1IFSV1XQs5MrShzUHiP5IoInMa9AXI4u8=; b=Ws5+hMdyDguQRZr2zyQOD65T8JumWHOTMIAISipw1zM1Rwy9Gk/wZJ7amJii3sh4gnjat3 fjVaYgUJLRyvGjksiwLAs2x1Wuq0E4Gnblo+cPHjN++7pEOkUP1GzFWb7x2BliMNTXbVLd 3W+yhDoGniOydroATbwLmPSYDFMRKQX/X5ABSI9LbvYkJUfYass6F2ZLtxM0ze5A3bMQsF 4gvg8QLN6stR/sTolo57VyHqsHWFqFjM4ogcC3gxuAzjG2fW2OlQ3TXsPPOA5w+K2syow2 xo8lz729EiX9hX0rHLiiNUvEc1eV7dlmeMnduESKmARKWHYF71plvlkn22db3w== 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 655B77C3; Tue, 18 Jan 2022 21:15:39 +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 20ILFd4N035588; Tue, 18 Jan 2022 21:15:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20ILFdoc035587; Tue, 18 Jan 2022 21:15:39 GMT (envelope-from git) Date: Tue, 18 Jan 2022 21:15:39 GMT Message-Id: <202201182115.20ILFdoc035587@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Joerg Wunsch Subject: git: 081853844bd4 - stable/12 - usbconfig: use getopt(3) for option handling List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: joerg X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 081853844bd4c43a59ac22357d41bb3abc39a45a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642540539; 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=RcEeBbzcvJ1IFSV1XQs5MrShzUHiP5IoInMa9AXI4u8=; b=weincEu1qm5NabYySsVPNr3za8pekp68qB/SHgexoSdcaECeC7DcbR7ks1zbnJk8F/T79Y bJBxlhpAq/BKitpu4y0KnuIpCtok/uy9rg0bIpt6MT2RfCt0+GjYnjNVkJnsFR2wjvW7o+ sBBvCDLEzzhaUma1gvvh5z2TpOGTtycBkG7ZT1KK8KUH5Jg+bqtCmH+T2SPaQqf+d3IZiu TJrNFDwgGNcnB4EHJE+n41ejsshPtmSYndC/C8Ok31ibisSbTZsrdGl6MGMl4eGJFxuV/S aQeUpg7nkPLK8NSnEWrEB6zqeh1YYlkGKgIrQOfLmOJn+kNX8GSp/HtE/0LSww== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642540539; a=rsa-sha256; cv=none; b=smd5+62BsWIZFaDTe25E4EcBohHjYO4WvGtdNpRY9e1hOWWvAx8j5gkRjPUUwzzGsuWax2 mgIeYM0iSMKLhqgTrIpgvm/sTq/XY2y/R9k5rJXsMDcPwy5fJKxyD5mbyUERPOq/sFHvGc utm2iXoMlLiZ1CW8i2S9qtjU75Hk9cwp9gcel3qN2cHPUfO4faqbSki8oVY4llSj8zvuYf 64bB5Ajw24SPP9O44ntTVT9RIdMJbvqkgesqZ5oRtXif+2G2KlVw3d0x4vnNirWTRl6Iq0 VHx8EXvTUKykyP/WhFebAuh8bxA/2S0+YXxOwNwZdJkaCifNEDgDvy2IAJrc8Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by joerg: URL: https://cgit.FreeBSD.org/src/commit/?id=081853844bd4c43a59ac22357d41bb3abc39a45a commit 081853844bd4c43a59ac22357d41bb3abc39a45a Author: Joerg Wunsch AuthorDate: 2021-12-19 22:49:23 +0000 Commit: Joerg Wunsch CommitDate: 2022-01-18 21:14:49 +0000 usbconfig: use getopt(3) for option handling This makes option handling consistent with other utilities as well as Posix rules. By that, it's no longer important whether option name and its argument are separated by a space or not, so -d5.3 works the same as -d 5.3. Also, recognize either /dev/ugen or ugen as prefix to the -d argument. Note that this removes the undocumented feature that allowed to specify multiple -d n.m options interleaved with commands referring to that particular device in a single run. (cherry picked from commit ae450e6de96b5ec65f425a52b08dc859576ab8d0) --- usr.sbin/usbconfig/usbconfig.8 | 4 +- usr.sbin/usbconfig/usbconfig.c | 104 +++++++++++++++++++---------------------- 2 files changed, 52 insertions(+), 56 deletions(-) diff --git a/usr.sbin/usbconfig/usbconfig.8 b/usr.sbin/usbconfig/usbconfig.8 index 79f070b169c6..ecfd0246eaac 100644 --- a/usr.sbin/usbconfig/usbconfig.8 +++ b/usr.sbin/usbconfig/usbconfig.8 @@ -51,7 +51,9 @@ Limit device range to the given USB device index. Should only be used in conjunction with the unit argument. .It Fl d Ar [ugen]. Limit device range to USB devices connected to the given unit and address. -The unit and address coordinates may be prefixed by the lowercased word "ugen". +The unit and address coordinates may be prefixed by the lowercased word "ugen", +or the full path name +.Pa /dev/ugen . .It Fl i Ar interface_index Specify interface index as indicated by the command description. If this argument is not specified a value of zero will be used for the interface index. diff --git a/usr.sbin/usbconfig/usbconfig.c b/usr.sbin/usbconfig/usbconfig.c index c25468fe6da4..a19ff8039186 100644 --- a/usr.sbin/usbconfig/usbconfig.c +++ b/usr.sbin/usbconfig/usbconfig.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -100,10 +101,6 @@ struct token { }; enum { - T_UNIT, - T_ADDR, - T_UGEN, - T_IFACE, T_SET_CONFIG, T_SET_ALT, T_SET_TEMPLATE, @@ -136,10 +133,6 @@ enum { static struct options options; static const struct token token[] = { - {"-u", T_UNIT, 1}, - {"-a", T_ADDR, 1}, - {"-d", T_UGEN, 1}, - {"-i", T_IFACE, 1}, {"set_config", T_SET_CONFIG, 1}, {"set_alt", T_SET_ALT, 1}, {"set_template", T_SET_TEMPLATE, 1}, @@ -563,6 +556,7 @@ main(int argc, char **argv) int addr; int n; int t; + int ch; if (argc < 1) { usage(); @@ -571,7 +565,53 @@ main(int argc, char **argv) if (pbe == NULL) err(1, "could not access USB backend\n"); - for (n = 1; n != argc; n++) { + while ((ch = getopt(argc, argv, "a:d:i:u:")) != -1) { + switch (ch) { + case 'a': + opt->addr = num_id(optarg, "addr"); + opt->got_addr = 1; + break; + + case 'd': + if (strncmp(optarg, "ugen", strlen("ugen")) == 0) { + ptr = optarg + strlen("ugen"); + } else if (strncmp(optarg, "/dev/ugen", + strlen("/dev/ugen")) == 0) { + ptr = optarg + strlen("/dev/ugen"); + } else { + ptr = optarg; + } + if ((sscanf(ptr, "%d.%d", + &unit, &addr) != 2) || + (unit < 0) || (unit > 65535) || + (addr < 0) || (addr > 65535)) { + errx(1, "cannot " + "parse '%s'", optarg); + } + opt->bus = unit; + opt->addr = addr; + opt->got_bus = 1; + opt->got_addr = 1; + break; + + case 'i': + opt->iface = num_id(optarg, "iface"); + opt->got_iface = 1; + break; + + case 'u': + opt->bus = num_id(optarg, "busnum"); + opt->got_bus = 1; + break; + + default: + usage(); + } + } + argc -= optind; + argv += optind; + + for (n = 0; n != argc; n++) { /* get number of additional options */ t = (argc - n - 1); @@ -654,52 +694,6 @@ main(int argc, char **argv) opt->got_show_iface_driver = 1; break; - case T_UGEN: - if (opt->got_any) { - /* allow multiple commands on the same line */ - flush_command(pbe, opt); - } - ptr = argv[n + 1]; - - if ((ptr[0] == 'u') && - (ptr[1] == 'g') && - (ptr[2] == 'e') && - (ptr[3] == 'n')) - ptr += 4; - - if ((sscanf(ptr, "%d.%d", - &unit, &addr) != 2) || - (unit < 0) || (unit > 65535) || - (addr < 0) || (addr > 65535)) { - errx(1, "cannot " - "parse '%s'", argv[n + 1]); - } - opt->bus = unit; - opt->addr = addr; - opt->got_bus = 1; - opt->got_addr = 1; - n++; - break; - - case T_UNIT: - if (opt->got_any) { - /* allow multiple commands on the same line */ - flush_command(pbe, opt); - } - opt->bus = num_id(argv[n + 1], "busnum"); - opt->got_bus = 1; - n++; - break; - case T_ADDR: - opt->addr = num_id(argv[n + 1], "addr"); - opt->got_addr = 1; - n++; - break; - case T_IFACE: - opt->iface = num_id(argv[n + 1], "iface"); - opt->got_iface = 1; - n++; - break; case T_SET_CONFIG: if (opt->got_set_config) duplicate_option(argv[n]);