CVS commit: src/usr.bin/units

2020-04-23 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Apr 23 09:38:17 UTC 2020

Modified Files:
src/usr.bin/units: units.lib

Log Message:
If we're having Thai units, make them correct.  A tarangwah is a square wah,
which is ~4m^2 but not exactly (just as a wah is not exactly 2m, but close).
(wah apparently comes from the width of a person with hands outstretched...)


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/units/units.lib

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.lib
diff -u src/usr.bin/units/units.lib:1.23 src/usr.bin/units/units.lib:1.24
--- src/usr.bin/units/units.lib:1.23	Wed Apr 22 16:57:57 2020
+++ src/usr.bin/units/units.lib	Thu Apr 23 09:38:17 2020
@@ -1,4 +1,4 @@
-/	$NetBSD: units.lib,v 1.23 2020/04/22 16:57:57 scole Exp $
+/	$NetBSD: units.lib,v 1.24 2020/04/23 09:38:17 kre Exp $
 
 / primitive units
 
@@ -665,7 +665,7 @@ yot			400 sen
 
 / Thai area
 
-tarangwah		4 m2
+tarangwah		wah2
 ngan			100 tarangwah
 rai			4 ngan
 



CVS commit: src/usr.bin/units

2020-04-22 Thread Sean Cole
Module Name:src
Committed By:   scole
Date:   Wed Apr 22 16:57:58 UTC 2020

Modified Files:
src/usr.bin/units: units.lib

Log Message:
Add troyounce


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/units/units.lib

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.lib
diff -u src/usr.bin/units/units.lib:1.22 src/usr.bin/units/units.lib:1.23
--- src/usr.bin/units/units.lib:1.22	Wed Apr 22 16:35:47 2020
+++ src/usr.bin/units/units.lib	Wed Apr 22 16:57:57 2020
@@ -1,4 +1,4 @@
-/	$NetBSD: units.lib,v 1.22 2020/04/22 16:35:47 scole Exp $
+/	$NetBSD: units.lib,v 1.23 2020/04/22 16:57:57 scole Exp $
 
 / primitive units
 
@@ -136,6 +136,7 @@ apdram			60 grain
 apounce			480 grain
 appound			5760 grain
 troypound		appound
+troyounce		1|12 troypound
 
 / Length
 



CVS commit: src/usr.bin/units

2020-04-22 Thread Sean Cole
Module Name:src
Committed By:   scole
Date:   Wed Apr 22 16:35:47 UTC 2020

Modified Files:
src/usr.bin/units: units.lib

Log Message:
On second thought, don't include more than one spelling for thai units


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/units/units.lib

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.lib
diff -u src/usr.bin/units/units.lib:1.21 src/usr.bin/units/units.lib:1.22
--- src/usr.bin/units/units.lib:1.21	Wed Apr 22 16:21:37 2020
+++ src/usr.bin/units/units.lib	Wed Apr 22 16:35:47 2020
@@ -1,4 +1,4 @@
-/	$NetBSD: units.lib,v 1.21 2020/04/22 16:21:37 scole Exp $
+/	$NetBSD: units.lib,v 1.22 2020/04/22 16:35:47 scole Exp $
 
 / primitive units
 
@@ -658,15 +658,13 @@ krabiat			0.5208 cm
 nio			4 krabiat
 khuep			12 nio
 sok			2 khuep
-wa			4 sok
-wah			wa
-sen			20 wa
+wah			4 sok
+sen			20 wah
 yot			400 sen
 
 / Thai area
 
 tarangwah		4 m2
-talangwah		tarangwah
 ngan			100 tarangwah
 rai			4 ngan
 
@@ -674,7 +672,6 @@ rai			4 ngan
 
 salueng			3.75 gm
 baht			4 salueng
-bat			baht
 tamlueng		4 baht
 chang			20 tamlueng
 hap			50 chang



CVS commit: src/usr.bin/units

2020-04-22 Thread Sean Cole
Module Name:src
Committed By:   scole
Date:   Wed Apr 22 16:21:37 UTC 2020

Modified Files:
src/usr.bin/units: units.lib

Log Message:
Add more Thai length, area and weight units


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/units/units.lib

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.lib
diff -u src/usr.bin/units/units.lib:1.20 src/usr.bin/units/units.lib:1.21
--- src/usr.bin/units/units.lib:1.20	Tue Mar 21 01:21:59 2017
+++ src/usr.bin/units/units.lib	Wed Apr 22 16:21:37 2020
@@ -1,4 +1,4 @@
-/	$NetBSD: units.lib,v 1.20 2017/03/21 01:21:59 scole Exp $
+/	$NetBSD: units.lib,v 1.21 2020/04/22 16:21:37 scole Exp $
 
 / primitive units
 
@@ -652,9 +652,30 @@ worstedyarncount	1680 ft/pound
 metricyarncount		meter/gram
 jewlerspoint		2 milligram
 
-/ thai measurements
+/ Thai length
 
-wah			2 m
-ngan			400 m2
-rai			1600 m2
+krabiat			0.5208 cm
+nio			4 krabiat
+khuep			12 nio
+sok			2 khuep
+wa			4 sok
+wah			wa
+sen			20 wa
+yot			400 sen
+
+/ Thai area
+
+tarangwah		4 m2
+talangwah		tarangwah
+ngan			100 tarangwah
+rai			4 ngan
+
+/ Thai weight
+
+salueng			3.75 gm
+baht			4 salueng
+bat			baht
+tamlueng		4 baht
+chang			20 tamlueng
+hap			50 chang
 



CVS commit: src/usr.bin/units

2017-03-20 Thread Sean Cole
Module Name:src
Committed By:   scole
Date:   Tue Mar 21 01:21:59 UTC 2017

Modified Files:
src/usr.bin/units: units.lib

Log Message:
Add most common thai length/area measurements of wah rai ngan


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/units/units.lib

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.lib
diff -u src/usr.bin/units/units.lib:1.19 src/usr.bin/units/units.lib:1.20
--- src/usr.bin/units/units.lib:1.19	Fri Feb  5 03:38:50 2016
+++ src/usr.bin/units/units.lib	Tue Mar 21 01:21:59 2017
@@ -1,4 +1,4 @@
-/	$NetBSD: units.lib,v 1.19 2016/02/05 03:38:50 dholland Exp $
+/	$NetBSD: units.lib,v 1.20 2017/03/21 01:21:59 scole Exp $
 
 / primitive units
 
@@ -652,3 +652,9 @@ worstedyarncount	1680 ft/pound
 metricyarncount		meter/gram
 jewlerspoint		2 milligram
 
+/ thai measurements
+
+wah			2 m
+ngan			400 m2
+rai			1600 m2
+



CVS commit: src/usr.bin/units

2016-02-04 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Fri Feb  5 03:32:49 UTC 2016

Modified Files:
src/usr.bin/units: units.c

