This is at least supported by FreeBSD's units(1) as well as by systemd/Linux.
With a personal library like this: $ cat ~/units.lib assload 8 stone butt 2 hogshead buttload 6 seams solarmass 1.98847e30 kg I can convert my mass into more convenient units: $ units -f '' -f ~/units.lib 622 units, 67 prefixes You have: 93 kg You want: assloads * 1.8306241 / 0.54626178 You have: 93 kg You want: solarmasses * 4.6769627e-29 / 2.1381398e+28 Note that the imperial buttload is a unit of volume while the assload is a unit of mass: You have: buttload You want: assload conformability error 1.6914754 m^3 50.802345 kg On the other hand, you need about 4^28 standard donkeys to lug the sun around: You have: solarmass You want: assload * 3.9141303e+28 / 2.554846e-29 OK? diff --git units.1 units.1 index d7a45f729b3..916d1b03d32 100644 --- units.1 +++ units.1 @@ -79,6 +79,11 @@ The options are as follows: .Bl -tag -width Ds .It Fl f Ar filename Specifies the name of the units data file to load. +This options may be specified multiple times. +The standard units library is read if +.Ar filename +is the empty string. +This allows extending the standard units library with a personal library. .It Fl q Suppresses prompting of the user for units and the display of statistics about the number of units loaded. diff --git units.c units.c index 98af5031fb1..488795c78cb 100644 --- units.c +++ units.c @@ -100,7 +100,6 @@ readunits(char *userfile) int len, linenum, i; FILE *unitfile; - unitcount = 0; linenum = 0; if (userfile) { @@ -626,8 +625,7 @@ main(int argc, char **argv) struct unittype have, want; char havestr[81], wantstr[81]; int optchar; - char *userfile = 0; - int quiet = 0; + int quiet = 0, units_read = 0; extern char *optarg; extern int optind; @@ -638,7 +636,8 @@ main(int argc, char **argv) while ((optchar = getopt(argc, argv, "vqf:")) != -1) { switch (optchar) { case 'f': - userfile = optarg; + units_read = 1; + readunits(*optarg == '\0' ? NULL : optarg); break; case 'q': quiet = 1; @@ -662,7 +661,8 @@ main(int argc, char **argv) if (argc != 3 && argc != 2 && argc != 0) usage(); - readunits(userfile); + if (!units_read) + readunits(NULL); if (pledge("stdio", NULL) == -1) err(1, "pledge"); -- I'm not entirely sure you are real.