diff --git a/usr.sbin/usbconfig/usbconfig.8 b/usr.sbin/usbconfig/usbconfig.8 --- a/usr.sbin/usbconfig/usbconfig.8 +++ b/usr.sbin/usbconfig/usbconfig.8 @@ -51,7 +51,9 @@ 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 --- 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 @@ }; enum { - T_UNIT, - T_ADDR, - T_UGEN, - T_IFACE, T_SET_CONFIG, T_SET_ALT, T_SET_TEMPLATE, @@ -136,10 +133,6 @@ 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 @@ int addr; int n; int t; + int ch; if (argc < 1) { usage(); @@ -571,7 +565,53 @@ 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 @@ 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]);