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