echo.c 839 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. main(argc, argv)
  2. char **argv;
  3. {
  4. register char *cp;
  5. register int i, wd;
  6. int j;
  7. if(--argc == 0) {
  8. putchar('\n');
  9. exit(0);
  10. }
  11. for(i = 1; i <= argc; i++) {
  12. for(cp = argv[i]; *cp; cp++) {
  13. if(*cp == '\\')
  14. switch(*++cp) {
  15. case 'b':
  16. putchar('\b');
  17. continue;
  18. case 'c':
  19. exit(0);
  20. case 'f':
  21. putchar('\f');
  22. continue;
  23. case 'n':
  24. putchar('\n');
  25. continue;
  26. case 'r':
  27. putchar('\r');
  28. continue;
  29. case 't':
  30. putchar('\t');
  31. continue;
  32. case '\\':
  33. putchar('\\');
  34. continue;
  35. case '0':
  36. j = wd = 0;
  37. while ((*++cp >= '0' && *cp <= '7') && j++ < 3) {
  38. wd <<= 3;
  39. wd |= (*cp - '0');
  40. }
  41. putchar(wd);
  42. --cp;
  43. continue;
  44. default:
  45. cp--;
  46. }
  47. putchar(*cp);
  48. }
  49. putchar(i == argc? '\n': ' ');
  50. }
  51. exit(0);
  52. }