echo.c 810 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <string.h>
  2. #include <grass/gis.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. /******************************************
  6. * $GISBASE/etc/echo [-n] [-e] args
  7. *
  8. * echos its args to stdout
  9. * suppressing the newline if -n specified
  10. * prints to stderr instead if -e specified
  11. *
  12. * replaces the standard UNIX echo which
  13. * varies from machine to machine
  14. *******************************************/
  15. int
  16. main (int argc, char *argv[])
  17. {
  18. int i;
  19. int newline;
  20. int any;
  21. FILE *stream = stdout;
  22. newline = 1;
  23. any = 0;
  24. for (i = 1; i < argc; i++)
  25. if (strcmp (argv[i],"-n") == 0)
  26. newline = 0;
  27. else if (strcmp (argv[i],"-e") == 0)
  28. stream = stderr;
  29. else
  30. fprintf (stream, "%s%s", any++?" ":"", argv[i]);
  31. if (any && newline)
  32. fprintf (stream, "\n");
  33. exit(0);
  34. }