[GRASS-SVN] r33266 - in grass/trunk/general: . g.mlist g.mremove

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Sep 4 18:24:02 EDT 2008


Author: glynn
Date: 2008-09-04 18:24:02 -0400 (Thu, 04 Sep 2008)
New Revision: 33266

Added:
   grass/trunk/general/g.mlist/
   grass/trunk/general/g.mremove/
Removed:
   grass/trunk/general/g.mlist/gisdefs.h
   grass/trunk/general/g.mlist/join.c
   grass/trunk/general/g.mlist/ls.c
   grass/trunk/general/g.mremove/gisdefs.h
   grass/trunk/general/g.mremove/join.c
   grass/trunk/general/g.mremove/ls.c
   grass/trunk/general/g.mremove/sighold.c
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.mlist/read_list.c
   grass/trunk/general/g.mremove/Makefile
   grass/trunk/general/g.mremove/do_remove.c
   grass/trunk/general/g.mremove/global.h
   grass/trunk/general/g.mremove/main.c
   grass/trunk/general/g.mremove/read_list.c
Log:
Add g.mlist, g.mremove


Copied: grass/trunk/general/g.mlist (from rev 33262, grass-addons/general/g.xlist)


Property changes on: grass/trunk/general/g.mlist
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Modified: grass/trunk/general/g.mlist/Makefile
===================================================================
--- grass-addons/general/g.xlist/Makefile	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mlist/Makefile	2008-09-04 22:24:02 UTC (rev 33266)
@@ -1,6 +1,6 @@
-MODULE_TOPDIR = ../../../grass
+MODULE_TOPDIR = ../..
 
-PGM = g.xlist
+PGM = g.mlist
 
 LIBES = $(GISLIB)
 DEPENDENCIES = $(GISDEP)

Deleted: grass/trunk/general/g.mlist/gisdefs.h
===================================================================
--- grass-addons/general/g.xlist/gisdefs.h	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mlist/gisdefs.h	2008-09-04 22:24:02 UTC (rev 33266)
@@ -1,15 +0,0 @@
-#ifndef GISDEFS_H
-#define GISDEFS_H
-
-#define G_JOIN_ELEMENT_TYPE 0x1
-#define G_JOIN_ELEMENT_MAPSET 0x2
-
-/* join.c */
-const char *G_join_element(const char *, const char *, const char *,
-			   const char *, int, int *);
-
-/* ls.c */
-void G_set_ls_filter(int (*)(const char *, void *), void *);
-char **G__ls(const char *, int *);
-
-#endif

Modified: grass/trunk/general/g.mlist/global.h
===================================================================
--- grass-addons/general/g.xlist/global.h	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mlist/global.h	2008-09-04 22:24:02 UTC (rev 33266)
@@ -19,11 +19,5 @@
 /* wc2regex.c */
 char *wc2regex(const char *);
 
-#ifdef MAIN
-#	define GLOBAL
-#else
-#	define GLOBAL extern
-#endif
-
-GLOBAL int nlist;
-GLOBAL struct list *list;
+extern int nlist;
+extern struct list *list;

