Pádraig Brady <[email protected]> writes:
> Following commit v9.9-109-gcd5229222
>
> * src/cksum.c (PROGRAM_NAME): In legacy mode, i.e., when built
> as a single binary, set the PROGRAM_NAME dynamically based on
> the selected digest type. This is significant in --help
> to ensure the correct texinfo node is referenced, and in
> --version to ensure the correct utility name is output.
> ---
> src/cksum.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/src/cksum.c b/src/cksum.c
> index 977394eea..bab319bdb 100644
> --- a/src/cksum.c
> +++ b/src/cksum.c
> @@ -77,7 +77,6 @@
> #elif HASH_ALGO_CKSUM
> # define MAX_DIGEST_BITS 512
> # define MAX_DIGEST_ALIGN 8
> -# define PROGRAM_NAME "cksum"
> # define DIGEST_TYPE_STRING algorithm_tags[cksum_algorithm]
> # define DIGEST_STREAM cksumfns[cksum_algorithm]
> # define DIGEST_OUT cksum_output_fns[cksum_algorithm]
> @@ -139,6 +138,17 @@
> # define DIGEST_OUT output_file
> #endif
>
> +#if HASH_ALGO_CKSUM
> +# define PROGRAM_NAME (!legacy_mode ? "cksum" \
> + : cksum_algorithm == md5 ? "md5sum" \
> + : cksum_algorithm == sha1 ? "sha1sum" \
> + : cksum_algorithm == sha224 ? "sha224sum" \
> + : cksum_algorithm == sha256 ? "sha256sum" \
> + : cksum_algorithm == sha384 ? "sha384sum" \
> + : cksum_algorithm == sha512 ? "sha512sum" \
> + : "cksum")
> +#endif
> +
> #if HASH_ALGO_SUM
> # define AUTHORS \
> proper_name ("Kayvan Aghaiepour"), \
Looks good to me. This command:
$ ./src/coreutils --coreutils-prog=cksum -a md5 --help -a md5
prints the help for 'cksum'. It wasn't obvious to me that it would until
I saw this code snippet:
#if HASH_ALGO_CKSUM
if (cksum_algorithm != crc)
{
legacy_mode = true;
prefix_tag = 0;
algorithm_specified = true;
long_opts = legacy_long_options;
}
#endif
Since md5sum, sha*sum, etc. will have their cksum_algorithm set
according to their name and legacy_mode is initialized to false. Might
be worth a comment to help new readers.
Collin