[GRASS-SVN] r45093 - in grass/trunk: . general/g.copy
general/g.findfile general/g.list general/g.mlist
general/g.mremove general/g.remove general/g.rename include
lib/gis lib/manage
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jan 20 07:10:50 EST 2011
Author: martinl
Date: 2011-01-20 04:10:50 -0800 (Thu, 20 Jan 2011)
New Revision: 45093
Added:
grass/trunk/general/g.findfile/element.c
grass/trunk/general/g.findfile/local_proto.h
grass/trunk/include/manage.h
grass/trunk/lib/manage/element_list
grass/trunk/lib/manage/list.c
grass/trunk/lib/manage/manage_local_proto.h
grass/trunk/lib/manage/managelib.dox
grass/trunk/lib/manage/option.c
Removed:
grass/trunk/lib/gis/element_list
grass/trunk/lib/manage/README
grass/trunk/lib/manage/list.h
Modified:
grass/trunk/general/g.copy/main.c
grass/trunk/general/g.findfile/
grass/trunk/general/g.findfile/Makefile
grass/trunk/general/g.findfile/g.findfile.html
grass/trunk/general/g.findfile/main.c
grass/trunk/general/g.list/main.c
grass/trunk/general/g.mlist/main.c
grass/trunk/general/g.mremove/check_reclass.c
grass/trunk/general/g.mremove/main.c
grass/trunk/general/g.remove/main.c
grass/trunk/general/g.rename/main.c
grass/trunk/grasslib.dox
grass/trunk/include/gis.h
grass/trunk/lib/gis/Makefile
grass/trunk/lib/gis/parser_standard_options.c
grass/trunk/lib/manage/
grass/trunk/lib/manage/Makefile
grass/trunk/lib/manage/add_elem.c
grass/trunk/lib/manage/do_copy.c
grass/trunk/lib/manage/do_list.c
grass/trunk/lib/manage/do_remove.c
grass/trunk/lib/manage/do_rename.c
grass/trunk/lib/manage/empty.c
grass/trunk/lib/manage/find.c
grass/trunk/lib/manage/get_len.c
grass/trunk/lib/manage/read_list.c
grass/trunk/lib/manage/show_elem.c
grass/trunk/lib/manage/sighold.c
Log:
Update managelib + related modules
Modified: grass/trunk/general/g.copy/main.c
===================================================================
--- grass/trunk/general/g.copy/main.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/general/g.copy/main.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -20,45 +20,35 @@
#include <stdlib.h>
#include <string.h>
+#include <grass/gis.h>
#include <grass/glocale.h>
-#include <grass/list.h>
+#include <grass/manage.h>
int main(int argc, char *argv[])
{
- int i, n;
+ int i, n, nlist;
const char *mapset;
struct GModule *module;
- struct Option **parm, *p;
+ struct Option **parm;
char *from, *to;
int result = EXIT_SUCCESS;
G_gisinit(argv[0]);
- read_list(0);
+ M_read_list(FALSE, &nlist);
module = G_define_module();
G_add_keyword(_("general"));
G_add_keyword(_("map management"));
+ G_add_keyword(_("copy"));
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.");
+ _("Copies available data files in the current mapset "
+ "search path to the user's current mapset.");
- parm = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
+ 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;
+ parm[n] = M_define_option(n, _("copied"), NO);
}
if (G_parser(argc, argv))
@@ -71,7 +61,7 @@
while (parm[n]->answers[i]) {
from = parm[n]->answers[i++];
to = parm[n]->answers[i++];
- mapset = find(n, from, "");
+ mapset = M_find(n, from, "");
if (!mapset) {
G_warning(_("<%s> not found"), from);
continue;
@@ -82,7 +72,7 @@
parm[n]->key, from, to);
continue;
}
- if (find(n, to, G_mapset()) && !(module->overwrite)) {
+ if (M_find(n, to, G_mapset()) && !(module->overwrite)) {
G_warning(_("<%s> already exists"), to);
continue;
}
@@ -90,7 +80,7 @@
G_warning(_("<%s> is an illegal file name"), to);
continue;
}
- if (do_copy(n, from, mapset, to) == 1) {
+ if (M_do_copy(n, from, mapset, to) == 1) {
result = EXIT_FAILURE;
}
G_remove_misc("cell_misc", "reclassed_to", to);
Property changes on: grass/trunk/general/g.findfile
___________________________________________________________________
Modified: svn:ignore
- OBJ.*
+ *.tmp.html
*OBJ*
Modified: grass/trunk/general/g.findfile/Makefile
===================================================================
--- grass/trunk/general/g.findfile/Makefile 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/general/g.findfile/Makefile 2011-01-20 12:10:50 UTC (rev 45093)
@@ -3,8 +3,8 @@
PGM = g.findfile
-LIBES = $(GISLIB)
-DEPENDENCIES = $(GISDEP)
+LIBES = $(GISLIB) $(MANAGELIB)
+DEPENDENCIES = $(GISDEP) $(MANAGEDEP)
include $(MODULE_TOPDIR)/include/Make/Module.make
Added: grass/trunk/general/g.findfile/element.c
===================================================================
--- grass/trunk/general/g.findfile/element.c (rev 0)
+++ grass/trunk/general/g.findfile/element.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -0,0 +1,15 @@
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include <grass/manage.h>
+
+void list_elements()
+{
+ G_message(_("List of available elements:"));
+ M_read_list(FALSE, NULL);
+ M_show_elements();
+}
+
+int check_element(const char *element)
+{
+ M_read_list(FALSE, NULL);
+}
Property changes on: grass/trunk/general/g.findfile/element.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass/trunk/general/g.findfile/g.findfile.html
===================================================================
--- grass/trunk/general/g.findfile/g.findfile.html 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/general/g.findfile/g.findfile.html 2011-01-20 12:10:50 UTC (rev 45093)
@@ -59,8 +59,6 @@
fi
</pre></div>
-Note that region files are searched as <em>element=windows</em>.
-
<h2>PYTHON</h2>
See <em><a href="http://grass.osgeo.org/programming7/pythonlib.html">Python
Added: grass/trunk/general/g.findfile/local_proto.h
===================================================================
--- grass/trunk/general/g.findfile/local_proto.h (rev 0)
+++ grass/trunk/general/g.findfile/local_proto.h 2011-01-20 12:10:50 UTC (rev 45093)
@@ -0,0 +1,3 @@
+/* element.c */
+void list_elements();
+int check_element(const char *);
Property changes on: grass/trunk/general/g.findfile/local_proto.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Modified: grass/trunk/general/g.findfile/main.c
===================================================================
--- grass/trunk/general/g.findfile/main.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/general/g.findfile/main.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -7,12 +7,13 @@
* Bernhard Reiter <bernhard intevation.de>,
* Glynn Clements <glynn gclements.plus.com>,
* Jan-Oliver Wagner <jan intevation.de>
+ * Martin landa <landa.martin gmail.com>
* PURPOSE:
- * COPYRIGHT: (C) 1999-2008 by the GRASS Development Team
+ * COPYRIGHT: (C) 1999-2008, 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.
+ * This program is free software under the GNU General
+ * Public License (>=v2). Read the file COPYING that
+ * comes with GRASS for details.
*
*****************************************************************************/
#include <string.h>
@@ -21,6 +22,8 @@
#include <grass/gis.h>
#include <grass/glocale.h>
+#include "local_proto.h"
+
int main(int argc, char *argv[])
{
char file[GPATH_MAX], name[GNAME_MAX];
@@ -29,7 +32,7 @@
struct Option *elem_opt;
struct Option *mapset_opt;
struct Option *file_opt;
- struct Flag *n_flag;
+ struct Flag *n_flag, *l_flag;
module = G_define_module();
G_add_keyword(_("general"));
@@ -65,9 +68,19 @@
n_flag->key = 'n';
n_flag->description = _("Don't add quotes");
+ l_flag = G_define_flag();
+ l_flag->key = 'l';
+ l_flag->description = _("List available elements and exit");
+ l_flag->suppress_required = YES;
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
+ if (l_flag->answer) {
+ list_elements();
+ return EXIT_SUCCESS;
+ }
+
search_mapset = mapset_opt->answer;
if (!search_mapset) {
search_mapset = G_store("");
Modified: grass/trunk/general/g.list/main.c
===================================================================
--- grass/trunk/general/g.list/main.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/general/g.list/main.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -10,7 +10,7 @@
* PURPOSE: Lists available GRASS data base elements of the user-specified data type to
* standard output
*
- * COPYRIGHT: (C) 1999-2009 by the GRASS Development Team
+ * 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
@@ -21,62 +21,39 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <grass/gis.h>
#include <grass/spawn.h>
-#include <grass/list.h>
+#include <grass/glocale.h>
+#include <grass/manage.h>
struct Option *element;
-int parse(const char *data_type);
-
int main(int argc, char *argv[])
{
- int i, n, len;
+ int i, n, nlist;
struct GModule *module;
struct Option *mapset_opt;
struct Flag *full;
const char *mapset;
- char *str;
G_gisinit(argv[0]);
- read_list(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 GIS elements "
"of the user-specified data type.");
- element = G_define_option();
- element->key = "type";
- 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_opt = G_define_option();
- mapset_opt->key = "mapset";
- mapset_opt->type = TYPE_STRING;
- mapset_opt->required = NO;
- mapset_opt->multiple = NO;
- mapset_opt->label = _("Mapset to list (default: current search path");
- mapset_opt->description = _("'.' for current mapset");
-
+ 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)");
@@ -93,21 +70,21 @@
i = 0;
while (element->answers[i]) {
- n = parse(element->answers[i]);
+ n = M_get_element(element->answers[i]);
if (full->answer) {
char lister[GPATH_MAX];
sprintf(lister, "%s/etc/lister/%s", G_gisbase(),
- list[n].element[0]);
+ M_get_list(n)->element[0]);
G_debug(3, "lister CMD: %s", lister);
if (access(lister, 1) == 0) /* execute permission? */
G_spawn(lister, lister, mapset, NULL);
else
- do_list(n, mapset);
+ M_do_list(n, mapset);
}
else {
- do_list(n, mapset);
+ M_do_list(n, mapset);
}
i++;
@@ -115,15 +92,3 @@
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;
-}
Modified: grass/trunk/general/g.mlist/main.c
===================================================================
--- grass/trunk/general/g.mlist/main.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/general/g.mlist/main.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -21,7 +21,7 @@
#include <unistd.h>
#include <string.h>
#include <grass/gis.h>
-#include <grass/list.h>
+#include <grass/manage.h>
#include <grass/glocale.h>
#include <grass/spawn.h>
@@ -30,7 +30,6 @@
static void make_list(const struct list *,
const char *, const char *,
int, int, int);
-static int parse(const char *);
int main(int argc, char *argv[])
{
@@ -52,42 +51,28 @@
struct Flag *pretty;
struct Flag *full;
} flag;
- int i, n, all, num_types;
+ int i, n, all, num_types, nlist;
void *filter = NULL, *exclude = NULL;
const char *mapset;
- char separator[2], *buf;
+ char separator[2];
G_gisinit(argv[0]);
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 to standard output.");
- read_list(0);
+ M_read_list(FALSE, &nlist);
- opt.type = G_define_option();
- opt.type->key = "type";
- opt.type->key_desc = "datatype";
- opt.type->type = TYPE_STRING;
- opt.type->required = YES;
+ opt.type = G_define_standard_option(G_OPT_M_DATATYPE);
opt.type->multiple = YES;
- opt.type->answer = "rast";
- opt.type->description = "Data type";
- for (i = 0, n = 0; n < nlist; n++)
- i += strlen(list[n].alias) + 1;
- buf = G_malloc(i + 4);
-
- buf[0] = 0;
- for (n = 0; n < nlist; n++) {
- strcat(buf, list[n].alias);
- strcat(buf, ",");
- }
- strcat(buf, "all");
- opt.type->options = buf;
-
+ opt.type->options = M_get_options(TRUE);
+ opt.type->descriptions = M_get_option_desc(TRUE);
+
opt.pattern = G_define_option();
opt.pattern->key = "pattern";
opt.pattern->type = TYPE_STRING;
@@ -102,23 +87,13 @@
opt.exclude->multiple = NO;
opt.exclude->description = _("Map name exclusion pattern (default: none)");
- opt.separator = G_define_option();
- opt.separator->key = "separator";
- opt.separator->type = TYPE_STRING;
- opt.separator->required = NO;
- opt.separator->multiple = NO;
+ opt.mapset = G_define_standard_option(G_OPT_M_MAPSET);
+ opt.mapset->label =
+ _("Name of mapset to list (default: current search path)");
+
+ opt.separator = G_define_standard_option(G_OPT_F_SEP);
opt.separator->answer = "newline";
- opt.separator->description =
- _("One-character output separator, newline, comma, space, or tab");
- opt.mapset = G_define_option();
- opt.mapset->key = "mapset";
- opt.mapset->type = TYPE_STRING;
- opt.mapset->required = NO;
- opt.mapset->multiple = NO;
- opt.mapset->description =
- _("Mapset to list (default: current search path)");
-
flag.regex = G_define_flag();
flag.regex->key = 'r';
flag.regex->description =
@@ -148,8 +123,6 @@
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
- G_free(buf);
-
if (flag.regex->answer && flag.extended->answer)
G_fatal_error(_("-r and -e are mutually exclusive"));
@@ -201,13 +174,13 @@
}
for (i = 0; i < num_types; i++) {
- n = all ? i : parse(opt.type->answers[i]);
+ n = all ? i : M_get_element(opt.type->answers[i]);
if (flag.full->answer) {
char lister[GPATH_MAX];
sprintf(lister, "%s/etc/lister/%s", G_gisbase(),
- list[n].element[0]);
+ M_get_list(n)->element[0]);
G_debug(3, "lister CMD: %s", lister);
@@ -217,7 +190,7 @@
}
}
else
- make_list(&list[n], mapset, separator,
+ make_list(M_get_list(n), mapset, separator,
flag.pretty->answer, flag.type->answer,
flag.mapset->answer);
}
@@ -289,15 +262,3 @@
G_free(list);
}
-static 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;
-}
-
Modified: grass/trunk/general/g.mremove/check_reclass.c
===================================================================
--- grass/trunk/general/g.mremove/check_reclass.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/general/g.mremove/check_reclass.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,7 +1,7 @@
#include <string.h>
#include <grass/gis.h>
-#include <grass/list.h>
+#include <grass/manage.h>
#include <grass/raster.h>
#include <grass/glocale.h>
@@ -15,11 +15,11 @@
for (; *rmaps; rmaps++) {
/* force remove */
if (force)
- G_warning(_("[%s@%s] is a base map for [%s]. Remove forced."),
+ G_warning(_("Raster map <%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"),
+ ("Raster map <%s@%s> is a base map. Remove reclassed map first: %s"),
name, mapset, *rmaps);
}
Modified: grass/trunk/general/g.mremove/main.c
===================================================================
--- grass/trunk/general/g.mremove/main.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/general/g.mremove/main.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -29,7 +29,7 @@
#include <unistd.h>
#include <grass/gis.h>
-#include <grass/list.h>
+#include <grass/manage.h>
#include <grass/glocale.h>
/* check_reclass.c */
@@ -48,9 +48,9 @@
} flag;
const char *mapset, *location_path;
char *name, path[GPATH_MAX], **files;
- char *buf, *buf2;
+ char *alias;
int num_files, rast, result = EXIT_SUCCESS;
- int i, j, n;
+ int i, j, n, nlist;
void *filter;
G_gisinit(argv[0]);
@@ -58,6 +58,8 @@
module = G_define_module();
G_add_keyword(_("general"));
G_add_keyword(_("map management"));
+ G_add_keyword(_("remove"));
+ G_add_keyword(_("multi"));
module->description =
_("Removes data base element files from "
"the user's current mapset.");
@@ -81,22 +83,12 @@
flag.basemap->key = 'b';
flag.basemap->description = _("Remove base maps");
- read_list(0);
+ M_read_list(FALSE, &nlist);
opt = (struct Option **)G_calloc(nlist, sizeof(struct Option *));
for (n = 0; n < nlist; n++) {
- o = opt[n] = G_define_option();
- o->key = list[n].alias;
- o->type = TYPE_STRING;
- o->required = NO;
- o->multiple = YES;
- buf = G_malloc(64);
- sprintf(buf, "old,%s,%s", list[n].mainelem, list[n].maindesc);
- o->gisprompt = buf;
- buf2 = G_malloc(64);
- sprintf(buf2, _("%s file(s) to be removed"), list[n].alias);
- o->description = buf2;
+ o = opt[n] = M_define_option(n, _("removed"), YES);
}
if (G_parser(argc, argv))
@@ -118,11 +110,12 @@
mapset = G_mapset();
for (n = 0; n < nlist; n++) {
+ alias = M_get_list(n)->alias;
if (opt[n]->answers) {
- G_file_name(path, list[n].element[0], "", mapset);
+ G_file_name(path, M_get_list(n)->element[0], "", mapset);
if (access(path, 0) != 0)
continue;
- rast = !G_strcasecmp(list[n].alias, "rast");
+ rast = !G_strcasecmp(alias, "rast");
for (i = 0; (name = opt[n]->answers[i]); i++) {
if (!flag.regex->answer && !flag.extended->answer)
filter = G_ls_glob_filter(name, 0);
@@ -139,7 +132,7 @@
for (j = 0; j < num_files; j++) {
if (!flag.force->answer) {
- fprintf(stdout, "%s/%s@%s\n", list[n].alias, files[j],
+ fprintf(stdout, "%s/%s@%s\n", alias, files[j],
mapset);
continue;
}
@@ -147,7 +140,7 @@
check_reclass(files[j], mapset, flag.basemap->answer))
continue;
- if (do_remove(n, (char *)files[j]) == 1)
+ if (M_do_remove(n, (char *)files[j]) == 1)
result = EXIT_FAILURE;
}
}
Modified: grass/trunk/general/g.remove/main.c
===================================================================
--- grass/trunk/general/g.remove/main.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/general/g.remove/main.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -11,7 +11,7 @@
* 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
+ * 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
@@ -23,7 +23,7 @@
#include <grass/raster.h>
#include <grass/glocale.h>
-#include <grass/list.h>
+#include <grass/manage.h>
static int check_reclass(const char *name, const char *mapset, int force)
{
@@ -35,10 +35,10 @@
for (; *rmaps; rmaps++) {
/* force remove */
if (force)
- G_warning(_("[%s@%s] is a base map for [%s]. Remove forced."),
+ G_warning(_("Raster map <%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"),
+ G_warning(_("Raster <%s@%s> is a base map. Remove reclassed map <%s> first."),
name, mapset, *rmaps);
}
@@ -60,7 +60,7 @@
if (nrmaps == 1 && !G_strcasecmp(rmaps[0], qname)) {
if (remove(path) < 0)
- G_warning(_("Removing information about reclassed map from [%s@%s] failed"),
+ G_warning(_("Removing information about reclassed map from <%s@%s> failed"),
rname, rmapset);
}
else {
@@ -73,7 +73,7 @@
fclose(fp);
}
else
- G_warning(_("Removing information about reclassed map from [%s@%s] failed"),
+ G_warning(_("Removing information about reclassed map from <%s@%s> failed"),
rname, rmapset);
}
@@ -84,7 +84,7 @@
int main(int argc, char *argv[])
{
- int i, n;
+ int i, n, nlist;
struct GModule *module;
struct Option **parm, *p;
struct Flag *force_flag;
@@ -95,11 +95,12 @@
G_gisinit(argv[0]);
- read_list(0);
+ 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.");
@@ -111,17 +112,7 @@
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;
+ p = parm[n] = M_define_option(n, "removed", YES);
}
if (G_parser(argc, argv))
@@ -136,11 +127,11 @@
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 &&
+ if (G_strcasecmp(M_get_list(n)->alias, "rast") == 0 &&
check_reclass(name, mapset, force))
continue;
- if (do_remove(n, name) == 1) {
+ if (M_do_remove(n, name) == 1) {
result = EXIT_FAILURE;
}
}
Modified: grass/trunk/general/g.rename/main.c
===================================================================
--- grass/trunk/general/g.rename/main.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/general/g.rename/main.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -9,7 +9,7 @@
* Markus Neteler <neteler itc.it>,
* Martin Landa <landa.martin gmail.com>
* PURPOSE:
- * COPYRIGHT: (C) 1994-2007 by the GRASS Development Team
+ * COPYRIGHT: (C) 1994-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
@@ -22,7 +22,7 @@
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/glocale.h>
-#include <grass/list.h>
+#include <grass/manage.h>
int main(int argc, char *argv[])
{
@@ -30,36 +30,26 @@
struct GModule *module;
struct Option **parm, *p;
char *old, *new;
- int nrmaps;
+ int nrmaps, nlist;
const char *mapset, *location_path;
char **rmaps;
int result = EXIT_SUCCESS;
G_gisinit(argv[0]);
- read_list(0);
+ M_read_list(FALSE, &nlist);
module = G_define_module();
G_add_keyword(_("general"));
G_add_keyword(_("map management"));
+ G_add_keyword(_("rename"));
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;
+ p = parm[n] = M_define_option(n, _("renamed"), NO);
}
if (G_parser(argc, argv))
@@ -75,13 +65,13 @@
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);
+ if (!M_find(n, old, mapset)) {
+ G_warning(_("%s <%s> not found"), M_get_list(n)->maindesc, old);
continue;
}
- if (find(n, new, "") && !(module->overwrite)) {
+ if (M_find(n, new, "") && !(module->overwrite)) {
G_warning(_("<%s> already exists in mapset <%s>"), new,
- find(n, new, ""));
+ M_find(n, new, ""));
continue;
}
if (G_legal_filename(new) < 0) {
@@ -141,7 +131,7 @@
fclose(fp);
}
}
- if (do_rename(n, old, new) == 1) {
+ if (M_do_rename(n, old, new) == 1) {
result = EXIT_FAILURE;
}
}
Modified: grass/trunk/grasslib.dox
===================================================================
--- grass/trunk/grasslib.dox 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/grasslib.dox 2011-01-20 12:10:50 UTC (rev 45093)
@@ -92,6 +92,7 @@
- imagery: \ref imagerylib
- init: \ref init (GRASS initialization code + scripts)
- linkm: Linked list memory manager - \ref linkm (obsolete?)
+ - manage: \ref managelib
- ogsf: \ref ogsflib (OpenGL (R) ported gsurf library (required for NVIZ))
- pngdriver: PNG display driver library - \ref pngdriver
- proj: \ref projlib (wrapper to PROJ4 projection library)
Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/include/gis.h 2011-01-20 12:10:50 UTC (rev 45093)
@@ -211,6 +211,8 @@
G_OPT_C_BG, /* background color */
G_OPT_M_UNITS, /* units */
+ G_OPT_M_DATATYPE, /* datatype */
+ G_OPT_M_MAPSET, /* mapset */
} STD_OPT;
/* Message format */
Copied: grass/trunk/include/manage.h (from rev 45057, grass/trunk/lib/manage/list.h)
===================================================================
--- grass/trunk/include/manage.h (rev 0)
+++ grass/trunk/include/manage.h 2011-01-20 12:10:50 UTC (rev 45093)
@@ -0,0 +1,65 @@
+#ifndef GRASS_MANAGE_H
+#define GRASS_MANAGE_H
+
+struct list
+{
+ const char **element; /* list of related elements */
+ char *alias; /* element alias */
+ const char **desc; /* description of elements */
+ char *text; /* menu text */
+ int nelem; /* number of elements */
+ char status;
+ char *mainelem; /* main element */
+ char *maindesc; /* main element description */
+};
+
+#define REMOVE 1
+#define RENAME 2
+#define COPY 3
+#define LIST 4
+
+#include <grass/gis.h>
+
+/* add_elem.c */
+void M__add_element(const char *, const char *);
+
+/* do_copy.c */
+int M_do_copy(int, const char *, const char *, const char *);
+
+/* do_list.c */
+void M_do_list(int, const char *);
+
+/* do_remove.c */
+int M_do_remove(int, const char *);
+
+/* do_rename.c */
+int M_do_rename(int, const char *, const char *);
+
+/* empty.c */
+int M__empty(char *);
+
+/* find.c */
+const char *M_find(int, char *, const char *);
+
+/* get_len.c */
+int M__get_description_len(int);
+
+/* list.c */
+int M_get_element(const char *);
+const struct list *M_get_list(int);
+
+/* read_list.c */
+int M_read_list(int, int *);
+
+/* option.c */
+struct Option* M_define_option(int, const char *, int);
+const char *M_get_options(int);
+const char *M_get_option_desc(int);
+
+/* show_elem.c */
+void M_show_elements(void);
+
+/* sighold.c */
+int M__hold_signals(int);
+
+#endif
Modified: grass/trunk/lib/gis/Makefile
===================================================================
--- grass/trunk/lib/gis/Makefile 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/gis/Makefile 2011-01-20 12:10:50 UTC (rev 45093)
@@ -18,7 +18,7 @@
COLORSRC := $(filter-out colors/CVS,$(wildcard colors/[abcdefghijklmnopqrstuvwxyz]*))
COLORFILES := $(patsubst colors/%,$(ETC)/colors/%,$(COLORSRC))
-default: lib $(FMODE_OBJ) $(DATAFILES) $(COLORFILES) $(ETC)/colors.desc $(ETC)/element_list
+default: lib $(FMODE_OBJ) $(DATAFILES) $(COLORFILES) $(ETC)/colors.desc
ifdef MINGW
$(FMODE_OBJ): $(OBJDIR)/fmode.o
Deleted: grass/trunk/lib/gis/element_list
===================================================================
--- grass/trunk/lib/gis/element_list 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/gis/element_list 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,32 +0,0 @@
-# @(#)Element_List
-# this file specifies the database elements that
-# are processed by RENAME, REMOVE, COPY, and LIST
-#
-# format:
-# main_element:alias:description:menu text
-# support_element:description
-#
-cell:rast:raster:raster files
- cellhd:header
- cats:category
- colr:color
- hist:history
- cell_misc:misc
- fcell:fcell
- g3dcell:g3dcell
-grid3:rast3d:raster3D:raster3D files
-vector:vect:vector:binary vector files
-dig:oldvect:old vector:old (GRASS 5.0) binary vector files
- dig_att:attributes
- dig_plus:topology
- dig_cats:category
- dig_misc:misc
- reg:point registration
-dig_ascii:asciivect:asciivector:ascii vector files
-icons:icon:icon:paint icon files
-paint/labels:labels:label:paint label files
-site_lists:sites:site list:site list files
-windows:region:region definition:region definition files
-windows3d:region3d:region3D definition:region3D definition files
-group:group:imagery group:imagery group files
-3d.view:3dview:3D viewing parameters:3D view parameters
Modified: grass/trunk/lib/gis/parser_standard_options.c
===================================================================
--- grass/trunk/lib/gis/parser_standard_options.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/gis/parser_standard_options.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -85,6 +85,8 @@
* - misc
*
* - G_OPT_M_UNITS
+ * - G_OPT_M_DATATYPE
+ * - G_OPT_M_MAPSET
*
* \param opt type of Option struct to create
*
@@ -478,6 +480,25 @@
"miles,feet,meters,kilometers,acres,hectares";
Opt->description = _("Units");
break;
+
+ case G_OPT_M_DATATYPE:
+ Opt->key = "type";
+ Opt->key_desc = "datatype";
+ Opt->type = TYPE_STRING;
+ Opt->required = YES;
+ Opt->multiple = YES;
+ Opt->description = _("Data type(s)");
+ break;
+
+ case G_OPT_M_MAPSET:
+ Opt->key = "mapset";
+ Opt->type = TYPE_STRING;
+ Opt->required = NO;
+ Opt->multiple = NO;
+ Opt->key_desc = "name";
+ Opt->label =
+ _("Name of mapset (default: current search path)");
+ Opt->description = _("'.' for current mapset");
}
return (Opt);
Property changes on: grass/trunk/lib/manage
___________________________________________________________________
Modified: svn:ignore
- OBJ.*
+ *.tmp.html
*OBJ*
Modified: grass/trunk/lib/manage/Makefile
===================================================================
--- grass/trunk/lib/manage/Makefile 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/Makefile 2011-01-20 12:10:50 UTC (rev 45093)
@@ -4,8 +4,14 @@
DEPENDENCIES = $(GISDEP) $(VECTDEP) $(G3DDEP)
include $(MODULE_TOPDIR)/include/Make/Lib.make
+include $(MODULE_TOPDIR)/include/Make/Doxygen.make
EXTRA_INC = $(VECT_INC)
EXTRA_CFLAGS = $(VECT_CFLAGS)
-default: lib $(ARCH_INCDIR)/list.h
+default: lib $(ETC)/element_list
+
+$(ETC)/%: %
+ $(INSTALL_DATA) $< $@
+
+DOXNAME = manage
\ No newline at end of file
Deleted: grass/trunk/lib/manage/README
===================================================================
--- grass/trunk/lib/manage/README 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/README 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,25 +0,0 @@
-/****************************************************************************
- *
- * MODULE: general database maintenance routines (lib)
- *
- * AUTHOR(S): Michael Shapiro (original contributor),
- * U.S.Army Construction Engineering Research Laboratory
- * Radim Blazek <radim.blazek gmail.com>,
- * Markus Neteler <neteler itc.it>,
- * Paul Kelly <paul-grass stjohnspoint.co.uk>,
- * Glynn Clements <glynn gclements.plus.com>,
- * Brad Douglas <rez touchofmadness.com>,
- * Huidae Cho <grass4u gmail.com>,
- * Cedric Shock <cedricgrass shockfamily.net>,
- * Martin Landa <landa.martin gmail.com>,
- * Hamish Bowman <hamish_b yahoo.com>
- *
- * PURPOSE: Maintenance operations on GRASS data base 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.
- *
- *****************************************************************************/
Modified: grass/trunk/lib/manage/add_elem.c
===================================================================
--- grass/trunk/lib/manage/add_elem.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/add_elem.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,5 +1,27 @@
-#include "list.h"
-int add_element(const char *elem, const char *desc)
+/*!
+ \file lib/manage/add_elem.c
+
+ \brief Manage Library - Add element to the list
+
+ (C) 2001-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.
+
+ \author Original author CERL
+*/
+
+#include <grass/gis.h>
+
+#include "manage_local_proto.h"
+
+/*!
+ \brief Add element to the list
+
+ \param elem element name
+ \param desc description of the element
+*/
+void M__add_element(const char *elem, const char *desc)
{
int n;
int nelem;
@@ -13,6 +35,4 @@
list[n].element[nelem] = G_store(elem);
list[n].desc = G_realloc(list[n].desc, (nelem + 1) * sizeof(const char *));
list[n].desc[nelem] = G_store(desc);
-
- return 0;
}
Modified: grass/trunk/lib/manage/do_copy.c
===================================================================
--- grass/trunk/lib/manage/do_copy.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/do_copy.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,15 +1,38 @@
+/*!
+ \file lib/manage/do_copy.c
+
+ \brief Manage Library - Copy element
+
+ (C) 2001-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.
+
+ \author Original author CERL
+*/
+
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+
#include <grass/gis.h>
+#include <grass/glocale.h>
#include <grass/vector.h>
-#include "list.h"
-/*
- * returns 0 - success
- * 1 - error
- */
-int do_copy(int n, const char *old, const char *mapset, const char *new)
+#include "manage_local_proto.h"
+
+/*!
+ \brief Copy element
+
+ \param n element id
+ \param old source name
+ \param mapset name of source mapset
+ \param new destination name
+
+ \return 0 on success
+ \return 1 on error
+*/
+int M_do_copy(int n, const char *old, const char *mapset, const char *new)
{
int i, ret, len;
char path[GPATH_MAX], path2[GPATH_MAX];
@@ -20,13 +43,13 @@
G_message(_("Copy %s <%s> to current mapset as <%s>"),
list[n].maindesc, G_fully_qualified_name(old, mapset), new);
- len = get_description_len(n);
+ len = M__get_description_len(n);
- hold_signals(1);
+ M__hold_signals(1);
if (G_strcasecmp(list[n].alias, "vect") == 0) {
ret = Vect_copy(old, mapset, new);
if (ret == -1) {
- G_warning("Cannot copy <%s> to current mapset as <%s>",
+ G_warning(_("Unable to copy <%s> to current mapset as <%s>"),
G_fully_qualified_name(old, mapset), new);
result = 1;
}
@@ -37,8 +60,7 @@
G_file_name(path, list[n].element[i], old, mapset);
if (access(path, 0) != 0) {
G_remove(list[n].element[i], new);
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: missing"), list[n].desc[i]);
+ G_verbose_message(_("%s is missing"), list[n].desc[i]);
continue;
}
@@ -47,8 +69,7 @@
result = 1;
}
else {
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: copied"), list[n].desc[i]);
+ G_verbose_message(_("%s copied"), list[n].desc[i]);
}
}
}
@@ -60,7 +81,7 @@
sprintf(colr2, "colr2/%s", G_mapset());
G_remove(colr2, new);
}
- hold_signals(0);
+ M__hold_signals(0);
return result;
}
Modified: grass/trunk/lib/manage/do_list.c
===================================================================
--- grass/trunk/lib/manage/do_list.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/do_list.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,5 +1,27 @@
-#include "list.h"
-void do_list(int n, const char *mapset)
+/*!
+ \file lib/manage/do_list.c
+
+ \brief Manage Library - List elements
+
+ (C) 2001-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.
+
+ \author Original author CERL
+*/
+
+#include <grass/gis.h>
+
+#include "manage_local_proto.h"
+
+/*!
+ \brief List elements
+
+ \param n element id
+ \param mapset name of mapset
+*/
+void M_do_list(int n, const char *mapset)
{
G_list_element(list[n].element[0], list[n].desc[0], mapset, (int (*)())0);
}
Modified: grass/trunk/lib/manage/do_remove.c
===================================================================
--- grass/trunk/lib/manage/do_remove.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/do_remove.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,15 +1,35 @@
+/*!
+ \file lib/manage/do_remove.c
+
+ \brief Manage Library - Remove elements
+
+ (C) 2001-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.
+
+ \author Original author CERL
+*/
+
#include <string.h>
+
#include <grass/gis.h>
#include <grass/vector.h>
#include <grass/glocale.h>
#include <grass/G3d.h>
-#include "list.h"
-/*
- * returns 0 - success
- * 1 - error
- */
-int do_remove(int n, const char *old)
+#include "manage_local_proto.h"
+
+/*!
+ \brief Remove elements from data base
+
+ \param n element id
+ \param old name of element to be removed
+
+ \return 0 on success
+ \return 1 on error
+*/
+int M_do_remove(int n, const char *old)
{
int i, ret;
@@ -23,7 +43,7 @@
/* len = get_description_len(n); */
- hold_signals(1);
+ M__hold_signals(1);
if (G_name_is_fully_qualified(old, xname, xmapset)) {
if (strcmp(xmapset, G_mapset()) != 0)
@@ -42,7 +62,7 @@
removed = 1;
}
else {
- G_warning(_("couldn't be removed"));
+ G_warning(_("Unable to delete vector map"));
result = 1;
}
}
@@ -62,16 +82,14 @@
switch (G_remove(list[n].element[i], old)) {
case -1:
- G_warning(_("%s: couldn't be removed"), list[n].desc[i]);
+ G_warning(_("Unable to remove %s element"), list[n].desc[i]);
result = 1;
break;
case 0:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: missing"), list[n].desc[i]);
+ G_verbose_message(_("%s is missing"), list[n].desc[i]);
break;
case 1:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: removed"), list[n].desc[i]);
+ G_verbose_message(_("%s removed"), list[n].desc[i]);
removed = 1;
break;
}
@@ -84,22 +102,20 @@
sprintf(colr2, "colr2/%s", G_mapset());
switch (G_remove(colr2, old)) {
case -1:
- G_warning("%s: %s", colr2, _("couldn't be removed"));
+ G_warning(_("Unable to remove %s"), colr2);
result = 1;
break;
case 0:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: missing"), colr2);
+ G_verbose_message(_("%s is missing"), colr2);
break;
case 1:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: removed"), colr2);
+ G_verbose_message(_("%s removed"), colr2);
removed = 1;
break;
}
}
- hold_signals(0);
+ M__hold_signals(0);
if (!removed)
G_warning(_("<%s> nothing removed"), old);
Modified: grass/trunk/lib/manage/do_rename.c
===================================================================
--- grass/trunk/lib/manage/do_rename.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/do_rename.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,15 +1,37 @@
+/*!
+ \file lib/manage/do_rename.c
+
+ \brief Manage Library - Rename elements
+
+ (C) 2001-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.
+
+ \author Original author CERL
+*/
+
#include <stdlib.h>
#include <string.h>
+
#include <grass/gis.h>
#include <grass/vector.h>
#include <grass/G3d.h>
-#include "list.h"
+#include <grass/glocale.h>
-/*
- * returns 0 - success
- * 1 - error
- */
-int do_rename(int n, const char *old, const char *new)
+#include "manage_local_proto.h"
+
+/*!
+ \brief Rename element
+
+ \param n element id
+ \param old source name
+ \param new destination name
+
+ \return 0 on success
+ \return 1 on error
+*/
+int M_do_rename(int n, const char *old, const char *new)
{
int i, ret;
int len;
@@ -17,20 +39,15 @@
int result = 0;
int renamed = 0;
- /* verbosity: --quiet is completely quiet.
- GRASS_VERBOSE=1 shows only map names.
- normal and --verbose show map names and elements. */
- /* there should be used G_message or other derived fn */
- if (G_verbose() > G_verbose_min())
- fprintf(stderr, _("Rename %s <%s> to <%s>\n"),
- list[n].maindesc, old, new);
-
+ G_message(_("Rename %s <%s> to <%s>"),
+ list[n].maindesc, old, new);
+
if (G_strcasecmp(old, new) == 0)
return 1;
- len = get_description_len(n);
+ len = M__get_description_len(n);
- hold_signals(1);
+ M__hold_signals(1);
if (G_strcasecmp(list[n].alias, "vect") == 0) {
if ((mapset = G_find_vector2(old, "")) == NULL) {
@@ -42,7 +59,8 @@
renamed = 1;
}
else {
- G_warning(_("Cannot rename <%s> to <%s>"), old, new);
+ G_warning(_("Unable to rename vector map <%s> to <%s>"),
+ old, new);
result = 1;
}
}
@@ -62,16 +80,14 @@
G_remove(list[n].element[i], new);
switch (G_rename(list[n].element[i], old, new)) {
case -1:
- G_warning(_("%s: couldn't be removed"), list[n].desc[i]);
+ G_warning(_("Unable to rename %s"), list[n].desc[i]);
result = 1;
break;
case 0:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: missing"), list[n].desc[i]);
+ G_verbose_message(_("%s is missing"), list[n].desc[i]);
break;
case 1:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: renamed"), list[n].desc[i]);
+ G_verbose_message(_("%s renamed"), list[n].desc[i]);
renamed = 1;
break;
}
@@ -84,22 +100,20 @@
G_remove(colr2, new);
switch (G_rename(colr2, old, new)) {
case -1:
- G_warning(_("%s: couldn't be renamed"), colr2);
+ G_warning(_("Unable to rename %s"), colr2);
result = 1;
break;
case 0:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: missing"), colr2);
+ G_verbose_message(_("%s is missing"), colr2);
break;
case 1:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: renamed"), colr2);
+ G_verbose_message(_("%s renamed"), colr2);
renamed = 1;
break;
}
}
}
- hold_signals(0);
+ M__hold_signals(0);
if (!renamed)
G_warning(_("<%s> nothing renamed"), old);
Copied: grass/trunk/lib/manage/element_list (from rev 45057, grass/trunk/lib/gis/element_list)
===================================================================
--- grass/trunk/lib/manage/element_list (rev 0)
+++ grass/trunk/lib/manage/element_list 2011-01-20 12:10:50 UTC (rev 45093)
@@ -0,0 +1,32 @@
+# @(#)Element_List
+# this file specifies the database elements that
+# are processed by RENAME, REMOVE, COPY, and LIST
+#
+# format:
+# main_element:alias:description:menu text
+# support_element:description
+#
+cell:rast:raster:raster map(s)
+ cellhd:header
+ cats:category
+ colr:color
+ hist:history
+ cell_misc:misc
+ fcell:fcell
+ g3dcell:g3dcell
+grid3:rast3d:raster3D:3D raster map(s)
+vector:vect:vector:vector map(s)
+dig:oldvect:old vector:old (GRASS 5.0) vector map(s)
+ dig_att:attributes
+ dig_plus:topology
+ dig_cats:category
+ dig_misc:misc
+ reg:point registration
+dig_ascii:asciivect:asciivector:ASCII vector map(s)
+icons:icon:icon:paint icon file(s)
+paint/labels:labels:label:paint label file(s)
+site_lists:sites:site list:site list file(s)
+windows:region:region definition:region definition(s)
+windows3d:region3d:region3D definition:3D region definition(s)
+group:group:imagery group:imagery group(s)
+3d.view:view3d:3D viewing parameters:3D view parameter(s)
Modified: grass/trunk/lib/manage/empty.c
===================================================================
--- grass/trunk/lib/manage/empty.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/empty.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,9 +1,31 @@
+/*!
+ \file lib/manage/empty.c
+
+ \brief Manage Library - Check if element is empty
+
+ (C) 2001-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.
+
+ \author Original author CERL
+*/
+
/* look for at least one file in the element */
#include <sys/types.h>
#include <dirent.h>
+
#include <grass/gis.h>
-int empty(char *elem)
+/*!
+ \brief Check if element is empty
+
+ \param elem element name
+
+ \return 1 empty
+ \return 0 not empty
+*/
+int M__empty(char *elem)
{
DIR *dirp;
struct dirent *dp;
Modified: grass/trunk/lib/manage/find.c
===================================================================
--- grass/trunk/lib/manage/find.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/find.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,7 +1,32 @@
+/*!
+ \file lib/manage/find.c
+
+ \brief Manage Library - Find element in data base
+
+ (C) 2001-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.
+
+ \author Original author CERL
+*/
+
#include <string.h>
-#include "list.h"
+#include <grass/gis.h>
-const char *find(int n, char *name, const char *mapsets)
+#include "manage_local_proto.h"
+
+/*!
+ \brief Find element in data base
+
+ \param n element id
+ \param name element name
+ \param mapsets name of mapsets
+
+ \return mapset if found
+ \return if not found
+*/
+const char *M_find(int n, char *name, const char *mapsets)
{
const char *mapset;
Modified: grass/trunk/lib/manage/get_len.c
===================================================================
--- grass/trunk/lib/manage/get_len.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/get_len.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,7 +1,28 @@
+/*!
+ \file lib/manage/get_len.c
+
+ \brief Manage Library - Get max length of element's description
+
+ (C) 2001-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.
+
+ \author Original author CERL
+*/
+
#include <string.h>
-#include "list.h"
-int get_description_len(int n)
+#include "manage_local_proto.h"
+
+/*!
+ \brief Get max length of element's description
+
+ \param n element id
+
+ \return buffer length
+*/
+int M__get_description_len(int n)
{
int len;
int l;
Added: grass/trunk/lib/manage/list.c
===================================================================
--- grass/trunk/lib/manage/list.c (rev 0)
+++ grass/trunk/lib/manage/list.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -0,0 +1,52 @@
+/*!
+ \file lib/manage/list.c
+
+ \brief Manage Library - Element info
+
+ (C) 2001-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.
+
+ \author Original author CERL
+*/
+
+#include <grass/gis.h>
+
+#include "manage_local_proto.h"
+
+/*!
+ \brief Get list structure
+
+ \param element id
+
+ \return pointer to list structure
+ \return NULL on error
+*/
+const struct list *M_get_list(int n)
+{
+ if (n >= nlist)
+ return NULL;
+
+ return &(list[n]);
+}
+
+/*!
+ \brief Find element type by name
+
+ \param data_type element type
+
+ \return element id
+ \return -1 not found
+*/
+int M_get_element(const char *data_type)
+{
+ int n;
+
+ for (n = 0; n < nlist; n++) {
+ if (G_strcasecmp(list[n].alias, data_type) == 0)
+ return n;
+ }
+
+ return -1;
+}
Property changes on: grass/trunk/lib/manage/list.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Deleted: grass/trunk/lib/manage/list.h
===================================================================
--- grass/trunk/lib/manage/list.h 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/list.h 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,62 +0,0 @@
-
-#ifndef GRASS_LIST_H
-#define GRASS_LIST_H
-
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
-struct list
-{
- const char **element; /* list of related elements */
- char *alias; /* element alias */
- const char **desc; /* description of elements */
- char *text; /* menu text */
- int nelem; /* number of elements */
- char status;
- char *mainelem; /* main element */
- char *maindesc; /* main element description */
-};
-
-extern int nlist;
-extern struct list *list;
-
-#define REMOVE 1
-#define RENAME 2
-#define COPY 3
-#define LIST 4
-
-/* add_elem.c */
-int add_element(const char *, const char *);
-
-/* do_copy.c */
-int do_copy(int, const char *, const char *, const char *);
-
-/* do_list.c */
-void do_list(int, const char *);
-
-/* do_remove.c */
-int do_remove(int, const char *);
-
-/* do_rename.c */
-int do_rename(int, const char *, const char *);
-
-/* empty.c */
-int empty(char *);
-
-/* find.c */
-const char *find(int, char *, const char *);
-
-/* get_len.c */
-int get_description_len(int);
-
-/* read_list.c */
-int read_list(int);
-
-/* show_elem.c */
-int show_elements(void);
-
-/* sighold.c */
-int hold_signals(int);
-
-#endif
-
Added: grass/trunk/lib/manage/manage_local_proto.h
===================================================================
--- grass/trunk/lib/manage/manage_local_proto.h (rev 0)
+++ grass/trunk/lib/manage/manage_local_proto.h 2011-01-20 12:10:50 UTC (rev 45093)
@@ -0,0 +1,9 @@
+#ifndef __MANAGE_LOCAL_PROTO_H__
+#define __MANAGE_LOCAL_PROTO_H__
+
+#include <grass/manage.h>
+
+extern int nlist;
+extern struct list *list;
+
+#endif
Property changes on: grass/trunk/lib/manage/manage_local_proto.h
___________________________________________________________________
Added: svn:mime-type
+ text/x-chdr
Added: svn:eol-style
+ native
Added: grass/trunk/lib/manage/managelib.dox
===================================================================
--- grass/trunk/lib/manage/managelib.dox (rev 0)
+++ grass/trunk/lib/manage/managelib.dox 2011-01-20 12:10:50 UTC (rev 45093)
@@ -0,0 +1,30 @@
+/*! \page managelib GRASS Data Elements Manage Library
+
+by GRASS Development Team (http://grass.osgeo.org)
+
+\section manageintro Introduction
+
+This library used for management of data base elements. See modules
+<tt>g.list, g.mlist, g.remove, g.mremove, g.copy</tt> or
+<tt>g.rename</tt>.
+
+\code
+#include <grass/manage.h>
+\endcode
+
+\section listFn List of functions
+
+ - M_do_copy()
+ - M_do_list()
+ - M_do_remove()
+ - M_do_rename()
+ - M_find()
+ - M_read_list()
+ - M_show_elements()
+ - M_define_option()
+ - M_get_options()
+ - M_get_option_desc()
+ - M_get_element()
+ - M_get_list()
+
+*/
Added: grass/trunk/lib/manage/option.c
===================================================================
--- grass/trunk/lib/manage/option.c (rev 0)
+++ grass/trunk/lib/manage/option.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -0,0 +1,132 @@
+/*!
+ \file lib/manage/option.c
+
+ \brief Manage Library - Define option for parser
+
+ (C) 2001-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.
+
+ \author Original author CERL
+*/
+
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#include "manage_local_proto.h"
+
+/*!
+ \brief Define option for parser
+
+ \param n element id
+
+ \return pointer to Option structure
+ \return NULL on error
+*/
+struct Option* M_define_option(int n, const char *desc, int multiple)
+{
+ char *str;
+ struct Option *p;
+
+ if (n >= nlist)
+ return NULL;
+
+ p = G_define_option();
+ p->key = list[n].alias;
+ p->type = TYPE_STRING;
+ if (multiple)
+ p->key_desc = "name";
+ else
+ p->key_desc = "from,to";
+ p->required = NO;
+ p->multiple = multiple;
+ G_asprintf(&str, "old,%s,%s", list[n].mainelem, list[n].maindesc);
+ p->gisprompt = str;
+ G_asprintf(&str, _("%s to be %s"),
+ list[n].text, desc);
+ p->description = str;
+
+ return p;
+}
+
+/*!
+ \brief Get list of element types separated by comma
+
+ String buffer is allocated by G_malloc().
+
+ \param do_all TRUE to add "all" to the buffer
+
+ \return pointer to allocated buffer with types
+*/
+const char *M_get_options(int do_all)
+{
+ int len, n;
+ char *str;
+
+ for (len = 0, n = 0; n < nlist; n++)
+ len += strlen(list[n].alias) + 1;
+ if (do_all)
+ len += 4;
+ 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);
+ }
+
+ if (do_all)
+ strcat(str, ",all");
+
+ return str;
+}
+
+/*!
+ \brief Get list of element desc separated by comma
+
+ String buffer is allocated by G_malloc().
+
+ \param do_all TRUE to add "all" to the buffer
+
+ \return pointer to allocated buffer with desc
+*/
+const char *M_get_option_desc(int do_all)
+{
+ int len, n;
+ char *str;
+ const char *str_all = "all;all types";
+
+ for (len = 0, n = 0; n < nlist; n++) {
+ len += strlen(list[n].alias) + 1;
+ len += strlen(list[n].text) + 1;
+ }
+ if (do_all)
+ len += strlen(str_all);
+ str = G_malloc(len);
+
+ for (n = 0; n < nlist; n++) {
+ if (n) {
+ strcat(str, ";");
+ strcat(str, list[n].alias);
+ strcat(str, ";");
+ strcat(str, list[n].text);
+ }
+ else {
+ strcat(str, list[n].alias);
+ strcat(str, ";");
+ strcat(str, list[n].text);
+ }
+ }
+
+ if (do_all) {
+ strcat(str, ";");
+ strcat(str, str_all);
+ }
+
+ return str;
+}
Property changes on: grass/trunk/lib/manage/option.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass/trunk/lib/manage/read_list.c
===================================================================
--- grass/trunk/lib/manage/read_list.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/read_list.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,13 +1,36 @@
+/*!
+ \file lib/manage/read_list.c
+
+ \brief Manage Library - Read list of elements
+
+ (C) 2001-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.
+
+ \author Original author CERL
+*/
+
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
-#include "list.h"
-/*******************************************************************
-read the element list file
+#include <grass/gis.h>
+#include <grass/glocale.h>
- format is:
+#include "manage_local_proto.h"
+int nlist;
+struct list *list;
+
+static void format_error(char *, int, char *);
+
+/*!
+ \brief Read list of elements
+
+ Format:
+
+ \code
# ... comments
main element:alias:description:menu text
sub element:description
@@ -15,14 +38,14 @@
.
.
.
-******************************************************************/
+ \endcode
-int nlist;
-struct list *list;
+ \param chech_if_empty TRUE for check if element is empty
-static int format_error(char *, int, char *);
-
-int read_list(int check_if_empty)
+ \return 0
+ \return 1
+*/
+int M_read_list(int check_if_empty, int *num)
{
FILE *fd;
char element_list[GPATH_MAX];
@@ -47,7 +70,7 @@
fd = fopen(element_list, "r");
if (!fd)
- G_fatal_error("can't open database element list <%s>", element_list);
+ G_fatal_error(_("Unable to open data base element list '%s'"), element_list);
line = 0;
while (G_getl(buf, sizeof(buf), fd)) {
@@ -65,7 +88,7 @@
G_strip(elem);
G_strip(desc);
- add_element(elem, desc);
+ M__add_element(elem, desc);
}
else { /* main element */
@@ -89,24 +112,25 @@
list[nlist].element = 0;
list[nlist].desc = 0;
list[nlist].status = 0;
- if (!check_if_empty || !empty(elem)) {
+ if (!check_if_empty || !M__empty(elem)) {
list[nlist].status = 1;
any = 1;
}
nlist++;
- add_element(elem, desc);
+ M__add_element(elem, desc);
}
}
+ if (num)
+ *num = nlist;
+
fclose(fd);
return any;
}
-static int format_error(char *element_list, int line, char *buf)
+void format_error(char *element_list, int line, char *buf)
{
- G_fatal_error(_("Format error: <%s>\nLine: %d\n%s"), element_list, line,
+ G_fatal_error(_("Format error: file ('%s') line (%d) - %s"), element_list, line,
buf);
-
- return 1;
}
Modified: grass/trunk/lib/manage/show_elem.c
===================================================================
--- grass/trunk/lib/manage/show_elem.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/show_elem.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,17 +1,33 @@
+/*!
+ \file lib/manage/show_elem.c
+
+ \brief Manage Library - Show elements
+
+ (C) 2001-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.
+
+ \author Original author CERL
+*/
+
+#include <stdio.h>
#include <string.h>
-#include "list.h"
-int show_elements(void)
+#include "manage_local_proto.h"
+
+/*!
+ \brief Print element name/desc to stdout
+*/
+void M_show_elements(void)
{
int n;
- int len;
+ unsigned int len;
len = 0;
for (n = 0; n < nlist; n++)
if (strlen(list[n].alias) > len)
len = strlen(list[n].alias);
for (n = 0; n < nlist; n++)
- fprintf(stderr, " %-*s (%s)\n", len, list[n].alias, list[n].text);
-
- return 0;
+ fprintf(stdout, " %-*s (%s)\n", len, list[n].alias, list[n].text);
}
Modified: grass/trunk/lib/manage/sighold.c
===================================================================
--- grass/trunk/lib/manage/sighold.c 2011-01-19 22:57:57 UTC (rev 45092)
+++ grass/trunk/lib/manage/sighold.c 2011-01-20 12:10:50 UTC (rev 45093)
@@ -1,7 +1,27 @@
+/*!
+ \file lib/manage/sighol.c
+
+ \brief Manage Library - Hold signals
+
+ (C) 2001-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.
+
+ \author Original author CERL
+*/
+
#include <signal.h>
#include <grass/config.h>
-int hold_signals(int hold)
+/*!
+ \brief Hold signals
+
+ \param hold
+
+ \return 0
+*/
+int M__hold_signals(int hold)
{
RETSIGTYPE (*sig)() = hold ? SIG_IGN : SIG_DFL;
More information about the grass-commit
mailing list