echo.c 929 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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(struct cmd_tbl *cmdtp, int flag, int argc,
  9. char *const argv[])
  10. {
  11. int i;
  12. int putnl = 1;
  13. for (i = 1; i < argc; i++) {
  14. char *p = argv[i];
  15. char *nls; /* new-line suppression */
  16. if (i > 1)
  17. putc(' ');
  18. nls = strstr(p, "\\c");
  19. if (nls) {
  20. char *prenls = p;
  21. putnl = 0;
  22. /*
  23. * be paranoid and guess that someone might
  24. * say \c more than once
  25. */
  26. while (nls) {
  27. *nls = '\0';
  28. puts(prenls);
  29. *nls = '\\';
  30. prenls = nls + 2;
  31. nls = strstr(prenls, "\\c");
  32. }
  33. puts(prenls);
  34. } else {
  35. puts(p);
  36. }
  37. }
  38. if (putnl)
  39. putc('\n');
  40. return 0;
  41. }
  42. U_BOOT_CMD(
  43. echo, CONFIG_SYS_MAXARGS, 1, do_echo,
  44. "echo args to console",
  45. "[args..]\n"
  46. " - echo args to console; \\c suppresses newline"
  47. );