[GRASS-SVN] r62396 - in grass/branches/releasebranch_7_0/general: . g.list g.remove

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Oct 26 17:17:35 PDT 2014


Author: hcho
Date: 2014-10-26 17:17:35 -0700 (Sun, 26 Oct 2014)
New Revision: 62396

Added:
   grass/branches/releasebranch_7_0/general/g.list/
   grass/branches/releasebranch_7_0/general/g.list/g.list.html
   grass/branches/releasebranch_7_0/general/g.remove/
   grass/branches/releasebranch_7_0/general/g.remove/g.remove.html
Removed:
   grass/branches/releasebranch_7_0/general/g.list.old/
   grass/branches/releasebranch_7_0/general/g.list/g.mlist.html
   grass/branches/releasebranch_7_0/general/g.mlist/
   grass/branches/releasebranch_7_0/general/g.mremove/
   grass/branches/releasebranch_7_0/general/g.remove.old/
   grass/branches/releasebranch_7_0/general/g.remove/g.mremove.html
Modified:
   grass/branches/releasebranch_7_0/general/Makefile
   grass/branches/releasebranch_7_0/general/g.list/Makefile
   grass/branches/releasebranch_7_0/general/g.list/main.c
   grass/branches/releasebranch_7_0/general/g.remove/Makefile
   grass/branches/releasebranch_7_0/general/g.remove/main.c
Log:
Replace old g.list/g.remove with g.mlist/g.mremove

Modified: grass/branches/releasebranch_7_0/general/Makefile
===================================================================
--- grass/branches/releasebranch_7_0/general/Makefile	2014-10-27 00:17:27 UTC (rev 62395)
+++ grass/branches/releasebranch_7_0/general/Makefile	2014-10-27 00:17:35 UTC (rev 62396)
@@ -16,8 +16,6 @@
 	g.mapsets \
 	g.message \
 	g.mkfontcap \
-	g.mlist \
-	g.mremove \
 	g.parser \
 	g.pnmcomp \
 	g.ppmtopng \

Modified: grass/branches/releasebranch_7_0/general/g.list/Makefile
===================================================================
--- grass/branches/releasebranch_7_0/general/g.mlist/Makefile	2014-10-26 20:28:00 UTC (rev 62392)
+++ grass/branches/releasebranch_7_0/general/g.list/Makefile	2014-10-27 00:17:35 UTC (rev 62396)
@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../..
 
-PGM = g.mlist
+PGM = g.list
 
 LIBES = $(MANAGELIB) $(GISLIB) $(RASTERLIB) $(RASTER3DLIB) $(VECTORLIB)
 DEPENDENCIES = $(MANAGEDEP) $(GISDEP) $(RASTERDEP) $(RASTER3DDEP) $(VECTORDEP)

