target.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <grass/gis.h>
  5. #include <grass/imagery.h>
  6. #include <grass/glocale.h>
  7. #include "global.h"
  8. int get_target(char *group)
  9. {
  10. char location[GMAPSET_MAX];
  11. char mapset[GMAPSET_MAX];
  12. char buf[1024];
  13. int stat;
  14. if (group && *group) {
  15. if (!I_get_target(group, location, mapset)) {
  16. sprintf(buf, _("Target information for group <%s> missing"), group);
  17. goto error;
  18. }
  19. }
  20. else {
  21. sprintf(location, "%s", G_location());
  22. sprintf(mapset, "%s", G_mapset());
  23. }
  24. sprintf(buf, "%s/%s", G_gisdbase(), location);
  25. if (access(buf, 0) != 0) {
  26. sprintf(buf, _("Target location <%s> not found"), location);
  27. goto error;
  28. }
  29. select_target_env();
  30. G_setenv_nogisrc("LOCATION_NAME", location);
  31. stat = G_mapset_permissions(mapset);
  32. if (stat > 0) {
  33. G_setenv_nogisrc("MAPSET", mapset);
  34. select_current_env();
  35. return 1;
  36. }
  37. sprintf(buf, _("Mapset <%s> in target location <%s> - "), mapset, location);
  38. strcat(buf, stat == 0 ? _("permission denied") : _("not found"));
  39. error:
  40. strcat(buf, _("Please run i.target for group."));
  41. strcat(buf, group);
  42. G_fatal_error("%s", buf);
  43. return 1; /* never reached */
  44. }