int get_target(void) { char location[GNAME_MAX]; char mapset[GMAPSET_MAX]; char buf[1024]; int stat; if (!I_get_target(group.name, location, mapset)) { sprintf(buf, "Target information for group [%s] missing\n", group.name); goto error; } sprintf(buf, "%s/%s", G_gisdbase(), location); if (access(buf, 0) != 0) { sprintf(buf, "Target location [%s] not found\n", location); goto error; } G_create_alt_env(); G__setenv("LOCATION_NAME", location); stat = G__mapset_permissions(mapset); if (stat > 0) { G__setenv("MAPSET", mapset); G_create_alt_search_path(); G_switch_env(); G_switch_search_path(); which_env = 0; return 1; } sprintf(buf, "Mapset [%s] in target location [%s] - ", mapset, location); strcat(buf, stat == 0 ? "permission denied\n" : "not found\n"); error: strcat(buf, "Please run i.target for group "); strcat(buf, group.name); G_fatal_error(buf); return -1; }
int main(int argc, char *argv[]) { struct GModule *module; struct Option *group_opt; char location[GMAPSET_MAX]; char mapset[GMAPSET_MAX]; char group[GNAME_MAX]; char buf[100]; int stat; /* must run in a term window */ G_putenv("GRASS_UI_TERM", "1"); G_gisinit(argv[0]); module = G_define_module(); module->keywords = _("imagery, orthorectify"); module->description = _("Interactively select or modify the target elevation model."); group_opt = G_define_standard_option(G_OPT_I_GROUP); group_opt->description = _("Name of imagery group for ortho-rectification"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); elev_layer = (char *)G_malloc(GNAME_MAX * sizeof(char)); mapset_elev = (char *)G_malloc(GMAPSET_MAX * sizeof(char)); tl = (char *)G_malloc(80 * sizeof(char)); math_exp = (char *)G_malloc(80 * sizeof(char)); units = (char *)G_malloc(80 * sizeof(char)); nd = (char *)G_malloc(80 * sizeof(char)); *elev_layer = 0; *mapset_elev = 0; *tl = 0; *math_exp = 0; *units = 0; *nd = 0; strcpy(group, group_opt->answer); G_suppress_warnings(1); if (!I_get_target(group, location, mapset)) { sprintf(buf, _("Target information for group [%s] missing\n"), group); goto error; } G_suppress_warnings(0); sprintf(buf, "%s/%s", G_gisdbase(), location); if (access(buf, 0) != 0) { sprintf(buf, _("Target location [%s] not found\n"), location); goto error; } I_get_group_elev(group, elev_layer, mapset_elev, tl, math_exp, units, nd); G__create_alt_env(); G__setenv("LOCATION_NAME", location); stat = G__mapset_permissions(mapset); if (stat > 0) { G__setenv("MAPSET", mapset); G__create_alt_search_path(); G__switch_env(); G__switch_search_path(); which_env = 0; /* get elevation layer raster map in target location */ select_target_env(); ask_elev(group, location, mapset); /* select current location */ select_current_env(); I_put_group_elev(group, elev_layer, mapset_elev, tl, math_exp, units, nd); exit(EXIT_SUCCESS); } sprintf(buf, _("Mapset [%s] in target location [%s] - "), mapset, location); strcat(buf, stat == 0 ? _("permission denied\n") : _("not found\n")); error: strcat(buf, _("Please select a target for group")); strcat(buf, group); G_suppress_warnings(0); G_fatal_error(buf); }
int main(int argc, char *argv[]) { struct Option *group, *mapset, *loc; struct GModule *module; struct Flag *c; char t_mapset[GMAPSET_MAX], t_location[GMAPSET_MAX]; char group_name[GNAME_MAX], mapset_name[GMAPSET_MAX]; G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("imagery")); G_add_keyword(_("map management")); module->description = _("Targets an imagery group to a GRASS location and mapset."); group = G_define_standard_option(G_OPT_I_GROUP); group->gisprompt = "any,group,group"; loc = G_define_option(); loc->key = "location"; loc->type = TYPE_STRING; loc->required = NO; loc->description = _("Name of imagery target location"); mapset = G_define_option(); mapset->key = "mapset"; mapset->type = TYPE_STRING; mapset->required = NO; mapset->description = _("Name of target mapset"); c = G_define_flag(); c->key = 'c'; c->description = _("Set current location and mapset as target for imagery group"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); /* check if current mapset: (imagery libs are very lacking in this dept) - abort if not, - remove @mapset part if it is */ if (G_name_is_fully_qualified(group->answer, group_name, mapset_name)) { if (strcmp(mapset_name, G_mapset())) G_fatal_error(_("Group must exist in the current mapset")); } else { strcpy(group_name, group->answer); /* FIXME for buffer overflow (have the parser check that?) */ } /* if no setting options are given, print the current target info */ if (!c->answer && !mapset->answer && !loc->answer) { if (I_get_target(group_name, t_location, t_mapset)) G_message(_("Group <%s> targeted for location [%s], mapset [%s]"), group_name, t_location, t_mapset); else G_message(_("Group <%s> has no target"), group_name); exit(EXIT_SUCCESS); } /* error if -c is specified with other options, or options are incomplete */ if ((c->answer && (mapset->answer || loc->answer)) || (!c->answer && (!mapset->answer || !loc->answer))) G_fatal_error(_("Use either the Current Mapset and " "Location Flag (-c)\n OR\n manually enter the variables")); if (c->answer) { /* point group target to current mapset and location */ I_put_target(group_name, G_location(), G_mapset()); G_message(_("Group <%s> targeted for location [%s], mapset [%s]"), group_name, G_location(), G_mapset()); } else { /* point group target to specified mapset and location */ /* TODO: check if it is in current mapset and strip off @mapset part, if present */ I_put_target(group_name, loc->answer, mapset->answer); G_message(_("Group <%s> targeted for location [%s], mapset [%s]"), group_name, loc->answer, mapset->answer); } G_done_msg(" "); exit(EXIT_SUCCESS); }