blob: a7f21e73d7530972eefb3255d799ed45de30c82f [file] [log] [blame]
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +01001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * The 'exception' command can be used for testing exception handling.
4 *
5 * Copyright (c) 2018, Heinrich Schuchardt <xypron.glpk@gmx.de>
6 */
7
Simon Glassed38aef2020-05-10 11:40:03 -06008#include <command.h>
9
10static int do_exception(struct cmd_tbl *cmdtp, int flag, int argc,
11 char *const argv[])
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010012{
Simon Glassed38aef2020-05-10 11:40:03 -060013 struct cmd_tbl *cp;
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010014
15 if (argc != 2)
16 return CMD_RET_USAGE;
17
18 /* drop sub-command parameter */
19 argc--;
20 argv++;
21
22 cp = find_cmd_tbl(argv[0], cmd_sub, ARRAY_SIZE(cmd_sub));
23
24 if (cp)
25 return cp->cmd(cmdtp, flag, argc, argv);
26
27 return CMD_RET_USAGE;
28}
29
Simon Glassed38aef2020-05-10 11:40:03 -060030static int exception_complete(int argc, char *const argv[], char last_char,
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010031 int maxv, char *cmdv[])
32{
33 int len = 0;
34 int i = 0;
Simon Glassed38aef2020-05-10 11:40:03 -060035 struct cmd_tbl *cmdtp;
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010036
37 switch (argc) {
38 case 1:
39 break;
40 case 2:
41 len = strlen(argv[1]);
42 break;
43 default:
44 return 0;
45 }
46 for (cmdtp = cmd_sub; cmdtp != cmd_sub + ARRAY_SIZE(cmd_sub); cmdtp++) {
47 if (i >= maxv - 1)
48 return i;
49 if (!strncmp(argv[1], cmdtp->name, len))
50 cmdv[i++] = cmdtp->name;
51 }
52 cmdv[i] = NULL;
53 return i;
54}
55
56U_BOOT_CMD_COMPLETE(
57 exception, 2, 0, do_exception,
58 "Forces an exception to occur",
59 exception_help_text, exception_complete
60);