ソースを参照

Replace old g.list/g.remove with g.mlist/g.mremove

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@62396 15284696-431f-4ddb-bdfa-cd5b030d7da7
Huidae Cho 10 年 前
コミット
3d25ab74bf

+ 0 - 2
general/Makefile

@@ -16,8 +16,6 @@ SUBDIRS = \
 	g.mapsets \
 	g.message \
 	g.mkfontcap \
-	g.mlist \
-	g.mremove \
 	g.parser \
 	g.pnmcomp \
 	g.ppmtopng \

+ 0 - 12
general/g.list.old/Makefile

@@ -1,12 +0,0 @@
-
-MODULE_TOPDIR = ../..
-
-PGM = g.list
-
-include $(MODULE_TOPDIR)/include/Make/Module.make
-
-LIBES = $(MANAGELIB) $(GISLIB)
-DEPENDENCIES = $(MANAGEDEP) $(GISDEP)
-
-default: cmd
-

+ 0 - 62
general/g.list.old/g.list.html

@@ -1,62 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>g.list</em> allows the user to list user-specified, available and
-accessible files from <em>mapsets</em> under the user's current
-location.
-
-
-<h2>NOTES</h2>
-
-If unspecified, files of the specified <b>type</b> from all mapsets in
-the user's current search path will be listed to standard output. To
-find out which mapsets are in the current search path, use
-<em><a href="g.mapsets.html">g.mapsets</a></em> with the <b>-p</b>
-flag.
-
-<p>
-If the <b>mapset</b> option is set to &quot;.&quot; then only files
-from the current mapset will be displayed.
-
-<p>
-If the user requests that files from a mapset to which access has been
-restricted (see <em><a href="g.access.html">g.access</a></em>) be
-listed, no files from this mapset will be listed.
-
-
-<h2>EXAMPLES</h2>
-
-List all raster maps:
-
-<div class="code"><pre>
-   g.list type=rast
-</pre></div>
-
-<p>
-List all raster and vector maps from mapset &quot;user&quot;:
-
-<div class="code"><pre>
-   g.list type=rast,vect mapset=user
-</pre></div>
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="g.access.html">g.access</a>,
-<a href="g.mapsets.html">g.mapsets</a>,
-<a href="g.mlist.html">g.mlist</a>,
-<a href="i.group.html">i.group</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>
-
-
-<h2>AUTHOR</h2>
-
-Michael Shapiro,
-U.S.Army Construction Engineering 
-Research Laboratory
-
-<p>
-<i>Last changed: $Date$</i>

+ 0 - 96
general/g.list.old/main.c

@@ -1,96 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       g.list
- *               
- * AUTHOR(S):    Michael Shapiro,
- *               U.S.Army Construction Engineering Research Laboratory
- *               Some updates by various authors from GRASS Development Team
- *               
- * PURPOSE:      Lists available GRASS data base elements of the user-specified data type to
- *               standard output
- *
- * COPYRIGHT:    (C) 1999-2009, 2011 by the GRASS Development Team
- *
- *               This program is free software under the GNU General
- *               Public License (>=v2). Read the file COPYING that
- *               comes with GRASS for details.
- *
- *****************************************************************************/
-
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <grass/gis.h>
-#include <grass/spawn.h>
-#include <grass/glocale.h>
-#include <grass/manage.h>
-
-struct Option *element;
-
-int main(int argc, char *argv[])
-{
-    int i, n, nlist;
-    struct GModule *module;
-    struct Option *mapset_opt;
-    struct Flag *full;
-    const char *mapset;
-
-    G_gisinit(argv[0]);
-
-    M_read_list(0, &nlist);
-
-    module = G_define_module();
-    G_add_keyword(_("general"));
-    G_add_keyword(_("map management"));
-    G_add_keyword(_("list"));
-    module->description =
-	_("Lists available GRASS data base files "
-	  "of the user-specified data type.");
-
-    element = G_define_standard_option(G_OPT_M_DATATYPE);
-    element->options = M_get_options(TRUE);
-    element->descriptions = M_get_option_desc(TRUE);
-    
-    mapset_opt = G_define_standard_option(G_OPT_M_MAPSET);
-    
-    full = G_define_flag();
-    full->key = 'f';
-    full->description = _("Verbose listing (also list map titles)");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    mapset = mapset_opt->answer;
-    if (!mapset)
-	mapset = "";
-
-    if (strcmp(mapset, ".") == 0)
-	mapset = G_mapset();
-
-    i = 0;
-    while (element->answers[i]) {
-	n = M_get_element(element->answers[i]);
-
-	if (full->answer) {
-	    char lister[GPATH_MAX];
-	    
-	    if (n > -1) {
-		sprintf(lister, "%s/etc/lister/%s", G_gisbase(),
-			M_get_list(n)->element[0]);
-		G_debug(3, "lister CMD: %s", lister);
-	    }
-	    if (n > -1 && access(lister, X_OK) == 0) /* execute permission */
-		G_spawn(lister, lister, mapset, NULL);
-	    else
-		M_do_list(n, mapset);
-	}
-	else {
-	    M_do_list(n, mapset);
-	}
-
-	i++;
-    }
-
-    exit(EXIT_SUCCESS);
-}