Copied: grass/branches/releasebranch_7_0/general/g.list/g.list.html (from rev 62392, grass/branches/releasebranch_7_0/general/g.mlist/g.mlist.html)
===================================================================
--- grass/branches/releasebranch_7_0/general/g.list/g.list.html	                        (rev 0)
+++ grass/branches/releasebranch_7_0/general/g.list/g.list.html	2014-10-27 00:17:35 UTC (rev 62396)
@@ -0,0 +1,186 @@
+<h2>DESCRIPTION</h2>
+
+<em>g.list</em> searches for data files matching a pattern given by
+wildcards or POSIX Extended Regular Expressions.
+
+<h2>NOTES</h2>
+
+The output of <em>g.list</em> may be useful for other programs' parameter
+input (e.g. time series for <em><a href="r.series.html">r.series</a></em>)
+when used with <em>separator=comma</em>.
+
+<h2>EXAMPLES</h2>
+
+List all available GRASS data base files:
+<div class="code"><pre>
+g.list type=all
+</pre></div>
+
+List all raster and vector maps:
+<div class="code"><pre>
+g.list type=rast,vect
+</pre></div>
+
+<h3>Mapset search path</h3>
+
+If <b>mapset</b> is not specified than <em>g.list</em> searches for
+data files in the mapsets which are included in the search path
+(defined by <em><a href="g.mapsets.html">g.mapsets</a></em>),
+see <tt>g.mapsets -p</tt>.
+
+<div class="code"><pre>
+g.list rast
+
+raster map(s) available in mapset <user1>:
+dmt
+...
+raster map(s) available in mapset <PERMANENT>:
+aspect
+...
+</pre></div>
+
+By option <b>mapset</b>=. (one dot) can be listed only data files from
+the current mapset:
+
+<div class="code"><pre>
+g.list rast mapset=.
+raster map(s) available in mapset <user1>:
+dmt
+</pre></div>
+
+Similarly <b>mapset</b>=* (one asterisk) prints data files from all
+available mapsets also including those which are not listed in the
+current search path (see <tt>g.mapsets -l</tt>).
+
+<div class="code"><pre>
+g.list rast mapset=*
+
+raster map(s) available in mapset <landsat>:
+lsat5_1987_10
+...
+raster map(s) available in mapset <user1>:
+dmt
+...
+raster map(s) available in mapset <PERMANENT>:
+aspect
+...
+</pre></div>
+
+<h3>Wildcards</h3>
+
+List all vector maps starting with letter "r":
+<div class="code"><pre>
+g.list type=vect pattern="r*"
+</pre></div>
+
+List all vector maps starting with letter "r" or "a":
+<div class="code"><pre>
+g.list type=vect pattern="[ra]*"
+</pre></div>
+
+List all raster maps starting with "soil_" or "landuse_":
+<div class="code"><pre>
+g.list type=rast pattern="{soil,landuse}_*"
+</pre></div>
+
+List certain raster maps with one variable character/number:
+<div class="code"><pre>
+g.list type=rast pattern="N45E00?.meters"
+</pre></div>
+
+Use of <b>exclude</b> parameter:
+<div class="code"><pre>
+# without exclude:
+  g.list rast pat="r*" mapset=PERMANENT
+  railroads
+  roads
+  rstrct.areas
+  rushmore
+
+# exclude only complete word(s):
+  g.list rast pat="r*" exclude=roads mapset=PERMANENT
+  railroads
+  rstrct.areas
+  rushmore
+
+# exclude with wildcard:
+  g.list rast pat="r*" exclude="*roads*" mapset=PERMANENT
+  rstrct.areas
+  rushmore
+</pre></div>
+
+<h3>Regular expressions</h3>
+
+List all soil maps starting with "soils" in their name:
+<div class="code"><pre>
+g.list -r type=rast pattern='^soils'
+</pre></div>
+
+List "tmp" if "tmp" raster map exists:
+<div class="code"><pre>
+g.list -r type=rast pattern='^tmp$'
+</pre></div>
+
+List "tmp0" ..."tmp9" if corresponding vector map exists
+(each map name linewise):
+<div class="code"><pre>
+g.list -r type=vect pattern='^tmp[0-9]$'
+</pre></div>
+
+List "tmp0"..."tmp9" if corresponding vector map exists
+(each map name comma separated):
+<div class="code"><pre>
+g.list -r type=vect separator=comma pattern='^tmp[0-9]$'
+</pre></div>
+
+<h3>Extended regular expressions</h3>
+
+List all precipitation maps for the years 1997-2012, comma separated:
+<div class="code"><pre>
+g.list -e type=rast separator=comma pattern="precip_total.(199[7-9]|200[0-9]|201[0-2]).sum"
+</pre></div>
+
+<h3>Maps whose region overlaps with a saved region</h3>
+
+List all raster maps starting with "tmp_" whose region overlaps with
+the region of "test" raster map:
+<div class="code"><pre>
+g.region rast=test save=test_region
+g.list type=rast pattern='tmp_*' region=test_region
+</pre></div>
+
+List "tmp0"..."tmp9" vector maps whose region overlaps with
+the current region:
+<div class="code"><pre>
+g.list -r type=vect pattern='^tmp[0-9]$' region=.
+</pre></div>
+
+List all raster and vector maps whose region overlaps with the default region
+of the PERMANENT mapset in the current location (DEFAULT_WIND):
+<div class="code"><pre>
+g.list type=rast,vect region=*
+</pre></div>
+
+Note that, without <tt>region=*</tt>, <tt>g.list type=rast,vect</tt> simply
+lists all available raster and vector maps from the current search path
+regardless of their region.
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.series.html">r.series</a>,
+<a href="t.list.html">t.list</a>,
+<a href="t.rast.list.html">t.rast.list</a>,
+<a href="t.vect.list.html">t.vect.list</a>
+</em>
+<p>
+<a href="http://en.wikipedia.org/wiki/Regular_expression">Regular expressions</a>
+(aka regex) - from Wikipedia, the free encyclopedia
+
+<h2>AUTHOR</h2>
+
+Huidae Cho<br>
+grass4u at gmail.com
+
+<p>
+<i>Last changed: $Date$</i>

