[GRASS-SVN] r55080 - grass/trunk/general/g.mapsets
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Feb 17 02:33:10 PST 2013
Author: martinl
Date: 2013-02-17 02:33:10 -0800 (Sun, 17 Feb 2013)
New Revision: 55080
Modified:
grass/trunk/general/g.mapsets/g.mapsets.html
grass/trunk/general/g.mapsets/get_maps.c
grass/trunk/general/g.mapsets/local_proto.h
grass/trunk/general/g.mapsets/main.c
Log:
g.mapsets: substitute '.' as name of current mapset
Modified: grass/trunk/general/g.mapsets/g.mapsets.html
===================================================================
--- grass/trunk/general/g.mapsets/g.mapsets.html 2013-02-17 08:24:22 UTC (rev 55079)
+++ grass/trunk/general/g.mapsets/g.mapsets.html 2013-02-17 10:33:10 UTC (rev 55080)
@@ -125,6 +125,12 @@
g.mapsets mapset=user1,PERMANENT operation=set
</pre></div>
+Alternatively the current mapset can be defined by a shortcut "."
+
+<div class="code"><pre>
+g.mapsets mapset=.,PERMANENT operation=set
+</pre></div>
+
<i>Note:</i> The current mapset will be always included in the search
path on the first position even if you change its position or omit the
current mapset from the <b>mapset</b> option.
Modified: grass/trunk/general/g.mapsets/get_maps.c
===================================================================
--- grass/trunk/general/g.mapsets/get_maps.c 2013-02-17 08:24:22 UTC (rev 55079)
+++ grass/trunk/general/g.mapsets/get_maps.c 2013-02-17 10:33:10 UTC (rev 55080)
@@ -30,3 +30,11 @@
{
return (strcmp(*(char **)a, *(char **)b));
}
+
+const char *substitute_mapset(const char *mapset)
+{
+ if (strcmp(mapset, ".") == 0)
+ return G_mapset();
+
+ return mapset;
+}
Modified: grass/trunk/general/g.mapsets/local_proto.h
===================================================================
--- grass/trunk/general/g.mapsets/local_proto.h 2013-02-17 08:24:22 UTC (rev 55079)
+++ grass/trunk/general/g.mapsets/local_proto.h 2013-02-17 10:33:10 UTC (rev 55080)
@@ -1,5 +1,6 @@
/* get_maps.c */
-char** get_available_mapsets(int *);
+char **get_available_mapsets(int *);
+const char *substitute_mapset(const char *);
/* list.c */
void list_available_mapsets(const char **, int, const char *);
Modified: grass/trunk/general/g.mapsets/main.c
===================================================================
--- grass/trunk/general/g.mapsets/main.c 2013-02-17 08:24:22 UTC (rev 55079)
+++ grass/trunk/general/g.mapsets/main.c 2013-02-17 10:33:10 UTC (rev 55080)
@@ -25,6 +25,7 @@
#include <grass/gis.h>
#include <grass/spawn.h>
#include <grass/glocale.h>
+
#include "local_proto.h"
#define OP_UKN 0
@@ -38,13 +39,13 @@
{
int n, i;
int skip;
- const char *cur_mapset;
+ const char *cur_mapset, *mapset;
char **ptr;
char **tokens;
int no_tokens;
FILE *fp;
char path_buf[GPATH_MAX];
- char *path;
+ char *path, *fs;
int operation, nchoices;
char **mapset_name;
@@ -71,7 +72,7 @@
opt.mapset->type = TYPE_STRING;
opt.mapset->required = YES;
opt.mapset->multiple = YES;
- opt.mapset->description = _("Name(s) of existing mapset(s)");
+ opt.mapset->description = _("Name(s) of existing mapset(s) to add/remove or set");
opt.mapset->guisection = _("Search path");
opt.op = G_define_option();
@@ -131,6 +132,8 @@
}
}
+ fs = G_option_to_separator(opt.fs);
+
/* list available mapsets */
if (opt.list->answer) {
if (opt.print->answer)
@@ -140,7 +143,7 @@
if (opt.mapset->answer)
G_warning(_("Option <%s> ignored"), opt.mapset->key);
mapset_name = get_available_mapsets(&nmapsets);
- list_available_mapsets((const char **)mapset_name, nmapsets, opt.fs->answer);
+ list_available_mapsets((const char **)mapset_name, nmapsets, fs);
exit(EXIT_SUCCESS);
}
@@ -149,7 +152,7 @@
G_warning(_("Flag -%c ignored"), opt.dialog->key);
if (opt.mapset->answer)
G_warning(_("Option <%s> ignored"), opt.mapset->key);
- list_accessible_mapsets(opt.fs->answer);
+ list_accessible_mapsets(fs);
exit(EXIT_SUCCESS);
}
@@ -166,12 +169,11 @@
/* modify search path */
if (operation == OP_SET) {
- const char *mapset;
int cur_found;
cur_found = FALSE;
for (ptr = opt.mapset->answers; *ptr != NULL; ptr++) {
- mapset = *ptr;
+ mapset = substitute_mapset(*ptr);
if (G__mapset_permissions(mapset) < 0)
G_fatal_error(_("Mapset <%s> not found"), mapset);
if (strcmp(mapset, cur_mapset) == 0)
@@ -198,9 +200,8 @@
/* fetch and add new mapsets from param list */
for (ptr = opt.mapset->answers; *ptr != NULL; ptr++) {
- char *mapset;
- mapset = *ptr;
+ mapset = substitute_mapset(*ptr);
if (G_is_mapset_in_search_path(mapset))
continue;
@@ -230,21 +231,24 @@
found = FALSE;
for (ptr = opt.mapset->answers; *ptr && !found; ptr++)
- if (strcmp(oldname, *ptr) == 0)
+
+ mapset = substitute_mapset(*ptr);
+
+ if (strcmp(oldname, mapset) == 0)
found = TRUE;
- if (found) {
- if (strcmp(oldname, cur_mapset) == 0)
- G_warning(_("Current mapset (<%s>) must always included in the search path"),
- cur_mapset);
- else
- G_verbose_message(_("Mapset <%s> removed from search path"),
- oldname);
- continue;
- }
-
- nchoices++;
- append_mapset(&path, oldname);
+ if (found) {
+ if (strcmp(oldname, cur_mapset) == 0)
+ G_warning(_("Current mapset (<%s>) must always included in the search path"),
+ cur_mapset);
+ else
+ G_verbose_message(_("Mapset <%s> removed from search path"),
+ oldname);
+ continue;
+ }
+
+ nchoices++;
+ append_mapset(&path, oldname);
}
}
/* stuffem sets nchoices */
More information about the grass-commit
mailing list