+ 1 - 1
general/g.mlist/Makefile

@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../..
 
-PGM = g.mlist
+PGM = g.list
 
 LIBES = $(MANAGELIB) $(GISLIB) $(RASTERLIB) $(RASTER3DLIB) $(VECTORLIB)
 DEPENDENCIES = $(MANAGEDEP) $(GISDEP) $(RASTERDEP) $(RASTER3DDEP) $(VECTORDEP)

+ 25 - 31
general/g.mlist/g.mlist.html

@@ -1,16 +1,11 @@
 <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.
+<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.mlist</em> may be useful for other programs' parameter
+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>.
 
@@ -18,23 +13,23 @@ when used with <em>separator=comma</em>.
 
 List all available GRASS data base files:
 <div class="code"><pre>
-g.mlist type=all
+g.list type=all
 </pre></div>
 
 List all raster and vector maps:
 <div class="code"><pre>
-g.mlist type=rast,vect
+g.list type=rast,vect
 </pre></div>
 
 <h3>Mapset search path</h3>
 
-If <b>mapset</b> is not specified than <em>g.mlist</em> searches for
+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.mlist rast
+g.list rast
 
 raster map(s) available in mapset &lt;user1&gt;:
 dmt
@@ -48,7 +43,7 @@ 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=.
+g.list rast mapset=.
 raster map(s) available in mapset &lt;user1&gt;:
 dmt
 </pre></div>
@@ -58,7 +53,7 @@ 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=*
+g.list rast mapset=*
 
 raster map(s) available in mapset &lt;landsat&gt;:
 lsat5_1987_10
@@ -75,41 +70,41 @@ aspect
 
 List all vector maps starting with letter "r":
 <div class="code"><pre>
-g.mlist type=vect pattern="r*"
+g.list 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]*"
+g.list 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}_*"
+g.list 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"
+g.list 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
+  g.list rast pat="r*" mapset=PERMANENT
   railroads
   roads
   rstrct.areas
   rushmore
 
 # exclude only complete word(s):
-  g.mlist rast pat="r*" exclude=roads mapset=PERMANENT
+  g.list rast pat="r*" exclude=roads mapset=PERMANENT
   railroads
   rstrct.areas
   rushmore
 
 # exclude with wildcard:
-  g.mlist rast pat="r*" exclude="*roads*" mapset=PERMANENT
+  g.list rast pat="r*" exclude="*roads*" mapset=PERMANENT
   rstrct.areas
   rushmore
 </pre></div>
@@ -118,31 +113,31 @@ Use of <b>exclude</b> parameter:
 
 List all soil maps starting with &quot;soils&quot; in their name:
 <div class="code"><pre>
-g.mlist -r type=rast pattern='^soils'
+g.list -r type=rast pattern='^soils'
 </pre></div>
 
 List &quot;tmp&quot; if &quot;tmp&quot; raster map exists:
 <div class="code"><pre>
-g.mlist -r type=rast pattern='^tmp$'
+g.list -r type=rast pattern='^tmp$'
 </pre></div>
 
 List &quot;tmp0&quot; ...&quot;tmp9&quot; if corresponding vector map exists
 (each map name linewise):
 <div class="code"><pre>
-g.mlist -r type=vect pattern='^tmp[0-9]$'
+g.list -r type=vect pattern='^tmp[0-9]$'
 </pre></div>
 
 List &quot;tmp0&quot;...&quot;tmp9&quot; 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]$'
+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.mlist -e type=rast separator=comma pattern="precip_total.(199[7-9]|200[0-9]|201[0-2]).sum"
+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>
@@ -151,29 +146,28 @@ List all raster maps starting with &quot;tmp_&quot; whose region overlaps with
 the region of &quot;test&quot; raster map:
 <div class="code"><pre>
 g.region rast=test save=test_region
-g.mlist type=rast pattern='tmp_*' region=test_region
+g.list type=rast pattern='tmp_*' region=test_region
 </pre></div>
 
 List &quot;tmp0&quot;...&quot;tmp9&quot; vector maps whose region overlaps with
 the current region:
 <div class="code"><pre>