Deleted: grass/branches/releasebranch_7_0/general/g.list/g.mlist.html
===================================================================
--- grass/branches/releasebranch_7_0/general/g.mlist/g.mlist.html	2014-10-26 20:28:00 UTC (rev 62392)
+++ grass/branches/releasebranch_7_0/general/g.list/g.mlist.html	2014-10-27 00:17:35 UTC (rev 62396)
@@ -1,192 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>g.mlist</em> searches for data files matching a pattern given by
-wildcards or POSIX Extended Regular Expressions. It is an extended
-version of <em><a href="g.list.html">g.list</a></em>.
-
-<p>
-See also the <em><a href="g.list.html">g.list</a></em> help page for
-discussion of some module options.
-
-<h2>NOTES</h2>
-
-The output of <em>g.mlist</em> may be useful for other programs' parameter
-input (e.g. time series for <em><a href="r.series.html">r.series</a></em>)
-when used with <em>separator=comma</em>.
-
-<h2>EXAMPLES</h2>
-
-List all available GRASS data base files:
-<div class="code"><pre>
-g.mlist type=all
-</pre></div>
-
-List all raster and vector maps:
-<div class="code"><pre>
-g.mlist type=rast,vect
-</pre></div>
-
-<h3>Mapset search path</h3>
-
-If <b>mapset</b> is not specified than <em>g.mlist</em> searches for
-data files in the mapsets which are included in the search path
-(defined by <em><a href="g.mapsets.html">g.mapsets</a></em>),
-see <tt>g.mapsets -p</tt>.
-
-<div class="code"><pre>
-g.mlist rast
-
-raster map(s) available in mapset <user1>:
-dmt
-...
-raster map(s) available in mapset <PERMANENT>:
-aspect
-...
-</pre></div>
-
-By option <b>mapset</b>=. (one dot) can be listed only data files from
-the current mapset:
-
-<div class="code"><pre>
-g.mlist rast mapset=.
-raster map(s) available in mapset <user1>:
-dmt
-</pre></div>
-
-Similarly <b>mapset</b>=* (one asterisk) prints data files from all
-available mapsets also including those which are not listed in the
-current search path (see <tt>g.mapsets -l</tt>).
-
-<div class="code"><pre>
-g.mlist rast mapset=*
-
-raster map(s) available in mapset <landsat>:
-lsat5_1987_10
-...
-raster map(s) available in mapset <user1>:
-dmt
-...
-raster map(s) available in mapset <PERMANENT>:
-aspect
-...
-</pre></div>
-
-<h3>Wildcards</h3>
-
-List all vector maps starting with letter "r":
-<div class="code"><pre>
-g.mlist type=vect pattern="r*"
-</pre></div>
-
-List all vector maps starting with letter "r" or "a":
-<div class="code"><pre>
-g.mlist type=vect pattern="[ra]*"
-</pre></div>
-
-List all raster maps starting with "soil_" or "landuse_":
-<div class="code"><pre>
-g.mlist type=rast pattern="{soil,landuse}_*"
-</pre></div>
-
-List certain raster maps with one variable character/number:
-<div class="code"><pre>
-g.mlist type=rast pattern="N45E00?.meters"
-</pre></div>
-
-Use of <b>exclude</b> parameter:
-<div class="code"><pre>
-# without exclude:
-  g.mlist rast pat="r*" mapset=PERMANENT
-  railroads
-  roads
-  rstrct.areas
-  rushmore
-
-# exclude only complete word(s):
-  g.mlist rast pat="r*" exclude=roads mapset=PERMANENT
-  railroads
-  rstrct.areas
-  rushmore
-
-# exclude with wildcard:
-  g.mlist rast pat="r*" exclude="*roads*" mapset=PERMANENT
-  rstrct.areas
-  rushmore
-</pre></div>
-
-<h3>Regular expressions</h3>
-
-List all soil maps starting with "soils" in their name:
-<div class="code"><pre>
-g.mlist -r type=rast pattern='^soils'
-</pre></div>
-
-List "tmp" if "tmp" raster map exists:
-<div class="code"><pre>
-g.mlist -r type=rast pattern='^tmp$'
-</pre></div>
-
-List "tmp0" ..."tmp9" if corresponding vector map exists
-(each map name linewise):
-<div class="code"><pre>
-g.mlist -r type=vect pattern='^tmp[0-9]$'
-</pre></div>
-
-List "tmp0"..."tmp9" if corresponding vector map exists
-(each map name comma separated):
-<div class="code"><pre>
-g.mlist -r type=vect separator=comma pattern='^tmp[0-9]$'
-</pre></div>
-
-<h3>Extended regular expressions</h3>
-
-List all precipitation maps for the years 1997-2012, comma separated:
-<div class="code"><pre>
-g.mlist -e type=rast separator=comma pattern="precip_total.(199[7-9]|200[0-9]|201[0-2]).sum"
-</pre></div>
-
-<h3>Maps whose region overlaps with a saved region</h3>
-
-List all raster maps starting with "tmp_" whose region overlaps with
-the region of "test" raster map:
-<div class="code"><pre>
-g.region rast=test save=test_region
-g.mlist type=rast pattern='tmp_*' region=test_region
-</pre></div>
-
-List "tmp0"..."tmp9" vector maps whose region overlaps with
-the current region:
-<div class="code"><pre>
-g.mlist -r type=vect pattern='^tmp[0-9]$' region=.
-</pre></div>
-
-List all raster and vector maps whose region overlaps with the default region
-of the PERMANENT mapset in the current location (DEFAULT_WIND):
-<div class="code"><pre>
-g.mlist type=rast,vect region=*
-</pre></div>
-
-Note that, without <tt>region=*</tt>, <tt>g.mlist type=rast,vect</tt> simply
-lists all available raster and vector maps from the current search path
-regardless of their region.
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="g.list.html">g.list</a>,
-<a href="r.series.html">r.series</a>,
-<a href="t.list.html">t.list</a>,
-<a href="t.rast.list.html">t.rast.list</a>,
-<a href="t.vect.list.html">t.vect.list</a>
-</em>
-<p>
-<a href="http://en.wikipedia.org/wiki/Regular_expression">Regular expressions</a>
-(aka regex) - from Wikipedia, the free encyclopedia
-
-<h2>AUTHOR</h2>
-
-Huidae Cho<br>
-grass4u at gmail.com
-
-<p>
-<i>Last changed: $Date$</i>

