On 2022/12/24 11:56:37 +0100, Florian Obser <flor...@openbsd.org> wrote:
> This is at least supported by FreeBSD's units(1) as well as by
> systemd/Linux.
> 
> [...]
> 
> OK?

it's really handy, ok for me!  (with s/options/option as mentioned by
Crystal Kolipe.)

the -f '' seems a bit weird to be fair, but it's also possible to do
-f /usr/share/misc/units.lib now at least :)

> 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");

Reply via email to