aboutsummaryrefslogtreecommitdiff
path: root/include/exception.h
blob: fc0249022398b0c8837ae3d4d878df5de5e63f35 (plain)
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
/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * The 'exception' command can be used for testing exception handling.
 *
 * Copyright (c) 2018, Heinrich Schuchardt <xypron.glpk@gmx.de>
 */

static int do_exception(cmd_tbl_t *cmdtp, int flag, int argc,
			char * const argv[])
{
	cmd_tbl_t *cp;

	if (argc != 2)
		return CMD_RET_USAGE;

	/* drop sub-command parameter */
	argc--;
	argv++;

	cp = find_cmd_tbl(argv[0], cmd_sub, ARRAY_SIZE(cmd_sub));

	if (cp)
		return cp->cmd(cmdtp, flag, argc, argv);

	return CMD_RET_USAGE;
}

static int exception_complete(int argc, char * const argv[], char last_char,
			      int maxv, char *cmdv[])
{
	int len = 0;
	int i = 0;
	cmd_tbl_t *cmdtp;

	switch (argc) {
	case 1:
		break;
	case 2:
		len = strlen(argv[1]);
		break;
	default:
		return 0;
	}
	for (cmdtp = cmd_sub; cmdtp != cmd_sub + ARRAY_SIZE(cmd_sub); cmdtp++) {
		if (i >= maxv - 1)
			return i;
		if (!strncmp(argv[1], cmdtp->name, len))
			cmdv[i++] = cmdtp->name;
	}
	cmdv[i] = NULL;
	return i;
}

U_BOOT_CMD_COMPLETE(
	exception, 2, 0, do_exception,
	"Forces an exception to occur",
	exception_help_text, exception_complete
);