exception.h 1.1 KB

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