summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorKris Kennaway <kris@FreeBSD.org>2001-03-04 09:22:35 +0000
committerKris Kennaway <kris@FreeBSD.org>2001-03-04 09:22:35 +0000
commit5e5e98b9d02a0683354fbbbc7bc61aa15b63a8f3 (patch)
treeebdce5197179305ea2011861e09d3e72f577e575 /usr.bin
parent409b03ece390f707d3664c6dcfd97ee31b9950ec (diff)
downloadsrc-test2-5e5e98b9d02a0683354fbbbc7bc61aa15b63a8f3.tar.gz
src-test2-5e5e98b9d02a0683354fbbbc7bc61aa15b63a8f3.zip
Notes
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/units/units.14
-rw-r--r--usr.bin/units/units.c58
-rw-r--r--usr.bin/units/units.lib29
3 files changed, 46 insertions, 45 deletions
diff --git a/usr.bin/units/units.1 b/usr.bin/units/units.1
index 52982c8dbc25..b648ecab87a8 100644
--- a/usr.bin/units/units.1
+++ b/usr.bin/units/units.1
@@ -32,7 +32,7 @@ program converts quantities expressed in various scales to
their equivalents in other scales. The
.Nm
program can only
-handle multiplicative scale changes. It cannot convert Centigrade
+handle multiplicative scale changes. It cannot convert Celsius
to Fahrenheit, for example. It works interactively by prompting
the user for input:
.Bd -literal
@@ -94,7 +94,7 @@ metric prefixes. Some constants of nature included are:
.El
.Pp
The unit 'pound' is a unit of mass. Compound names are run together
-so 'poundforce' is a unit of force. The unit 'ounce' is also a unit
+so 'pound force' is a unit of force. The unit 'ounce' is also a unit
of mass. The fluid ounce is 'floz'. British units that differ from
their US counterparts are prefixed with 'br', and currency is prefixed
with its country name: 'belgiumfranc', 'britainpound'. When searching
diff --git a/usr.bin/units/units.c b/usr.bin/units/units.c
index c0ba09a330dc..603de30525c5 100644
--- a/usr.bin/units/units.c
+++ b/usr.bin/units/units.c
@@ -36,13 +36,13 @@ static const char rcsid[] =
#endif
#define MAXUNITS 1000
-#define MAXPREFIXES 50
+#define MAXPREFIXES 100
#define MAXSUBUNITS 500
#define PRIMITIVECHAR '!'
-char *powerstring = "^";
+const char *powerstring = "^";
struct {
char *uname;
@@ -61,10 +61,10 @@ struct {
} prefixtable[MAXPREFIXES];
-char *NULLUNIT = "";
+char NULLUNIT[] = "";
#ifdef MSDOS
-#define SEPERATOR ";"
+#define SEPARATOR ";"
#else
#define SEPARATOR ":"
#endif
@@ -74,7 +74,7 @@ int prefixcount;
char *
-dupstr(char *str)
+dupstr(const char *str)
{
char *ret;
@@ -87,17 +87,10 @@ dupstr(char *str)
void
-readerror(int linenum)
-{
- warnx("error in units file '%s' line %d", UNITSFILE, linenum);
-}
-
-
-void
-readunits(char *userfile)
+readunits(const char *userfile)
{
FILE *unitfile;
- char line[80], *lineptr;
+ char line[512], *lineptr;
int len, linenum, i;
unitcount = 0;
@@ -131,7 +124,7 @@ readunits(char *userfile)
}
}
while (!feof(unitfile)) {
- if (!fgets(line, 79, unitfile))
+ if (!fgets(line, sizeof(line), unitfile))
break;
linenum++;
lineptr = line;
@@ -156,12 +149,13 @@ readunits(char *userfile)
continue;
}
lineptr += len + 1;
- if (!strlen(lineptr)) {
- readerror(linenum);
- continue;
- }
lineptr += strspn(lineptr, " \n\t");
len = strcspn(lineptr, "\n\t");
+ if (len == 0) {
+ warnx("unexpected end of prefix on line %d",
+ linenum);
+ continue;
+ }
lineptr[len] = 0;
prefixtable[prefixcount++].prefixval = dupstr(lineptr);
}
@@ -180,7 +174,8 @@ readunits(char *userfile)
lineptr += len + 1;
lineptr += strspn(lineptr, " \n\t");
if (!strlen(lineptr)) {
- readerror(linenum);
+ warnx("unexpected end of unit on line %d",
+ linenum);
continue;
}
len = strcspn(lineptr, "\n\t");
@@ -263,7 +258,7 @@ showunit(struct unittype * theunit)
void
-zeroerror()
+zeroerror(void)
{
warnx("unit reduces to zero");
}
@@ -366,7 +361,7 @@ addunit(struct unittype * theunit, char *toadd, int flip)
int
compare(const void *item1, const void *item2)
{
- return strcmp(*(char **) item1, *(char **) item2);
+ return strcmp(*(const char **) item1, *(const char **) item2);
}
@@ -374,7 +369,7 @@ void
sortunit(struct unittype * theunit)
{
char **ptr;
- int count;
+ unsigned int count;
for (count = 0, ptr = theunit->numerator; *ptr; ptr++, count++);
qsort(theunit->numerator, count, sizeof(char *), compare);
@@ -420,7 +415,7 @@ static char buffer[100]; /* buffer for lookupunit answers with
prefixes */
char *
-lookupunit(char *unit)
+lookupunit(const char *unit)
{
int i;
char *copy;
@@ -465,12 +460,11 @@ lookupunit(char *unit)
free(copy);
}
for (i = 0; i < prefixcount; i++) {
- if (!strncmp(prefixtable[i].prefixname, unit,
- strlen(prefixtable[i].prefixname))) {
- unit += strlen(prefixtable[i].prefixname);
- if (!strlen(unit) || lookupunit(unit)) {
+ size_t len = strlen(prefixtable[i].prefixname);
+ if (!strncmp(prefixtable[i].prefixname, unit, len)) {
+ if (!strlen(unit + len) || lookupunit(unit + len)) {
snprintf(buffer, sizeof(buffer), "%s %s",
- prefixtable[i].prefixval, unit);
+ prefixtable[i].prefixval, unit + len);
return buffer;
}
}
@@ -608,7 +602,7 @@ showanswer(struct unittype * have, struct unittype * want)
void
-usage()
+usage(void)
{
fprintf(stderr,
"usage: units [-f unitsfile] [-q] [-v] [from-unit to-unit]\n");
@@ -670,7 +664,7 @@ main(int argc, char **argv)
initializeunit(&have);
if (!quiet)
printf("You have: ");
- if (!fgets(havestr, 80, stdin)) {
+ if (!fgets(havestr, sizeof(havestr), stdin)) {
if (!quiet)
putchar('\n');
exit(0);
@@ -681,7 +675,7 @@ main(int argc, char **argv)
initializeunit(&want);
if (!quiet)
printf("You want: ");
- if (!fgets(wantstr, 80, stdin)) {
+ if (!fgets(wantstr, sizeof(wantstr), stdin)) {
if (!quiet)
putchar('\n');
exit(0);
diff --git a/usr.bin/units/units.lib b/usr.bin/units/units.lib
index 2e62cae7695d..b4624f41e927 100644
--- a/usr.bin/units/units.lib
+++ b/usr.bin/units/units.lib
@@ -52,12 +52,28 @@ da- deka
d- deci
c- centi
m- milli
+n- nano
p- pico
f- femto
a- atto
z- zopto
y- yocto
+/ binary prefixes introduced in 1999
+exbi- 1152921504606846976
+pebi- 1125899906842624
+tebi- 1099511627776
+gibi- 1073741824
+mebi- 1048576
+kibi- 1024
+
+Ei- exbi
+Pi- pebi
+Ti- tebi
+Gi- gibi
+Mi- mebi
+Ki- kibi
+
/ constants
fuzz 1
@@ -104,14 +120,12 @@ week 7 day
year 365.24219879 day fuzz
yr year
month 1|12 year
-ms millisec
us microsec
/ Mass
gram millikg
gm gram
-mg milligram
metricton kilokg
/ Avoirdupois
@@ -140,10 +154,6 @@ troypound appound
/ Length
meter m
-cm centimeter
-mm millimeter
-km kilometer
-nm nanometer
micron micrometer
angstrom decinanometer
@@ -180,6 +190,7 @@ pt pint
floz 1|16 pt
fldr 1|8 floz
+shot 3|2 floz
/ US Dry
@@ -428,9 +439,6 @@ hz /sec
imaginarycubicfoot 1.4 ft3
jeroboam 4|5 gal
karat 1|24
-kcal kilocal
-kcalorie kilocal
-kev 1e+3 e-volt
key kg
khz 1e+3 /sec
kilderkin 18 gal
@@ -454,7 +462,7 @@ mgd megagal/day
mh millihenry
mhz 1e+6 /sec
mil 1e-3 in
-millenium 1000 year
+millennium 1000 year
minersinch 1.5 ft3/min
minim 1|60 fldr
mo month
@@ -465,7 +473,6 @@ nauticalmile nmile
nit cd/m2
noggin 1|8 qt
nox 1e-3 lux
-ns nanosec
oersted 2.5e+2 pi-amp/m
oe oersted
pace 36 in