[GRASS-SVN] r34177 - in grass/trunk: general/g.mlist
general/g.mremove general/manage general/manage/cmd
general/manage/lib include/Make lib lib/manage
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Nov 7 05:42:46 EST 2008
Author: glynn
Date: 2008-11-07 05:42:45 -0500 (Fri, 07 Nov 2008)
New Revision: 34177
Added:
grass/trunk/lib/manage/
grass/trunk/lib/manage/Makefile
grass/trunk/lib/manage/README
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/list.h
grass/trunk/lib/manage/read_list.c
grass/trunk/lib/manage/show_elem.c
grass/trunk/lib/manage/sighold.c
Removed:
grass/trunk/general/g.mlist/read_list.c
grass/trunk/general/g.mremove/do_remove.c
grass/trunk/general/g.mremove/read_list.c
grass/trunk/general/manage/lib/Makefile
grass/trunk/general/manage/lib/README
grass/trunk/general/manage/lib/add_elem.c
grass/trunk/general/manage/lib/copy.sh
grass/trunk/general/manage/lib/do_copy.c
grass/trunk/general/manage/lib/do_list.c
grass/trunk/general/manage/lib/do_remove.c
grass/trunk/general/manage/lib/do_rename.c
grass/trunk/general/manage/lib/empty.c
grass/trunk/general/manage/lib/find.c
grass/trunk/general/manage/lib/get_len.c
grass/trunk/general/manage/lib/read_list.c
grass/trunk/general/manage/lib/show_elem.c
grass/trunk/general/manage/lib/sighold.c
grass/trunk/general/manage/list.h
Modified:
grass/trunk/general/g.mlist/Makefile
grass/trunk/general/g.mlist/global.h
grass/trunk/general/g.mlist/main.c
grass/trunk/general/g.mremove/Makefile
grass/trunk/general/g.mremove/global.h
grass/trunk/general/g.mremove/main.c
grass/trunk/general/manage/Makefile
grass/trunk/general/manage/cmd/Makefile
grass/trunk/general/manage/cmd/copy.c
grass/trunk/general/manage/cmd/init.c
grass/trunk/general/manage/cmd/list.c
grass/trunk/general/manage/cmd/remove.c
grass/trunk/general/manage/cmd/rename.c
grass/trunk/include/Make/Rules.make
grass/trunk/lib/Makefile
Log:
Move general/manage/lib -> lib/manage
Remove local copies of lib/manage functions from g.mlist, g.mremove
Modified: grass/trunk/general/g.mlist/Makefile
===================================================================
--- grass/trunk/general/g.mlist/Makefile 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/g.mlist/Makefile 2008-11-07 10:42:45 UTC (rev 34177)
@@ -3,8 +3,8 @@
PGM = g.mlist
EXTRA_INC = $(REGEXINCPATH)
-LIBES = $(GISLIB) $(REGEXLIBPATH) $(REGEXLIB)
-DEPENDENCIES = $(GISDEP)
+LIBES = $(MANAGELIB) $(GISLIB) $(REGEXLIBPATH) $(REGEXLIB)
+DEPENDENCIES = $(MANAGEDEP) $(GISDEP)
include $(MODULE_TOPDIR)/include/Make/Module.make
Modified: grass/trunk/general/g.mlist/global.h
===================================================================
--- grass/trunk/general/g.mlist/global.h 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/g.mlist/global.h 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,23 +1,7 @@
#include <grass/gis.h>
#include <grass/glocale.h>
+#include <grass/list.h>
-struct list
-{
- char **element; /* list of related elements */
- char *alias; /* element alias */
- 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 */
-};
-
-/* read_list.c */
-int read_list(int);
-
/* wc2regex.c */
char *wc2regex(const char *);
-extern int nlist;
-extern struct list *list;
Modified: grass/trunk/general/g.mlist/main.c
===================================================================
--- grass/trunk/general/g.mlist/main.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/g.mlist/main.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -22,16 +22,14 @@
#include <string.h>
#include <regex.h>
#include <grass/spawn.h>
+#include <grass/list.h>
#include "global.h"
-int nlist;
-struct list *list;
-
static int any;
-static void do_list(const struct list *,
- const char *, const char *, const char *,
- int, int, int);
+static void make_list(const struct list *,
+ const char *, const char *, const char *,
+ int, int, int);
static int parse(const char *);
static int ls_filter(const char *, void *);
@@ -204,9 +202,9 @@
}
}
else
- do_list(&list[n], pattern, opt.mapset->answer, separator,
- flag.pretty->answer, flag.type->answer,
- flag.mapset->answer);
+ make_list(&list[n], pattern, opt.mapset->answer, separator,
+ flag.pretty->answer, flag.type->answer,
+ flag.mapset->answer);
}
if (!flag.pretty->answer && any)
@@ -220,7 +218,7 @@
exit(EXIT_SUCCESS);
}
-static void do_list(
+static void make_list(
const struct list *elem,
const char *pattern, const char *mapset, const char *separator,
int pretty, int add_type, int add_mapset)
@@ -240,8 +238,8 @@
if (!mapset || !*mapset) {
int n;
for (n = 0; mapset = G__mapset_name(n), mapset; n++)
- do_list(elem, pattern, mapset, separator,
- pretty, add_type, add_mapset);
+ make_list(elem, pattern, mapset, separator,
+ pretty, add_type, add_mapset);
return;
}
Deleted: grass/trunk/general/g.mlist/read_list.c
===================================================================
--- grass/trunk/general/g.mlist/read_list.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/g.mlist/read_list.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,148 +0,0 @@
-/* Copied from general/manage */
-
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <dirent.h>
-#include "global.h"
-
-/*******************************************************************
-read the element list file
-
- format is:
-
- # ... comments
- main element:alias:description:menu text
- sub element:description
- sub element:description
- .
- .
- .
-******************************************************************/
-
-static int add_element(const char *, const char *);
-static int empty(const char *);
-static int format_error(const char *, int, const char *);
-
-int read_list(int check_if_empty)
-{
- FILE *fd;
- char element_list[600], buf[1024], elem[100], alias[100], desc[100],
- text[100], *env;
- int any, line;
-
- nlist = 0;
- list = 0;
- any = 0;
-
- if ((env = G__getenv("ELEMENT_LIST")))
- strcpy(element_list, env);
- else
- sprintf(element_list, "%s/etc/element_list", G_gisbase());
- fd = fopen(element_list, "r");
-
- if (!fd)
- G_fatal_error("can't open database element list <%s>", element_list);
-
- line = 0;
- while (G_getl(buf, sizeof(buf), fd)) {
- line++;
- if (*buf == '#')
- continue;
- if (*buf == ' ' || *buf == '\t') { /* support element */
- *desc = 0;
- if (sscanf(buf, "%[^:]:%[^\n]", elem, desc) < 1)
- continue;
- if (*elem == '#')
- continue;
- if (nlist == 0)
- format_error(element_list, line, buf);
-
- G_strip(elem);
- G_strip(desc);
- add_element(elem, desc);
- }
- else { /* main element */
-
- if (sscanf
- (buf, "%[^:]:%[^:]:%[^:]:%[^\n]", elem, alias, desc,
- text) != 4)
- format_error(element_list, line, buf);
-
- G_strip(elem);
- G_strip(alias);
- G_strip(desc);
- G_strip(text);
-
- list =
- (struct list *)G_realloc(list, (nlist + 1) * sizeof(*list));
- list[nlist].mainelem = G_store(elem);
- list[nlist].alias = G_store(alias);
- list[nlist].maindesc = G_store(desc);
- list[nlist].text = G_store(text);
- list[nlist].nelem = 0;
- list[nlist].element = 0;
- list[nlist].desc = 0;
- list[nlist].status = 0;
- if (!check_if_empty || !empty(elem)) {
- list[nlist].status = 1;
- any = 1;
- }
- nlist++;
- add_element(elem, desc);
- }
- }
-
- fclose(fd);
-
- return any;
-}
-
-static int add_element(const char *elem, const char *desc)
-{
- int n;
- int nelem;
-
- if (*desc == 0)
- desc = elem;
-
- n = nlist - 1;
- nelem = list[n].nelem++;
- list[n].element =
- (char **)G_realloc(list[n].element, (nelem + 1) * sizeof(char *));
- list[n].element[nelem] = G_store(elem);
- list[n].desc =
- (char **)G_realloc(list[n].desc, (nelem + 1) * sizeof(char *));
- list[n].desc[nelem] = G_store(desc);
-
- return 0;
-}
-
-static int empty(const char *elem)
-{
- DIR *dirp;
- struct dirent *dp;
- char dir[1024];
- int any;
-
- G__file_name(dir, elem, "", G_mapset());
-
- any = 0;
- if ((dirp = opendir(dir)) != NULL) {
- while (!any && (dp = readdir(dirp)) != NULL) {
- if (dp->d_name[0] != '.')
- any = 1;
- }
- closedir(dirp);
- }
-
- return any == 0;
-}
-
-static int format_error(const char *element_list, int line, const char *buf)
-{
- G_fatal_error(_("Format error: <%s>\nLine: %d\n%s"), element_list, line,
- buf);
-
- return 1;
-}
Modified: grass/trunk/general/g.mremove/Makefile
===================================================================
--- grass/trunk/general/g.mremove/Makefile 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/g.mremove/Makefile 2008-11-07 10:42:45 UTC (rev 34177)
@@ -2,8 +2,8 @@
PGM = g.mremove
-LIBES = $(GISLIB) $(VECTLIB) $(G3DLIB) $(REGEXLIBPATH) $(REGEXLIB)
-DEPENDENCIES = $(GISDEP) $(VECTDEP) $(G3DDEP)
+LIBES = $(MANAGELIB) $(VECTLIB) $(G3DLIB) $(GISLIB) $(REGEXLIBPATH) $(REGEXLIB)
+DEPENDENCIES = $(MANAGEDEP) $(VECTDEP) $(G3DDEP) $(GISDEP)
EXTRA_INC = $(VECT_INC) $(REGEXINCPATH)
EXTRA_CFLAGS = $(VECT_CFLAGS)
Deleted: grass/trunk/general/g.mremove/do_remove.c
===================================================================
--- grass/trunk/general/g.mremove/do_remove.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/g.mremove/do_remove.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,102 +0,0 @@
-#include <string.h>
-#include <grass/Vect.h>
-#include <grass/G3d.h>
-#include "global.h"
-
-/*
- * returns 0 - success
- * 1 - error
- */
-int do_remove(int n, char *old)
-{
- int i, ret;
-
- /* int len; */
- char *mapset;
- int result = 0;
- int removed = 0;
- char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
-
- G_message(_("Removing %s <%s>"), list[n].maindesc, old);
-
- /* len = get_description_len(n); */
-
- if (G__name_is_fully_qualified(old, xname, xmapset)) {
- if (strcmp(xmapset, G_mapset()) != 0)
- G_fatal_error("%s is not in the current mapset (%s)", old,
- G_mapset());
- old = xname;
- }
-
- if (G_strcasecmp(list[n].alias, "vect") == 0) {
- if ((mapset = G_find_vector2(old, "")) == NULL) {
- G_warning(_("Vector map <%s> not found"), old);
- }
- else {
- ret = Vect_delete(old);
- if (ret != -1) {
- removed = 1;
- }
- else {
- G_warning(_("couldn't be removed"));
- result = 1;
- }
- }
- }
- else {
- if (G_strcasecmp(list[n].alias, "rast") == 0) {
- if ((mapset = G_find_cell2(old, "")) == NULL)
- G_warning(_("Raster map <%s> not found"), old);
- }
-
- if (G_strcasecmp(list[n].alias, "rast3d") == 0) {
- if ((mapset = G_find_grid3(old, "")) == NULL)
- G_warning(_("3D raster map <%s> not found"), old);
- }
-
- for (i = 0; i < list[n].nelem; i++) {
-
- switch (G_remove(list[n].element[i], old)) {
- case -1:
- G_warning(_("%s: couldn't be removed"), list[n].desc[i]);
- result = 1;
- break;
- case 0:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: missing"), list[n].desc[i]);
- break;
- case 1:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: removed"), list[n].desc[i]);
- removed = 1;
- break;
- }
- }
- }
-
- if (G_strcasecmp(list[n].element[0], "cell") == 0) {
- char colr2[GMAPSET_MAX + 6];
-
- sprintf(colr2, "colr2/%s", G_mapset());
- switch (G_remove(colr2, old)) {
- case -1:
- G_warning("%s: %s", colr2, _("couldn't be removed"));
- result = 1;
- break;
- case 0:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: missing"), colr2);
- break;
- case 1:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: removed"), colr2);
- removed = 1;
- break;
- }
- }
-
- if (!removed)
- G_warning(_("<%s> nothing removed"), old);
-
- return result;
-}
Modified: grass/trunk/general/g.mremove/global.h
===================================================================
--- grass/trunk/general/g.mremove/global.h 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/g.mremove/global.h 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,29 +1,9 @@
#include <grass/gis.h>
#include <grass/glocale.h>
+#include <grass/list.h>
-struct list
-{
- char **element; /* list of related elements */
- char *alias; /* element alias */
- 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 */
-};
-
-/* read_list.c */
-int read_list(int);
-
/* wc2regex.c */
char *wc2regex(const char *);
/* check_reclass.c */
int check_reclass(const char *, const char *, int);
-
-/* do_remove.c */
-int do_remove(int, char *);
-
-extern int nlist;
-extern struct list *list;
Modified: grass/trunk/general/g.mremove/main.c
===================================================================
--- grass/trunk/general/g.mremove/main.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/g.mremove/main.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -30,9 +30,6 @@
#include <regex.h>
#include "global.h"
-int nlist;
-struct list *list;
-
static int ls_filter(const char *, void *);
int main(int argc, char *argv[])
Deleted: grass/trunk/general/g.mremove/read_list.c
===================================================================
--- grass/trunk/general/g.mremove/read_list.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/g.mremove/read_list.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,148 +0,0 @@
-/* Copied from general/manage */
-
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <dirent.h>
-#include "global.h"
-
-/*******************************************************************
-read the element list file
-
- format is:
-
- # ... comments
- main element:alias:description:menu text
- sub element:description
- sub element:description
- .
- .
- .
-******************************************************************/
-
-static int add_element(const char *, const char *);
-static int empty(const char *);
-static int format_error(const char *, int, const char *);
-
-int read_list(int check_if_empty)
-{
- FILE *fd;
- char element_list[600], buf[1024], elem[100], alias[100], desc[100],
- text[100], *env;
- int any, line;
-
- nlist = 0;
- list = 0;
- any = 0;
-
- if ((env = G__getenv("ELEMENT_LIST")))
- strcpy(element_list, env);
- else
- sprintf(element_list, "%s/etc/element_list", G_gisbase());
- fd = fopen(element_list, "r");
-
- if (!fd)
- G_fatal_error("can't open database element list <%s>", element_list);
-
- line = 0;
- while (G_getl(buf, sizeof(buf), fd)) {
- line++;
- if (*buf == '#')
- continue;
- if (*buf == ' ' || *buf == '\t') { /* support element */
- *desc = 0;
- if (sscanf(buf, "%[^:]:%[^\n]", elem, desc) < 1)
- continue;
- if (*elem == '#')
- continue;
- if (nlist == 0)
- format_error(element_list, line, buf);
-
- G_strip(elem);
- G_strip(desc);
- add_element(elem, desc);
- }
- else { /* main element */
-
- if (sscanf
- (buf, "%[^:]:%[^:]:%[^:]:%[^\n]", elem, alias, desc,
- text) != 4)
- format_error(element_list, line, buf);
-
- G_strip(elem);
- G_strip(alias);
- G_strip(desc);
- G_strip(text);
-
- list =
- (struct list *)G_realloc(list, (nlist + 1) * sizeof(*list));
- list[nlist].mainelem = G_store(elem);
- list[nlist].alias = G_store(alias);
- list[nlist].maindesc = G_store(desc);
- list[nlist].text = G_store(text);
- list[nlist].nelem = 0;
- list[nlist].element = 0;
- list[nlist].desc = 0;
- list[nlist].status = 0;
- if (!check_if_empty || !empty(elem)) {
- list[nlist].status = 1;
- any = 1;
- }
- nlist++;
- add_element(elem, desc);
- }
- }
-
- fclose(fd);
-
- return any;
-}
-
-static int add_element(const char *elem, const char *desc)
-{
- int n;
- int nelem;
-
- if (*desc == 0)
- desc = elem;
-
- n = nlist - 1;
- nelem = list[n].nelem++;
- list[n].element =
- (char **)G_realloc(list[n].element, (nelem + 1) * sizeof(char *));
- list[n].element[nelem] = G_store(elem);
- list[n].desc =
- (char **)G_realloc(list[n].desc, (nelem + 1) * sizeof(char *));
- list[n].desc[nelem] = G_store(desc);
-
- return 0;
-}
-
-static int empty(const char *elem)
-{
- DIR *dirp;
- struct dirent *dp;
- char dir[1024];
- int any;
-
- G__file_name(dir, elem, "", G_mapset());
-
- any = 0;
- if ((dirp = opendir(dir)) != NULL) {
- while (!any && (dp = readdir(dirp)) != NULL) {
- if (dp->d_name[0] != '.')
- any = 1;
- }
- closedir(dirp);
- }
-
- return any == 0;
-}
-
-static int format_error(const char *element_list, int line, const char *buf)
-{
- G_fatal_error(_("Format error: <%s>\nLine: %d\n%s"), element_list, line,
- buf);
-
- return 1;
-}
Modified: grass/trunk/general/manage/Makefile
===================================================================
--- grass/trunk/general/manage/Makefile 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/Makefile 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,10 +1,7 @@
MODULE_TOPDIR = ../..
-SUBDIRS = \
- lib \
- cmd \
- lister
+SUBDIRS = cmd lister
include $(MODULE_TOPDIR)/include/Make/Dir.make
Modified: grass/trunk/general/manage/cmd/Makefile
===================================================================
--- grass/trunk/general/manage/cmd/Makefile 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/cmd/Makefile 2008-11-07 10:42:45 UTC (rev 34177)
@@ -14,7 +14,5 @@
LIST = $(OBJDIR)/init.o
DEPENDENCIES = $(GISDEP) $(VECTDEP) $(DBMIDEP) $(MANAGEDEP) $(G3DDEP)
-EXTRA_INC = -I..
-
default: multi
Modified: grass/trunk/general/manage/cmd/copy.c
===================================================================
--- grass/trunk/general/manage/cmd/copy.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/cmd/copy.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -21,7 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include <grass/glocale.h>
-#include "list.h"
+#include <grass/list.h>
#include "local_proto.h"
int main(int argc, char *argv[])
Modified: grass/trunk/general/manage/cmd/init.c
===================================================================
--- grass/trunk/general/manage/cmd/init.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/cmd/init.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,4 +1,4 @@
-#include "list.h"
+#include <grass/list.h>
#include "local_proto.h"
int init(char *pgm)
Modified: grass/trunk/general/manage/cmd/list.c
===================================================================
--- grass/trunk/general/manage/cmd/list.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/cmd/list.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -21,8 +21,8 @@
#include <string.h>
#include <unistd.h>
#include <grass/spawn.h>
+#include <grass/list.h>
#include "local_proto.h"
-#include "list.h"
struct Option *element;
Modified: grass/trunk/general/manage/cmd/remove.c
===================================================================
--- grass/trunk/general/manage/cmd/remove.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/cmd/remove.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -21,8 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include <grass/glocale.h>
-
-#include "list.h"
+#include <grass/list.h>
#include "local_proto.h"
static int check_reclass(const char *name, const char *mapset, int force)
Modified: grass/trunk/general/manage/cmd/rename.c
===================================================================
--- grass/trunk/general/manage/cmd/rename.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/cmd/rename.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -21,7 +21,7 @@
#include <string.h>
#include <grass/gis.h>
#include <grass/glocale.h>
-#include "list.h"
+#include <grass/list.h>
#include "local_proto.h"
int main(int argc, char *argv[])
Deleted: grass/trunk/general/manage/lib/Makefile
===================================================================
--- grass/trunk/general/manage/lib/Makefile 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/Makefile 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,14 +0,0 @@
-MODULE_TOPDIR = ../../..
-
-LIB_NAME = $(MANAGE_LIBNAME)
-DEPENDENCIES = $(GISDEP) $(VECTDEP) $(G3DDEP)
-
-include $(MODULE_TOPDIR)/include/Make/Lib.make
-
-LOCAL_HEADERS := $(wildcard *.h) ../list.h
-
-EXTRA_INC = -I.. $(VECT_INC)
-EXTRA_CFLAGS = $(VECT_CFLAGS)
-EXTRA_LIBS = $(GISLIB) $(VECTLIB) $(G3DLIB)
-
-default: stlib
Deleted: grass/trunk/general/manage/lib/README
===================================================================
--- grass/trunk/general/manage/lib/README 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/README 2008-11-07 10:42:45 UTC (rev 34177)
@@ -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_nospam 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.
- *
- *****************************************************************************/
Deleted: grass/trunk/general/manage/lib/add_elem.c
===================================================================
--- grass/trunk/general/manage/lib/add_elem.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/add_elem.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,20 +0,0 @@
-#include "list.h"
-int add_element(char *elem, char *desc)
-{
- int n;
- int nelem;
-
- if (*desc == 0)
- desc = elem;
-
- n = nlist - 1;
- nelem = list[n].nelem++;
- list[n].element =
- (char **)G_realloc(list[n].element, (nelem + 1) * sizeof(char *));
- list[n].element[nelem] = G_store(elem);
- list[n].desc =
- (char **)G_realloc(list[n].desc, (nelem + 1) * sizeof(char *));
- list[n].desc[nelem] = G_store(desc);
-
- return 0;
-}
Deleted: grass/trunk/general/manage/lib/copy.sh
===================================================================
--- grass/trunk/general/manage/lib/copy.sh 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/copy.sh 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,36 +0,0 @@
-:
-# copies files or directories
-# new file or directory should not exist, but this
-# is not enforced - copy a a should be avoided
-# files beginning with . are not copied
-
-case $# in
- 2) a=$1 ; b=$2 ;;
- *) echo "usage: $0 a b"; exit 1 ;;
-esac
-
-if [ -d $a ]
-then
- if [ -f $b ]
- then
- rm -f $b
- fi
- if [ ! -d $b ]
- then
- mkdir $b
- fi
- for f in . `cd $a; ls`
- do
- if [ "$f" != "." ]
- then
- $0 $a/$f $b/$f
- fi
- done
-elif [ -f $a ]
-then
- cp $a $b
-else
- echo $0: $a not found
- exit 2
-fi
-exit 0
Deleted: grass/trunk/general/manage/lib/do_copy.c
===================================================================
--- grass/trunk/general/manage/lib/do_copy.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/do_copy.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,66 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <grass/gis.h>
-#include <grass/Vect.h>
-#include "list.h"
-
-/*
- * returns 0 - success
- * 1 - error
- */
-int do_copy(int n, char *old, char *mapset, char *new)
-{
- int i, ret, len;
- char path[GPATH_MAX], path2[GPATH_MAX];
- int result = 0;
-
- G_debug(3, "Copy %s", list[n].alias);
-
- 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);
-
- hold_signals(1);
- if (G_strcasecmp(list[n].alias, "vect") == 0) {
- ret = Vect_copy(old, mapset, new, stderr);
- if (ret == -1) {
- G_warning("Cannot copy <%s> to current mapset as <%s>",
- G_fully_qualified_name(old, mapset), new);
- result = 1;
- }
- }
- else {
- for (i = 0; i < list[n].nelem; i++) {
- G__make_mapset_element(list[n].element[i]);
- 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]);
-
- continue;
- }
- G__file_name(path2, list[n].element[i], new, G_mapset());
- if (G_recursive_copy(path, path2) == 1) {
- result = 1;
- }
- else {
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: copied"), list[n].desc[i]);
- }
- }
- }
-
- /* special case: remove (yes, remove) the secondary color table, if it exists */
- if (G_strcasecmp(list[n].element[0], "cell") == 0) {
- char colr2[GNAME_MAX];
-
- sprintf(colr2, "colr2/%s", G_mapset());
- G_remove(colr2, new);
- }
- hold_signals(0);
-
- return result;
-}
Deleted: grass/trunk/general/manage/lib/do_list.c
===================================================================
--- grass/trunk/general/manage/lib/do_list.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/do_list.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,7 +0,0 @@
-#include "list.h"
-int do_list(int n, char *mapset)
-{
- G_list_element(list[n].element[0], list[n].desc[0], mapset, (int (*)())0);
-
- return 0;
-}
Deleted: grass/trunk/general/manage/lib/do_remove.c
===================================================================
--- grass/trunk/general/manage/lib/do_remove.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/do_remove.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,108 +0,0 @@
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/Vect.h>
-#include <grass/glocale.h>
-#include <grass/G3d.h>
-#include "list.h"
-
-/*
- * returns 0 - success
- * 1 - error
- */
-int do_remove(int n, char *old)
-{
- int i, ret;
-
- /* int len; */
- char *mapset;
- int result = 0;
- int removed = 0;
- char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
-
- G_message(_("Removing %s <%s>"), list[n].maindesc, old);
-
- /* len = get_description_len(n); */
-
- hold_signals(1);
-
- if (G__name_is_fully_qualified(old, xname, xmapset)) {
- if (strcmp(xmapset, G_mapset()) != 0)
- G_fatal_error("%s is not in the current mapset (%s)", old,
- G_mapset());
- old = xname;
- }
-
- if (G_strcasecmp(list[n].alias, "vect") == 0) {
- if ((mapset = G_find_vector2(old, "")) == NULL) {
- G_warning(_("Vector map <%s> not found"), old);
- }
- else {
- ret = Vect_delete(old);
- if (ret != -1) {
- removed = 1;
- }
- else {
- G_warning(_("couldn't be removed"));
- result = 1;
- }
- }
- }
- else {
- if (G_strcasecmp(list[n].alias, "rast") == 0) {
- if ((mapset = G_find_cell2(old, "")) == NULL)
- G_warning(_("Raster map <%s> not found"), old);
- }
-
- if (G_strcasecmp(list[n].alias, "rast3d") == 0) {
- if ((mapset = G_find_grid3(old, "")) == NULL)
- G_warning(_("3D raster map <%s> not found"), old);
- }
-
- for (i = 0; i < list[n].nelem; i++) {
-
- switch (G_remove(list[n].element[i], old)) {
- case -1:
- G_warning(_("%s: couldn't be removed"), list[n].desc[i]);
- result = 1;
- break;
- case 0:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: missing"), list[n].desc[i]);
- break;
- case 1:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: removed"), list[n].desc[i]);
- removed = 1;
- break;
- }
- }
- }
-
- if (G_strcasecmp(list[n].element[0], "cell") == 0) {
- char colr2[50];
-
- sprintf(colr2, "colr2/%s", G_mapset());
- switch (G_remove(colr2, old)) {
- case -1:
- G_warning("%s: %s", colr2, _("couldn't be removed"));
- result = 1;
- break;
- case 0:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: missing"), colr2);
- break;
- case 1:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: removed"), colr2);
- removed = 1;
- break;
- }
- }
-
- hold_signals(0);
-
- if (!removed)
- G_warning(_("<%s> nothing removed"), old);
-
- return result;
-}
Deleted: grass/trunk/general/manage/lib/do_rename.c
===================================================================
--- grass/trunk/general/manage/lib/do_rename.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/do_rename.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,108 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/Vect.h>
-#include <grass/G3d.h>
-#include "list.h"
-
-/*
- * returns 0 - success
- * 1 - error
- */
-int do_rename(int n, char *old, char *new)
-{
- int i, ret;
- int len;
- char *mapset;
- 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);
-
- if (G_strcasecmp(old, new) == 0)
- return 1;
-
- len = get_description_len(n);
-
- hold_signals(1);
-
- if (G_strcasecmp(list[n].alias, "vect") == 0) {
- if ((mapset = G_find_vector2(old, "")) == NULL) {
- G_warning(_("Vector map <%s> not found"), old);
- }
- else {
- ret = Vect_rename(old, new, stderr);
- if (ret != -1) {
- renamed = 1;
- }
- else {
- G_warning(_("Cannot rename <%s> to <%s>"), old, new);
- result = 1;
- }
- }
- }
- else {
- if (G_strcasecmp(list[n].alias, "rast") == 0) {
- if ((mapset = G_find_cell2(old, "")) == NULL)
- G_warning(_("Raster map <%s> not found"), old);
- }
-
- if (G_strcasecmp(list[n].alias, "rast3d") == 0) {
- if ((mapset = G_find_grid3(old, "")) == NULL)
- G_warning(_("3D raster map <%s> not found"), old);
- }
-
- for (i = 0; i < list[n].nelem; i++) {
- 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]);
- result = 1;
- break;
- case 0:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: missing"), list[n].desc[i]);
- break;
- case 1:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: renamed"), list[n].desc[i]);
- renamed = 1;
- break;
- }
- }
-
- if (G_strcasecmp(list[n].element[0], "cell") == 0) {
- char colr2[50];
-
- sprintf(colr2, "colr2/%s", G_mapset());
- G_remove(colr2, new);
- switch (G_rename(colr2, old, new)) {
- case -1:
- G_warning(_("%s: couldn't be renamed"), colr2);
- result = 1;
- break;
- case 0:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: missing"), colr2);
- break;
- case 1:
- if (G_verbose() == G_verbose_max())
- G_message(_("%s: renamed"), colr2);
- renamed = 1;
- break;
- }
- }
- }
- hold_signals(0);
-
- if (!renamed)
- G_warning(_("<%s> nothing renamed"), old);
-
- return result;
-}
Deleted: grass/trunk/general/manage/lib/empty.c
===================================================================
--- grass/trunk/general/manage/lib/empty.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/empty.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,25 +0,0 @@
-/* look for at least one file in the element */
-#include <sys/types.h>
-#include <dirent.h>
-#include <grass/gis.h>
-
-int empty(char *elem)
-{
- DIR *dirp;
- struct dirent *dp;
- char dir[1024];
- int any;
-
- G__file_name(dir, elem, "", G_mapset());
-
- any = 0;
- if ((dirp = opendir(dir)) != NULL) {
- while (!any && (dp = readdir(dirp)) != NULL) {
- if (dp->d_name[0] != '.')
- any = 1;
- }
- closedir(dirp);
- }
-
- return any == 0;
-}
Deleted: grass/trunk/general/manage/lib/find.c
===================================================================
--- grass/trunk/general/manage/lib/find.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/find.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,16 +0,0 @@
-#include <string.h>
-#include "list.h"
-
-char *find(int n, char *name, char *mapsets)
-{
- char *mapset;
-
- mapset = G_find_file(list[n].element[0], name, mapsets);
- if (mapset) {
- char temp[GNAME_MAX];
-
- sscanf(name, "%s", temp);
- strcpy(name, temp);
- }
- return mapset;
-}
Deleted: grass/trunk/general/manage/lib/get_len.c
===================================================================
--- grass/trunk/general/manage/lib/get_len.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/get_len.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,17 +0,0 @@
-#include <string.h>
-#include "list.h"
-
-int get_description_len(int n)
-{
- int len;
- int l;
- int i;
-
- len = 1;
- for (i = 0; i < list[n].nelem; i++) {
- l = strlen(list[n].desc[i]);
- if (l > len)
- len = l;
- }
- return len;
-}
Deleted: grass/trunk/general/manage/lib/read_list.c
===================================================================
--- grass/trunk/general/manage/lib/read_list.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/read_list.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,112 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "list.h"
-
-/*******************************************************************
-read the element list file
-
- format is:
-
- # ... comments
- main element:alias:description:menu text
- sub element:description
- sub element:description
- .
- .
- .
-******************************************************************/
-
-int nlist;
-struct list *list;
-
-static int format_error(char *, int, char *);
-
-int read_list(int check_if_empty)
-{
- FILE *fd;
- char element_list[GPATH_MAX];
- char buf[1024];
- char elem[100];
- char alias[100];
- char desc[100];
- char text[100];
- int any;
- int line;
- char *env;
-
- nlist = 0;
- list = 0;
- any = 0;
-
- env = getenv("ELEMENT_LIST");
- if (env)
- strcpy(element_list, env);
- else
- sprintf(element_list, "%s/etc/element_list", G_gisbase());
- fd = fopen(element_list, "r");
-
- if (!fd)
- G_fatal_error("can't open database element list <%s>", element_list);
-
- line = 0;
- while (G_getl(buf, sizeof(buf), fd)) {
- line++;
- if (*buf == '#')
- continue;
- if (*buf == ' ' || *buf == '\t') { /* support element */
- *desc = 0;
- if (sscanf(buf, "%[^:]:%[^\n]", elem, desc) < 1)
- continue;
- if (*elem == '#')
- continue;
- if (nlist == 0)
- format_error(element_list, line, buf);
-
- G_strip(elem);
- G_strip(desc);
- add_element(elem, desc);
- }
- else { /* main element */
-
- if (sscanf
- (buf, "%[^:]:%[^:]:%[^:]:%[^\n]", elem, alias, desc,
- text) != 4)
- format_error(element_list, line, buf);
-
- G_strip(elem);
- G_strip(alias);
- G_strip(desc);
- G_strip(text);
-
- list =
- (struct list *)G_realloc(list, (nlist + 1) * sizeof(*list));
- list[nlist].mainelem = G_store(elem);
- list[nlist].alias = G_store(alias);
- list[nlist].maindesc = G_store(desc);
- list[nlist].text = G_store(text);
- list[nlist].nelem = 0;
- list[nlist].element = 0;
- list[nlist].desc = 0;
- list[nlist].status = 0;
- if (!check_if_empty || !empty(elem)) {
- list[nlist].status = 1;
- any = 1;
- }
- nlist++;
- add_element(elem, desc);
- }
- }
-
- fclose(fd);
-
- return any;
-}
-
-static int format_error(char *element_list, int line, char *buf)
-{
- G_fatal_error(_("Format error: <%s>\nLine: %d\n%s"), element_list, line,
- buf);
-
- return 1;
-}
Deleted: grass/trunk/general/manage/lib/show_elem.c
===================================================================
--- grass/trunk/general/manage/lib/show_elem.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/show_elem.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,17 +0,0 @@
-#include <string.h>
-#include "list.h"
-
-int show_elements(void)
-{
- int n;
- 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;
-}
Deleted: grass/trunk/general/manage/lib/sighold.c
===================================================================
--- grass/trunk/general/manage/lib/sighold.c 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/lib/sighold.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,21 +0,0 @@
-#include "signal.h"
-
-void (*sig) ();
-
-int hold_signals(int hold)
-{
-
- sig = hold ? SIG_IGN : SIG_DFL;
-
- signal(SIGINT, sig);
-
-#ifndef __MINGW32__
- signal(SIGQUIT, sig);
-#endif
-
-#ifdef SIGTSTP
- signal(SIGTSTP, sig);
-#endif
-
- return 0;
-}
Deleted: grass/trunk/general/manage/list.h
===================================================================
--- grass/trunk/general/manage/list.h 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/general/manage/list.h 2008-11-07 10:42:45 UTC (rev 34177)
@@ -1,65 +0,0 @@
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
-struct list
-{
- char **element; /* list of related elements */
- char *alias; /* element alias */
- 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(char *, char *);
-
-/* copyfile.c */
-int copyfile(char *, char *, char *, char *);
-
-/* do_copy.c */
-int do_copy(int, char *, char *, char *);
-
-/* do_list.c */
-int do_list(int, char *);
-
-/* do_remove.c */
-int do_remove(int, char *);
-
-/* do_rename.c */
-int do_rename(int, char *, char *);
-
-/* empty.c */
-int empty(char *);
-
-/* find.c */
-char *find(int, char *, char *);
-
-/* get_len.c */
-int get_description_len(int);
-
-/* menu.c */
-int menu(int);
-int build_menu(void);
-int free_menu(void);
-int display_menu(void);
-
-/* read_list.c */
-int read_list(int);
-
-/* show_elem.c */
-int show_elements(void);
-
-/* sighold.c */
-int hold_signals(int);
Modified: grass/trunk/include/Make/Rules.make
===================================================================
--- grass/trunk/include/Make/Rules.make 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/include/Make/Rules.make 2008-11-07 10:42:45 UTC (rev 34177)
@@ -16,6 +16,9 @@
$(OBJDIR):
-test -d $(OBJDIR) || $(MKDIR) $(OBJDIR)
+$(ARCH_INCDIR)/%.h: %.h
+ $(INSTALL_DATA) $< $@
+
# default clean rules
clean:
-rm -rf $(OBJDIR) $(EXTRA_CLEAN_DIRS)
Modified: grass/trunk/lib/Makefile
===================================================================
--- grass/trunk/lib/Makefile 2008-11-07 10:33:29 UTC (rev 34176)
+++ grass/trunk/lib/Makefile 2008-11-07 10:42:45 UTC (rev 34177)
@@ -40,13 +40,10 @@
arraystats \
python \
ogsf \
- nviz
+ nviz \
+ iostream \
+ manage
-#compile if C++ compiler present:
-ifneq ($(strip $(CXX)),)
- SUBDIRS += iostream
-endif
-
#doxygen:
DOXNAME=grass
Property changes on: grass/trunk/lib/manage
___________________________________________________________________
Name: svn:ignore
+ *OBJ*
Copied: grass/trunk/lib/manage/Makefile (from rev 34171, grass/trunk/general/manage/lib/Makefile)
===================================================================
--- grass/trunk/lib/manage/Makefile (rev 0)
+++ grass/trunk/lib/manage/Makefile 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,12 @@
+MODULE_TOPDIR = ../..
+
+LIB_NAME = $(MANAGE_LIBNAME)
+DEPENDENCIES = $(GISDEP) $(VECTDEP) $(G3DDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Lib.make
+
+EXTRA_INC = $(VECT_INC)
+EXTRA_CFLAGS = $(VECT_CFLAGS)
+EXTRA_LIBS = $(GISLIB) $(VECTLIB) $(G3DLIB)
+
+default: stlib $(ARCH_INCDIR)/list.h
Property changes on: grass/trunk/lib/manage/Makefile
___________________________________________________________________
Name: svn:mime-type
+ text/x-sh
Name: svn:keywords
+ Author Date Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: grass/trunk/lib/manage/README (from rev 34171, grass/trunk/general/manage/lib/README)
===================================================================
--- grass/trunk/lib/manage/README (rev 0)
+++ grass/trunk/lib/manage/README 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,25 @@
+/****************************************************************************
+ *
+ * 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_nospam 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.
+ *
+ *****************************************************************************/
Property changes on: grass/trunk/lib/manage/README
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Date Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: grass/trunk/lib/manage/add_elem.c (from rev 34171, grass/trunk/general/manage/lib/add_elem.c)
===================================================================
--- grass/trunk/lib/manage/add_elem.c (rev 0)
+++ grass/trunk/lib/manage/add_elem.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,20 @@
+#include "list.h"
+int add_element(char *elem, char *desc)
+{
+ int n;
+ int nelem;
+
+ if (*desc == 0)
+ desc = elem;
+
+ n = nlist - 1;
+ nelem = list[n].nelem++;
+ list[n].element =
+ (char **)G_realloc(list[n].element, (nelem + 1) * sizeof(char *));
+ list[n].element[nelem] = G_store(elem);
+ list[n].desc =
+ (char **)G_realloc(list[n].desc, (nelem + 1) * sizeof(char *));
+ list[n].desc[nelem] = G_store(desc);
+
+ return 0;
+}
Property changes on: grass/trunk/lib/manage/add_elem.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/lib/manage/do_copy.c (from rev 34171, grass/trunk/general/manage/lib/do_copy.c)
===================================================================
--- grass/trunk/lib/manage/do_copy.c (rev 0)
+++ grass/trunk/lib/manage/do_copy.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,66 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <grass/gis.h>
+#include <grass/Vect.h>
+#include "list.h"
+
+/*
+ * returns 0 - success
+ * 1 - error
+ */
+int do_copy(int n, char *old, char *mapset, char *new)
+{
+ int i, ret, len;
+ char path[GPATH_MAX], path2[GPATH_MAX];
+ int result = 0;
+
+ G_debug(3, "Copy %s", list[n].alias);
+
+ 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);
+
+ hold_signals(1);
+ if (G_strcasecmp(list[n].alias, "vect") == 0) {
+ ret = Vect_copy(old, mapset, new, stderr);
+ if (ret == -1) {
+ G_warning("Cannot copy <%s> to current mapset as <%s>",
+ G_fully_qualified_name(old, mapset), new);
+ result = 1;
+ }
+ }
+ else {
+ for (i = 0; i < list[n].nelem; i++) {
+ G__make_mapset_element(list[n].element[i]);
+ 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]);
+
+ continue;
+ }
+ G__file_name(path2, list[n].element[i], new, G_mapset());
+ if (G_recursive_copy(path, path2) == 1) {
+ result = 1;
+ }
+ else {
+ if (G_verbose() == G_verbose_max())
+ G_message(_("%s: copied"), list[n].desc[i]);
+ }
+ }
+ }
+
+ /* special case: remove (yes, remove) the secondary color table, if it exists */
+ if (G_strcasecmp(list[n].element[0], "cell") == 0) {
+ char colr2[GNAME_MAX];
+
+ sprintf(colr2, "colr2/%s", G_mapset());
+ G_remove(colr2, new);
+ }
+ hold_signals(0);
+
+ return result;
+}
Property changes on: grass/trunk/lib/manage/do_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/lib/manage/do_list.c (from rev 34171, grass/trunk/general/manage/lib/do_list.c)
===================================================================
--- grass/trunk/lib/manage/do_list.c (rev 0)
+++ grass/trunk/lib/manage/do_list.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,7 @@
+#include "list.h"
+int do_list(int n, char *mapset)
+{
+ G_list_element(list[n].element[0], list[n].desc[0], mapset, (int (*)())0);
+
+ return 0;
+}
Property changes on: grass/trunk/lib/manage/do_list.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/lib/manage/do_remove.c (from rev 34171, grass/trunk/general/manage/lib/do_remove.c)
===================================================================
--- grass/trunk/lib/manage/do_remove.c (rev 0)
+++ grass/trunk/lib/manage/do_remove.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,108 @@
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/Vect.h>
+#include <grass/glocale.h>
+#include <grass/G3d.h>
+#include "list.h"
+
+/*
+ * returns 0 - success
+ * 1 - error
+ */
+int do_remove(int n, char *old)
+{
+ int i, ret;
+
+ /* int len; */
+ char *mapset;
+ int result = 0;
+ int removed = 0;
+ char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
+
+ G_message(_("Removing %s <%s>"), list[n].maindesc, old);
+
+ /* len = get_description_len(n); */
+
+ hold_signals(1);
+
+ if (G__name_is_fully_qualified(old, xname, xmapset)) {
+ if (strcmp(xmapset, G_mapset()) != 0)
+ G_fatal_error("%s is not in the current mapset (%s)", old,
+ G_mapset());
+ old = xname;
+ }
+
+ if (G_strcasecmp(list[n].alias, "vect") == 0) {
+ if ((mapset = G_find_vector2(old, "")) == NULL) {
+ G_warning(_("Vector map <%s> not found"), old);
+ }
+ else {
+ ret = Vect_delete(old);
+ if (ret != -1) {
+ removed = 1;
+ }
+ else {
+ G_warning(_("couldn't be removed"));
+ result = 1;
+ }
+ }
+ }
+ else {
+ if (G_strcasecmp(list[n].alias, "rast") == 0) {
+ if ((mapset = G_find_cell2(old, "")) == NULL)
+ G_warning(_("Raster map <%s> not found"), old);
+ }
+
+ if (G_strcasecmp(list[n].alias, "rast3d") == 0) {
+ if ((mapset = G_find_grid3(old, "")) == NULL)
+ G_warning(_("3D raster map <%s> not found"), old);
+ }
+
+ for (i = 0; i < list[n].nelem; i++) {
+
+ switch (G_remove(list[n].element[i], old)) {
+ case -1:
+ G_warning(_("%s: couldn't be removed"), list[n].desc[i]);
+ result = 1;
+ break;
+ case 0:
+ if (G_verbose() == G_verbose_max())
+ G_message(_("%s: missing"), list[n].desc[i]);
+ break;
+ case 1:
+ if (G_verbose() == G_verbose_max())
+ G_message(_("%s: removed"), list[n].desc[i]);
+ removed = 1;
+ break;
+ }
+ }
+ }
+
+ if (G_strcasecmp(list[n].element[0], "cell") == 0) {
+ char colr2[50];
+
+ sprintf(colr2, "colr2/%s", G_mapset());
+ switch (G_remove(colr2, old)) {
+ case -1:
+ G_warning("%s: %s", colr2, _("couldn't be removed"));
+ result = 1;
+ break;
+ case 0:
+ if (G_verbose() == G_verbose_max())
+ G_message(_("%s: missing"), colr2);
+ break;
+ case 1:
+ if (G_verbose() == G_verbose_max())
+ G_message(_("%s: removed"), colr2);
+ removed = 1;
+ break;
+ }
+ }
+
+ hold_signals(0);
+
+ if (!removed)
+ G_warning(_("<%s> nothing removed"), old);
+
+ return result;
+}
Property changes on: grass/trunk/lib/manage/do_remove.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/lib/manage/do_rename.c (from rev 34171, grass/trunk/general/manage/lib/do_rename.c)
===================================================================
--- grass/trunk/lib/manage/do_rename.c (rev 0)
+++ grass/trunk/lib/manage/do_rename.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,108 @@
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/Vect.h>
+#include <grass/G3d.h>
+#include "list.h"
+
+/*
+ * returns 0 - success
+ * 1 - error
+ */
+int do_rename(int n, char *old, char *new)
+{
+ int i, ret;
+ int len;
+ char *mapset;
+ 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);
+
+ if (G_strcasecmp(old, new) == 0)
+ return 1;
+
+ len = get_description_len(n);
+
+ hold_signals(1);
+
+ if (G_strcasecmp(list[n].alias, "vect") == 0) {
+ if ((mapset = G_find_vector2(old, "")) == NULL) {
+ G_warning(_("Vector map <%s> not found"), old);
+ }
+ else {
+ ret = Vect_rename(old, new, stderr);
+ if (ret != -1) {
+ renamed = 1;
+ }
+ else {
+ G_warning(_("Cannot rename <%s> to <%s>"), old, new);
+ result = 1;
+ }
+ }
+ }
+ else {
+ if (G_strcasecmp(list[n].alias, "rast") == 0) {
+ if ((mapset = G_find_cell2(old, "")) == NULL)
+ G_warning(_("Raster map <%s> not found"), old);
+ }
+
+ if (G_strcasecmp(list[n].alias, "rast3d") == 0) {
+ if ((mapset = G_find_grid3(old, "")) == NULL)
+ G_warning(_("3D raster map <%s> not found"), old);
+ }
+
+ for (i = 0; i < list[n].nelem; i++) {
+ 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]);
+ result = 1;
+ break;
+ case 0:
+ if (G_verbose() == G_verbose_max())
+ G_message(_("%s: missing"), list[n].desc[i]);
+ break;
+ case 1:
+ if (G_verbose() == G_verbose_max())
+ G_message(_("%s: renamed"), list[n].desc[i]);
+ renamed = 1;
+ break;
+ }
+ }
+
+ if (G_strcasecmp(list[n].element[0], "cell") == 0) {
+ char colr2[50];
+
+ sprintf(colr2, "colr2/%s", G_mapset());
+ G_remove(colr2, new);
+ switch (G_rename(colr2, old, new)) {
+ case -1:
+ G_warning(_("%s: couldn't be renamed"), colr2);
+ result = 1;
+ break;
+ case 0:
+ if (G_verbose() == G_verbose_max())
+ G_message(_("%s: missing"), colr2);
+ break;
+ case 1:
+ if (G_verbose() == G_verbose_max())
+ G_message(_("%s: renamed"), colr2);
+ renamed = 1;
+ break;
+ }
+ }
+ }
+ hold_signals(0);
+
+ if (!renamed)
+ G_warning(_("<%s> nothing renamed"), old);
+
+ return result;
+}
Property changes on: grass/trunk/lib/manage/do_rename.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/lib/manage/empty.c (from rev 34171, grass/trunk/general/manage/lib/empty.c)
===================================================================
--- grass/trunk/lib/manage/empty.c (rev 0)
+++ grass/trunk/lib/manage/empty.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,25 @@
+/* look for at least one file in the element */
+#include <sys/types.h>
+#include <dirent.h>
+#include <grass/gis.h>
+
+int empty(char *elem)
+{
+ DIR *dirp;
+ struct dirent *dp;
+ char dir[1024];
+ int any;
+
+ G__file_name(dir, elem, "", G_mapset());
+
+ any = 0;
+ if ((dirp = opendir(dir)) != NULL) {
+ while (!any && (dp = readdir(dirp)) != NULL) {
+ if (dp->d_name[0] != '.')
+ any = 1;
+ }
+ closedir(dirp);
+ }
+
+ return any == 0;
+}
Property changes on: grass/trunk/lib/manage/empty.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/lib/manage/find.c (from rev 34171, grass/trunk/general/manage/lib/find.c)
===================================================================
--- grass/trunk/lib/manage/find.c (rev 0)
+++ grass/trunk/lib/manage/find.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,16 @@
+#include <string.h>
+#include "list.h"
+
+char *find(int n, char *name, char *mapsets)
+{
+ char *mapset;
+
+ mapset = G_find_file(list[n].element[0], name, mapsets);
+ if (mapset) {
+ char temp[GNAME_MAX];
+
+ sscanf(name, "%s", temp);
+ strcpy(name, temp);
+ }
+ return mapset;
+}
Property changes on: grass/trunk/lib/manage/find.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/lib/manage/get_len.c (from rev 34171, grass/trunk/general/manage/lib/get_len.c)
===================================================================
--- grass/trunk/lib/manage/get_len.c (rev 0)
+++ grass/trunk/lib/manage/get_len.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,17 @@
+#include <string.h>
+#include "list.h"
+
+int get_description_len(int n)
+{
+ int len;
+ int l;
+ int i;
+
+ len = 1;
+ for (i = 0; i < list[n].nelem; i++) {
+ l = strlen(list[n].desc[i]);
+ if (l > len)
+ len = l;
+ }
+ return len;
+}
Property changes on: grass/trunk/lib/manage/get_len.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/lib/manage/list.h (from rev 34171, grass/trunk/general/manage/list.h)
===================================================================
--- grass/trunk/lib/manage/list.h (rev 0)
+++ grass/trunk/lib/manage/list.h 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,62 @@
+
+#ifndef GRASS_LIST_H
+#define GRASS_LIST_H
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+struct list
+{
+ char **element; /* list of related elements */
+ char *alias; /* element alias */
+ 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(char *, char *);
+
+/* do_copy.c */
+int do_copy(int, char *, char *, char *);
+
+/* do_list.c */
+int do_list(int, char *);
+
+/* do_remove.c */
+int do_remove(int, char *);
+
+/* do_rename.c */
+int do_rename(int, char *, char *);
+
+/* empty.c */
+int empty(char *);
+
+/* find.c */
+char *find(int, char *, 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
+
Property changes on: grass/trunk/lib/manage/list.h
___________________________________________________________________
Name: svn:mime-type
+ text/x-chdr
Name: svn:keywords
+ Author Date Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: grass/trunk/lib/manage/read_list.c (from rev 34174, grass/trunk/general/manage/lib/read_list.c)
===================================================================
--- grass/trunk/lib/manage/read_list.c (rev 0)
+++ grass/trunk/lib/manage/read_list.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,112 @@
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "list.h"
+
+/*******************************************************************
+read the element list file
+
+ format is:
+
+ # ... comments
+ main element:alias:description:menu text
+ sub element:description
+ sub element:description
+ .
+ .
+ .
+******************************************************************/
+
+int nlist;
+struct list *list;
+
+static int format_error(char *, int, char *);
+
+int read_list(int check_if_empty)
+{
+ FILE *fd;
+ char element_list[GPATH_MAX];
+ char buf[1024];
+ char elem[100];
+ char alias[100];
+ char desc[100];
+ char text[100];
+ int any;
+ int line;
+ char *env;
+
+ nlist = 0;
+ list = 0;
+ any = 0;
+
+ env = getenv("ELEMENT_LIST");
+ if (env)
+ strcpy(element_list, env);
+ else
+ sprintf(element_list, "%s/etc/element_list", G_gisbase());
+ fd = fopen(element_list, "r");
+
+ if (!fd)
+ G_fatal_error("can't open database element list <%s>", element_list);
+
+ line = 0;
+ while (G_getl(buf, sizeof(buf), fd)) {
+ line++;
+ if (*buf == '#')
+ continue;
+ if (*buf == ' ' || *buf == '\t') { /* support element */
+ *desc = 0;
+ if (sscanf(buf, "%[^:]:%[^\n]", elem, desc) < 1)
+ continue;
+ if (*elem == '#')
+ continue;
+ if (nlist == 0)
+ format_error(element_list, line, buf);
+
+ G_strip(elem);
+ G_strip(desc);
+ add_element(elem, desc);
+ }
+ else { /* main element */
+
+ if (sscanf
+ (buf, "%[^:]:%[^:]:%[^:]:%[^\n]", elem, alias, desc,
+ text) != 4)
+ format_error(element_list, line, buf);
+
+ G_strip(elem);
+ G_strip(alias);
+ G_strip(desc);
+ G_strip(text);
+
+ list =
+ (struct list *)G_realloc(list, (nlist + 1) * sizeof(*list));
+ list[nlist].mainelem = G_store(elem);
+ list[nlist].alias = G_store(alias);
+ list[nlist].maindesc = G_store(desc);
+ list[nlist].text = G_store(text);
+ list[nlist].nelem = 0;
+ list[nlist].element = 0;
+ list[nlist].desc = 0;
+ list[nlist].status = 0;
+ if (!check_if_empty || !empty(elem)) {
+ list[nlist].status = 1;
+ any = 1;
+ }
+ nlist++;
+ add_element(elem, desc);
+ }
+ }
+
+ fclose(fd);
+
+ return any;
+}
+
+static int format_error(char *element_list, int line, char *buf)
+{
+ G_fatal_error(_("Format error: <%s>\nLine: %d\n%s"), element_list, line,
+ buf);
+
+ return 1;
+}
Property changes on: grass/trunk/lib/manage/read_list.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/lib/manage/show_elem.c (from rev 34171, grass/trunk/general/manage/lib/show_elem.c)
===================================================================
--- grass/trunk/lib/manage/show_elem.c (rev 0)
+++ grass/trunk/lib/manage/show_elem.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,17 @@
+#include <string.h>
+#include "list.h"
+
+int show_elements(void)
+{
+ int n;
+ 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;
+}
Property changes on: grass/trunk/lib/manage/show_elem.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/lib/manage/sighold.c (from rev 34171, grass/trunk/general/manage/lib/sighold.c)
===================================================================
--- grass/trunk/lib/manage/sighold.c (rev 0)
+++ grass/trunk/lib/manage/sighold.c 2008-11-07 10:42:45 UTC (rev 34177)
@@ -0,0 +1,19 @@
+#include <signal.h>
+#include <grass/config.h>
+
+int hold_signals(int hold)
+{
+ RETSIGTYPE (*sig)() = hold ? SIG_IGN : SIG_DFL;
+
+ signal(SIGINT, sig);
+
+#ifndef __MINGW32__
+ signal(SIGQUIT, sig);
+#endif
+
+#ifdef SIGTSTP
+ signal(SIGTSTP, sig);
+#endif
+
+ return 0;
+}
Property changes on: grass/trunk/lib/manage/sighold.c
___________________________________________________________________
Name: svn:mime-type
+ text/x-csrc
Name: svn:keywords
+ Author Date Id
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
More information about the grass-commit
mailing list