Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/units Fix a spelling error in the usage, and while I...



details:   https://anonhg.NetBSD.org/src/rev/87a9806fe3d0
branches:  trunk
changeset: 524937:87a9806fe3d0
user:      atatat <atatat%NetBSD.org@localhost>
date:      Tue Apr 02 18:08:28 2002 +0000

description:
Fix a spelling error in the usage, and while I'm here, make it a
little more intelligent about the arguments.  A count of the
"from-unit" can now be passed more easily on the command line.

diffstat:

 usr.bin/units/units.1 |  13 ++++++++++---
 usr.bin/units/units.c |  24 ++++++++++++++++++------
 2 files changed, 28 insertions(+), 9 deletions(-)

diffs (83 lines):

diff -r 3ab105e51bcc -r 87a9806fe3d0 usr.bin/units/units.1
--- a/usr.bin/units/units.1     Tue Apr 02 17:46:20 2002 +0000
+++ b/usr.bin/units/units.1     Tue Apr 02 18:08:28 2002 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: units.1,v 1.10 2001/12/18 01:06:09 wiz Exp $
+.\"    $NetBSD: units.1,v 1.11 2002/04/02 18:08:28 atatat Exp $
 .Dd December 18, 2001
 .Dt UNITS 1
 .Os
@@ -9,7 +9,10 @@
 .Nm
 .Op Fl f Ar filename
 .Op Fl qv
-.Op Ar from-unit to-unit
+.Oo
+.Op Ar count
+.Ar from-unit to-unit
+.Oc
 .Sh DESCRIPTION
 The units program converts quantities expression in various scales to
 their equivalents in other scales.  The units program can only
@@ -28,7 +31,11 @@
 .It Ar from-unit Ar 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.
+only the result of this single conversion.  The
+.Ar count
+argument can be prepended to the
+.Ar from-unit
+or it can be separate.
 .El
 .Pp
 .Nm
diff -r 3ab105e51bcc -r 87a9806fe3d0 usr.bin/units/units.c
--- a/usr.bin/units/units.c     Tue Apr 02 17:46:20 2002 +0000
+++ b/usr.bin/units/units.c     Tue Apr 02 18:08:28 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: units.c,v 1.9 2000/04/14 06:11:11 simonb Exp $ */
+/*     $NetBSD: units.c,v 1.10 2002/04/02 18:08:28 atatat Exp $        */
 
 /*
  * units.c   Copyright (c) 1993 by Adrian Mariano (adrian%cam.cornell.edu@localhost)
@@ -638,7 +638,7 @@
        fprintf(stderr,
            "\nunits [-f unitsfile] [-q] [-v] [from-unit to-unit]\n");
        fprintf(stderr, "\n    -f specify units file\n");
-       fprintf(stderr, "    -q supress prompting (quiet)\n");
+       fprintf(stderr, "    -q suppress prompting (quiet)\n");
        fprintf(stderr, "    -v print version number\n");
        exit(3);
 }
@@ -673,14 +673,26 @@
                }
        }
 
-       if (optind != argc - 2 && optind != argc)
+       argc -= optind;
+       argv += optind;
+
+       if (argc != 3 && argc != 2 && argc != 0)
                usage();
 
        readunits(userfile);
 
-       if (optind == argc - 2) {
-               strcpy(havestr, argv[optind]);
-               strcpy(wantstr, argv[optind + 1]);
+       if (argc == 3) {
+               strcpy(havestr, argv[0]);
+               strcat(havestr, " ");
+               strcat(havestr, argv[1]);
+               argc--;
+               argv++;
+               argv[0] = havestr;
+       }
+
+       if (argc == 2) {
+               strcpy(havestr, argv[0]);
+               strcpy(wantstr, argv[1]);
                initializeunit(&have);
                addunit(&have, havestr, 0);
                completereduce(&have);



Home | Main Index | Thread Index | Old Index