Deleted: grass/trunk/general/g.mlist/join.c
===================================================================
--- grass-addons/general/g.xlist/join.c	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mlist/join.c	2008-09-04 22:24:02 UTC (rev 33266)
@@ -1,158 +0,0 @@
-
-/**
-   \file join.c
-
-   \brief Return a string that contains elements
-
-   \author Huidae Cho
-
-   (C) 2008 by the GRASS Development Team
-
-   This program is free software under the GNU General Public
-   License (>=v2). Read the file COPYING that comes with GRASS
-   for details.
-*/
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <string.h>
-#include <sys/types.h>
-#include <dirent.h>
-
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
-#include "gisdefs.h"
-
-static int join_element(const char *, const char *, const char *,
-			const char *, int, const char **);
-
-/**
-   \brief General purpose join function.
-
-   Will collect file names from all mapsets
-   in the mapset list for a specified database element
-   and join them into a string.
-
-   Note: Use G_(set|get)_ls_filter functions to filter out unwanted file names.
-
-   \param element    Database element (eg, "cell", "cellhd", etc)
-   \param alias      Alias for element (if NULL, element is used)
-   \param mapset     Mapset to be listed "" to list all mapsets in mapset search list
-   "." will list current mapset
-   \param separator  Map name separator
-   \param flags      G_JOIN_ELEMENT_TYPE   Include alias
-                     G_JOIN_ELEMENT_MAPSET Include mapset name
-   \param count      Return the number of elements (if NULL, ignored)
-
-   \return String pointer
-*/
-const char *G_join_element(const char *element,
-			   const char *alias,
-			   const char *mapset,
-			   const char *separator, int flags, int *count)
-{
-    int c, n;
-    const char *buf;
-
-    c = 0;
-    if (alias == 0 || *alias == 0)
-	alias = element;
-
-    /*
-     * if no specific mapset is requested, list the mapsets
-     * from the mapset search list
-     * otherwise just list the specified mapset
-     */
-    buf = G_strdup("");
-    if (mapset == 0 || *mapset == 0)
-	for (n = 0; (mapset = G__mapset_name(n)); n++)
-	    c += join_element(element, alias, mapset, separator, flags, &buf);
-    else
-	c = join_element(element, alias, mapset, separator, flags, &buf);
-
-    if (count)
-	*count = c;
-    return buf;
-}
-
-static int join_element(const char *element,
-			const char *alias,
-			const char *mapset,
-			const char *separator, int flags, const char **buf)
-{
-    char path[GPATH_MAX], *p;
-    int i, count = 0;
-    int buf_len, alias_len, list_len, sep_len = strlen(separator), mapset_len;
-    char **list;
-
-    /*
-     * convert . to current mapset
-     */
-    if (strcmp(mapset, ".") == 0)
-	mapset = G_mapset();
-
-    mapset_len = strlen(mapset);
-
-    /*
-     * get the full name of the GIS directory within the mapset
-     * and list its contents (if it exists)
-     */
-    G__file_name(path, element, "", mapset);
-    if (access(path, 0) != 0)
-	return count;
-
-    list = G__ls(path, &count);
-
-    alias_len = strlen(alias);
-    for (i = 0; i < count; i++) {
-	buf_len = strlen(*buf);
-	list_len = strlen(list[i]);
-	*buf = (char *)G_realloc((char *)*buf,
-				 (buf_len ? buf_len + sep_len : 0) +
-				 (flags & G_JOIN_ELEMENT_TYPE ? alias_len +
-				  1 : 0) + list_len +
-				 (flags & G_JOIN_ELEMENT_MAPSET ? mapset_len +
-				  1 : 0) + 1);
-	p = (char *)*buf + buf_len;
-
-	/* looks dirty but fast! */
-	if (buf_len) {
-	    if (flags & G_JOIN_ELEMENT_TYPE) {
-		if (flags & G_JOIN_ELEMENT_MAPSET)
-		    sprintf(p, "%s%s/%s@%s", separator, alias, list[i],
-			    mapset);
-		else
-		    sprintf(p, "%s%s/%s", separator, alias, list[i]);
-	    }
-	    else {
-		if (flags & G_JOIN_ELEMENT_MAPSET)
-		    sprintf(p, "%s%s@%s", separator, list[i], mapset);
-		else
-		    sprintf(p, "%s%s", separator, list[i]);
-	    }
-	}
-	else {
-	    if (flags & G_JOIN_ELEMENT_TYPE) {
-		if (flags & G_JOIN_ELEMENT_MAPSET)
-		    sprintf(p, "%s/%s@%s", alias, list[i], mapset);
-		else
-		    sprintf(p, "%s/%s", alias, list[i]);
-	    }
-	    else {
-		if (flags & G_JOIN_ELEMENT_MAPSET)
-		    sprintf(p, "%s@%s", list[i], mapset);
-		else
-		    sprintf(p, "%s", list[i]);
-	    }
-	}
-    }
-
-    for (i = 0; i < count; i++)
-	G_free((char *)list[i]);
-    if (list)
-	G_free(list);
-
-    return count;
-}

