echo.c 920 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2000-2009
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. static int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  9. {
  10. int i;
  11. int putnl = 1;
  12. for (i = 1; i < argc; i++) {
  13. char *p = argv[i];
  14. char *nls; /* new-line suppression */
  15. if (i > 1)
  16. putc(' ');
  17. nls = strstr(p, "\\c");
  18. if (nls) {
  19. char *prenls = p;
  20. putnl = 0;
  21. /*
  22. * be paranoid and guess that someone might
  23. * say \c more than once
  24. */
  25. while (nls) {
  26. *nls = '\0';
  27. puts(prenls);
  28. *nls = '\\';
  29. prenls = nls + 2;
  30. nls = strstr(prenls, "\\c");
  31. }
  32. puts(prenls);
  33. } else {
  34. puts(p);
  35. }
  36. }
  37. if (putnl)
  38. putc('\n');
  39. return 0;
  40. }
  41. U_BOOT_CMD(
  42. echo, CONFIG_SYS_MAXARGS, 1, do_echo,
  43. "echo args to console",
  44. "[args..]\n"
  45. " - echo args to console; \\c suppresses newline"
  46. );