1 #include <unistd.h>
2 #include <string.h>
3 #include "global.h"
4 
get_target(char * group)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 	sprintf(buf, _("Target information for group <%s> missing"), group);
14 	goto error;
15     }
16 
17     sprintf(buf, "%s/%s", G_gisdbase(), location);
18     if (access(buf, 0) != 0) {
19 	sprintf(buf, _("Target location <%s> not found"), location);
20 	goto error;
21     }
22     select_target_env();
23     G_setenv_nogisrc("LOCATION_NAME", location);
24     stat = G_mapset_permissions(mapset);
25     if (stat > 0) {
26 	G_setenv_nogisrc("MAPSET", mapset);
27 	G_get_window(&target_window);
28 	select_current_env();
29 	return 1;
30     }
31     sprintf(buf, _("Mapset <%s> in target location <%s> - "), mapset, location);
32     strcat(buf, stat == 0 ? _("permission denied") : _("not found"));
33   error:
34     strcat(buf, "\n");
35     strcat(buf, _("Please run i.target for group "));
36     strcat(buf, group);
37     G_fatal_error("%s", buf);
38     return 1;			/* never reached */
39 }
40