Преглед изворни кода

Move general/manage/lib -> lib/manage
Remove local copies of lib/manage functions from g.mlist, g.mremove


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@34177 15284696-431f-4ddb-bdfa-cd5b030d7da7

Glynn Clements пре 16 година
родитељ
комит
8c496cb51b

+ 2 - 2
general/g.mlist/Makefile

@@ -3,8 +3,8 @@ MODULE_TOPDIR = ../..
 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
 

+ 1 - 17
general/g.mlist/global.h

@@ -1,23 +1,7 @@
 #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 */
-};
-
-/* read_list.c */
-int read_list(int);
+#include <grass/list.h>
 
 /* wc2regex.c */
 char *wc2regex(const char *);
 
-extern int nlist;
-extern struct list *list;

+ 10 - 12
general/g.mlist/main.c

@@ -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 @@ int main(int argc, char *argv[])
 	    }
 	}
 	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 @@ int main(int argc, char *argv[])
     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 @@ static void do_list(
     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;
     }
 

+ 0 - 148
general/g.mlist/read_list.c

@@ -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;
-}

+ 2 - 2
general/g.mremove/Makefile

@@ -2,8 +2,8 @@ MODULE_TOPDIR = ../..
 
 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)
 

+ 0 - 102
general/g.mremove/do_remove.c

@@ -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;
-}

+ 1 - 21
general/g.mremove/global.h

@@ -1,29 +1,9 @@
 #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 */
-};
-
-/* read_list.c */
-int read_list(int);
+#include <grass/list.h>
 
 /* 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;

+ 0 - 3
general/g.mremove/main.c

@@ -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[])

+ 0 - 148
general/g.mremove/read_list.c

@@ -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;
-}

+ 1 - 4
general/manage/Makefile

@@ -1,10 +1,7 @@
 
 MODULE_TOPDIR = ../..
 
-SUBDIRS = \
-	lib \
-	cmd \
-	lister
+SUBDIRS = cmd lister
 
 include $(MODULE_TOPDIR)/include/Make/Dir.make
 

+ 0 - 2
general/manage/cmd/Makefile

@@ -14,7 +14,5 @@ LIBES = $(MANAGELIB) $(VECTLIB) $(DBMILIB) $(GISLIB) $(G3DLIB)
 LIST = $(OBJDIR)/init.o  
 DEPENDENCIES = $(GISDEP) $(VECTDEP) $(DBMIDEP) $(MANAGEDEP) $(G3DDEP)
 
-EXTRA_INC = -I..
-
 default: multi
 

+ 1 - 1
general/manage/cmd/copy.c

@@ -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[])

+ 1 - 1
general/manage/cmd/init.c

@@ -1,4 +1,4 @@
-#include "list.h"
+#include <grass/list.h>
 #include "local_proto.h"
 
 int init(char *pgm)

+ 1 - 1
general/manage/cmd/list.c

@@ -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;
 

+ 1 - 2
general/manage/cmd/remove.c

@@ -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)

+ 1 - 1
general/manage/cmd/rename.c

@@ -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[])

+ 0 - 36
general/manage/lib/copy.sh

@@ -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

+ 3 - 0
include/Make/Rules.make

@@ -16,6 +16,9 @@ $(ARCH_DIRS):
 $(OBJDIR):
 	-test -d $(OBJDIR) || $(MKDIR) $(OBJDIR)
 
+$(ARCH_INCDIR)/%.h: %.h
+	$(INSTALL_DATA) $< $@
+
 # default clean rules
 clean:
 	-rm -rf $(OBJDIR) $(EXTRA_CLEAN_DIRS)

+ 3 - 6
lib/Makefile

@@ -40,12 +40,9 @@ SUBDIRS = \
 	arraystats \
 	python \
 	ogsf \
-	nviz
-
-#compile if C++ compiler present:
-ifneq ($(strip $(CXX)),)
-    SUBDIRS += iostream
-endif
+	nviz \
+	iostream \
+	manage
 
 #doxygen:
 DOXNAME=grass

+ 3 - 5
general/manage/lib/Makefile

@@ -1,14 +1,12 @@
-MODULE_TOPDIR = ../../..
+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_INC = $(VECT_INC)
 EXTRA_CFLAGS = $(VECT_CFLAGS)
 EXTRA_LIBS = $(GISLIB) $(VECTLIB) $(G3DLIB)
 
-default: stlib
+default: stlib $(ARCH_INCDIR)/list.h

general/manage/lib/README → lib/manage/README


general/manage/lib/add_elem.c → lib/manage/add_elem.c


general/manage/lib/do_copy.c → lib/manage/do_copy.c


general/manage/lib/do_list.c → lib/manage/do_list.c


general/manage/lib/do_remove.c → lib/manage/do_remove.c


general/manage/lib/do_rename.c → lib/manage/do_rename.c


general/manage/lib/empty.c → lib/manage/empty.c


general/manage/lib/find.c → lib/manage/find.c


general/manage/lib/get_len.c → lib/manage/get_len.c


+ 7 - 10
general/manage/list.h

@@ -1,3 +1,7 @@
+
+#ifndef GRASS_LIST_H
+#define GRASS_LIST_H
+
 #include <grass/gis.h>
 #include <grass/glocale.h>
 
@@ -21,13 +25,9 @@ extern struct list *list;
 #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 *);
 
@@ -49,12 +49,6 @@ 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);
 
@@ -63,3 +57,6 @@ int show_elements(void);
 
 /* sighold.c */
 int hold_signals(int);
+
+#endif
+

general/manage/lib/read_list.c → lib/manage/read_list.c


general/manage/lib/show_elem.c → lib/manage/show_elem.c


+ 3 - 5
general/manage/lib/sighold.c

@@ -1,11 +1,9 @@
-#include "signal.h"
-
-void (*sig) ();
+#include <signal.h>
+#include <grass/config.h>
 
 int hold_signals(int hold)
 {
-
-    sig = hold ? SIG_IGN : SIG_DFL;
+    RETSIGTYPE (*sig)() = hold ? SIG_IGN : SIG_DFL;
 
     signal(SIGINT, sig);