Deleted: grass/trunk/general/g.mlist/ls.c
===================================================================
--- grass-addons/general/g.xlist/ls.c	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mlist/ls.c	2008-09-04 22:24:02 UTC (rev 33266)
@@ -1,105 +0,0 @@
-
-/**
-   \file ls.c
-
-   \brief Functions to list the files in a directory.
-
-   \author Paul Kelly, Huidae Cho
-
-   (C) 2007, 2008 by the GRASS Development Team
-
-   This program is free software under the GNU General Public
-   License (>=v2). Read the file COPYING that comes with GRASS
-   for details.
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <unistd.h>
-
-#include <grass/gis.h>
-#include <grass/config.h>
-#include <grass/glocale.h>
-
-#ifdef HAVE_SYS_IOCTL_H
-#  include <sys/ioctl.h>
-#endif
-
-typedef int ls_filter_func(const char * /*filename */ , void * /*closure */ );
-static ls_filter_func *ls_filter = NULL;
-static void *ls_closure = NULL;
-
-static int cmp_names(const void *aa, const void *bb)
-{
-    char *const *a = (char *const *)aa;
-    char *const *b = (char *const *)bb;
-
-    return strcmp(*a, *b);
-}
-
-/**
- * \brief Sets a function and its complementary data for G__ls filtering.
- *
- * Defines a filter function and its rule data that allow G__ls to filter out
- * unwanted file names.  Call this function before G__ls.
- *
- * \param func      Filter callback function to compare a file name and closure
- * 		    pattern (if NULL, no filter will be used).
- * 		    func(filename, closure) should return 1 on success, 0 on
- * 		    failure.
- * \param closure   Data used to determine if a file name matches the rule.
- **/
-
-void G_set_ls_filter(ls_filter_func * func, void *closure)
-{
-    ls_filter = func;
-    ls_closure = closure;
-    return;
-}
-
-/**
- * \brief Stores a sorted directory listing in an array
- *
- * The filenames in the specified directory are stored in an array of
- * strings, then sorted alphabetically. Each filename has space allocated
- * using G_store(), which can be freed using G_free() if necessary. The
- * same goes for the array itself.
- *
- *
- * \param dir       Directory to list
- * \param num_files Pointer to an integer in which the total number of
- *                  files listed will be stored
- *
- * \return          Pointer to array of strings containing the listing
- **/
-
-char **G__ls(const char *dir, int *num_files)
-{
-    struct dirent *dp;
-    DIR *dfd;
-    char **dir_listing = NULL;
-    int n = 0;
-
-    if ((dfd = opendir(dir)) == NULL)
-	G_fatal_error(_("Unable to open directory %s"), dir);
-
-    while ((dp = readdir(dfd)) != NULL) {
-	if ((dp->d_name[0] == '.' && dp->d_name[1] == 0) ||
-	    (dp->d_name[0] == '.' && dp->d_name[1] == '.' &&
-	     dp->d_name[2] == 0) || (ls_filter &&
-				     !(*ls_filter) (dp->d_name, ls_closure)))
-	    continue;
-	dir_listing = (char **)G_realloc(dir_listing, (1 + n) * sizeof(char *));
-	dir_listing[n] = G_store(dp->d_name);
-	n++;
-    }
-
-    /* Sort list of filenames alphabetically */
-    qsort(dir_listing, n, sizeof(char *), cmp_names);
-
-    *num_files = n;
-    return dir_listing;
-}

Modified: grass/trunk/general/g.mlist/main.c
===================================================================
--- grass-addons/general/g.xlist/main.c	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mlist/main.c	2008-09-04 22:24:02 UTC (rev 33266)
@@ -17,16 +17,21 @@
  *
  *****************************************************************************/
 
-#define MAIN
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
 #include <regex.h>
 #include <grass/spawn.h>
-#include "gisdefs.h"
 #include "global.h"
 
-static int do_list(int, const char *, const char *, int, const char *, int);
+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 int parse(const char *);
 static int ls_filter(const char *, void *);
 
@@ -48,7 +53,7 @@
 	struct Flag *pretty;
 	struct Flag *full;
     } flag;
-    int i, n, all, num_types, any, flags = 0;
+    int i, n, all, num_types;
     char *pattern = NULL, separator[2], *buf;
     regex_t regex;
 
@@ -76,10 +81,10 @@
 
     buf[0] = 0;
     for (n = 0; n < nlist; n++) {
-	G_strcat(buf, list[n].alias);
-	G_strcat(buf, ",");
+	strcat(buf, list[n].alias);
+	strcat(buf, ",");
     }
