From nobody Mon Dec 20 11:49:51 2021 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 2591D1903BAE; Mon, 20 Dec 2021 11:49:52 +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 4JHdDb6CxFz4g4p; Mon, 20 Dec 2021 11:49:51 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 B59A015B53; Mon, 20 Dec 2021 11:49:51 +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 1BKBnpkm055754; Mon, 20 Dec 2021 11:49:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BKBnp9j055753; Mon, 20 Dec 2021 11:49:51 GMT (envelope-from git) Date: Mon, 20 Dec 2021 11:49:51 GMT Message-Id: <202112201149.1BKBnp9j055753@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Joerg Wunsch Subject: git: ae450e6de96b - main - 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/main X-Git-Reftype: branch X-Git-Commit: ae450e6de96b5ec65f425a52b08dc859576ab8d0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640000991; 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=DDG3XJM1JQUpoWIVvgSIotISNwk74MQVc9Xd2oSgGZU=; b=Z9W7u+L6D9eeIKEIGZVawTetyypdZB9oXiJwN0fFygJHy96WvlkNyzO02WQwO/5IE870Wp toLJUdadfaw++XTO4hyJ4PeyYYYlMv5PAfiqayx9ANN1a/PEyc7PJNCge5PUEbdYAwALmd PzU/XXH32tplNMUMjh5c9pWbMC5iV+ROubJ0AawZEIjnOOvJnF1n3x0zVhw3t7eBTk9mNT 0gkr0cMBNQgaRmX2Wo0o51zxbZJRgcEvwidCXaxTEiVGO9SUS+0s9j6sPER2OHTVxjicpY Rqy6BqASzP1PmwAYFzqFJU8u0CP94fGsKnUSfo5lgx2b86I41GO7q3Jn/ElXfg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640000991; a=rsa-sha256; cv=none; b=Nh/lD8sAkWWn90YKsYW/3qLxKJBFSzKW3v6GUL6Ohy/njo9g7vxKRMBPYfUhvCohvF5+ck jfP+3lL8rUnXvHyos+jr6/G886LnlX9v030rdD4ZYIlAGJVKvazGdfYfAFnX9qXgPYbTGW pggN13uhfwyGVTI/Uec1+r9ewex1xpeXKeYQWTSQtW0G47+xCbt5wpklwAMiLsC3Ufo/fr y/UVzmangmn2HwRzfrofI+cRs1crsH+AqFGw2/43d/4aKXD+jQXON5VCRwn2wk3l0eQ3z8 3RcReCx9a/F/Xh7q7A4unXLu1P86R1fDJGb7ONCv0RjHHLwSxz7SIH9LKmjrhw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by joerg: URL: https://cgit.FreeBSD.org/src/commit/?id=ae450e6de96b5ec65f425a52b08dc859576ab8d0 commit ae450e6de96b5ec65f425a52b08dc859576ab8d0 Author: Joerg Wunsch AuthorDate: 2021-12-19 22:49:23 +0000 Commit: Joerg Wunsch CommitDate: 2021-12-20 11:49:30 +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. --- 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]);