non-character as a pseudo short option, starting with CHAR_MAX + 1. */
enum
{
- STATUS_OPTION = CHAR_MAX + 1,
- STRING_OPTION
+ STATUS_OPTION = CHAR_MAX + 1
};
static const struct option long_options[] =
{ "binary", no_argument, 0, 'b' },
{ "check", no_argument, 0, 'c' },
{ "status", no_argument, 0, STATUS_OPTION },
- { "string", required_argument, 0, STRING_OPTION },
{ "text", no_argument, 0, 't' },
{ "warn", no_argument, 0, 'w' },
{ GETOPT_HELP_OPTION_DECL },
unsigned char bin_buffer[MAX_DIGEST_BIN_BYTES];
bool do_check = false;
int opt;
- char **string = NULL;
- size_t n_strings = 0;
bool ok = true;
bool file_type_specified = false;
while ((opt = getopt_long (argc, argv, "bctw", long_options, NULL)) != -1)
switch (opt)
{
- case STRING_OPTION:
- {
- if (string == NULL)
- string = xnmalloc (argc - 1, sizeof *string);
- string[n_strings++] = optarg;
- }
- break;
case 'b':
file_type_specified = true;
binary = true;
usage (EXIT_FAILURE);
}
- if (n_strings > 0 && do_check)
- {
- error (0, 0,
- _("the --string and --check options are mutually exclusive"));
- usage (EXIT_FAILURE);
- }
-
if (status_only & !do_check)
{
error (0, 0,
usage (EXIT_FAILURE);
}
- if (n_strings > 0)
- {
- size_t i;
-
- if (optind < argc)
- {
- error (0, 0, _("extra operand %s"), quote (argv[optind]));
- fprintf (stderr, "%s\n",
- _("File operands cannot be combined with --string."));
- usage (EXIT_FAILURE);
- }
- for (i = 0; i < n_strings; ++i)
- {
- size_t cnt;
- if (algorithm == ALG_MD5)
- md5_buffer (string[i], strlen (string[i]), bin_buffer);
- else
- sha1_buffer (string[i], strlen (string[i]), bin_buffer);
-
- for (cnt = 0; cnt < (digest_hex_bytes / 2); ++cnt)
- printf ("%02x", bin_buffer[cnt]);
-
- printf (" \"%s\"\n", string[i]);
- }
- }
- else if (do_check)
+ if (do_check)
{
if (optind + 1 < argc)
{