echo.c 810 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 main(int argc, char *argv[])
  16. {
  17. int i;
  18. int newline;
  19. int any;
  20. FILE *stream = stdout;
  21. newline = 1;
  22. any = 0;
  23. for (i = 1; i < argc; i++)
  24. if (strcmp(argv[i], "-n") == 0)
  25. newline = 0;
  26. else if (strcmp(argv[i], "-e") == 0)
  27. stream = stderr;
  28. else
  29. fprintf(stream, "%s%s", any++ ? " " : "", argv[i]);
  30. if (any && newline)
  31. fprintf(stream, "\n");
  32. exit(0);
  33. }