Modified: grass/branches/releasebranch_7_0/general/g.list/main.c
===================================================================
--- grass/branches/releasebranch_7_0/general/g.mlist/main.c	2014-10-26 20:28:00 UTC (rev 62392)
+++ grass/branches/releasebranch_7_0/general/g.list/main.c	2014-10-27 00:17:35 UTC (rev 62396)
@@ -1,7 +1,7 @@
 
 /****************************************************************************
  *
- * MODULE:       g.mlist
+ * MODULE:       g.list
  *
  * AUTHOR(S):    Huidae Cho
  * 		 Based on general/manage/cmd/list.c by Michael Shapiro.
@@ -31,7 +31,6 @@
     TYPE_RAST,
     TYPE_RAST3D,
     TYPE_VECT,
-    TYPE_3DVIEW,
     TYPE_OTHERS
 };
 
@@ -67,9 +66,8 @@
     void *filter, *exclude;
     struct Popen pager;
     FILE *fp;
-    const char *mapset;
     char *separator;
-    int use_region;
+    int use_region, use_pager;
     struct Cell_head window;
 
     G_gisinit(argv[0]);
@@ -88,12 +86,14 @@
     opt.type->multiple = YES;
     opt.type->options = M_get_options(TRUE);
     opt.type->descriptions = M_get_option_desc(TRUE);
+    opt.type->guidependency = "pattern,exclude";
 
     opt.pattern = G_define_option();
     opt.pattern->key = "pattern";
     opt.pattern->type = TYPE_STRING;
     opt.pattern->required = NO;
     opt.pattern->multiple = NO;
+    opt.pattern->gisprompt = "new,element,element";
     opt.pattern->description = _("Map name search pattern (default: all)");
     opt.pattern->guisection = _("Pattern");
 
@@ -102,6 +102,7 @@
     opt.exclude->type = TYPE_STRING;
     opt.exclude->required = NO;
     opt.exclude->multiple = NO;
+    opt.exclude->gisprompt = "new,element,element";
     opt.exclude->description = _("Map name exclusion pattern (default: none)");
     opt.exclude->guisection = _("Pattern");
 
@@ -113,6 +114,7 @@
 	_("'.' for current mapset; '*' for all mapsets in location");
     opt.separator = G_define_standard_option(G_OPT_F_SEP);
     opt.separator->answer = "newline";
+    opt.separator->guisection = _("Print");
 
     opt.region = G_define_standard_option(G_OPT_M_REGION);
     opt.region->label = _("Name of saved region for map search (default: not restricted)");
@@ -123,6 +125,7 @@
     opt.output->required = NO;
     opt.output->label = _("Name for output file");
     opt.output->description = _("If not given or '-' then standard output");
+    opt.output->guisection = _("Print");
 
     flag.regex = G_define_flag();
     flag.regex->key = 'r';
@@ -159,10 +162,6 @@
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
-    if ((flag.pretty->answer || flag.full->answer) && opt.output->answer)
-        G_fatal_error(_("-%c/-%c and %s= are mutually exclusive"),
-		      flag.pretty->key, flag.full->key, opt.output->key);
-
     if ((flag.pretty->answer || flag.full->answer) && opt.region->answer)
         G_fatal_error(_("-%c/-%c and %s= are mutually exclusive"),
 		      flag.pretty->key, flag.full->key, opt.region->key);
@@ -264,6 +263,8 @@
     }
 
     if (opt.mapset->answers && opt.mapset->answers[0]) {
+	const char *mapset;
+
 	G_create_alt_search_path();
 	for (i = 0; (mapset = opt.mapset->answers[i]); i++) {
 	    if (strcmp(mapset, "*") == 0) {
@@ -283,13 +284,17 @@
 	}
     }
 
-    if (flag.pretty->answer || flag.full->answer) {
+    use_pager = !opt.output->answer || !opt.output->answer[0] ||
+		strcmp(opt.output->answer, "-") == 0;
+
+    if (use_pager)
 	fp = G_open_pager(&pager);
-	dup2(fileno(fp), STDOUT_FILENO);
-    }
     else
 	fp = G_open_option_file(opt.output);
 
+    if (flag.pretty->answer || flag.full->answer)
+	dup2(fileno(fp), STDOUT_FILENO);
+
     for (i = 0; i < num_types; i++) {
 	const struct list *elem;
 
@@ -303,29 +308,42 @@
 
 	    G_debug(3, "lister CMD: %s", lister);
 
-	    if (access(lister, X_OK) == 0)	/* execute permission? */
-		G_spawn(lister, lister, mapset, NULL);
-	    else
+	    if (access(lister, X_OK) == 0) {	/* execute permission? */
+		const char **args;
+		const char *mapset;
+
+		for (j = 0; (mapset = G_get_mapset_name(j)); j++);
+		args = (const char **)G_calloc(j + 2, sizeof(char *));
+
+		args[0] = lister;
+		for (j = 0; (mapset = G_get_mapset_name(j)); j++)
+		    args[j + 1] = mapset;
+		args[j + 1] = NULL;
+
+		G_vspawn_ex(lister, args);
+	    } else
 		M_do_list(n, "");
 	}
 	else if (flag.pretty->answer)
 	    M_do_list(n, "");
 	else {
+	    const char *mapset;
+
 	    for (j = 0; (mapset = G_get_mapset_name(j)); j++)
 		make_list(fp, elem, mapset, separator, flag.type->answer,
 			  flag.mapset->answer, use_region ? &window : NULL);
 	}
     }
 
