diff options
author | 2013-01-04 19:31:28 +0000 | |
---|---|---|
committer | 2013-01-04 19:31:28 +0000 | |
commit | 3be404967b5b2ac554ac5cd0f3e204dc1fb43ad4 (patch) | |
tree | 06f896722b4aa00838fbca93c61dfef04ae7cc64 /usr.bin/units/units.c | |
parent | no more ussr; diff originally from Jeff Ross (diff) | |
download | wireguard-openbsd-3be404967b5b2ac554ac5cd0f3e204dc1fb43ad4.tar.xz wireguard-openbsd-3be404967b5b2ac554ac5cd0f3e204dc1fb43ad4.zip |
an undocumented feature of units was the ability to specify a prefix
in non-interactive mode. document that now, but also allow for the
prefix to be given without a need to quote it;
code lifted from atatat (netbsd -r1.10); otto helped me paste it in.
ok otto millert
Diffstat (limited to 'usr.bin/units/units.c')
-rw-r--r-- | usr.bin/units/units.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/usr.bin/units/units.c b/usr.bin/units/units.c index 71621adddd7..3f0c676eebc 100644 --- a/usr.bin/units/units.c +++ b/usr.bin/units/units.c @@ -1,4 +1,4 @@ -/* $OpenBSD: units.c,v 1.17 2011/10/07 20:07:25 jmc Exp $ */ +/* $OpenBSD: units.c,v 1.18 2013/01/04 19:31:28 jmc Exp $ */ /* $NetBSD: units.c,v 1.6 1996/04/06 06:01:03 thorpej Exp $ */ /* @@ -612,7 +612,7 @@ void usage(void) { fprintf(stderr, - "usage: units [-qv] [-f filename] [from-unit to-unit]\n"); + "usage: units [-qv] [-f filename] [[count] from-unit to-unit]\n"); exit(3); } @@ -651,14 +651,26 @@ main(int argc, char **argv) } } - if (optind != argc - 2 && optind != argc) + argc -= optind; + argv += optind; + + if (argc != 3 && argc != 2 && argc != 0) usage(); readunits(userfile); - if (optind == argc - 2) { - strlcpy(havestr, argv[optind], sizeof(havestr)); - strlcpy(wantstr, argv[optind + 1], sizeof(wantstr)); + if (argc == 3) { + strlcpy(havestr, argv[0], sizeof(havestr)); + strlcat(havestr, " ", sizeof(havestr)); + strlcat(havestr, argv[1], sizeof(havestr)); + argc--; + argv++; + argv[0] = havestr; + } + + if (argc == 2) { + strlcpy(havestr, argv[0], sizeof(havestr)); + strlcpy(wantstr, argv[1], sizeof(wantstr)); initializeunit(&have); addunit(&have, havestr, 0); completereduce(&have); |