From owner-svn-src-all@FreeBSD.ORG Mon Apr 14 20:51:05 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6CCDDF3D; Mon, 14 Apr 2014 20:51:05 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5981619E2; Mon, 14 Apr 2014 20:51:05 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s3EKp5Ax031837; Mon, 14 Apr 2014 20:51:05 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s3EKp581031835; Mon, 14 Apr 2014 20:51:05 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201404142051.s3EKp581031835@svn.freebsd.org> From: Eitan Adler Date: Mon, 14 Apr 2014 20:51:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r264470 - head/usr.bin/units X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Apr 2014 20:51:05 -0000 Author: eadler Date: Mon Apr 14 20:51:04 2014 New Revision: 264470 URL: http://svnweb.freebsd.org/changeset/base/264470 Log: units(1): Add v option: verbose For increased compatibility with GNU units: support a -v option which produces more verbose output when spitting out the answer. GNU -v does additional work in the version, information, and check output which we do not (yet?) replicate. Modified: head/usr.bin/units/units.1 head/usr.bin/units/units.c Modified: head/usr.bin/units/units.1 ============================================================================== --- head/usr.bin/units/units.1 Mon Apr 14 20:34:48 2014 (r264469) +++ head/usr.bin/units/units.1 Mon Apr 14 20:51:04 2014 (r264470) @@ -8,7 +8,7 @@ .Sh SYNOPSIS .Nm .Op Fl f Ar filename -.Op Fl qUV +.Op Fl qvUV .Op Ar from-unit to-unit .Sh OPTIONS The following options are available: @@ -31,6 +31,8 @@ line. The program will not print prompts. It will print out the result of the single specified conversion. +.It Fl v +Print the units in the conversion output. Be more verbose in general. .El .Sh DESCRIPTION The Modified: head/usr.bin/units/units.c ============================================================================== --- head/usr.bin/units/units.c Mon Apr 14 20:34:48 2014 (r264469) +++ head/usr.bin/units/units.c Mon Apr 14 20:51:04 2014 (r264470) @@ -76,6 +76,10 @@ static char NULLUNIT[] = ""; static int unitcount; static int prefixcount; +static bool verbose = false; +static const char * havestr; +static const char * wantstr; + char *dupstr(const char *str); void readunits(const char *userfile); @@ -254,7 +258,7 @@ showunit(struct unittype * theunit) int printedslash; int counter = 1; - printf("\t%.8g", theunit->factor); + printf("%.8g", theunit->factor); if (theunit->offset) printf("&%.8g", theunit->offset); for (ptr = theunit->numerator; *ptr; ptr++) { @@ -289,7 +293,7 @@ showunit(struct unittype * theunit) counter = 1; } } - if (counter > 1) + if ( counter > 1) printf("%s%d", powerstring, counter); printf("\n"); } @@ -645,32 +649,50 @@ completereduce(struct unittype * unit) return 0; } - void showanswer(struct unittype * have, struct unittype * want) { + double ans; + if (compareunits(have, want)) { printf("conformability error\n"); + if (verbose) + printf("\t%s = ", havestr); + else + printf("\t"); showunit(have); + if (verbose) + printf("\t%s = ", wantstr); + else + printf("\t"); showunit(want); } else if (have->offset != want->offset) { if (want->quantity) printf("WARNING: conversion of non-proportional quantities.\n"); - printf("\t"); if (have->quantity) - printf("%.8g\n", + printf("\t%.8g\n", (have->factor + have->offset-want->offset)/want->factor); - else - printf(" (-> x*%.8g %+.8g)\n\t (<- y*%.8g %+.8g)\n", + else { + printf("\t (-> x*%.8g %+.8g)\n\t (<- y*%.8g %+.8g)\n", have->factor / want->factor, (have->offset-want->offset)/want->factor, want->factor / have->factor, (want->offset - have->offset)/have->factor); + } + } + else { + ans = have->factor / want->factor; + if (verbose) + printf("\t%s = %.8g * %s\n", havestr, ans, wantstr); + else + printf("\t* %.8g\n", ans); + + if (verbose) + printf("\t%s = (1 / %.8g) * %s\n", havestr, 1/ans, wantstr); + else + printf("\t/ %.8g\n", 1/ans); } - else - printf("\t* %.8g\n\t/ %.8g\n", have->factor / want->factor, - want->factor / have->factor); } @@ -688,8 +710,6 @@ main(int argc, char **argv) { struct unittype have, want; - const char * havestr; - const char * wantstr; int optchar; bool quiet; bool readfile; @@ -700,7 +720,7 @@ main(int argc, char **argv) quiet = false; readfile = false; - while ((optchar = getopt(argc, argv, "UVqf:")) != -1) { + while ((optchar = getopt(argc, argv, "fqvUV:")) != -1) { switch (optchar) { case 'f': readfile = true; @@ -712,6 +732,9 @@ main(int argc, char **argv) case 'q': quiet = true; break; + case 'v': + verbose = true; + break; case 'U': if (access(UNITSFILE, F_OK) == 0) printf("%s\n", UNITSFILE);