]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ti-u-boot/ti-u-boot.git/blob - include/exception.h
Prepare v2024.04
[ti-u-boot/ti-u-boot.git] / include / exception.h
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  */
8 #include <command.h>
10 static int do_exception(struct cmd_tbl *cmdtp, int flag, int argc,
11                         char *const argv[])
12 {
13         struct cmd_tbl *cp;
15         if (argc != 2)
16                 return CMD_RET_USAGE;
18         /* drop sub-command parameter */
19         argc--;
20         argv++;
22         cp = find_cmd_tbl(argv[0], cmd_sub, ARRAY_SIZE(cmd_sub));
24         if (cp)
25                 return cp->cmd(cmdtp, flag, argc, argv);
27         return CMD_RET_USAGE;
28 }
30 static int exception_complete(int argc, char *const argv[], char last_char,
31                               int maxv, char *cmdv[])
32 {
33         int len = 0;
34         int i = 0;
35         struct cmd_tbl *cmdtp;
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 }
56 U_BOOT_CMD_COMPLETE(
57         exception, 2, 0, do_exception,
58         "Forces an exception to occur",
59         exception_help_text, exception_complete
60 );