pager.c 982 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <signal.h>
  4. #include <unistd.h>
  5. #include <grass/gis.h>
  6. #ifdef SIGPIPE
  7. static RETSIGTYPE (*sigpipe)(int);
  8. #endif
  9. FILE *G_open_pager(struct Popen *pager)
  10. {
  11. const char *program = getenv("GRASS_PAGER");
  12. FILE *fp;
  13. if (!program)
  14. return stdout;
  15. if (!isatty(STDOUT_FILENO))
  16. return stdout;
  17. #ifdef SIGPIPE
  18. sigpipe = signal(SIGPIPE, SIG_IGN);
  19. #endif
  20. fp = G_popen_write(pager, program, NULL);
  21. return fp ? fp : stdout;
  22. }
  23. void G_close_pager(struct Popen *pager)
  24. {
  25. G_popen_close(pager);
  26. #ifdef SIGPIPE
  27. if (sigpipe)
  28. signal(SIGPIPE, sigpipe);
  29. #endif
  30. }
  31. FILE *G_open_mail(struct Popen *mail)
  32. {
  33. const char *user = G_whoami();
  34. const char *argv[3];
  35. FILE *fp;
  36. if (!user || !*user)
  37. return NULL;
  38. argv[0] = "mail";
  39. argv[1] = user;
  40. argv[2] = NULL;
  41. fp = G_popen_write(mail, "mail", argv);
  42. return fp;
  43. }
  44. void G_close_mail(struct Popen *mail)
  45. {
  46. G_popen_close(mail);
  47. }