env.c 803 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <grass/gis.h>
  4. #include "global.h"
  5. static int which_env = -1; /* 0 = cur, 1 = target */
  6. int select_current_env(void)
  7. {
  8. if (which_env < 0) {
  9. G_create_alt_env();
  10. which_env = 0;
  11. }
  12. if (which_env != 0) {
  13. G_switch_env();
  14. which_env = 0;
  15. }
  16. return 0;
  17. }
  18. int select_target_env(void)
  19. {
  20. if (which_env < 0) {
  21. G_create_alt_env();
  22. which_env = 1;
  23. }
  24. if (which_env != 1) {
  25. G_switch_env();
  26. which_env = 1;
  27. }
  28. return 0;
  29. }
  30. int show_env(void)
  31. {
  32. fprintf(stderr, "env(%d) switch to LOCATION %s, MAPSET %s\n", which_env,
  33. G_getenv_nofatal("LOCATION_NAME") ==
  34. NULL ? "?" : G_getenv_nofatal("LOCATION_NAME"),
  35. G_getenv_nofatal("MAPSET") == NULL ? "?" : G_getenv_nofatal("MAPSET"));
  36. G_sleep(2);
  37. return 0;
  38. }