Pádraig Brady <[email protected]> writes:

> +/* Print the program names separated by SEP, wrapping at 80 columns for ' '. 
>  */
> +static void
> +list_programs (char sep)
> +{
> +  static char const names[] =
> +#ifdef SINGLE_BINARY
> +# define SINGLE_BINARY_PROGRAM(prog_name_str, main_name) prog_name_str "\0"
> +# include "coreutils.h"
> +# undef SINGLE_BINARY_PROGRAM
> +#endif
> +    "";
> +
> +  size_t width = 0;
> +  for (char const *p = names; *p; )
> +    {
> +      size_t len = strlen (p);
> +      if (sep == ' ' && 80 < width + 1 + len)
> +        {
> +          putchar ('\n');
> +          width = 0;
> +        }
> +      if (sep == ' ' || p != names)
> +        putchar (sep);
> +      fputs (p, stdout);
> +      width += len + 1;
> +      p += len + 1;
> +    }
> +  if (*names)
> +    putchar ('\n');
> +}

Did you consider just generating the wrapped list in ./configure or
something like that and placing it in a generated header or something?

FWIW, I probably would have done that since it seems easier than making
sure the wrapping implementation is correct. Perhaps my laziness is
speaking.

Collin

Reply via email to