-g.mlist -r type=vect pattern='^tmp[0-9]$' region=.
+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.mlist type=rast,vect region=*
+g.list type=rast,vect region=*
 </pre></div>
 
-Note that, without <tt>region=*</tt>, <tt>g.mlist type=rast,vect</tt> simply
+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="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>,

+ 38 - 41
general/g.mlist/main.c

@@ -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 @@ enum {
     TYPE_RAST,
     TYPE_RAST3D,
     TYPE_VECT,
-    TYPE_3DVIEW,
     TYPE_OTHERS
 };
 
@@ -67,9 +66,8 @@ int main(int argc, char *argv[])
     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 @@ int main(int argc, char *argv[])
     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 @@ int main(int argc, char *argv[])
     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 @@ int main(int argc, char *argv[])
 	_("'.' 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 @@ int main(int argc, char *argv[])
     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 @@ int main(int argc, char *argv[])
     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 @@ int main(int argc, char *argv[])
     }
 
     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 @@ int main(int argc, char *argv[])
 	}
     }
 
-    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 @@ int main(int argc, char *argv[])
 
 	    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 @@ static void make_list(FILE *fp, const struct list *elem, const char *mapset,
 	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 @@ static int region_overlaps(struct Cell_head *window, const char *name,
     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 @@ static int region_overlaps(struct Cell_head *window, const char *name,
 	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;

+ 0 - 38
general/g.mremove/g.mremove.html

@@ -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@gmail.com
-
-<p>
-<i>Last changed: $Date$</i>

+ 0 - 12
general/g.remove.old/Makefile

@@ -1,12 +0,0 @@
-
-MODULE_TOPDIR = ../..
-
-PGM = g.remove
-
-include $(MODULE_TOPDIR)/include/Make/Module.make
-
-LIBES = $(MANAGELIB) $(RASTERLIB) $(GISLIB)
-DEPENDENCIES = $(MANAGEDEP) $(RASTERDEP) $(GISDEP)
-
-default: cmd
-

+ 0 - 58
general/g.remove.old/g.remove.html

@@ -1,58 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>g.remove</em> allows the user to remove specified data
-base element files from the current mapset.  
-
-<h2>EXAMPLE</h2>
-
-For example, the below command will cause the raster maps
-named <em>soils</em>, <em>slope</em>, and <em>temp</em>,
-the vector maps named <em>roads</em> and <em>rail</em>,
-and the
-
-
-<a href="i.group.html">imagery</a> group files
-
-named <em>nhap.1</em> and <em>nhap.2</em>, and these files'
-associated support files (e.g., cell header files, category
-files, etc.), to be removed from the user's current
-mapset.
-
-<div class="code"><pre>
-g.remove rast=soils,slope,temp vect=roads,rail group=nhap.1,nhap.2
-</pre></div>
-
-<h2>NOTE</h2>
-
-If a particular data base element file has support files
-associated with it (e.g., as is commonly the case with
-raster maps), <em>g.remove</em> will remove these support
-files along with the data base element file specified.
-
-<p>
-The user can only use <em>g.remove</em> to remove data
-files existing under the user's <em>current mapset</em>.
-
-<p> 
-To remove multiple files, the script <em>g.mremove</em> may be used.
-
-<h2>FILES</h2>
-
-<kbd>$GISBASE/etc/element_list</kbd> lists the element 
-types whose files can be removed by the user.
-
-<h2>SEE ALSO</h2>
-
-<em><a href="g.copy.html">g.copy</a></em><br>
-<em><a href="g.list.html">g.list</a></em><br>
-
-<em><a href="g.rename.html">g.rename</a></em><br>
-<em>g.mremove</em> 
-
-<h2>AUTHOR</h2>
-
-Michael Shapiro,
-U.S.Army Construction Engineering 
-Research Laboratory
-
-<p><i>Last changed: $Date$</i>

+ 0 - 136
general/g.remove.old/main.c

@@ -1,136 +0,0 @@
-\
-/****************************************************************************
- *
- * MODULE:       g.remove
- * AUTHOR(S):    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
- * COPYRIGHT:    (C) 1999-2007, 2011 by the GRASS Development Team
- *
- *               This program is free software under the GNU General Public
- *               License (>=v2). Read the file COPYING that comes with GRASS
- *               for details.
- *
- *****************************************************************************/
-#include <stdlib.h>
-#include <string.h>
-
-#include <grass/raster.h>
-#include <grass/glocale.h>
-#include <grass/manage.h>
-
-static int check_reclass(const char *name, const char *mapset, int force)
-{
-    char rname[GNAME_MAX], rmapset[GMAPSET_MAX];
-    char **rmaps;
-    int nrmaps;
-
-    if (Rast_is_reclassed_to(name, mapset, &nrmaps, &rmaps) > 0) {
-	for (; *rmaps; rmaps++) {
-	    /* force remove */
-	    if (force)
-		G_warning(_("Raster map <%s@%s> is a base map for <%s>. Remove forced."),
-			  name, mapset, *rmaps);
-	    else
-		G_warning(_("Raster <%s@%s> is a base map. Remove reclassed map <%s> first."),
-			  name, mapset, *rmaps);
-	}
-
-	if (!force)
-	    return 1;
-    }
-
-    if (Rast_is_reclass(name, mapset, rname, rmapset) > 0 &&
-	Rast_is_reclassed_to(rname, rmapset, &nrmaps, &rmaps) > 0) {
-	char path[GPATH_MAX];
-	char *p = strchr(rname, '@');
-	char *qname = G_fully_qualified_name(name, mapset);
-
-	if (p)
-	    *p = '\0';
-
-	G_file_name_misc(path, "cell_misc", "reclassed_to", rname, rmapset);
-
-	if (nrmaps == 1 && !G_strcasecmp(rmaps[0], qname)) {
-
-	    if (remove(path) < 0)
-		G_warning(_("Removing information about reclassed map from <%s@%s> failed"),
-			  rname, rmapset);
-	}
-	else {
-	    FILE *fp = fopen(path, "w");
-
-	    if (fp) {
-		for (; *rmaps; rmaps++)
-		    if (G_strcasecmp(*rmaps, qname))
-			fprintf(fp, "%s\n", *rmaps);
-		fclose(fp);
-	    }
-	    else
-		G_warning(_("Removing information about reclassed map from <%s@%s> failed"),
-			  rname, rmapset);
-
-	}
-    }
-
-    return 0;
-}
-
-int main(int argc, char *argv[])
-{
-    int i, n, nlist;
-    struct GModule *module;
-    struct Option **parm;
-    struct Flag *force_flag;
-    const char *name, *mapset;
-    int result;
-
-    G_gisinit(argv[0]);
-
-    result = EXIT_SUCCESS;
-    
-    M_read_list(FALSE, &nlist);
-
-    module = G_define_module();
-    G_add_keyword(_("general"));
-    G_add_keyword(_("map management"));
-    G_add_keyword(_("remove"));
-    module->description =
-	_("Removes data base element files from "
-	  "the user's current mapset.");
-
-    force_flag = G_define_flag();
-    force_flag->key = 'f';
-    force_flag->description = _("Force removal for base raster maps");
-
-    parm = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
-
-    for (n = 0; n < nlist; n++) {
-	parm[n] = M_define_option(n, "removed", YES);
-    }
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    mapset = G_mapset();
-
-    for (n = 0; n < nlist; n++) {
-	if (parm[n]->answers)
-	    for (i = 0; (name = parm[n]->answers[i]); i++) {
-		if (G_strcasecmp(M_get_list(n)->alias, "rast") == 0 &&
-		    check_reclass(name, mapset, force_flag->answer))
-		    continue;
-
-		if (M_do_remove(n, name) == 1) {
-		    result = EXIT_FAILURE;
-		}
-	    }
-    }
-    exit(result);
-}

+ 1 - 1
general/g.mremove/Makefile

@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../..
 
-PGM = g.mremove
+PGM = g.remove
 
 LIBES = $(MANAGELIB) $(RASTERLIB) $(GISLIB)
 DEPENDENCIES = $(MANAGEDEP) $(RASTERDEP) $(GISDEP)

general/g.mremove/check_reclass.c → general/g.remove/check_reclass.c


+ 38 - 0
general/g.remove/g.remove.html

@@ -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@gmail.com
+
+<p>
+<i>Last changed: $Date$</i>

+ 76 - 43
general/g.mremove/main.c

@@ -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 @@ int main(int argc, char *argv[])
 	struct Option *type;
 	struct Option *pattern;
 	struct Option *exclude;
+	struct Option *names;
+	struct Option *ignore;
     } opt;
     struct
     {
@@ -51,15 +54,16 @@ int main(int argc, char *argv[])
 	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 @@ int main(int argc, char *argv[])
     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 @@ int main(int argc, char *argv[])
     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 (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)
-	filter = G_ls_regex_filter(opt.pattern->answer, 0,
-				   (int)flag.extended->answer);
+    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 @@ int main(int argc, char *argv[])
 
 	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 @@ int main(int argc, char *argv[])
 
     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 "