-    G_strcat(buf, "all");
+    strcat(buf, "all");
     opt.type->options = buf;
 
     opt.pattern = G_define_option();
@@ -171,32 +176,28 @@
 	num_types = i;
     }
 
-    if (flag.type->answer)
-	flags |= G_JOIN_ELEMENT_TYPE;
-    if (flag.mapset->answer)
-	flags |= G_JOIN_ELEMENT_MAPSET;
-
     for (i = 0; i < num_types; i++) {
 	n = all ? i : parse(opt.type->answers[i]);
 
 	if (flag.full->answer) {
-	    char lister[300];
+	    char lister[GPATH_MAX];
 
 	    sprintf(lister, "%s/etc/lister/%s", G_gisbase(),
 		    list[n].element[0]);
+
 	    G_debug(3, "lister CMD: %s", lister);
-	    if (access(lister, 1) == 0)	/* execute permission? */
+
+	    if (access(lister, 1) == 0) {	/* execute permission? */
 		G_spawn(lister, lister, opt.mapset->answer, NULL);
-	    else
-		any =
-		    do_list(n, pattern, opt.mapset->answer,
-			    flag.pretty->answer, separator, flags);
+		continue;
+	    }
 	}
 	else
-	    any =
-		do_list(n, pattern, opt.mapset->answer, flag.pretty->answer,
-			separator, flags);
+	    do_list(&list[n], pattern, opt.mapset->answer, separator,
+		    flag.pretty->answer, flag.type->answer,
+		    flag.mapset->answer);
     }
+
     if (!flag.pretty->answer && any)
 	fprintf(stdout, "\n");
 
@@ -208,32 +209,59 @@
     exit(EXIT_SUCCESS);
 }
 
-static int do_list(int n, const char *pattern, const char *mapset,
-		   int pretty, const char *separator, int flags)
+static void do_list(
+    const struct list *elem,
+    const char *pattern, const char *mapset, const char *separator,
+    int pretty, int add_type, int add_mapset)
 {
-    static int any = 0;
-    const char *buf;
-    int len;
+    char path[GPATH_MAX];
+    const char *element = elem->element[0];
+    const char *alias = elem->alias;
+    char **list;
+    int count;
+    int i;
 
     if (pretty) {
-	G_list_element(list[n].element[0], list[n].alias, mapset,
-		       (int (*)())0);
-	return 1;
+	G_list_element(element, alias, mapset, NULL);
+	return;
     }
 
-    buf =
-	G_join_element(list[n].element[0], list[n].alias, mapset, separator,
-		       flags, NULL);
-    len = strlen(buf);
-    if (any && len)
-	fprintf(stdout, "%s", separator);
-    if (len)
-	fprintf(stdout, "%s", buf);
-    G_free((char *)buf);
+    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);
+	return;
+    }
 
-    any += len > 0;
+    G__file_name(path, element, "", mapset);
+    if (access(path, 0) != 0)
+	return;
 
-    return any;
+    list = G__ls(path, &count);
+    if (!list)
+	return;
+
+    for (i = 0; i < count; i++) {
+	char *name = list[i];
+
+	if (any)
+	    fprintf(stdout, "%s", separator);
+
+	if (add_type)
+	    fprintf(stdout, "%s/", alias);
+
+	fprintf(stdout, "%s", name);
+
+	if (add_mapset)
+	    fprintf(stdout, "@%s", mapset);
+
+	G_free(name);
+
+	any++;
+    }
+
+    G_free(list);
 }
 
 static int parse(const char *data_type)

Modified: grass/trunk/general/g.mlist/read_list.c
===================================================================
--- grass-addons/general/g.xlist/read_list.c	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mlist/read_list.c	2008-09-04 22:24:02 UTC (rev 33266)
@@ -36,7 +36,7 @@
     any = 0;
 
     if ((env = G__getenv("ELEMENT_LIST")))
-	G_strcpy(element_list, env);
+	strcpy(element_list, env);
     else
 	sprintf(element_list, "%s/etc/element_list", G_gisbase());
     fd = fopen(element_list, "r");

Copied: grass/trunk/general/g.mremove (from rev 33262, grass-addons/general/g.xremove)


Property changes on: grass/trunk/general/g.mremove
___________________________________________________________________
Name: svn:ignore
   + *OBJ*