-    if (flag.pretty->answer || flag.full->answer) {
+    if (flag.pretty->answer || flag.full->answer)
 	fclose(stdout);
+    else if (any)
+	fprintf(fp, "\n");
+
+    if (use_pager)
 	G_close_pager(&pager);
-    }
-    else {
-	if (any)
-	    fprintf(fp, "\n");
+    else
 	G_close_option_file(fp);
-    }
 
     if (filter)
 	G_free_ls_filter(filter);
@@ -363,8 +381,6 @@
 	type = TYPE_RAST3D;
     else if (strcmp(alias, "vect") == 0)
 	type = TYPE_VECT;
-    else if (strcmp(alias, "3dview") == 0)
-	type = TYPE_3DVIEW;
     else
 	type = TYPE_OTHERS;
 
@@ -431,8 +447,6 @@
     RASTER3D_Region region3d;
     struct Map_info Map;
     struct bound_box box;
-    int ret;
-    struct G_3dview view3d;
 
     switch (type) {
     case TYPE_RAST:
@@ -460,23 +474,6 @@
 	map_window.east = box.E;
 	has_region = 1;
 	break;
-    case TYPE_3DVIEW:
-	if ((ret = G_get_3dview(name, mapset, &view3d)) < 0)
-	    G_fatal_error(_("Unable to read 3dview file <%s@%s>"),
-			  name, mapset);
-	if (ret == 0) {
-	    G_warning(_("No region support in an old 3dview file <%s@%s>. Listing anyway"),
-		      name, mapset);
-	    has_region = 0;
-	}
-	else {
-	    map_window.north = view3d.vwin.north;
-	    map_window.south = view3d.vwin.south;
-	    map_window.west = view3d.vwin.west;
-	    map_window.east = view3d.vwin.east;
-	    has_region = 1;
-	}
-	break;
     default:
 	has_region = 0;
 	break;

Modified: grass/branches/releasebranch_7_0/general/g.remove/Makefile
===================================================================
--- grass/branches/releasebranch_7_0/general/g.mremove/Makefile	2014-10-26 20:28:00 UTC (rev 62392)
+++ grass/branches/releasebranch_7_0/general/g.remove/Makefile	2014-10-27 00:17:35 UTC (rev 62396)
@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../..
 
-PGM = g.mremove
+PGM = g.remove
 
 LIBES = $(MANAGELIB) $(RASTERLIB) $(GISLIB)
 DEPENDENCIES = $(MANAGEDEP) $(RASTERDEP) $(GISDEP)

Deleted: grass/branches/releasebranch_7_0/general/g.remove/g.mremove.html
===================================================================
--- grass/branches/releasebranch_7_0/general/g.mremove/g.mremove.html	2014-10-26 20:28:00 UTC (rev 62392)
+++ grass/branches/releasebranch_7_0/general/g.remove/g.mremove.html	2014-10-27 00:17:35 UTC (rev 62396)
@@ -1,38 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>g.mremove</em> removes data files matching a pattern given by wildcards or
-POSIX Extended Regular Expressions. If the <b>-f</b> force flag is not given
-then nothing is removed, instead the list of selected file names is printed to
-<tt>stdout</tt> as a preview of the files to be deleted.
-
-<h2>EXAMPLES</h2>
-
-Delete all raster maps starting with "<tt>tmp_</tt>" in the current mapset:
-
-<div class="code"><pre>
-# show matching raster maps but do not delete yet (as verification)
-g.mremove type=rast pattern="tmp_*"
-
-# actually delete the matching raster maps
-g.mremove -f type=rast pattern="tmp_*"
-</pre></div>
-
-Delete all raster maps starting with "<tt>stream_</tt>" in the current mapset,
-but exclude those ending with "<tt>_final</tt>":
-<div class="code"><pre>
-g.mremove -f type=rast pattern="stream_*" exclude="*_final"
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="g.remove.html">g.remove</a>
-</em>
-
-<h2>AUTHOR</h2>
-
-Huidae Cho<br>
-grass4u at gmail.com
-
-<p>
-<i>Last changed: $Date$</i>

Copied: grass/branches/releasebranch_7_0/general/g.remove/g.remove.html (from rev 62392, grass/branches/releasebranch_7_0/general/g.mremove/g.mremove.html)
===================================================================
--- grass/branches/releasebranch_7_0/general/g.remove/g.remove.html	                        (rev 0)
+++ grass/branches/releasebranch_7_0/general/g.remove/g.remove.html	2014-10-27 00:17:35 UTC (rev 62396)
@@ -0,0 +1,38 @@
+<h2>DESCRIPTION</h2>
+
+<em>g.remove</em> removes data files matching a pattern given by wildcards or
+POSIX Extended Regular Expressions. The <b>pattern</b> option can also take a
+list of map names separated by a comma. If the <b>-f</b> force flag is not
+given then nothing is removed, instead the list of selected file names is
+printed to <tt>stdout</tt> as a preview of the files to be deleted.
+
+<h2>EXAMPLES</h2>
+
+Delete <tt>map1</tt> and <tt>map2</tt> raster maps in the current mapset:
+<div class="code"><pre>
+g.remove -f type=rast pattern=tmp1,tmp2
+</pre></div>
+
+Delete all raster and vector maps starting with "<tt>tmp_</tt>" in the current
+mapset:
+<div class="code"><pre>
+# show matching raster and vector maps but do not delete yet (as verification)
+g.remove type=rast,vect pattern="tmp_*"
+
+# actually delete the matching raster and vector maps
+g.remove -f type=rast,vect pattern="tmp_*"
+</pre></div>
+
+Delete all vector maps starting with "<tt>stream_</tt>" in the current mapset,
+but exclude those ending with "<tt>_final</tt>":
+<div class="code"><pre>
+g.remove -f type=vect pattern="stream_*" exclude="*_final"
+</pre></div>
+
+<h2>AUTHOR</h2>
+
+Huidae Cho<br>
+grass4u at gmail.com
+
+<p>
+<i>Last changed: $Date$</i>

Modified: grass/branches/releasebranch_7_0/general/g.remove/main.c
===================================================================
--- grass/branches/releasebranch_7_0/general/g.mremove/main.c	2014-10-26 20:28:00 UTC (rev 62392)
+++ grass/branches/releasebranch_7_0/general/g.remove/main.c	2014-10-27 00:17:35 UTC (rev 62396)
@@ -1,7 +1,7 @@
 
 /****************************************************************************
  *
- * MODULE:       g.mremove
+ * MODULE:       g.remove
  *
  * AUTHOR(S):    Huidae Cho <grass4u gmail.com>
  *
@@ -9,13 +9,12 @@
  *               CERL (original contributor),
  *               Radim Blazek <radim.blazek gmail.com>,
  *               Cedric Shock <cedricgrass shockfamily.net>,
- *               Huidae Cho <grass4u gmail.com>,
  *               Glynn Clements <glynn gclements.plus.com>,
  *               Jachym Cepicky <jachym les-ejk.cz>,
  *               Markus Neteler <neteler itc.it>,
  *               Martin Landa <landa.martin gmail.com>
  *
- * PURPOSE:      lets users remove GRASS database files
+ * PURPOSE:      Lets users remove GRASS database files
  *
  * COPYRIGHT:    (C) 1999-2014 by the GRASS Development Team
  *
@@ -32,6 +31,8 @@
 #include <grass/manage.h>
 #include <grass/glocale.h>
 
+/* construct_pattern.c */
+char *construct_pattern(char **);
 /* check_reclass.c */
 int check_reclass(const char *, const char *, int);
 
@@ -43,6 +44,8 @@
 	struct Option *type;
 	struct Option *pattern;
 	struct Option *exclude;
+	struct Option *names;
+	struct Option *ignore;
     } opt;
     struct
     {
@@ -51,15 +54,16 @@
 	struct Flag *force;
 	struct Flag *basemap;
     } flag;
