[GRASS-SVN] r34417 - in grass/trunk/general: . g.copy g.list
g.remove g.rename manage
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Nov 20 17:48:50 EST 2008
Author: glynn
Date: 2008-11-20 17:48:50 -0500 (Thu, 20 Nov 2008)
New Revision: 34417
Added:
grass/trunk/general/g.copy/
grass/trunk/general/g.copy/Makefile
grass/trunk/general/g.copy/copy.c
grass/trunk/general/g.copy/g.copy.html
grass/trunk/general/g.list/
grass/trunk/general/g.list/Makefile
grass/trunk/general/g.list/g.list.html
grass/trunk/general/g.list/list.c
grass/trunk/general/g.remove/
grass/trunk/general/g.remove/Makefile
grass/trunk/general/g.remove/g.remove.html
grass/trunk/general/g.remove/remove.c
grass/trunk/general/g.rename/
grass/trunk/general/g.rename/Makefile
grass/trunk/general/g.rename/g.rename.html
grass/trunk/general/g.rename/rename.c
Removed:
grass/trunk/general/manage/cmd/
Modified:
grass/trunk/general/Makefile
grass/trunk/general/manage/Makefile
Log:
Split general/manage/cmd into separate modules
Modified: grass/trunk/general/Makefile
===================================================================
--- grass/trunk/general/Makefile 2008-11-20 22:37:21 UTC (rev 34416)
+++ grass/trunk/general/Makefile 2008-11-20 22:48:50 UTC (rev 34417)
@@ -3,12 +3,14 @@
SUBDIRS = \
g.access \
+ g.copy \
g.dirseps \
g.filename \
g.findetc \
g.findfile \
g.gisenv \
g.gui \
+ g.list \
g.mapset \
g.mapsets \
g.message \
@@ -16,9 +18,11 @@
g.mlist \
g.mremove \
g.parser \
+ g.pnmcomp \
g.proj \
- g.pnmcomp \
g.region \
+ g.remove \
+ g.rename \
g.tempfile \
g.transform \
g.version \
Property changes on: grass/trunk/general/g.copy
___________________________________________________________________
Name: svn:ignore
+ *OBJ*
Added: grass/trunk/general/g.copy/Makefile
===================================================================
--- grass/trunk/general/g.copy/Makefile (rev 0)
+++ grass/trunk/general/g.copy/Makefile 2008-11-20 22:48:50 UTC (rev 34417)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+PGM = g.copy
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+LIBES = $(MANAGELIB) $(VECTLIB) $(DBMILIB) $(GISLIB) $(G3DLIB)
+DEPENDENCIES = $(GISDEP) $(VECTDEP) $(DBMIDEP) $(MANAGEDEP) $(G3DDEP)
+
+default: cmd
+
Copied: grass/trunk/general/g.copy/copy.c (from rev 34416, grass/trunk/general/manage/cmd/copy.c)
===================================================================
--- grass/trunk/general/g.copy/copy.c (rev 0)
+++ grass/trunk/general/g.copy/copy.c 2008-11-20 22:48:50 UTC (rev 34417)
@@ -0,0 +1,100 @@
+
+/****************************************************************************
+ *
+ * MODULE: cmd
+ * 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>,
+ * Markus Neteler <neteler itc.it>,
+ * Martin Landa <landa.martin gmail.com>
+ * PURPOSE: lets users copy database files
+ * COPYRIGHT: (C) 2003-2007 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/glocale.h>
+#include <grass/list.h>
+
+int main(int argc, char *argv[])
+{
+ int i, n;
+ char *mapset;
+ struct GModule *module;
+ struct Option **parm, *p;
+ char *from, *to;
+ int result = EXIT_SUCCESS;
+
+ G_gisinit(argv[0]);
+
+ read_list(0);
+
+ module = G_define_module();
+ module->keywords = _("general, map management");
+ module->description =
+ _("Copies available data files in the user's current mapset "
+ "search path and location to the appropriate element "
+ "directories under the user's current mapset.");
+
+ parm = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
+
+ for (n = 0; n < nlist; n++) {
+ char *str;
+
+ p = parm[n] = G_define_option();
+ p->key = list[n].alias;
+ p->key_desc = "from,to";
+ p->type = TYPE_STRING;
+ p->required = NO;
+ p->multiple = NO;
+ G_asprintf(&str, "old,%s,%s", list[n].mainelem, list[n].maindesc);
+ p->gisprompt = str;
+ G_asprintf(&str, _("%s file(s) to be copied"), list[n].alias);
+ p->description = str;
+ }
+
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+
+ for (n = 0; n < nlist; n++) {
+ if (parm[n]->answers == NULL)
+ continue;
+ i = 0;
+ while (parm[n]->answers[i]) {
+ from = parm[n]->answers[i++];
+ to = parm[n]->answers[i++];
+ mapset = find(n, from, "");
+ if (!mapset) {
+ G_warning(_("<%s> not found"), from);
+ continue;
+ }
+ if (G_strcasecmp(mapset, G_mapset()) == 0 &&
+ G_strcasecmp(from, to) == 0) {
+ G_warning(_("%s=%s,%s: files are the same, no copy required"),
+ parm[n]->key, from, to);
+ continue;
+ }
+ if (find(n, to, G_mapset()) && !(module->overwrite)) {
+ G_warning(_("<%s> already exists"), to);
+ continue;
+ }
+ if (G_legal_filename(to) < 0) {
+ G_warning(_("<%s> is an illegal file name"), to);
+ continue;
+ }
+ if (do_copy(n, from, mapset, to) == 1) {
+ result = EXIT_FAILURE;
+ }
+ G_remove_misc("cell_misc", "reclassed_to", to);
+ }
+ }
+
+ exit(result);
+}
Property changes on: grass/trunk/general/g.copy/copy.c
___________________________________________________________________
Name: svn:mime-type
+ text/x-csrc
Name: svn:keywords
+ Author Date Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: grass/trunk/general/g.copy/g.copy.html (from rev 34410, grass/trunk/general/manage/cmd/g.copy.html)
===================================================================
--- grass/trunk/general/g.copy/g.copy.html (rev 0)
+++ grass/trunk/general/g.copy/g.copy.html 2008-11-20 22:48:50 UTC (rev 34417)
@@ -0,0 +1,83 @@
+<h2>DESCRIPTION</h2>
+
+A user may access data stored under the other mapsets
+listed in his mapset search path. However, the user may
+only modify data stored under his own current mapset.
+<em>g.copy</em> allows the user to copy existing data files
+<em>from</em> other mapsets <em>to</em> the user's current
+mapset ($MAPSET). The files to be copied must exist in the
+user's current mapset search path and location; output is
+sent to the relevant data element directory(ies) under the
+user's current mapset.
+
+<h2>EXAMPLES</h2>
+
+If the user wished to copy the existing raster
+file <em>soils</em> to a file called <em>soils.ph</em> and
+to copy an existing vector map <em>roads</em> to a file
+called <em>rds.old</em>, the user could type:
+
+<p>
+
+<div class="code"><pre>
+g.copy rast=soils,soils.ph vect=roads,rds.old
+</pre></div>
+
+<p>
+
+Data files can also be specified by their mapsets. For
+example, the below command copies the raster map named
+<em>soils</em> from the mapset <em>wilson</em> to a new
+file called <em>soils</em> to be placed under the user's
+current mapset:
+
+<p>
+
+<div class="code"><pre>
+g.copy rast='soils at wilson',soils
+</pre></div>
+
+<p>
+
+If no mapset name is specified, <em>g.copy</em> searches
+for the named <em>from</em> map in each of the mapset
+directories listed in the user's current mapset search path
+in the order in which mapsets are listed there (see
+
+<em><a HREF="g.mapsets.html">g.mapsets</a></em>).
+
+<H2>NOTES</H2>
+
+If the user does not enter parameter values but instead
+types only <b>g.copy</b> on the command line the program
+will prompt the user for a data type, the name of a file of
+this data type to copy, and the name of a new file to hold
+the copy. After both file names have been entered, the
+copy is created and the user is again prompted for a data
+element to be copied, until the user hits RETURN. When
+prompted for file names, the user may enter 'list' to see a
+list of existing files, or hit RETURN to end the file
+listing.
+
+<p>
+
+If a file has support files (e.g., as do raster data
+files), these support files will also be copied.
+
+<h2>SEE ALSO</h2>
+
+<em><a HREF="g.access.html">g.access</a></em><br>
+
+<em><a HREF="g.list.html">g.list</a></em><br>
+<em><a HREF="g.mapsets.html">g.mapsets</a></em><br>
+<em><a HREF="g.remove.html">g.remove</a></em><br>
+<em><a HREF="g.rename.html">g.rename</a></em><br>
+<em><a HREF="parser.html">parser</a></em>
+
+<h2>AUTHOR</h2>
+
+Michael Shapiro,
+U.S.Army Construction Engineering
+Research Laboratory
+
+<p><i>Last changed: $Date$</i><p>
Property changes on: grass/trunk/general/g.copy/g.copy.html
___________________________________________________________________
Name: svn:mime-type
+ text/html
Name: svn:keywords
+ Author Date Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Property changes on: grass/trunk/general/g.list
___________________________________________________________________
Name: svn:ignore
+ *OBJ*
Added: grass/trunk/general/g.list/Makefile
===================================================================
--- grass/trunk/general/g.list/Makefile (rev 0)
+++ grass/trunk/general/g.list/Makefile 2008-11-20 22:48:50 UTC (rev 34417)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+PGM = g.list
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+LIBES = $(MANAGELIB) $(VECTLIB) $(DBMILIB) $(GISLIB) $(G3DLIB)
+DEPENDENCIES = $(GISDEP) $(VECTDEP) $(DBMIDEP) $(MANAGEDEP) $(G3DDEP)
+
+default: cmd
+
Copied: grass/trunk/general/g.list/g.list.html (from rev 34410, grass/trunk/general/manage/cmd/g.list.html)
===================================================================
--- grass/trunk/general/g.list/g.list.html (rev 0)
+++ grass/trunk/general/g.list/g.list.html 2008-11-20 22:48:50 UTC (rev 34417)
@@ -0,0 +1,59 @@
+<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>OPTIONS</h2>
+
+When invoked simply as <b>g.list</b>, the program prompts
+the user for the type of data to be listed from all
+<em>mapsets</em> in the user's current mapset search path.
+The user can list files from a mapset not listed in the
+current mapset search path by running the program
+non-interactively, specifying the (optional) flag setting
+and parameter values on the command line. Program flag and
+parameters are described below.
+-->
+
+<h2>EXAMPLES</h2>
+
+List all raster maps:
+<br>
+<tt>g.list type=rast</tt>
+<p>
+
+List all raster and vector maps from mapset "user":
+<br>
+<tt>g.list type=rast,vect mapset=user</tt>
+<p>
+
+<h2>NOTES</h2>
+
+If unspecified, files of the specified <em>type</em> from all mapsets
+in the user's current search path will be listed to standard output. To
+find out which mapsets are in the cuurent search path, use
+<em><a HREF="g.mapsets.html">'g.mapsets</a> -p'</em>.
+
+<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>SEE ALSO</h2>
+
+<em><a HREF="g.access.html">g.access</a></em><br>
+<em><a HREF="g.mapsets.html">g.mapsets</a></em><br>
+<em><a HREF="g.mlist.html">g.mlist</a></em>
+
+<h2>AUTHOR</h2>
+
+Michael Shapiro,
+U.S.Army Construction Engineering
+Research Laboratory
+
+<p><i>Last changed: $Date$</i><p>
Property changes on: grass/trunk/general/g.list/g.list.html
___________________________________________________________________
Name: svn:mime-type
+ text/html
Name: svn:keywords
+ Author Date Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: grass/trunk/general/g.list/list.c (from rev 34416, grass/trunk/general/manage/cmd/list.c)
===================================================================
--- grass/trunk/general/g.list/list.c (rev 0)
+++ grass/trunk/general/g.list/list.c 2008-11-20 22:48:50 UTC (rev 34417)
@@ -0,0 +1,124 @@
+
+/****************************************************************************
+ *
+ * MODULE: g.list
+ *
+ * AUTHOR(S): Michael Shapiro,
+ * U.S.Army Construction Engineering Research Laboratory
+ *
+ * PURPOSE: Lists available GRASS data base files of the
+ * user-specified data type to standard output
+ *
+ * COPYRIGHT: (C) 1999-2007 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/spawn.h>
+#include <grass/list.h>
+
+struct Option *element;
+
+int parse(const char *data_type);
+
+int main(int argc, char *argv[])
+{
+ int i, n, len;
+ struct GModule *module;
+ struct Option *mapset;
+ struct Flag *full;
+ char *str;
+
+ G_gisinit(argv[0]);
+
+ read_list(0);
+
+ module = G_define_module();
+ module->keywords = _("general, map management");
+ module->description =
+ _("Lists available GRASS data base files "
+ "of the user-specified data type to standard output.");
+
+ element = G_define_option();
+ element->key = "type";
+ element->key_desc = "datatype";
+ element->type = TYPE_STRING;
+ element->required = YES;
+ element->multiple = YES;
+ element->description = "Data type";
+ for (len = 0, n = 0; n < nlist; n++)
+ len += strlen(list[n].alias) + 1;
+ str = G_malloc(len);
+
+ for (n = 0; n < nlist; n++) {
+ if (n) {
+ strcat(str, ",");
+ strcat(str, list[n].alias);
+ }
+ else
+ strcpy(str, list[n].alias);
+ }
+ element->options = str;
+
+ mapset = G_define_option();
+ mapset->key = "mapset";
+ mapset->type = TYPE_STRING;
+ mapset->required = NO;
+ mapset->multiple = NO;
+ mapset->description = _("Mapset to list (default: current search path)");
+
+ full = G_define_flag();
+ full->key = 'f';
+ full->description = _("Verbose listing (also list map titles)");
+
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+
+ if (mapset->answer == NULL)
+ mapset->answer = "";
+
+ if (G_strcasecmp(mapset->answer, ".") == 0)
+ mapset->answer = G_mapset();
+
+ i = 0;
+ while (element->answers[i]) {
+ n = parse(element->answers[i]);
+
+ if (full->answer) {
+ char lister[GPATH_MAX];
+
+ sprintf(lister, "%s/etc/lister/%s", G_gisbase(),
+ list[n].element[0]);
+ G_debug(3, "lister CMD: %s", lister);
+ if (access(lister, 1) == 0) /* execute permission? */
+ G_spawn(lister, lister, mapset->answer, NULL);
+ else
+ do_list(n, mapset->answer);
+ }
+ else {
+ do_list(n, mapset->answer);
+ }
+
+ i++;
+ }
+
+ exit(EXIT_SUCCESS);
+}
+
+int parse(const char *data_type)
+{
+ int n;
+
+ for (n = 0; n < nlist; n++) {
+ if (G_strcasecmp(list[n].alias, data_type) == 0)
+ break;
+ }
+
+ return n;
+}
Property changes on: grass/trunk/general/g.list/list.c
___________________________________________________________________
Name: svn:mime-type
+ text/x-csrc
Name: svn:keywords
+ Author Date Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Property changes on: grass/trunk/general/g.remove
___________________________________________________________________
Name: svn:ignore
+ *OBJ*
Added: grass/trunk/general/g.remove/Makefile
===================================================================
--- grass/trunk/general/g.remove/Makefile (rev 0)
+++ grass/trunk/general/g.remove/Makefile 2008-11-20 22:48:50 UTC (rev 34417)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+PGM = g.remove
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+LIBES = $(MANAGELIB) $(VECTLIB) $(DBMILIB) $(GISLIB) $(G3DLIB)
+DEPENDENCIES = $(GISDEP) $(VECTDEP) $(DBMIDEP) $(MANAGEDEP) $(G3DDEP)
+
+default: cmd
+
Copied: grass/trunk/general/g.remove/g.remove.html (from rev 34410, grass/trunk/general/manage/cmd/g.remove.html)
===================================================================
--- grass/trunk/general/g.remove/g.remove.html (rev 0)
+++ grass/trunk/general/g.remove/g.remove.html 2008-11-20 22:48:50 UTC (rev 34417)
@@ -0,0 +1,59 @@
+<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>
Property changes on: grass/trunk/general/g.remove/g.remove.html
___________________________________________________________________
Name: svn:mime-type
+ text/html
Name: svn:keywords
+ Author Date Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: grass/trunk/general/g.remove/remove.c (from rev 34416, grass/trunk/general/manage/cmd/remove.c)
===================================================================
--- grass/trunk/general/g.remove/remove.c (rev 0)
+++ grass/trunk/general/g.remove/remove.c 2008-11-20 22:48:50 UTC (rev 34417)
@@ -0,0 +1,146 @@
+
+/****************************************************************************
+ *
+ * MODULE: cmd
+ * 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 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/glocale.h>
+#include <grass/list.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 (G_is_reclassed_to(name, mapset, &nrmaps, &rmaps) > 0) {
+ for (; *rmaps; rmaps++) {
+ /* force remove */
+ if (force)
+ G_warning(_("[%s@%s] is a base map for [%s]. Remove forced."),
+ name, mapset, *rmaps);
+ else
+ G_warning(_("[%s@%s] is a base map. Remove reclassed map first: %s"),
+ name, mapset, *rmaps);
+ }
+
+ if (!force)
+ return 1;
+ }
+
+ if (G_is_reclass(name, mapset, rname, rmapset) > 0 &&
+ G_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;
+ struct GModule *module;
+ struct Option **parm, *p;
+ struct Flag *force_flag;
+ char *name, *mapset;
+ char *location_path;
+ int result = EXIT_SUCCESS;
+ int force = 0;
+
+ G_gisinit(argv[0]);
+
+ read_list(0);
+
+ module = G_define_module();
+ module->keywords = _("general, map management");
+ 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 remove");
+
+ parm = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
+
+ for (n = 0; n < nlist; n++) {
+ char *str;
+
+ p = parm[n] = G_define_option();
+ p->key = list[n].alias;
+ p->type = TYPE_STRING;
+ p->required = NO;
+ p->multiple = YES;
+ G_asprintf(&str, "old,%s,%s", list[n].mainelem, list[n].maindesc);
+ p->gisprompt = str;
+ G_asprintf(&str, _("%s file(s) to be removed"), list[n].alias);
+ p->description = str;
+ }
+
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+
+ location_path = G_location_path();
+ mapset = G_mapset();
+
+ if (force_flag->answer)
+ force = 1;
+
+ for (n = 0; n < nlist; n++) {
+ if (parm[n]->answers)
+ for (i = 0; (name = parm[n]->answers[i]); i++) {
+ if (G_strcasecmp(list[n].alias, "rast") == 0 &&
+ check_reclass(name, mapset, force))
+ continue;
+
+ if (do_remove(n, name) == 1) {
+ result = EXIT_FAILURE;
+ }
+ }
+ }
+ exit(result);
+}
Property changes on: grass/trunk/general/g.remove/remove.c
___________________________________________________________________
Name: svn:mime-type
+ text/x-csrc
Name: svn:keywords
+ Author Date Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Property changes on: grass/trunk/general/g.rename
___________________________________________________________________
Name: svn:ignore
+ *OBJ*
Added: grass/trunk/general/g.rename/Makefile
===================================================================
--- grass/trunk/general/g.rename/Makefile (rev 0)
+++ grass/trunk/general/g.rename/Makefile 2008-11-20 22:48:50 UTC (rev 34417)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+PGM = g.rename
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+LIBES = $(MANAGELIB) $(VECTLIB) $(DBMILIB) $(GISLIB) $(G3DLIB)
+DEPENDENCIES = $(GISDEP) $(VECTDEP) $(DBMIDEP) $(MANAGEDEP) $(G3DDEP)
+
+default: cmd
+
Copied: grass/trunk/general/g.rename/g.rename.html (from rev 34410, grass/trunk/general/manage/cmd/g.rename.html)
===================================================================
--- grass/trunk/general/g.rename/g.rename.html (rev 0)
+++ grass/trunk/general/g.rename/g.rename.html 2008-11-20 22:48:50 UTC (rev 34417)
@@ -0,0 +1,85 @@
+<h2>DESCRIPTION</h2>
+
+<em>g.rename</em> allows the user to rename data base
+element files in the user's current mapset. The user can
+specify all necessary information to <em>g.rename</em> on
+the command line, by specifying: the type of data base
+element to be renamed (one or more of: <b>rast</b>,
+<b>vect</b>, <b>icon</b>, <b>labels</b>, <b>sites</b>,
+
+<b>region</b>, and <b>group</b>); the specific file element
+in the current mapset to be renamed (<em>old</em>); and the
+new name to be assigned to this file element (<em>new</em>)
+in the current mapset. The file element <em>old</em> is
+then renamed to <em>new</em>.
+
+
+<p>
+
+Users can also simply type <em>g.rename -help</em> without
+arguments on the command line, to receive a menu of
+existing data base element types and files from which to
+choose for possible renaming:
+
+<div class="code">
+<pre>
+ rast rast file(s) to be renamed
+ oldvect oldvect file(s) to be renamed (GRASS 5.0)
+ vect vect file(s) to be renamed (GRASS >5.1)
+ icon icon file(s) to be renamed
+ labels labels file(s) to be renamed
+ sites sites file(s) to be renamed
+ region region file(s) to be renamed
+ group group file(s) to be renamed
+ 3dview 3dview file(s) to be renamed
+</pre></div>
+
+
+<h2>NOTES</h2>
+
+If a data base element has support files (e.g., as is
+commonly the case with raster maps), these support files
+also are renamed.
+
+<p>
+
+If the user attempts to rename a file to itself by setting
+the <em>new</em> file name equal to the <em>old</em> file
+name (e.g., <b>g.rename rast=soils,soils</b>),
+<em>g.rename</em> will not execute the rename, but instead
+state that no rename is needed. However, <em>g.rename</em>
+
+will allow the user to overwrite other existing files in
+the current mapset by making the <em>new</em> file name
+that of an already existing file.
+<p>
+For portability reasons, <em>g.rename</em> is ignoring case of
+names. To change the case of a map name, first rename the map
+to a name which differs by more than case, then rename it to
+the intended name.
+
+<h2>EXAMPLE</h2>
+
+<div class="code"><pre>
+# rename raster map
+g.rename rast=oldrast,newrast
+
+# rename vector map
+g.rename vect=oldvect,newvect
+
+# combined renaming
+g.rename rast=oldrast,newrast vect=oldvect,newvect
+</pre></div>
+<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.remove.html">g.remove</a></em>
+
+<h2>AUTHOR</h2>
+
+Michael Shapiro,
+U.S.Army Construction Engineering
+Research Laboratory
+
+<p><i>Last changed: $Date$</i><p>
Property changes on: grass/trunk/general/g.rename/g.rename.html
___________________________________________________________________
Name: svn:mime-type
+ text/html
Name: svn:keywords
+ Author Date Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: grass/trunk/general/g.rename/rename.c (from rev 34416, grass/trunk/general/manage/cmd/rename.c)
===================================================================
--- grass/trunk/general/g.rename/rename.c (rev 0)
+++ grass/trunk/general/g.rename/rename.c 2008-11-20 22:48:50 UTC (rev 34417)
@@ -0,0 +1,146 @@
+
+/****************************************************************************
+ *
+ * MODULE: g.rename cmd
+ * AUTHOR(S): CERL (original contributor)
+ * Radim Blazek <radim.blazek gmail.com>,
+ * Cedric Shock <cedricgrass shockfamily.net>,
+ * Glynn Clements <glynn gclements.plus.com>,
+ * Markus Neteler <neteler itc.it>,
+ * Martin Landa <landa.martin gmail.com>
+ * PURPOSE:
+ * COPYRIGHT: (C) 1994-2007 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/gis.h>
+#include <grass/glocale.h>
+#include <grass/list.h>
+
+int main(int argc, char *argv[])
+{
+ int i, n;
+ struct GModule *module;
+ struct Option **parm, *p;
+ char *old, *new;
+ int nrmaps;
+ char *mapset, *location_path, **rmaps;
+ int result = EXIT_SUCCESS;
+
+ G_gisinit(argv[0]);
+
+ read_list(0);
+
+ module = G_define_module();
+ module->keywords = _("general, map management");
+ module->description =
+ _("Renames data base element files in the user's current mapset.");
+
+ parm = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
+
+ for (n = 0; n < nlist; n++) {
+ char *str;
+
+ p = parm[n] = G_define_option();
+ p->key = list[n].alias;
+ p->key_desc = "old,new";
+ p->type = TYPE_STRING;
+ p->required = NO;
+ p->multiple = NO;
+ G_asprintf(&str, "old,%s,%s", list[n].mainelem, list[n].maindesc);
+ p->gisprompt = str;
+ G_asprintf(&str, _("%s file(s) to be renamed"), list[n].alias);
+ p->description = str;
+ }
+
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+
+ location_path = G__location_path();
+ mapset = G_mapset();
+
+ for (n = 0; n < nlist; n++) {
+ if (parm[n]->answers == NULL)
+ continue;
+ i = 0;
+ while (parm[n]->answers[i]) {
+ old = parm[n]->answers[i++];
+ new = parm[n]->answers[i++];
+ if (!find(n, old, mapset)) {
+ G_warning(_("%s <%s> not found"), list[n].maindesc, old);
+ continue;
+ }
+ if (find(n, new, "") && !(module->overwrite)) {
+ G_warning(_("<%s> already exists in mapset <%s>"), new,
+ find(n, new, ""));
+ continue;
+ }
+ if (G_legal_filename(new) < 0) {
+ G_warning(_("<%s> is an illegal file name"), new);
+ continue;
+ }
+ if (strcmp(old, new) == 0) {
+ G_warning(_("%s=%s,%s: files are the same, no rename required"),
+ parm[n]->key, old, new);
+ continue;
+ }
+
+ if (G_is_reclassed_to(old, mapset, &nrmaps, &rmaps) > 0) {
+ int ptr, l;
+ char buf1[256], buf2[256], buf3[256], *str;
+ FILE *fp;
+
+ G_message(_("Renaming reclass maps"));
+
+ for (; *rmaps; rmaps++) {
+ G_message(" %s", *rmaps);
+ sprintf(buf3, "%s", *rmaps);
+ if ((str = strchr(buf3, '@'))) {
+ *str = 0;
+ sprintf(buf2, "%s", str + 1);
+ }
+ else {
+ sprintf(buf2, "%s", mapset);
+ }
+ sprintf(buf1, "%s/%s/cellhd/%s", location_path, buf2,
+ buf3);
+
+ fp = fopen(buf1, "r");
+ if (fp == NULL)
+ continue;
+
+ fgets(buf2, 255, fp);
+ fgets(buf2, 255, fp);
+ fgets(buf2, 255, fp);
+
+ ptr = ftell(fp);
+ fseek(fp, 0L, SEEK_END);
+ l = ftell(fp) - ptr;
+
+ str = (char *)G_malloc(l);
+ fseek(fp, ptr, SEEK_SET);
+ fread(str, l, 1, fp);
+ fclose(fp);
+
+ fp = fopen(buf1, "w");
+ fprintf(fp, "reclass\n");
+ fprintf(fp, "name: %s\n", new);
+ fprintf(fp, "mapset: %s\n", mapset);
+ fwrite(str, l, 1, fp);
+ G_free(str);
+ fclose(fp);
+ }
+ }
+ if (do_rename(n, old, new) == 1) {
+ result = EXIT_FAILURE;
+ }
+ }
+ }
+ exit(result);
+}
Property changes on: grass/trunk/general/g.rename/rename.c
___________________________________________________________________
Name: svn:mime-type
+ text/x-csrc
Name: svn:keywords
+ Author Date Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Modified: grass/trunk/general/manage/Makefile
===================================================================
--- grass/trunk/general/manage/Makefile 2008-11-20 22:37:21 UTC (rev 34416)
+++ grass/trunk/general/manage/Makefile 2008-11-20 22:48:50 UTC (rev 34417)
@@ -1,7 +1,7 @@
MODULE_TOPDIR = ../..
-SUBDIRS = cmd lister
+SUBDIRS = lister
include $(MODULE_TOPDIR)/include/Make/Dir.make
More information about the grass-commit
mailing list