aboutsummaryrefslogtreecommitdiffstats
path: root/cmdline_other.c
blob: 167bc84a0dbba07f01af0421fe34933811c2dc88 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* See LICENSE file for copyright and license details. */
#include "common.h"


static int
parseopt_algorithm(void *config_, char *opt, char *val)
{
	struct config *config = config_;
	if (val)
		return 0;
	config->algorithms = ereallocarray(config->algorithms, config->nalgorithms + 1U, sizeof(*config->algorithms));
	memset(&config->algorithms[config->nalgorithms], 0, sizeof(*config->algorithms));
	config->algorithms[config->nalgorithms].algostr = opt;
	config->algorithms[config->nalgorithms].result = NULL;
	config->nalgorithms++;
	return 1;
}


int
cmdline_other(int argc, char **argv, enum command command, struct config *config)
{
	char *arg;

	ARGBEGIN {
	case 'b': /* binary input (compat) */
	case 't': /* text input (compat) */
		config->hexinput = 0;
		break;

	case 'c':
		config->verify = 1;
		break;

	case 'w':
		config->warn_improper_format = 1;
		break;

	case 'z':
		config->format &= (enum format)~WITH_LF;
		config->format |= WITH_NUL;
		break;

	case 'W':
		arg = parseopts(config, ARG(), &parseopt_algorithm);
		if (*arg)
			eprintf("unsupported -W options: %s", arg);
		break;

	case 'a':
		if (command != ANYSUM || *parseopts(config, ARG(), &parseopt_algorithm))
			usage();
		break;

	default:
		usage();
	} ARGEND;

	return argc;
}