+    char *pattern, *exclude;
     const char *mapset;
     int result;
     int i, all, num_types, nlist;
-    void *filter, *exclude;
+    void *filter, *exclude_filter;
 
     G_gisinit(argv[0]);
 
     result = EXIT_SUCCESS;
-    
+
     module = G_define_module();
     G_add_keyword(_("general"));
     G_add_keyword(_("map management"));
@@ -74,30 +78,48 @@
     opt.type->multiple = YES;
     opt.type->options = M_get_options(TRUE);
     opt.type->descriptions = M_get_option_desc(TRUE);
+    opt.type->guidependency = "pattern,exclude,names,ignore";
 
+    opt.names = G_define_option();
+    opt.names->key = "names";
+    opt.names->type = TYPE_STRING;
+    opt.names->multiple = YES;
+    opt.names->gisprompt = "old,element,element";
+    opt.names->description = _("File names separated by a comma");
+    opt.names->guisection = _("Names");
+
+    opt.ignore = G_define_option();
+    opt.ignore->key = "ignore";
+    opt.ignore->type = TYPE_STRING;
+    opt.ignore->multiple = YES;
+    opt.ignore->gisprompt = "old,element,element";
+    opt.ignore->description =
+	_("File names to ignore separated by a comma (default: none)");
+    opt.ignore->guisection = _("Names");
+
     opt.pattern = G_define_option();
     opt.pattern->key = "pattern";
     opt.pattern->type = TYPE_STRING;