Modified: grass/trunk/general/g.mremove/Makefile
===================================================================
--- grass-addons/general/g.xremove/Makefile	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mremove/Makefile	2008-09-04 22:24:02 UTC (rev 33266)
@@ -1,6 +1,6 @@
-MODULE_TOPDIR = ../../../grass
+MODULE_TOPDIR = ../..
 
-PGM = g.xremove
+PGM = g.mremove
 
 LIBES = $(GISLIB) $(VECTLIB) $(G3DLIB)
 DEPENDENCIES = $(GISDEP) $(VECTDEP) $(G3DDEP)

Modified: grass/trunk/general/g.mremove/do_remove.c
===================================================================
--- grass-addons/general/g.xremove/do_remove.c	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mremove/do_remove.c	2008-09-04 22:24:02 UTC (rev 33266)
@@ -21,8 +21,6 @@
 
     /* 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,
@@ -77,7 +75,7 @@
     }
 
     if (G_strcasecmp(list[n].element[0], "cell") == 0) {
-	char colr2[50];
+	char colr2[GMAPSET_MAX + 6];
 
 	sprintf(colr2, "colr2/%s", G_mapset());
 	switch (G_remove(colr2, old)) {
@@ -97,8 +95,6 @@
 	}
     }
 
-    hold_signals(0);
-
     if (!removed)
 	G_warning(_("<%s> nothing removed"), old);
 

Deleted: grass/trunk/general/g.mremove/gisdefs.h
===================================================================
--- grass-addons/general/g.xremove/gisdefs.h	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mremove/gisdefs.h	2008-09-04 22:24:02 UTC (rev 33266)
@@ -1,15 +0,0 @@
-#ifndef GISDEFS_H
-#define GISDEFS_H
-
-#define G_JOIN_ELEMENT_TYPE 0x1
-#define G_JOIN_ELEMENT_MAPSET 0x2
-
-/* join.c */
-const char *G_join_element(const char *, const char *, const char *,
-			   const char *, int, int *);
-
-/* ls.c */
-void G_set_ls_filter(int (*)(const char *, void *), void *);
-char **G__ls(const char *, int *);
-
-#endif

Modified: grass/trunk/general/g.mremove/global.h
===================================================================
--- grass-addons/general/g.xremove/global.h	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mremove/global.h	2008-09-04 22:24:02 UTC (rev 33266)
@@ -22,17 +22,8 @@
 /* check_reclass.c */
 int check_reclass(const char *, const char *, int);
 
-/* sighold.c */
-int hold_signals(int);
-
 /* do_remove.c */
 int do_remove(int, char *);
 
-#ifdef MAIN
-#	define GLOBAL
-#else
-#	define GLOBAL extern
-#endif
-
-GLOBAL int nlist;
-GLOBAL struct list *list;
+extern int nlist;
+extern struct list *list;