Log Message:
Improve previous slightly; while we accept e.g. "meter2" to mean "meter^2",
don't allow "meter-2" to be interpreted as "meter^-2" as that's very
confusing.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/units/units.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.c
diff -u src/usr.bin/units/units.c:1.26 src/usr.bin/units/units.c:1.27
--- src/usr.bin/units/units.c:1.26	Fri Feb  5 03:30:08 2016
+++ src/usr.bin/units/units.c	Fri Feb  5 03:32:49 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: units.c,v 1.26 2016/02/05 03:30:08 dholland Exp $	*/
+/*	$NetBSD: units.c,v 1.27 2016/02/05 03:32:49 dholland Exp $	*/
 
 /*
  * units.c   Copyright (c) 1993 by Adrian Mariano (adr...@cam.cornell.edu)
@@ -455,7 +455,8 @@ addunit(struct unittype * theunit, const
 	assert(pos > 0);
 }
 if (pos < len) {
-	if (pos > 0 && item[pos - 1] == '-') {
+	if (pos > 1 && item[pos - 1] == '-' &&
+	item[pos - 2] == '^') {
 		/* allow negative exponents */
 		pos--;
 	}



CVS commit: src/usr.bin/units

2016-02-04 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Fri Feb  5 03:30:08 UTC 2016

Modified Files:
src/usr.bin/units: units.c

Log Message:
Improve the parser. Now we understand negative exponents; fixes PR 50768.

Also handle negative numbers better in general (don't randomly drop
the sign in a number of cases) and don't choke on exponents > 9.

This commit alters the meaning of a few previously valid but marginal
inputs (e.g. "3 foot-5 pound" is now treated as "3*-5 foot-pound"
rather than "3*5 foot-pound"; if you want the latter insert another
space) but corrects obviously wrong handling of many more.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/units/units.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.c
diff -u src/usr.bin/units/units.c:1.25 src/usr.bin/units/units.c:1.26
--- src/usr.bin/units/units.c:1.25	Tue Jan  7 02:07:09 2014
+++ src/usr.bin/units/units.c	Fri Feb  5 03:30:08 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: units.c,v 1.25 2014/01/07 02:07:09 joerg Exp $	*/
+/*	$NetBSD: units.c,v 1.26 2016/02/05 03:30:08 dholland Exp $	*/
 
 /*
  * units.c   Copyright (c) 1993 by Adrian Mariano (adr...@cam.cornell.edu)
@@ -17,6 +17,7 @@
  * improvements you might make to this program.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -344,14 +345,41 @@ addunit(struct unittype * theunit, const
 	char *scratch, *savescr;
 	char *item;
 	char *divider, *slash;
+	char *minus;
+	size_t pos, len;
 	int doingtop;
 
 	savescr = scratch = dupstr(toadd);
-	for (slash = scratch + 1; *slash; slash++)
-		if (*slash == '-' &&
-		(tolower((unsigned char)*(slash - 1)) != 'e' ||
-		!strchr(".0123456789", *(slash + 1
-			*slash = ' ';
+
+	/*
+	 * "foot-pound" is the same as "foot pound". But don't
+	 * trash minus signs on numbers.
+	 *
+	 * 20160204 dholland: this used to let through only minus
+	 * signs at the beginning of the string or in the middle of a
+	 * floating constant (e.g. 3.6e-5), and a minus sign at the
+	 * beginning of the string failed further on. I have changed
+	 * it so any minus sign before a digit (or decimal point) is
+	 * treated as going with that digit.
+	 *
+	 * Note that this changed the interpretation of certain
+	 * marginally valid inputs like "3 N-5 s"; that used to be
+	 * interpreted as "3 N 5 s" or 15 N s, but now it reads as
+	 * "3 N -5 s" or -15 N s. However, it also makes negative
+	 * exponents on units work, which used to be silently trashed.
+	 */
+	for (minus = scratch + 1; *minus; minus++) {
+		if (*minus != '-') {
+			continue;
+		}
+		if (strchr(".0123456789", *(minus + 1))) {
+			continue;
+		}
+		*minus = ' ';
+	}
+
+	/* Process up to the next / in one go. */
+
 	slash = strchr(scratch, '/');
 	if (slash)
 		*slash = 0;
