units(1): Add U option

For increased compatibility with GNU units: support a -U option which tests for the
existence of the default units file and prints it to the screen.
This commit is contained in:
Eitan Adler 2014-04-14 16:55:09 +00:00
parent 3af082017a
commit 114022f58e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=264463
2 changed files with 16 additions and 4 deletions

View File

@ -1,5 +1,5 @@
.\" $FreeBSD$
.Dd July 14, 1993
.Dd April 14, 2014
.Dt UNITS 1
.Os
.Sh NAME
@ -8,7 +8,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl f Ar filename
.Op Fl qV
.Op Fl qUV
.Op Ar from-unit to-unit
.Sh OPTIONS
The following options are available:
@ -18,6 +18,11 @@ Specify the name of the units data file to load.
.It Fl q
Suppress prompting of the user for units and the display of statistics
about the number of units loaded.
.It Fl U
If the default unit file exists prints its location. If not, print
.Qo
Units data file not found
.Qc
.It Fl V
Print the version number, usage, and then exit.
.It Ar from-unit to-unit

View File

@ -678,7 +678,7 @@ void
usage(void)
{
fprintf(stderr,
"usage: units [-f unitsfile] [-q] [-v] [from-unit to-unit]\n");
"usage: units [-f unitsfile] [-UVq] [from-unit to-unit]\n");
exit(3);
}
@ -700,7 +700,7 @@ main(int argc, char **argv)
quiet = false;
readfile = false;
while ((optchar = getopt(argc, argv, "Vqf:")) != -1) {
while ((optchar = getopt(argc, argv, "UVqf:")) != -1) {
switch (optchar) {
case 'f':
readfile = true;
@ -712,6 +712,13 @@ main(int argc, char **argv)
case 'q':
quiet = true;
break;
case 'U':
if (access(UNITSFILE, F_OK) == 0)
printf("%s\n", UNITSFILE);
else
printf("Units data file not found");
exit(0);
break;
case 'V':
fprintf(stderr, "FreeBSD units\n");
usage();