diff options
author | Jason McIntyre <jmc@cvs.openbsd.org> | 2013-01-04 19:31:29 +0000 |
---|---|---|
committer | Jason McIntyre <jmc@cvs.openbsd.org> | 2013-01-04 19:31:29 +0000 |
commit | 244cb54e30b6c10df2d1875c89288c77e2e96d90 (patch) | |
tree | fe98f6c48ca69a1aa86efe2876e9c0816734c0e2 /usr.bin | |
parent | f7f83ca32d5a4b53e12761fa6897c1b9a0e10d8d (diff) |
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')
-rw-r--r-- | usr.bin/units/units.1 | 12 | ||||
-rw-r--r-- | usr.bin/units/units.c | 24 |
2 files changed, 26 insertions, 10 deletions
diff --git a/usr.bin/units/units.1 b/usr.bin/units/units.1 index db43aedfa86..5d49ec65ecc 100644 --- a/usr.bin/units/units.1 +++ b/usr.bin/units/units.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: units.1,v 1.24 2011/10/08 20:41:12 jmc Exp $ +.\" $OpenBSD: units.1,v 1.25 2013/01/04 19:31:28 jmc Exp $ .\" converted to new format by deraadt@openbsd.org .\" .\" Copyright (c) 1993 by Adrian Mariano (adrian@cam.cornell.edu) @@ -16,7 +16,7 @@ .\" I would appreciate (though I do not require) receiving a copy of any .\" improvements you might make to this program. .\" -.Dd $Mdocdate: October 8 2011 $ +.Dd $Mdocdate: January 4 2013 $ .Dt UNITS 1 .Os .Sh NAME @@ -26,7 +26,7 @@ .Nm units .Op Fl qv .Op Fl f Ar filename -.Op Ar from-unit to-unit +.Op Oo Ar count Oc Ar from-unit to-unit .Sh DESCRIPTION The .Nm @@ -84,11 +84,15 @@ Suppresses prompting of the user for units and the display of statistics about the number of units loaded. .It Fl v Prints the version number. -.It Ar from-unit Ar to-unit +.It Oo Ar count Oc Ar from-unit to-unit Allows a single unit conversion to be done directly from the command line. No prompting will occur. The units program will print out only the result of this single conversion. +A +.Ar count +can be given to specify multiples of +.Ar from-unit . .El .Pp Powers of units can be specified using the 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); |