瀏覽代碼

g.mapsets: substitute '.' as name of current mapset

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@55080 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 12 年之前
父節點
當前提交
3210f0dad7
共有 4 個文件被更改,包括 42 次插入23 次删除
  1. 6 0
      general/g.mapsets/g.mapsets.html
  2. 8 0
      general/g.mapsets/get_maps.c
  3. 2 1
      general/g.mapsets/local_proto.h
  4. 26 22
      general/g.mapsets/main.c

+ 6 - 0
general/g.mapsets/g.mapsets.html

@@ -125,6 +125,12 @@ Overwrite current search path
 g.mapsets mapset=user1,PERMANENT operation=set
 g.mapsets mapset=user1,PERMANENT operation=set
 </pre></div>
 </pre></div>
 
 
+Alternatively the current mapset can be defined by a shortcut &quot;.&quot;
+
+<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
 <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
 path on the first position even if you change its position or omit the
 current mapset from the <b>mapset</b> option.
 current mapset from the <b>mapset</b> option.

+ 8 - 0
general/g.mapsets/get_maps.c

@@ -30,3 +30,11 @@ int cmp(const void *a, const void *b)
 {
 {
     return (strcmp(*(char **)a, *(char **)b));
     return (strcmp(*(char **)a, *(char **)b));
 }
 }
+
+const char *substitute_mapset(const char *mapset)
+{
+    if (strcmp(mapset, ".") == 0)
+        return G_mapset();
+
+    return mapset;
+}

+ 2 - 1
general/g.mapsets/local_proto.h

@@ -1,5 +1,6 @@
 /* get_maps.c */
 /* get_maps.c */
-char** get_available_mapsets(int *);
+char **get_available_mapsets(int *);
+const char  *substitute_mapset(const char *);
 
 
 /* list.c */
 /* list.c */
 void list_available_mapsets(const char **, int, const char *);
 void list_available_mapsets(const char **, int, const char *);

+ 26 - 22
general/g.mapsets/main.c

@@ -25,6 +25,7 @@
 #include <grass/gis.h>
 #include <grass/gis.h>
 #include <grass/spawn.h>
 #include <grass/spawn.h>
 #include <grass/glocale.h>
 #include <grass/glocale.h>
+
 #include "local_proto.h"
 #include "local_proto.h"
 
 
 #define OP_UKN 0
 #define OP_UKN 0
@@ -38,13 +39,13 @@ int main(int argc, char *argv[])
 {
 {
     int n, i;
     int n, i;
     int skip;
     int skip;
-    const char *cur_mapset;
+    const char *cur_mapset, *mapset;
     char **ptr;
     char **ptr;
     char **tokens;
     char **tokens;
     int no_tokens;
     int no_tokens;
     FILE *fp;
     FILE *fp;
     char path_buf[GPATH_MAX];
     char path_buf[GPATH_MAX];
-    char *path;
+    char *path, *fs;
     int operation, nchoices;
     int operation, nchoices;
     
     
     char **mapset_name;
     char **mapset_name;
@@ -71,7 +72,7 @@ int main(int argc, char *argv[])
     opt.mapset->type = TYPE_STRING;
     opt.mapset->type = TYPE_STRING;
     opt.mapset->required = YES;
     opt.mapset->required = YES;
     opt.mapset->multiple = 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.mapset->guisection = _("Search path");
     
     
     opt.op = G_define_option();
     opt.op = G_define_option();
@@ -131,6 +132,8 @@ int main(int argc, char *argv[])
         }
         }
     }
     }
     
     
+    fs = G_option_to_separator(opt.fs);
+
     /* list available mapsets */
     /* list available mapsets */
     if (opt.list->answer) {
     if (opt.list->answer) {
         if (opt.print->answer)
         if (opt.print->answer)
@@ -140,7 +143,7 @@ int main(int argc, char *argv[])
         if (opt.mapset->answer)
         if (opt.mapset->answer)
             G_warning(_("Option <%s> ignored"), opt.mapset->key);
             G_warning(_("Option <%s> ignored"), opt.mapset->key);
         mapset_name = get_available_mapsets(&nmapsets);
         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);
         exit(EXIT_SUCCESS);
     }
     }
 
 
@@ -149,7 +152,7 @@ int main(int argc, char *argv[])
             G_warning(_("Flag -%c ignored"), opt.dialog->key);
             G_warning(_("Flag -%c ignored"), opt.dialog->key);
         if (opt.mapset->answer)
         if (opt.mapset->answer)
             G_warning(_("Option <%s> ignored"), opt.mapset->key);
             G_warning(_("Option <%s> ignored"), opt.mapset->key);
-        list_accessible_mapsets(opt.fs->answer);
+        list_accessible_mapsets(fs);
         exit(EXIT_SUCCESS);
         exit(EXIT_SUCCESS);
     }
     }
     
     
@@ -166,12 +169,11 @@ int main(int argc, char *argv[])
     
     
     /* modify search path */
     /* modify search path */
     if (operation == OP_SET) {
     if (operation == OP_SET) {
-        const char *mapset;
         int cur_found;
         int cur_found;
         
         
         cur_found = FALSE;
         cur_found = FALSE;
         for (ptr = opt.mapset->answers; *ptr != NULL; ptr++) {
         for (ptr = opt.mapset->answers; *ptr != NULL; ptr++) {
-            mapset = *ptr;
+            mapset = substitute_mapset(*ptr);
             if (G__mapset_permissions(mapset) < 0)
             if (G__mapset_permissions(mapset) < 0)
                 G_fatal_error(_("Mapset <%s> not found"), mapset);
                 G_fatal_error(_("Mapset <%s> not found"), mapset);
             if (strcmp(mapset, cur_mapset) == 0)
             if (strcmp(mapset, cur_mapset) == 0)
@@ -198,9 +200,8 @@ int main(int argc, char *argv[])
 
 
         /* fetch and add new mapsets from param list */
         /* fetch and add new mapsets from param list */
         for (ptr = opt.mapset->answers; *ptr != NULL; ptr++) {
         for (ptr = opt.mapset->answers; *ptr != NULL; ptr++) {
-            char *mapset;
 
 
-            mapset = *ptr;
+            mapset = substitute_mapset(*ptr);
 
 
             if (G_is_mapset_in_search_path(mapset))
             if (G_is_mapset_in_search_path(mapset))
                 continue;
                 continue;
@@ -230,21 +231,24 @@ int main(int argc, char *argv[])
             found = FALSE;
             found = FALSE;
             
             
             for (ptr = opt.mapset->answers; *ptr && !found; ptr++)
             for (ptr = opt.mapset->answers; *ptr && !found; ptr++)
-                if (strcmp(oldname, *ptr) == 0)
-                    found = TRUE;
+
+                mapset = substitute_mapset(*ptr);
             
             
-            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;
-            }
+                if (strcmp(oldname, mapset) == 0)
+                    found = TRUE;
             
             
-            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 */
     /* stuffem sets nchoices */