exception.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include <command.h>
  8. static int do_exception(struct cmd_tbl *cmdtp, int flag, int argc,
  9. char *const argv[])
  10. {
  11. struct cmd_tbl *cp;
  12. if (argc != 2)
  13. return CMD_RET_USAGE;
  14. /* drop sub-command parameter */
  15. argc--;
  16. argv++;
  17. cp = find_cmd_tbl(argv[0], cmd_sub, ARRAY_SIZE(cmd_sub));
  18. if (cp)
  19. return cp->cmd(cmdtp, flag, argc, argv);
  20. return CMD_RET_USAGE;
  21. }
  22. static int exception_complete(int argc, char *const argv[], char last_char,
  23. int maxv, char *cmdv[])
  24. {
  25. int len = 0;
  26. int i = 0;
  27. struct cmd_tbl *cmdtp;
  28. switch (argc) {
  29. case 1:
  30. break;
  31. case 2:
  32. len = strlen(argv[1]);
  33. break;
  34. default:
  35. return 0;
  36. }
  37. for (cmdtp = cmd_sub; cmdtp != cmd_sub + ARRAY_SIZE(cmd_sub); cmdtp++) {
  38. if (i >= maxv - 1)
  39. return i;
  40. if (!strncmp(argv[1], cmdtp->name, len))
  41. cmdv[i++] = cmdtp->name;
  42. }
  43. cmdv[i] = NULL;
  44. return i;
  45. }
  46. U_BOOT_CMD_COMPLETE(
  47. exception, 2, 0, do_exception,
  48. "Forces an exception to occur",
  49. exception_help_text, exception_complete
  50. );