[GRASS-SVN] r30802 - in grass/trunk/imagery: i.group i.target
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Mar 29 23:53:03 EDT 2008
Author: hamish
Date: 2008-03-29 23:53:03 -0400 (Sat, 29 Mar 2008)
New Revision: 30802
Modified:
grass/trunk/imagery/i.group/main.c
grass/trunk/imagery/i.target/main.c
Log:
remove @mapset part and test to see if the group is in the current mapset (trac bug #70)
Modified: grass/trunk/imagery/i.group/main.c
===================================================================
--- grass/trunk/imagery/i.group/main.c 2008-03-30 02:48:26 UTC (rev 30801)
+++ grass/trunk/imagery/i.group/main.c 2008-03-30 03:53:03 UTC (rev 30802)
@@ -37,6 +37,7 @@
int main(int argc, char *argv[])
{
char title[80];
+ char group[GNAME_MAX], mapset[GMAPSET_MAX];
int m, k=0;
struct Option *grp, *rast, *sgrp;
@@ -93,70 +94,83 @@
}
k++;
}
-
+
if (k < 1 && !l->answer) /* remove if input is requirement */
G_fatal_error( _("No input raster map(s) specified") );
-
- I_location_info(title, argv[0]);
+
+ I_location_info(title, argv[0]); /* unused? */
+
+ /* 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(grp->answer, group, mapset)) {
+ if(strcmp(mapset, G_mapset()))
+ G_fatal_error(_("Group must exist in the current mapset"));
+ }
+ else {
+ strcpy(group, grp->answer); /* FIXME for buffer overflow (have the parser check that?) */
+ }
+
if (r->answer) {
/* Remove files from Group */
- if (I_find_group(grp->answer) == 0) {
- G_fatal_error(_("Specified group does not exist"));
+ if (I_find_group(group) == 0) {
+ G_fatal_error(_("Specified group does not exist in current mapset"));
}
if (sgrp->answer) {
G_verbose_message(_("Removing raster maps from subgroup <%s>..."), sgrp->answer);
- remove_subgroup_files(grp->answer, sgrp->answer, rast->answers, k);
+ remove_subgroup_files(group, sgrp->answer, rast->answers, k);
}
else {
- G_verbose_message(_("Removing raster maps from group <%s>..."), grp->answer);
- remove_group_files(grp->answer, rast->answers, k);
+ G_verbose_message(_("Removing raster maps from group <%s>..."), group);
+ remove_group_files(group, rast->answers, k);
}
}
else {
if (l->answer) {
+ /* List raster maps in group */
+
struct Ref ref;
-
- /* List raster maps */
- if (I_find_group(grp->answer) == 0) {
+ if (I_find_group(group) == 0) {
G_fatal_error(_("Specified group does not exist"));
}
if (sgrp->answer) {
/* list subgroup files */
- I_get_subgroup_ref(grp->answer, sgrp->answer, &ref);
+ I_get_subgroup_ref(group, sgrp->answer, &ref);
if(simple_flag->answer)
I_list_subgroup_simple(&ref, stdout);
else
- I_list_subgroup(grp->answer, sgrp->answer, &ref, stdout);
+ I_list_subgroup(group, sgrp->answer, &ref, stdout);
}
else {
/* list group files */
- I_get_group_ref(grp->answer, &ref);
+ I_get_group_ref(group, &ref);
if(simple_flag->answer)
I_list_group_simple(&ref, stdout);
else
- I_list_group(grp->answer, &ref, stdout);
+ I_list_group(group, &ref, stdout);
}
}
else {
/* Create or update Group REF */
- if (I_find_group(grp->answer) == 0)
- G_verbose_message(_("Group <%s> does not yet exist. Creating..."), grp->answer);
+ if (I_find_group(group) == 0)
+ G_verbose_message(_("Group <%s> does not yet exist. Creating..."), group);
if (sgrp->answer) {
- G_verbose_message(_("Adding raster maps to group <%s>..."), grp->answer);
- add_or_update_group(grp->answer, rast->answers, k);
+ G_verbose_message(_("Adding raster maps to group <%s>..."), group);
+ add_or_update_group(group, rast->answers, k);
G_verbose_message(_("Adding raster maps to subgroup <%s>..."), sgrp->answer);
- add_or_update_subgroup(grp->answer, sgrp->answer, rast->answers, k);
+ add_or_update_subgroup(group, sgrp->answer, rast->answers, k);
}
else {
- G_verbose_message(_("Adding raster maps to group <%s>..."), grp->answer);
- add_or_update_group(grp->answer, rast->answers, k);
+ G_verbose_message(_("Adding raster maps to group <%s>..."), group);
+ add_or_update_group(group, rast->answers, k);
}
}
}
Modified: grass/trunk/imagery/i.target/main.c
===================================================================
--- grass/trunk/imagery/i.target/main.c 2008-03-30 02:48:26 UTC (rev 30801)
+++ grass/trunk/imagery/i.target/main.c 2008-03-30 03:53:03 UTC (rev 30802)
@@ -36,6 +36,7 @@
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]);
@@ -67,14 +68,27 @@
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->answer, t_location, t_mapset))
+ if (I_get_target (group_name, t_location, t_mapset))
G_message (_("Group <%s> targeted for location [%s], mapset [%s]"),
- group->answer, t_location, t_mapset);
+ group_name, t_location, t_mapset);
else
- G_message (_("Group <%s> has no target"), group->answer);
+ G_message (_("Group <%s> has no target"), group_name);
exit (EXIT_SUCCESS);
}
@@ -87,17 +101,17 @@
if (c->answer) {
/* point group target to current mapset and location */
- I_put_target(group->answer, G_location(), G_mapset());
+ I_put_target(group_name, G_location(), G_mapset());
G_message(_("Group <%s> targeted for location [%s], mapset [%s]"),
- group->answer, G_location(), G_mapset());
+ 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->answer, loc->answer, mapset->answer);
+ I_put_target(group_name, loc->answer, mapset->answer);
G_message(_("Group <%s> targeted for location [%s], mapset [%s]"),
- group->answer, loc->answer, mapset->answer);
+ group_name, loc->answer, mapset->answer);
}
G_done_msg(" ");
More information about the grass-commit
mailing list