Deleted: grass/trunk/general/g.mremove/join.c
===================================================================
--- grass-addons/general/g.xremove/join.c	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mremove/join.c	2008-09-04 22:24:02 UTC (rev 33266)
@@ -1,158 +0,0 @@
-
-/**
-   \file join.c
-
-   \brief Return a string that contains elements
-
-   \author Huidae Cho
-
-   (C) 2008 by the GRASS Development Team
-
-   This program is free software under the GNU General Public
-   License (>=v2). Read the file COPYING that comes with GRASS
-   for details.
-*/
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <string.h>
-#include <sys/types.h>
-#include <dirent.h>
-
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
-#include "gisdefs.h"
-
-static int join_element(const char *, const char *, const char *,
-			const char *, int, const char **);
-
-/**
-   \brief General purpose join function.
-
-   Will collect file names from all mapsets
-   in the mapset list for a specified database element
-   and join them into a string.
-
-   Note: Use G_(set|get)_ls_filter functions to filter out unwanted file names.
-
-   \param element    Database element (eg, "cell", "cellhd", etc)
-   \param alias      Alias for element (if NULL, element is used)
-   \param mapset     Mapset to be listed "" to list all mapsets in mapset search list
-   "." will list current mapset
-   \param separator  Map name separator
-   \param flags      G_JOIN_ELEMENT_TYPE   Include alias
-                     G_JOIN_ELEMENT_MAPSET Include mapset name
-   \param count      Return the number of elements (if NULL, ignored)
-
-   \return String pointer
-*/
-const char *G_join_element(const char *element,
-			   const char *alias,
-			   const char *mapset,
-			   const char *separator, int flags, int *count)
-{
-    int c, n;
-    const char *buf;
-
-    c = 0;
-    if (alias == 0 || *alias == 0)
-	alias = element;
-
-    /*
-     * if no specific mapset is requested, list the mapsets
-     * from the mapset search list
-     * otherwise just list the specified mapset
-     */
-    buf = G_strdup("");
-    if (mapset == 0 || *mapset == 0)
-	for (n = 0; (mapset = G__mapset_name(n)); n++)
-	    c += join_element(element, alias, mapset, separator, flags, &buf);
-    else
-	c = join_element(element, alias, mapset, separator, flags, &buf);
-
-    if (count)
-	*count = c;
-    return buf;
-}
-
-static int join_element(const char *element,
-			const char *alias,
-			const char *mapset,
-			const char *separator, int flags, const char **buf)
-{
-    char path[GPATH_MAX], *p;
-    int i, count = 0;
-    int buf_len, alias_len, list_len, sep_len = strlen(separator), mapset_len;
-    char **list;
-
-    /*
-     * convert . to current mapset
-     */
-    if (strcmp(mapset, ".") == 0)
-	mapset = G_mapset();
-
-    mapset_len = strlen(mapset);
-
-    /*
-     * get the full name of the GIS directory within the mapset
-     * and list its contents (if it exists)
-     */
-    G__file_name(path, element, "", mapset);
-    if (access(path, 0) != 0)
-	return count;
-
-    list = G__ls(path, &count);
-
-    alias_len = strlen(alias);
-    for (i = 0; i < count; i++) {
-	buf_len = strlen(*buf);
-	list_len = strlen(list[i]);
-	*buf = (char *)G_realloc((char *)*buf,
-				 (buf_len ? buf_len + sep_len : 0) +
-				 (flags & G_JOIN_ELEMENT_TYPE ? alias_len +
-				  1 : 0) + list_len +
-				 (flags & G_JOIN_ELEMENT_MAPSET ? mapset_len +
-				  1 : 0) + 1);
-	p = (char *)*buf + buf_len;
-
-	/* looks dirty but fast! */
-	if (buf_len) {
-	    if (flags & G_JOIN_ELEMENT_TYPE) {
-		if (flags & G_JOIN_ELEMENT_MAPSET)
-		    sprintf(p, "%s%s/%s@%s", separator, alias, list[i],
-			    mapset);
-		else
-		    sprintf(p, "%s%s/%s", separator, alias, list[i]);
-	    }
-	    else {
-		if (flags & G_JOIN_ELEMENT_MAPSET)
-		    sprintf(p, "%s%s@%s", separator, list[i], mapset);
-		else
-		    sprintf(p, "%s%s", separator, list[i]);
-	    }
-	}
-	else {
-	    if (flags & G_JOIN_ELEMENT_TYPE) {
-		if (flags & G_JOIN_ELEMENT_MAPSET)
-		    sprintf(p, "%s/%s@%s", alias, list[i], mapset);
-		else
-		    sprintf(p, "%s/%s", alias, list[i]);
-	    }
-	    else {
-		if (flags & G_JOIN_ELEMENT_MAPSET)
-		    sprintf(p, "%s@%s", list[i], mapset);
-		else
-		    sprintf(p, "%s", list[i]);
-	    }
-	}
-    }
-
-    for (i = 0; i < count; i++)
-	G_free((char *)list[i]);
-    if (list)
-	G_free(list);
-
-    return count;
-}