-    opt.pattern->required = YES;
-    opt.pattern->description = _("Map name search pattern");
+    opt.pattern->description = _("File name search pattern");
     opt.pattern->guisection = _("Pattern");
 
     opt.exclude = G_define_option();
     opt.exclude->key = "exclude";
     opt.exclude->type = TYPE_STRING;
-    opt.exclude->required = NO;
-    opt.exclude->description = _("Map name exclusion pattern (default: none)");
+    opt.exclude->description = _("File name exclusion pattern (default: none)");
     opt.exclude->guisection = _("Pattern");
 
     flag.regex = G_define_flag();
     flag.regex->key = 'r';
     flag.regex->description =
 	_("Use basic regular expressions instead of wildcards");
+    flag.regex->guisection = _("Pattern");
 
     flag.extended = G_define_flag();
     flag.extended->key = 'e';
     flag.extended->description =
 	_("Use extended regular expressions instead of wildcards");
+    flag.extended->guisection = _("Pattern");
 
     flag.force = G_define_flag();
     flag.force->key = 'f';
@@ -107,57 +129,68 @@
     flag.basemap = G_define_flag();
     flag.basemap->key = 'b';
     flag.basemap->description = _("Remove base raster maps");
-    flag.basemap->guisection = _("Raster");
-    
+
+    G_option_exclusive(flag.regex, flag.extended, NULL);
+    G_option_exclusive(opt.pattern, opt.names, NULL);
+    G_option_exclusive(opt.exclude, opt.ignore, NULL);
+    G_option_required(opt.pattern, opt.names, NULL);
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
-    if (flag.regex->answer && flag.extended->answer)
-	G_fatal_error(_("-%c and -%c are mutually exclusive"),
-		      flag.regex->key, flag.extended->key);
+    if (opt.pattern->answer)
+	pattern = opt.pattern->answer;
+    else
+	pattern = construct_pattern(opt.names->answers);
 