@@ -359,7 +387,9 @@ addunit(struct unittype * theunit, const
 	do {
 		item = strtok(scratch, " *\t\n/");
 		while (item) {
-			if (strchr("0123456789.", *item)) {
+			if ((*item == '-' && strchr("0123456789.", *(item+1)))
+			|| strchr("0123456789.", *item)) {
+			
 /* item starts with a number */
 char *endptr;
 double num;
@@ -415,14 +445,36 @@ addunit(struct unittype * theunit, const
 			}
 			else {	/* item is not a number */
 int repeat = 1;
+int flipthis = 0;
 
-if (strchr("23456789",
-item[strlen(item) - 1])) {
-	repeat = item[strlen(item) - 1] - '0';
-	item[strlen(item) - 1] = 0;
+pos = len = strlen(item);
+assert(pos > 0);
+while (strchr("0123456789", item[pos - 1])) {
+	pos--;
+	/* string began with non-digit */
+	assert(pos > 0);
+}
+if (pos < len) {
+	if (pos > 0 && item[pos - 1] == '-') {
+		/* allow negative exponents */
+		pos--;
+	}
+	/* have an exponent */
+	repeat = strtol(item + pos, NULL, 10);
+	item[pos] = 0;
+	if (repeat == 0) {
+		/* not really the right msg */
+		zeroerror();
+		return 1;
+	}
+	if (repeat < 0) {
+		flipthis = 1;
+		repeat = -repeat;
+	}
 }
+flipthis ^= doingtop ^ flip;
 for (; repeat; repeat--)
-	if (addsubunit(doingtop ^ flip ? theunit->numerator : theunit->denominator, item))
+	if (addsubunit(flipthis ? theunit->numerator : theunit->denominator, item))
 		return 1;
 			}
 			item = strtok(NULL, " *\t/\n");



CVS commit: src/usr.bin/units

2016-02-04 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Fri Feb  5 03:38:50 UTC 2016

Modified Files:
src/usr.bin/units: units.lib

Log Message:
File watt in the right group, and accept W as well, as that's quite
standard.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/units/units.lib

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.lib
diff -u src/usr.bin/units/units.lib:1.18 src/usr.bin/units/units.lib:1.19
--- src/usr.bin/units/units.lib:1.18	Sun Sep 20 15:09:06 2015
+++ src/usr.bin/units/units.lib	Fri Feb  5 03:38:50 2016
@@ -1,4 +1,4 @@
-/	$NetBSD: units.lib,v 1.18 2015/09/20 15:09:06 martin Exp $
+/	$NetBSD: units.lib,v 1.19 2016/02/05 03:38:50 dholland Exp $
 
 / primitive units
 
@@ -230,6 +230,8 @@ newton			kg-m/sec2
 nt			newton
 N			newton
 joule			nt-m
+watt			joule/sec
+W			watt
 cal			4.1868 joule
 
 / Electrical
@@ -238,7 +240,6 @@ coulomb			coul
 C			coul
 ampere			coul/sec
 amp			ampere
-watt			joule/sec
 volt			watt/amp
 ohm			volt/amp
 mho			/ohm



CVS commit: src/usr.bin/units

2015-09-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Sep 20 15:09:06 UTC 2015

Modified Files:
src/usr.bin/units: units.lib

Log Message:
Add tera- and peta-bytes.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/units/units.lib

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.lib
diff -u src/usr.bin/units/units.lib:1.17 src/usr.bin/units/units.lib:1.18
--- src/usr.bin/units/units.lib:1.17	Fri Dec 28 17:57:46 2012
+++ src/usr.bin/units/units.lib	Sun Sep 20 15:09:06 2015
@@ -1,4 +1,4 @@
-/	$NetBSD: units.lib,v 1.17 2012/12/28 17:57:46 apb Exp $
+/	$NetBSD: units.lib,v 1.18 2015/09/20 15:09:06 martin Exp $
 
 / primitive units
 
@@ -345,6 +345,8 @@ kbyte			1024 byte
 megabyte		1024 kbyte
 gigabyte		1024 megabyte
 meg			megabyte
+terabyte		1024 gigabyte
+petabyte		1024 terabyte
 
 
 / Trivia



CVS commit: src/usr.bin/units

2013-01-05 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Jan  6 00:19:13 UTC 2013

Modified Files:
src/usr.bin/units: units.1 units.c

Log Message:
Sort options in man page SYNOPSIS and sync usage with it.
Bump date.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/units/units.1
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/units/units.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.1
diff -u src/usr.bin/units/units.1:1.19 src/usr.bin/units/units.1:1.20
--- src/usr.bin/units/units.1:1.19	Tue Jan  1 11:51:55 2013
+++ src/usr.bin/units/units.1	Sun Jan  6 00:19:13 2013
@@ -1,5 +1,5 @@
-.\	$NetBSD: units.1,v 1.19 2013/01/01 11:51:55 apb Exp $
-.Dd December 28, 2012
+.\	$NetBSD: units.1,v 1.20 2013/01/06 00:19:13 wiz Exp $
+.Dd January 6, 2013
 .Dt UNITS 1
 .Os
 .Sh NAME
@@ -7,8 +7,8 @@
 .Nd conversion program
 .Sh SYNOPSIS
 .Nm
+.Op Fl Llqv
 .Op Fl f Ar filename
-.Op Fl lLqv
 .Oo
 .Op Ar count
 .Ar from-unit to-unit

Index: src/usr.bin/units/units.c
diff -u src/usr.bin/units/units.c:1.23 src/usr.bin/units/units.c:1.24
--- src/usr.bin/units/units.c:1.23	Wed Jan  2 14:05:04 2013
+++ src/usr.bin/units/units.c	Sun Jan  6 00:19:13 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: units.c,v 1.23 2013/01/02 14:05:04 apb Exp $	*/
+/*	$NetBSD: units.c,v 1.24 2013/01/06 00:19:13 wiz Exp $	*/
 
 /*
  * units.c   Copyright (c) 1993 by Adrian Mariano (adr...@cam.cornell.edu)
@@ -794,8 +794,10 @@ static void
 usage(void)
 {
 	fprintf(stderr,
-	\nunits [-f unitsfile] [-q] [-v] [from-unit to-unit]\n);
+	\nunits [-Llqv] [-f filename] [[count] from-unit to-unit]\n);
 	fprintf(stderr, \n-f specify units file\n);
+	fprintf(stderr, -L list units in standardized base units\n);
+	fprintf(stderr, -l list units\n);
 	fprintf(stderr, -q suppress prompting (quiet)\n);
 	fprintf(stderr, -v print version number\n);
 	exit(3);



CVS commit: src/usr.bin/units

2013-01-02 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Wed Jan  2 14:05:04 UTC 2013

Modified Files:
src/usr.bin/units: units.c

Log Message:
Really expand the name, not the definition, as the comment says.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/units/units.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.c
diff -u src/usr.bin/units/units.c:1.22 src/usr.bin/units/units.c:1.23
--- src/usr.bin/units/units.c:1.22	Tue Jan  1 12:45:06 2013
+++ src/usr.bin/units/units.c	Wed Jan  2 14:05:04 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: units.c,v 1.22 2013/01/01 12:45:06 apb Exp $	*/
+/*	$NetBSD: units.c,v 1.23 2013/01/02 14:05:04 apb Exp $	*/
 
 /*
  * units.c   Copyright (c) 1993 by Adrian Mariano (adr...@cam.cornell.edu)
@@ -771,7 +771,7 @@ listunits(int expand)
 			 * will be interpreted as multiplication.
 			 */
 			initializeunit(theunit);
-			if (addunit(theunit, thedefn/*XXX*/, 0) != 0
+			if (addunit(theunit, thename, 0) != 0
 			|| completereduce(theunit) != 0) {
 errors++;
 printexpansion = 0;



CVS commit: src/usr.bin/units

2013-01-01 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Tue Jan  1 11:44:01 UTC 2013

Modified Files:
src/usr.bin/units: units.c

Log Message:
Correctly ignore duplicate definitions.  continue applies only to the
innermost loop.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/units/units.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.c
diff -u src/usr.bin/units/units.c:1.19 src/usr.bin/units/units.c:1.20
--- src/usr.bin/units/units.c:1.19	Fri Dec 28 17:07:03 2012
+++ src/usr.bin/units/units.c	Tue Jan  1 11:44:00 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: units.c,v 1.19 2012/12/28 17:07:03 apb Exp $	*/
+/*	$NetBSD: units.c,v 1.20 2013/01/01 11:44:00 apb Exp $	*/
 
 /*
  * units.c   Copyright (c) 1993 by Adrian Mariano (adr...@cam.cornell.edu)
@@ -109,7 +109,7 @@ readunits(const char *userfile)
 {
 	FILE *unitfile;
 	char line[80], *lineptr;
-	int len, linenum, i;
+	int len, linenum, i, isdup;
 
 	unitcount = 0;
 	linenum = 0;
@@ -173,14 +173,20 @@ readunits(const char *userfile)
 continue;
 			}
 			lineptr[strlen(lineptr) - 1] = 0;
-			prefixtable[prefixcount].prefixname = dupstr(lineptr);
-			for (i = 0; i  prefixcount; i++)
-if (!strcmp(prefixtable[i].prefixname, lineptr)) {
-	warnx(
-			Redefinition of prefix '%s' on line %d ignored,
-	lineptr, linenum);
-	continue;
+			for (isdup = 0, i = 0; i  prefixcount; i++) {
+if (!strcmp(prefixtable[i].prefixname,
+lineptr)) {
+	isdup = 1;
+	break;
 }
+			}
+			if (isdup) {
+warnx(
+			Redefinition of prefix '%s' on line %d ignored,
+lineptr, linenum);
+continue;
+			}
+			prefixtable[prefixcount].prefixname = dupstr(lineptr);
 			lineptr += len + 1;
 			if (!strlen(lineptr)) {
 readerror(linenum);
@@ -197,14 +203,19 @@ readunits(const char *userfile)
 linenum);
 continue;
 			}
-			unittable[unitcount].uname = dupstr(lineptr);
-			for (i = 0; i  unitcount; i++)
+			for (isdup = 0, i = 0; i  unitcount; i++) {
 if (!strcmp(unittable[i].uname, lineptr)) {
-	warnx(
-Redefinition of unit '%s' on line %d ignored,
-	lineptr, linenum);
-	continue;
+	isdup = 1;
+	break;
 }
+			}
+			if (isdup) {
+warnx(
+Redefinition of unit '%s' on line %d ignored,
+lineptr, linenum);
+continue;
+			}
+			unittable[unitcount].uname = dupstr(lineptr);
 			lineptr += len + 1;
 			lineptr += strspn(lineptr,  \n\t);
 			if (!strlen(lineptr)) {



CVS commit: src/usr.bin/units

2013-01-01 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Tue Jan  1 11:51:56 UTC 2013

Modified Files:
src/usr.bin/units: units.1 units.c

Log Message:
Add -l and -L options to units(1).  -l simply lists all unit
definitions, while -L alsoreduces them to depend only on a few
primitive units (such as m, kg, sec).


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/units/units.1
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/units/units.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.1
diff -u src/usr.bin/units/units.1:1.18 src/usr.bin/units/units.1:1.19
--- src/usr.bin/units/units.1:1.18	Fri Dec 28 13:25:25 2012
+++ src/usr.bin/units/units.1	Tue Jan  1 11:51:55 2013
@@ -1,4 +1,4 @@
-.\	$NetBSD: units.1,v 1.18 2012/12/28 13:25:25 apb Exp $
+.\	$NetBSD: units.1,v 1.19 2013/01/01 11:51:55 apb Exp $
 .Dd December 28, 2012
 .Dt UNITS 1
 .Os
@@ -8,7 +8,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl f Ar filename
-.Op Fl qv
+.Op Fl lLqv
 .Oo
 .Op Ar count
 .Ar from-unit to-unit
@@ -25,6 +25,24 @@ The following options and arguments are 
 .Bl -tag -width -fXfilenameX -offset indent
 .It Fl f Ar filename
 Specifies the name of the units data file to load.
+.It Fl l No or Fl L
+List all unit definitions to the standard output,
+instead of performing any conversions.
+The result may include error messages and comments, beginning with
+.Ql \/ .
+.Pp
+With the
+.Fl l
+option, unit definitions will be listed in a format
+almost identical to the the units data file that was loaded,
+except that comments will be removed, spacing may be changed,
+and lines may be re-ordered.
+.Pp
+With the
+.Fl L
+option, all unit definitions will be reduced to a form that
+depends on only a few primitive units (such as
+.Sy m , kg , sec ) .
 .It Fl q
 Suppresses prompting of the user for units and the display of statistics
 about the number of units loaded.

Index: src/usr.bin/units/units.c
diff -u src/usr.bin/units/units.c:1.20 src/usr.bin/units/units.c:1.21
--- src/usr.bin/units/units.c:1.20	Tue Jan  1 11:44:00 2013
+++ src/usr.bin/units/units.c	Tue Jan  1 11:51:55 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: units.c,v 1.20 2013/01/01 11:44:00 apb Exp $	*/
+/*	$NetBSD: units.c,v 1.21 2013/01/01 11:51:55 apb Exp $	*/
 
 /*
  * units.c   Copyright (c) 1993 by Adrian Mariano (adr...@cam.cornell.edu)
@@ -19,6 +19,7 @@
 
 #include ctype.h
 #include err.h
+#include float.h
 #include stdio.h
 #include string.h
 #include stdlib.h
@@ -39,6 +40,13 @@
 
 #define PRIMITIVECHAR '!'
 
+static int precision = 8;		/* for printf with %.*g format */
+
+static const char *errprefix = NULL;	/* if not NULL, then prepend this
+	 * to error messages and send them to
+	 * stdout instead of stderr.
+	 */
+
 static const char *powerstring = ^;
 
 static struct {
@@ -98,9 +106,27 @@ dupstr(const char *str)
 
 
 static void
+mywarnx(const char *fmt, ...)
+{
+	va_list args;
+
+	va_start(args, fmt);
+	if (errprefix) {
+		/* warn to stdout, with errprefix prepended */
+		printf(%s, errprefix);
+		vprintf(fmt, args);
+		printf(%s, \n);
+	} else {
+		/* warn to stderr */
+		vwarnx(fmt, args);
+	}
+	va_end(args);
+}
+
+static void
 readerror(int linenum)
 {
-	warnx(Error in units file '%s' line %d, UNITSFILE, linenum);
+	mywarnx(Error in units file '%s' line %d, UNITSFILE, linenum);
 }
 
 
@@ -168,8 +194,9 @@ readunits(const char *userfile)
 			continue;
 		if (lineptr[strlen(lineptr) - 1] == '-') { /* it's a prefix */
 			if (prefixcount == MAXPREFIXES) {
-warnx(Memory for prefixes exceeded in line %d,
-linenum);
+mywarnx(
+			Memory for prefixes exceeded in line %d,
+	linenum);
 continue;
 			}
 			lineptr[strlen(lineptr) - 1] = 0;
@@ -181,7 +208,7 @@ readunits(const char *userfile)
 }
 			}
 			if (isdup) {
-warnx(
+mywarnx(
 			Redefinition of prefix '%s' on line %d ignored,
 lineptr, linenum);
 continue;
@@ -199,7 +226,7 @@ readunits(const char *userfile)
 		}
 		else {		/* it's not a prefix */
 			if (unitcount == MAXUNITS) {
-warnx(Memory for units exceeded in line %d,
+mywarnx(Memory for units exceeded in line %d,
 linenum);
 continue;
 			}
@@ -210,7 +237,7 @@ readunits(const char *userfile)
 }
 			}
 			if (isdup) {
-warnx(
+mywarnx(
 Redefinition of unit '%s' on line %d ignored,
 lineptr, linenum);
 continue;
@@ -244,7 +271,7 @@ addsubunit(const char *product[], const 
 
 	for (ptr = product; *ptr  *ptr != NULLUNIT; ptr++);
 	if (ptr = product + MAXSUBUNITS) {
-		warnx(Memory overflow in unit reduction);
+		mywarnx(Memory overflow in unit reduction);
 		return 1;
 	}
 	if (!*ptr)
@@ -260,7 +287,7 @@ showunit(struct unittype * theunit)
 	int printedslash;
 	int counter = 1;
 
-	printf(\t%.8g, theunit-factor);
+	printf(\t%.*g, precision, theunit-factor);
 	for (ptr = theunit-numerator; *ptr; ptr++) {
 		if (ptr  theunit-numerator  **ptr 
 		

CVS commit: src/usr.bin/units

2013-01-01 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Tue Jan  1 12:45:06 UTC 2013

Modified Files:
src/usr.bin/units: units.c

Log Message:
fix incomplete comment


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/units/units.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.c
diff -u src/usr.bin/units/units.c:1.21 src/usr.bin/units/units.c:1.22
--- src/usr.bin/units/units.c:1.21	Tue Jan  1 11:51:55 2013
+++ src/usr.bin/units/units.c	Tue Jan  1 12:45:06 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: units.c,v 1.21 2013/01/01 11:51:55 apb Exp $	*/
+/*	$NetBSD: units.c,v 1.22 2013/01/01 12:45:06 apb Exp $	*/
 
 /*
  * units.c   Copyright (c) 1993 by Adrian Mariano (adr...@cam.cornell.edu)
@@ -768,7 +768,7 @@ listunits(int expand)
 			 * expand thename, not thedefn, so that
 			 * we can catch errors in the name itself.
 			 * e.g. a name that contains a hyphen
-			 * will be interpreted
+			 * will be interpreted as multiplication.
 			 */
 			initializeunit(theunit);
 			if (addunit(theunit, thedefn/*XXX*/, 0) != 0



CVS commit: src/usr.bin/units

2012-12-28 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Fri Dec 28 13:25:26 UTC 2012

Modified Files:
src/usr.bin/units: units.1

Log Message:
Improve the description of the [count] from-unit to-unit arguments.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/units/units.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.1
diff -u src/usr.bin/units/units.1:1.17 src/usr.bin/units/units.1:1.18
--- src/usr.bin/units/units.1:1.17	Sun Apr  3 19:44:15 2011
+++ src/usr.bin/units/units.1	Fri Dec 28 13:25:25 2012
@@ -1,5 +1,5 @@
-.\	$NetBSD: units.1,v 1.17 2011/04/03 19:44:15 dholland Exp $
-.Dd April 3, 2011
+.\	$NetBSD: units.1,v 1.18 2012/12/28 13:25:25 apb Exp $
+.Dd December 28, 2012
 .Dt UNITS 1
 .Os
 .Sh NAME
@@ -21,8 +21,8 @@ their equivalents in other scales.
 can only handle multiplicative scale changes.
 It cannot convert Centigrade to Fahrenheit, for example.
 .Pp
-The following options are supported:
-.Bl -tag -width from-unit to-unit -offset indent
+The following options and arguments are supported:
+.Bl -tag -width -fXfilenameX -offset indent
 .It Fl f Ar filename
 Specifies the name of the units data file to load.
 .It Fl q
@@ -30,17 +30,20 @@ Suppresses prompting of the user for uni
 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 Ar to-unit
 Allows a single unit conversion to be done directly from the command
 line.
 No prompting will occur.
 .Nm
 will print out only the result of this single conversion.
-The
+Specifying
 .Ar count
-argument can be prepended to the
+and
 .Ar from-unit
-or it can be separate.
+as two separate arguments is equivalent to embedding both parts
+inside a single
+.Ar from-unit
+argument, with the parts separated by a space.
 .El
 .Pp
 .Nm



CVS commit: src/usr.bin/units

2012-12-28 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Fri Dec 28 13:45:53 UTC 2012

Modified Files:
src/usr.bin/units: units.lib

Log Message:
Fix references to undefined units:
* southamericarand should be southafricarand;
* sidereal day should be siderealday;
* perusol should be perunewsol.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/units/units.lib

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.lib
diff -u src/usr.bin/units/units.lib:1.15 src/usr.bin/units/units.lib:1.16
--- src/usr.bin/units/units.lib:1.15	Mon Mar 28 00:08:47 2011
+++ src/usr.bin/units/units.lib	Fri Dec 28 13:45:53 2012
@@ -1,4 +1,4 @@
-/	$NetBSD: units.lib,v 1.15 2011/03/28 00:08:47 dholland Exp $
+/	$NetBSD: units.lib,v 1.16 2012/12/28 13:45:53 apb Exp $
 
 / primitive units
 
@@ -290,7 +290,7 @@ polandzloty		.59 $
 saudiarabiariyal	.26702 $
 singaporedollar		.6157 $
 slovakkoruna		.034 $
-southamericarand	.21 $
+southafricarand	.21 $
 southkoreawon		.001 $
 swedenkrona		.13 $
 switzerlandfranc	.66 $
@@ -322,7 +322,7 @@ bolivar			venezuelabolivar
 peseta			spainpeseta
 rand			southafricarand
 escudo			portugalescudo
-sol			perusol
+newsol			perunewsol
 guilder			netherlandsguilder
 hollandguilder		netherlandsguilder
 peso			mexicopeso
@@ -623,7 +623,7 @@ kilohm			kiloohm
 megohm			megaohm
 siderealyear		365.256360417 day
 siderealday		23.934469444 hour
-siderealhour		1|24 sidereal day
+siderealhour		1|24 siderealday
 lunarmonth		29.530 day
 synodicmonth		lunarmonth
 siderealmonth		27.32152777 day



CVS commit: src/usr.bin/units

2012-12-28 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Fri Dec 28 17:07:04 UTC 2012

Modified Files:
src/usr.bin/units: units.c

Log Message:
Allow a number and a unit to be juxtaposed without an intervening space.
Now litres/100km works as desired, instead of silently being
treated as litres/100.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/units/units.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.c
diff -u src/usr.bin/units/units.c:1.18 src/usr.bin/units/units.c:1.19
--- src/usr.bin/units/units.c:1.18	Tue Mar 20 20:34:59 2012
+++ src/usr.bin/units/units.c	Fri Dec 28 17:07:03 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: units.c,v 1.18 2012/03/20 20:34:59 matt Exp $	*/
+/*	$NetBSD: units.c,v 1.19 2012/12/28 17:07:03 apb Exp $	*/
 
 /*
  * units.c   Copyright (c) 1993 by Adrian Mariano (adr...@cam.cornell.edu)
@@ -321,22 +321,30 @@ addunit(struct unittype * theunit, const
 	do {
 		item = strtok(scratch,  *\t\n/);
 		while (item) {
-			if (strchr(0123456789., *item)) { /* item is a number */
+			if (strchr(0123456789., *item)) {
+/* item starts with a number */
+char *endptr;
 double num;
 
 divider = strchr(item, '|');
 if (divider) {
 	*divider = 0;
-	num = atof(item);
+	num = strtod(item, endptr);
 	if (!num) {
 		zeroerror();
 		return 1;
 	}
+	if (endptr != divider) {
+		/* 6foo|2 is an error */
+		warnx(Junk between number 
+		  and '|');
+		return 1;
+	}
 	if (doingtop ^ flip)
 		theunit-factor *= num;
 	else
 		theunit-factor /= num;
-	num = atof(divider + 1);
+	num = strtod(divider + 1, endptr);
 	if (!num) {
 		zeroerror();
 		return 1;
@@ -345,9 +353,14 @@ addunit(struct unittype * theunit, const
 		theunit-factor /= num;
 	else
 		theunit-factor *= num;
+	if (*endptr) {
+		/* 6|2foo is like 6|2 foo */
+		item = endptr;
+		continue;
+	}
 }
 else {
-	num = atof(item);
+	num = strtod(item, endptr);
 	if (!num) {
 		zeroerror();
 		return 1;
@@ -356,7 +369,11 @@ addunit(struct unittype * theunit, const
 		theunit-factor *= num;
 	else
 		theunit-factor /= num;
-
+	if (*endptr) {
+		/* 3foo is like 3 foo */
+		item = endptr;
+		continue;
+	}
 }
 			}
 			else {	/* item is not a number */



CVS commit: src/usr.bin/units

2012-12-28 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Fri Dec 28 17:57:46 UTC 2012

Modified Files:
src/usr.bin/units: units.lib

Log Message:
Rename tappit-hen to tappithen because unit names cannot contain
hyphens.  Also change the definition from 3 imperial (a dimensionless
quantity) to 3 bottle (2.25 litres).  Wikipedia and several other web
sites say 3 bottles or 2.25 litres, but
http://www.christies.com/lotfinder/wine/chateau-lafite-rothschild-vintage-1811-1-tappit-hen-per-4992576-details.aspx
says:

There seems to be no firm definition of the bottle size referred to
as tappit-hen. Believed to be of Scottish origin, a tappit-hen
can vary, according to which definition one follows, from 1 1/2
bottles to a tregnum or 3-bottle bottle. It is safest to say that it
approximates to a magnum.

and ends with:

1 Tappit-Hen (2.25 liters) per lot


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/units/units.lib

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.lib
diff -u src/usr.bin/units/units.lib:1.16 src/usr.bin/units/units.lib:1.17
--- src/usr.bin/units/units.lib:1.16	Fri Dec 28 13:45:53 2012
+++ src/usr.bin/units/units.lib	Fri Dec 28 17:57:46 2012
@@ -1,4 +1,4 @@
-/	$NetBSD: units.lib,v 1.16 2012/12/28 13:45:53 apb Exp $
+/	$NetBSD: units.lib,v 1.17 2012/12/28 17:57:46 apb Exp $
 
 / primitive units
 
@@ -220,7 +220,7 @@ sovereign		34 bottle
 
 pony			split
 fillette		half
-tappit-hen		3 imperial
+tappithen		3 bottle
 rheoboam		rehoboam
 shalmaneser		salmanazar
 



CVS commit: src/usr.bin/units

2011-09-06 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Sep  6 18:35:41 UTC 2011

Modified Files:
src/usr.bin/units: units.c

Log Message:
ANSIfy, static + __dead


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/units/units.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.c
diff -u src/usr.bin/units/units.c:1.16 src/usr.bin/units/units.c:1.17
--- src/usr.bin/units/units.c:1.16	Tue Apr 14 05:55:12 2009
+++ src/usr.bin/units/units.c	Tue Sep  6 18:35:41 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: units.c,v 1.16 2009/04/14 05:55:12 lukem Exp $	*/
+/*	$NetBSD: units.c,v 1.17 2011/09/06 18:35:41 joerg Exp $	*/
 
 /*
  * units.c   Copyright (c) 1993 by Adrian Mariano (adr...@cam.cornell.edu)
@@ -39,9 +39,9 @@
 
 #define PRIMITIVECHAR '!'
 
-const char *powerstring = ^;
+static const char *powerstring = ^;
 
-struct {
+static struct {
 	const char *uname;
 	const char *uval;
 }  unittable[MAXUNITS];
@@ -58,36 +58,34 @@
 }  prefixtable[MAXPREFIXES];
 
 
-const char *NULLUNIT = ;
-
-int unitcount;
-int prefixcount;
+static const char *NULLUNIT = ;
 
+static int unitcount;
+static int prefixcount;
 
-int	addsubunit __P((const char *[], const char *));
-int	addunit __P((struct unittype *, const char *, int));
-void	cancelunit __P((struct unittype *));
-int	compare __P((const void *, const void *));
-int	compareproducts __P((const char **, const char **));
-int	compareunits __P((struct unittype *, struct unittype *));
-int	compareunitsreciprocal __P((struct unittype *, struct unittype *));
-int	completereduce __P((struct unittype *));
-void	initializeunit __P((struct unittype *));
-int	main __P((int, char **));
-void	readerror __P((int));
-void	readunits __P((const char *));
-int	reduceproduct __P((struct unittype *, int));
-int	reduceunit __P((struct unittype *));
-void	showanswer __P((struct unittype *, struct unittype *));
-void	showunit __P((struct unittype *));
-void	sortunit __P((struct unittype *));
-void	usage __P((void));
-void	zeroerror __P((void));
-char   *dupstr __P((const char *));
-const char *lookupunit __P((const char *));
 
+static int	addsubunit(const char *[], const char *);
+static int	addunit(struct unittype *, const char *, int);
+static void	cancelunit(struct unittype *);
+static int	compare(const void *, const void *);
+static int	compareproducts(const char **, const char **);
+static int	compareunits(struct unittype *, struct unittype *);
+static int	compareunitsreciprocal(struct unittype *, struct unittype *);
+static int	completereduce(struct unittype *);
+static void	initializeunit(struct unittype *);
+static void	readerror(int);
+static void	readunits(const char *);
+static int	reduceproduct(struct unittype *, int);
+static int	reduceunit(struct unittype *);
+static void	showanswer(struct unittype *, struct unittype *);
+static void	showunit(struct unittype *);
+static void	sortunit(struct unittype *);
+__dead static void	usage(void);
+static void	zeroerror(void);
+static char   *dupstr(const char *);
+static const char *lookupunit(const char *);
 
-char *
+static char *
 dupstr(const char *str)
 {
 	char *ret;
@@ -99,14 +97,14 @@
 }
 
 
-void 
+static void
 readerror(int linenum)
 {
 	warnx(Error in units file '%s' line %d, UNITSFILE, linenum);
 }
 
 
-void 
+static void
 readunits(const char *userfile)
 {
 	FILE *unitfile;
@@ -221,15 +219,14 @@
 	fclose(unitfile);
 }
 
-void 
+static void
 initializeunit(struct unittype * theunit)
 {
 	theunit-factor = 1.0;
 	theunit-numerator[0] = theunit-denominator[0] = NULL;
 }
 
-
-int 
+static int
 addsubunit(const char *product[], const char *toadd)
 {
 	const char **ptr;
@@ -245,8 +242,7 @@
 	return 0;
 }
 
-
-void 
+static void
 showunit(struct unittype * theunit)
 {
 	const char **ptr;
@@ -291,8 +287,7 @@
 	printf(\n);
 }
 
-
-void 
+static void
 zeroerror()
 {
 	warnx(Unit reduces to zero);
@@ -305,7 +300,7 @@
Returns 0 for successful addition, nonzero on error.
 */
 
-int 
+static int
 addunit(struct unittype * theunit, const char *toadd, int flip)
 {
 	char *scratch, *savescr;
@@ -389,16 +384,14 @@
 	return 0;
 }
 
-
-int 
+static int
 compare(const void *item1, const void *item2)
 {
 	return strcmp(*(const char * const *) item1,
 		  *(const char * const *) item2);
 }
 
-
-void 
+static void
 sortunit(struct unittype * theunit)
 {
 	const char **ptr;
@@ -410,8 +403,7 @@
 	qsort(theunit-denominator, count, sizeof(char *), compare);
 }
 
-
-void 
+static void
 cancelunit(struct unittype * theunit)
 {
 	const char **den, **num;
@@ -447,7 +439,7 @@
 static char buffer[100];	/* buffer for lookupunit answers with
    prefixes */
 
-const char *
+static const char *
 lookupunit(const char *unit)
 {
 	int i;
@@ -522,7 +514,7 @@
 
 #define ERROR 4
 
-int 
+static int
 reduceproduct(struct unittype * theunit, int flip)
 {
 
@@ -565,7 +557,7 @@
Returns 0 on success, or 1 on unknown 

CVS commit: src/usr.bin/units

2011-04-03 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Apr  3 19:25:05 UTC 2011

Modified Files:
src/usr.bin/units: units.1

Log Message:
remove stray extra word


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/units/units.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.1
diff -u src/usr.bin/units/units.1:1.15 src/usr.bin/units/units.1:1.16
--- src/usr.bin/units/units.1:1.15	Mon Mar 28 16:09:10 2011
+++ src/usr.bin/units/units.1	Sun Apr  3 19:25:05 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: units.1,v 1.15 2011/03/28 16:09:10 fair Exp $
+.\	$NetBSD: units.1,v 1.16 2011/04/03 19:25:05 dholland Exp $
 .Dd March 28, 2011
 .Dt UNITS 1
 .Os
@@ -181,5 +181,5 @@
 it doesn't take so long to load the units list and check
 for duplication.
 .Pp
-The program should warn users when they're trying to do perform a conversion
+The program should warn users when they're trying to perform a conversion
 that doesn't make sense, since there are many such combinations.



CVS commit: src/usr.bin/units

2011-04-03 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Apr  3 19:44:15 UTC 2011

Modified Files:
src/usr.bin/units: units.1

Log Message:
Expand user warning (adding examples) and move to CAVEATS as it's not fixable.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/units/units.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.1
diff -u src/usr.bin/units/units.1:1.16 src/usr.bin/units/units.1:1.17
--- src/usr.bin/units/units.1:1.16	Sun Apr  3 19:25:05 2011
+++ src/usr.bin/units/units.1	Sun Apr  3 19:44:15 2011
@@ -1,5 +1,5 @@
-.\	$NetBSD: units.1,v 1.16 2011/04/03 19:25:05 dholland Exp $
-.Dd March 28, 2011
+.\	$NetBSD: units.1,v 1.17 2011/04/03 19:44:15 dholland Exp $
+.Dd April 3, 2011
 .Dt UNITS 1
 .Os
 .Sh NAME
@@ -159,6 +159,32 @@
 .An Adrian Mariano Aq adr...@cam.cornell.edu
 or
 .Aq mari...@geom.umn.edu
+.Sh CAVEATS
+While
+.Nm
+can be used as a calculator for many unit-related computations,
+caution is required: many computations require additional constant
+factors deriving from the physics (or chemistry or whatever) of the
+situation.
+As these factors are dimensionless,
+.Nm
+cannot itself either provide them or warn the user when they have been
+forgotten.
+For example, one joule is one kilogram meter squared per second
+squared, by definition; however, the kinetic energy of a one-kilogram
+object moving at one meter per second is half a joule, not one joule,
+because of a dimensionless factor that arises from integration.
+.Pp
+Also, some pairs of units that have the same dimensionality are
+nonetheless used to measure different things and attempting to convert
+between them may require additional fudge factors or be entirely
+meaningless.
+For example, torque and energy have the same dimensionality, but
+attempting to convert torque in newton-meters to energy in joules is
+nonsensical.
+There is no practical way for
+.Nm
+to warn about these issues either.
 .Sh BUGS
 The effect of including a
 .Sq \/
@@ -180,6 +206,3 @@
 The program should use a hash table to store units so that
 it doesn't take so long to load the units list and check
 for duplication.
-.Pp
-The program should warn users when they're trying to perform a conversion
-that doesn't make sense, since there are many such combinations.



CVS commit: src/usr.bin/units

2011-03-28 Thread Erik E. Fair
Module Name:src
Committed By:   fair
Date:   Mon Mar 28 16:09:10 UTC 2011

Modified Files:
src/usr.bin/units: units.1

Log Message:
Add dholland's comment about units not warning users about non-sensical
conversions to the BUGS section.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/units/units.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.1
diff -u src/usr.bin/units/units.1:1.14 src/usr.bin/units/units.1:1.15
--- src/usr.bin/units/units.1:1.14	Mon Mar 28 00:14:51 2011
+++ src/usr.bin/units/units.1	Mon Mar 28 16:09:10 2011
@@ -1,5 +1,5 @@
-.\	$NetBSD: units.1,v 1.14 2011/03/28 00:14:51 dholland Exp $
-.Dd December 18, 2001
+.\	$NetBSD: units.1,v 1.15 2011/03/28 16:09:10 fair Exp $
+.Dd March 28, 2011
 .Dt UNITS 1
 .Os
 .Sh NAME
@@ -180,3 +180,6 @@
 The program should use a hash table to store units so that
 it doesn't take so long to load the units list and check
 for duplication.
+.Pp
+The program should warn users when they're trying to do perform a conversion
+that doesn't make sense, since there are many such combinations.



CVS commit: src/usr.bin/units

2011-03-27 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Mar 28 00:08:47 UTC 2011

Modified Files:
src/usr.bin/units: units.lib

Log Message:
Update radioactivity-related units from http://physics.nist.gov/cuu/Units/.
The prior definition of sievert was, as far as I can tell, entirely wrong.

Caution: while gray and sievert have the same dimensionality,
they're not interchangeable -- you need to multiply by a fudge factor
that varies depending on the type of radiation and the tissue it's
affecting. (Dimensional analysis is often not a substitute for knowing
what you're doing.)

It would be nice if units had a way to warn users when they're trying
to do something that doesn't make sense, since there are lots of ways
to do so, but it doesn't, and it wouldn't be easy to arrange in the
general case.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/units/units.lib

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.lib
diff -u src/usr.bin/units/units.lib:1.14 src/usr.bin/units/units.lib:1.15
--- src/usr.bin/units/units.lib:1.14	Thu Feb 15 22:37:27 2007
+++ src/usr.bin/units/units.lib	Mon Mar 28 00:08:47 2011
@@ -1,4 +1,4 @@
-/	$NetBSD: units.lib,v 1.14 2007/02/15 22:37:27 dogcow Exp $
+/	$NetBSD: units.lib,v 1.15 2011/03/28 00:08:47 dholland Exp $
 
 / primitive units
 
@@ -378,6 +378,7 @@
 btu			britishthermalunit
 refrigeration		12000 btu/ton-hour
 buck			dollar
+Ci			curie
 cable			720 ft
 caliber			1e-2 in
 calorie			cal
@@ -430,6 +431,7 @@
 franklin		3.33564e-10 coul
 frigorie		kilocal
 furlong			220 yd
+Gy			gray
 galileo			1e-2 m/sec2
 gamma			1e-9 weber/m2
 gauss			1e-4 weber/m2
@@ -437,6 +439,7 @@
 geographicalmile	1852 m
 gilbert			7.95775e-1 amp
 gill			1|4 pt
+gray			joule/kg
 gross			144
 gunterschain		22 yd
 hand			4 in
@@ -518,17 +521,21 @@
 quartersection		1|4 mi2
 quintal			100 kg
 quire			25
+R			roentgen
 rackunit		1.75 in
 rad			100 erg/gm
 ream			500
 registerton		100 ft3
+rem			1e-2 sievert
 rhe			10 m2/nt-sec
-rontgen			2.58e-4 curie/kg
+roentgen		2.58e-4 coulomb/kg
+rontgen			roentgen
 rood			1.21e+3 yd
 rope			20 ft
 RU			rackunit
 rutherford		1e+6 /sec
 rydberg			1.36054e+1 ev
+Sv			sievert
 sabin			1 ft2
 sack			3 bu
 score			20
@@ -539,6 +546,7 @@
 shorthundredweight	100 lb
 shortquarter		25 lb
 siemens			/ohm
+sievert			joule/kg
 sigma			microsec
 skein			120 yd
 skot			1e-3 apostilb
@@ -627,7 +635,6 @@
 frenchfoot		16|15 ft
 frenchfeet		frenchfoot
 toise			6 frenchfeet
-sievert			8.4 rontgen
 candle			1.02 candela
 militarypace		2.5 feet
 metre			meter



CVS commit: src/usr.bin/units

2011-03-27 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon Mar 28 00:14:51 UTC 2011

Modified Files:
src/usr.bin/units: units.1

Log Message:
fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/units/units.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.1
diff -u src/usr.bin/units/units.1:1.13 src/usr.bin/units/units.1:1.14
--- src/usr.bin/units/units.1:1.13	Sun Sep 11 23:28:55 2005
+++ src/usr.bin/units/units.1	Mon Mar 28 00:14:51 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: units.1,v 1.13 2005/09/11 23:28:55 wiz Exp $
+.\	$NetBSD: units.1,v 1.14 2011/03/28 00:14:51 dholland Exp $
 .Dd December 18, 2001
 .Dt UNITS 1
 .Os
@@ -148,7 +148,7 @@
 will not detect infinite loops that could be caused
 by careless unit definitions.
 .Pp
-Prefixes are defined in the same was as standard units, but with
+Prefixes are defined in the same way as standard units, but with
 a trailing dash at the end of the prefix name.
 .Sh FILES
 .Bl -tag -width /usr/share/misc/units.lib -compact



CVS commit: src/usr.bin/units

2009-04-13 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Tue Apr 14 05:55:12 UTC 2009

Modified Files:
src/usr.bin/units: units.c

Log Message:
Appease -Wcast-qual with a liberal sprinkling of const.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/units/units.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/units/units.c
diff -u src/usr.bin/units/units.c:1.15 src/usr.bin/units/units.c:1.16
--- src/usr.bin/units/units.c:1.15	Mon May  1 00:00:12 2006
+++ src/usr.bin/units/units.c	Tue Apr 14 05:55:12 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: units.c,v 1.15 2006/05/01 00:00:12 christos Exp $	*/
+/*	$NetBSD: units.c,v 1.16 2009/04/14 05:55:12 lukem Exp $	*/
 
 /*
  * units.c   Copyright (c) 1993 by Adrian Mariano (adr...@cam.cornell.edu)
@@ -39,43 +39,43 @@
 
 #define PRIMITIVECHAR '!'
 
-char *powerstring = ^;
+const char *powerstring = ^;
 
 struct {
-	char *uname;
-	char *uval;
+	const char *uname;
+	const char *uval;
 }  unittable[MAXUNITS];
 
 struct unittype {
-	char *numerator[MAXSUBUNITS];
-	char *denominator[MAXSUBUNITS];
+	const char *numerator[MAXSUBUNITS];
+	const char *denominator[MAXSUBUNITS];
 	double factor;
 };
 
 struct {
-	char *prefixname;
-	char *prefixval;
+	const char *prefixname;
+	const char *prefixval;
 }  prefixtable[MAXPREFIXES];
 
 
-char *NULLUNIT = ;
+const char *NULLUNIT = ;
 
 int unitcount;
 int prefixcount;
 
 
-int	addsubunit __P((char *[], char *));
-int	addunit __P((struct unittype *, char *, int));
+int	addsubunit __P((const char *[], const char *));
+int	addunit __P((struct unittype *, const char *, int));
 void	cancelunit __P((struct unittype *));
 int	compare __P((const void *, const void *));
-int	compareproducts __P((char **, char **));
+int	compareproducts __P((const char **, const char **));
 int	compareunits __P((struct unittype *, struct unittype *));
 int	compareunitsreciprocal __P((struct unittype *, struct unittype *));
 int	completereduce __P((struct unittype *));
 void	initializeunit __P((struct unittype *));
 int	main __P((int, char **));
 void	readerror __P((int));
-void	readunits __P((char *));
+void	readunits __P((const char *));
 int	reduceproduct __P((struct unittype *, int));
 int	reduceunit __P((struct unittype *));
 void	showanswer __P((struct unittype *, struct unittype *));
@@ -83,12 +83,12 @@
 void	sortunit __P((struct unittype *));
 void	usage __P((void));
 void	zeroerror __P((void));
-char   *dupstr __P((char *));
-char   *lookupunit __P((char *));
+char   *dupstr __P((const char *));
+const char *lookupunit __P((const char *));
 
 
 char *
-dupstr(char *str)
+dupstr(const char *str)
 {
 	char *ret;
 
@@ -107,7 +107,7 @@
 
 
 void 
-readunits(char *userfile)
+readunits(const char *userfile)
 {
 	FILE *unitfile;
 	char line[80], *lineptr;
@@ -230,9 +230,9 @@
 
 
 int 
-addsubunit(char *product[], char *toadd)
+addsubunit(const char *product[], const char *toadd)
 {
-	char **ptr;
+	const char **ptr;
 
 	for (ptr = product; *ptr  *ptr != NULLUNIT; ptr++);
 	if (ptr = product + MAXSUBUNITS) {
@@ -249,7 +249,7 @@
 void 
 showunit(struct unittype * theunit)
 {
-	char **ptr;
+	const char **ptr;
 	int printedslash;
 	int counter = 1;
 
@@ -306,7 +306,7 @@
 */
 
 int 
-addunit(struct unittype * theunit, char *toadd, int flip)
+addunit(struct unittype * theunit, const char *toadd, int flip)
 {
 	char *scratch, *savescr;
 	char *item;
@@ -393,14 +393,15 @@
 int 
 compare(const void *item1, const void *item2)
 {
-	return strcmp(*(char **) item1, *(char **) item2);
+	return strcmp(*(const char * const *) item1,
+		  *(const char * const *) item2);
 }
 
 
 void 
 sortunit(struct unittype * theunit)
 {
-	char **ptr;
+	const char **ptr;
 	int count;
 
 	for (count = 0, ptr = theunit-numerator; *ptr; ptr++, count++);
@@ -413,7 +414,7 @@
 void 
 cancelunit(struct unittype * theunit)
 {
-	char **den, **num;
+	const char **den, **num;
 	int comp;
 
 	den = theunit-denominator;
@@ -446,8 +447,8 @@
 static char buffer[100];	/* buffer for lookupunit answers with
    prefixes */
 
-char *
-lookupunit(char *unit)
+const char *
+lookupunit(const char *unit)
 {
 	int i;
 	char *copy;
@@ -525,8 +526,8 @@
 reduceproduct(struct unittype * theunit, int flip)
 {
 
-	char *toadd;
-	char **product;
+	const char *toadd;
+	const char **product;
 	int didsomething = 2;
 
 	if (flip)
@@ -548,7 +549,7 @@
 break;
 			didsomething = 1;
 			if (*product != NULLUNIT) {
-free(*product);
+free(__UNCONST(*product));
 *product = NULLUNIT;
 			}
 			if (addunit(theunit, toadd, flip))
@@ -580,7 +581,7 @@
 
 
 int 
-compareproducts(char **one, char **two)
+compareproducts(const char **one, const char **two)
 {
 	while (*one || *two) {
 		if (!*one  *two != NULLUNIT)
@@ -669,7 +670,7 @@
 	struct unittype have, want;
 	char havestr[81], wantstr[81];
 	int optchar;
-	char *userfile = 0;
+	const char *userfile = 0;
 	int quiet = 0;