Deleted: grass/trunk/general/g.mremove/ls.c
===================================================================
--- grass-addons/general/g.xremove/ls.c	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mremove/ls.c	2008-09-04 22:24:02 UTC (rev 33266)
@@ -1,105 +0,0 @@
-
-/**
-   \file ls.c
-
-   \brief Functions to list the files in a directory.
-
-   \author Paul Kelly, Huidae Cho
-
-   (C) 2007, 2008 by the GRASS Development Team
-
-   This program is free software under the GNU General Public
-   License (>=v2). Read the file COPYING that comes with GRASS
-   for details.
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <unistd.h>
-
-#include <grass/gis.h>
-#include <grass/config.h>
-#include <grass/glocale.h>
-
-#ifdef HAVE_SYS_IOCTL_H
-#  include <sys/ioctl.h>
-#endif
-
-typedef int ls_filter_func(const char * /*filename */ , void * /*closure */ );
-static ls_filter_func *ls_filter = NULL;
-static void *ls_closure = NULL;
-
-static int cmp_names(const void *aa, const void *bb)
-{
-    char *const *a = (char *const *)aa;
-    char *const *b = (char *const *)bb;
-
-    return strcmp(*a, *b);
-}
-
-/**
- * \brief Sets a function and its complementary data for G__ls filtering.
- *
- * Defines a filter function and its rule data that allow G__ls to filter out
- * unwanted file names.  Call this function before G__ls.
- *
- * \param func      Filter callback function to compare a file name and closure
- * 		    pattern (if NULL, no filter will be used).
- * 		    func(filename, closure) should return 1 on success, 0 on
- * 		    failure.
- * \param closure   Data used to determine if a file name matches the rule.
- **/
-
-void G_set_ls_filter(ls_filter_func * func, void *closure)
-{
-    ls_filter = func;
-    ls_closure = closure;
-    return;
-}
-
-/**
- * \brief Stores a sorted directory listing in an array
- *
- * The filenames in the specified directory are stored in an array of
- * strings, then sorted alphabetically. Each filename has space allocated
- * using G_store(), which can be freed using G_free() if necessary. The
- * same goes for the array itself.
- *
- *
- * \param dir       Directory to list
- * \param num_files Pointer to an integer in which the total number of
- *                  files listed will be stored
- *
- * \return          Pointer to array of strings containing the listing
- **/
-
-char **G__ls(const char *dir, int *num_files)
-{
-    struct dirent *dp;
-    DIR *dfd;
-    char **dir_listing = NULL;
-    int n = 0;
-
-    if ((dfd = opendir(dir)) == NULL)
-	G_fatal_error(_("Unable to open directory %s"), dir);
-
-    while ((dp = readdir(dfd)) != NULL) {
-	if ((dp->d_name[0] == '.' && dp->d_name[1] == 0) ||
-	    (dp->d_name[0] == '.' && dp->d_name[1] == '.' &&
-	     dp->d_name[2] == 0) || (ls_filter &&
-				     !(*ls_filter) (dp->d_name, ls_closure)))
-	    continue;
-	dir_listing = (char **)G_realloc(dir_listing, (1 + n) * sizeof(char *));
-	dir_listing[n] = G_store(dp->d_name);
-	n++;
-    }
-
-    /* Sort list of filenames alphabetically */
-    qsort(dir_listing, n, sizeof(char *), cmp_names);
-
-    *num_files = n;
-    return dir_listing;
-}

Modified: grass/trunk/general/g.mremove/main.c
===================================================================
--- grass-addons/general/g.xremove/main.c	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mremove/main.c	2008-09-04 22:24:02 UTC (rev 33266)
@@ -25,11 +25,14 @@
  *
  *****************************************************************************/
 
-#define MAIN
 #include <stdlib.h>
+#include <unistd.h>
 #include <regex.h>
 #include "global.h"
 
+int nlist;
+struct list *list;
+
 static int ls_filter(const char *, void *);
 
 int main(int argc, char *argv[])

Modified: grass/trunk/general/g.mremove/read_list.c
===================================================================
--- grass-addons/general/g.xremove/read_list.c	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mremove/read_list.c	2008-09-04 22:24:02 UTC (rev 33266)
@@ -36,7 +36,7 @@
     any = 0;
 
     if ((env = G__getenv("ELEMENT_LIST")))
-	G_strcpy(element_list, env);
+	strcpy(element_list, env);
     else
 	sprintf(element_list, "%s/etc/element_list", G_gisbase());
     fd = fopen(element_list, "r");

Deleted: grass/trunk/general/g.mremove/sighold.c
===================================================================
--- grass-addons/general/g.xremove/sighold.c	2008-09-04 20:02:47 UTC (rev 33262)
+++ grass/trunk/general/g.mremove/sighold.c	2008-09-04 22:24:02 UTC (rev 33266)
@@ -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;
-}



More information about the grass-commit mailing list