-    if (flag.regex->answer || flag.extended->answer)
-	filter = G_ls_regex_filter(opt.pattern->answer, 0,
-				   (int)flag.extended->answer);
+    if (opt.exclude->answer)
+	exclude = opt.exclude->answer;
+    else if (opt.ignore->answer)
+	exclude = construct_pattern(opt.ignore->answers);
+    else
+	exclude = NULL;
+
+    if ((flag.regex->answer || flag.extended->answer) && opt.pattern->answer)
+	filter = G_ls_regex_filter(pattern, 0, (int)flag.extended->answer);
     else {
 	/* handle individual map names */
-	if (strchr(opt.pattern->answer, ',')) {
-	    char *pattern;
+	if (strchr(pattern, ',')) {
+	    char *buf;
 
-	    pattern = (char *)G_malloc(strlen(opt.pattern->answer) + 3);
-	    sprintf(pattern, "{%s}", opt.pattern->answer);
+	    buf = (char *)G_malloc(strlen(pattern) + 3);
+	    sprintf(buf, "{%s}", pattern);
 
-	    filter = G_ls_glob_filter(pattern, 0);
+	    filter = G_ls_glob_filter(buf, 0);
 	}
 	else
-	    filter = G_ls_glob_filter(opt.pattern->answer, 0);
+	    filter = G_ls_glob_filter(pattern, 0);
     }
     if (!filter)
-	G_fatal_error(_("Unable to compile pattern <%s>"), opt.pattern->answer);
+	G_fatal_error(_("Unable to compile pattern <%s>"), pattern);
 
-    if (opt.exclude->answer) {
-	if (flag.regex->answer || flag.extended->answer)
-	    exclude = G_ls_regex_filter(opt.exclude->answer, 1,
-			    		(int)flag.extended->answer);
+    if (exclude) {
+	if ((flag.regex->answer || flag.extended->answer) &&
+	    opt.exclude->answer)
+	    exclude_filter = G_ls_regex_filter(exclude, 1,
+					       (int)flag.extended->answer);
 	else {
 	    /* handle individual map names */
-	    if (strchr(opt.exclude->answer, ',')) {
-		char *pattern;
+	    if (strchr(exclude, ',')) {
+		char *buf;
 
-		pattern = (char *)G_malloc(strlen(opt.exclude->answer) + 3);
-		sprintf(pattern, "{%s}", opt.exclude->answer);
+		buf = (char *)G_malloc(strlen(exclude) + 3);
+		sprintf(buf, "{%s}", exclude);
 
-		exclude = G_ls_glob_filter(pattern, 1);
+		exclude_filter = G_ls_glob_filter(buf, 1);
 	    }
 	    else
-		exclude = G_ls_glob_filter(opt.exclude->answer, 1);
+		exclude_filter = G_ls_glob_filter(exclude, 1);
 	}
-	if (!exclude)
-	    G_fatal_error(_("Unable to compile pattern <%s>"),
-			  opt.exclude->answer);
+	if (!exclude_filter)
+	    G_fatal_error(_("Unable to compile pattern <%s>"), exclude);
     }
     else
-	exclude = NULL;
+	exclude_filter = NULL;
 
     if (!flag.force->answer)
 	G_message(_("The following data base element files would be deleted:"));
@@ -192,16 +225,16 @@
 
 	rast = !G_strcasecmp(elem->alias, "rast");
 	files = G__ls(path, &num_files);
-	
+
 	for (j = 0; j < num_files; j++) {
 	    if (!flag.force->answer) {
 		fprintf(stdout, "%s/%s@%s\n", elem->alias, files[j], mapset);
 		continue;
 	    }
-	    
+
 	    if (rast && check_reclass(files[j], mapset, flag.basemap->answer))
 		continue;
-	    
+
 	    if (M_do_remove(n, (char *)files[j]) == 1)
 		result = EXIT_FAILURE;
 	}
@@ -209,8 +242,8 @@
 
     G_free_ls_filter(filter);
 
-    if (exclude)
-	G_free_ls_filter(exclude);
+    if (exclude_filter)
+	G_free_ls_filter(exclude_filter);
 
     if (!flag.force->answer)
 	G_important_message(_("You must use the force flag (-%c) to actually "



More information about the grass-commit mailing list