Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 1 | /* 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 Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 8 | #include <command.h> |
| 9 | |
| 10 | static int do_exception(struct cmd_tbl *cmdtp, int flag, int argc, |
| 11 | char *const argv[]) |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 12 | { |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 13 | struct cmd_tbl *cp; |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 14 | |
| 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 Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 30 | static int exception_complete(int argc, char *const argv[], char last_char, |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 31 | int maxv, char *cmdv[]) |
| 32 | { |
| 33 | int len = 0; |
| 34 | int i = 0; |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 35 | struct cmd_tbl *cmdtp; |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 36 | |
| 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 | |
| 56 | U_BOOT_CMD_COMPLETE( |
| 57 | exception, 2, 0, do_exception, |
| 58 | "Forces an exception to occur", |
| 59 | exception_help_text, exception_complete |
| 60 | ); |