[GRASS-SVN] r36709 - grass/trunk/general/g.mapsets

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Apr 13 01:03:54 EDT 2009


Author: hcho
Date: 2009-04-13 01:03:54 -0400 (Mon, 13 Apr 2009)
New Revision: 36709

Removed:
   grass/trunk/general/g.mapsets/externs.h
Modified:
   grass/trunk/general/g.mapsets/dsply_maps.c
   grass/trunk/general/g.mapsets/dsply_path.c
   grass/trunk/general/g.mapsets/get_maps.c
   grass/trunk/general/g.mapsets/local_proto.h
   grass/trunk/general/g.mapsets/main.c
Log:
Removed unused variables.
Dynamic buffer for large number of mapsets and long mapset names.


Modified: grass/trunk/general/g.mapsets/dsply_maps.c
===================================================================
--- grass/trunk/general/g.mapsets/dsply_maps.c	2009-04-12 21:44:16 UTC (rev 36708)
+++ grass/trunk/general/g.mapsets/dsply_maps.c	2009-04-13 05:03:54 UTC (rev 36709)
@@ -1,10 +1,8 @@
 #include <string.h>
 #include <stdio.h>
-
 #include <grass/glocale.h>
+#include "local_proto.h"
 
-#include "externs.h"
-
 static int display1(void);
 static int display2(const char *fs);
 

Modified: grass/trunk/general/g.mapsets/dsply_path.c
===================================================================
--- grass/trunk/general/g.mapsets/dsply_path.c	2009-04-12 21:44:16 UTC (rev 36708)
+++ grass/trunk/general/g.mapsets/dsply_path.c	2009-04-13 05:03:54 UTC (rev 36709)
@@ -1,7 +1,7 @@
 #include <string.h>
 #include <grass/gis.h>
 #include <grass/glocale.h>
-#include "externs.h"
+#include "local_proto.h"
 
 int display_mapset_path(const char *fs)
 {
@@ -17,7 +17,6 @@
 	for (n = nmapsets; n /= 10; offset++) ;
 
 	fprintf(stdout, _("Your mapset search list:\n"));
-	ncurr_mapsets = 0;
     }
 
     nleft = 78;
@@ -42,8 +41,6 @@
 		fprintf(stdout, ", ");
 	    fprintf(stdout, "%s <%d>", name, map + 1);
 	    nleft -= (len + offset);
-	    curr_mapset[n] = map;
-	    ++ncurr_mapsets;
 	}
 	else {
 	    fprintf(stdout, "%s", name);

Deleted: grass/trunk/general/g.mapsets/externs.h
===================================================================
--- grass/trunk/general/g.mapsets/externs.h	2009-04-12 21:44:16 UTC (rev 36708)
+++ grass/trunk/general/g.mapsets/externs.h	2009-04-13 05:03:54 UTC (rev 36709)
@@ -1,11 +0,0 @@
-
-extern char *mapset_name[];
-extern int nmapsets;
-extern int choice[];
-extern int nchoices;
-extern int curr_mapset[];
-extern int ncurr_mapsets;
-
-#define	REPLACE	0
-#define ADD	1
-#define DELETE	2

Modified: grass/trunk/general/g.mapsets/get_maps.c
===================================================================
--- grass/trunk/general/g.mapsets/get_maps.c	2009-04-12 21:44:16 UTC (rev 36708)
+++ grass/trunk/general/g.mapsets/get_maps.c	2009-04-13 05:03:54 UTC (rev 36709)
@@ -1,15 +1,18 @@
 #include <stdio.h>
-#include "externs.h"
 #include <grass/gis.h>
+#include "local_proto.h"
 
 int get_available_mapsets(void)
 {
     char **ms;
+    int i;
 
     ms = G_available_mapsets();
+    for (nmapsets = 0; ms[nmapsets]; nmapsets++);
 
-    for (nmapsets = 0; ms[nmapsets]; nmapsets++)
-	mapset_name[nmapsets] = G_store(ms[nmapsets]);
+    mapset_name = (char **)G_malloc(nmapsets*sizeof(char *));
+    for(i = 0; i < nmapsets; i++)
+	mapset_name[i] = G_store(ms[i]);
 
     return 0;
 }

Modified: grass/trunk/general/g.mapsets/local_proto.h
===================================================================
--- grass/trunk/general/g.mapsets/local_proto.h	2009-04-12 21:44:16 UTC (rev 36708)
+++ grass/trunk/general/g.mapsets/local_proto.h	2009-04-13 05:03:54 UTC (rev 36709)
@@ -1,3 +1,12 @@
+#ifdef _MAIN_C_
+#define GLOBAL
+#else
+#define GLOBAL extern
+#endif
+
+GLOBAL char **mapset_name;
+GLOBAL int nmapsets;
+
 /* dsply_maps.c */
 int display_available_mapsets(const char *);
 

Modified: grass/trunk/general/g.mapsets/main.c
===================================================================
--- grass/trunk/general/g.mapsets/main.c	2009-04-12 21:44:16 UTC (rev 36708)
+++ grass/trunk/general/g.mapsets/main.c	2009-04-13 05:03:54 UTC (rev 36709)
@@ -7,8 +7,9 @@
  *               Glynn Clements <glynn gclements.plus.com>
  *               Hamish Bowman <hamish_nospam yahoo.com>, 
  *               Markus Neteler <neteler itc.it>, 
- *               Moritz Lennert <mlennert club.worldonline.be>
- *               Martin Landa <landa.martin gmail.com>
+ *               Moritz Lennert <mlennert club.worldonline.be>,
+ *               Martin Landa <landa.martin gmail.com>,
+ *               Huidae Cho <grass4u gmail.com>
  * PURPOSE:      set current mapset path
  * COPYRIGHT:    (C) 1994-2009 by the GRASS Development Team
  *
@@ -18,6 +19,7 @@
  *
  *****************************************************************************/
 
+#define _MAIN_C_
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -25,17 +27,9 @@
 #include <grass/spawn.h>
 #include <grass/glocale.h>
 #include "local_proto.h"
-#include "externs.h"
 
-char *mapset_name[GMAPSET_MAX];
-int nmapsets;
-int choice[GMAPSET_MAX];
-int nchoices;
-int curr_mapset[GMAPSET_MAX];
-int ncurr_mapsets;
+static void append_mapset(char **, const char *);
 
-static char Path[GPATH_MAX];
-
 int main(int argc, char *argv[])
 {
     int n;
@@ -47,6 +41,8 @@
     int no_tokens;
     FILE *fp;
     char path[GPATH_MAX];
+    char *Path;
+    int nchoices;
 
     struct GModule *module;    
     struct _opt {
@@ -104,7 +100,7 @@
     opt.dialog->key = 's';
     opt.dialog->description = _("Show mapset selection dialog");
 
-    Path[0] = '\0';
+    Path = NULL;
     nchoices = 0;
 
     if (G_parser(argc, argv))
@@ -128,8 +124,7 @@
 	    if (G__mapset_permissions(mapset) < 0)
 		G_fatal_error(_("Mapset <%s> not found"), mapset);
 	    nchoices++;
-	    strcat(Path, mapset);
-	    strcat(Path, " ");
+	    append_mapset(&Path, mapset);
 	}
     }
 
@@ -137,13 +132,14 @@
     if (opt.add->answer) {
 	const char *oldname;
 
-	Path[0] = '\0';
+	if (Path) {
+	    G_free(Path);
+	    Path = NULL;
+	}
 
 	/* read existing mapsets from SEARCH_PATH */
-	for (n = 0; (oldname = G__mapset_name(n)); n++) {
-	    strcat(Path, oldname);
-	    strcat(Path, " ");
-	}
+	for (n = 0; (oldname = G__mapset_name(n)); n++)
+	    append_mapset(&Path, oldname);
 
 	/* fetch and add new mapsets from param list */
 	for (ptr = opt.add->answers; *ptr != NULL; ptr++) {
@@ -161,8 +157,7 @@
 				  mapset);
 
 	    nchoices++;
-	    strcat(Path, mapset);
-	    strcat(Path, " ");
+	    append_mapset(&Path, mapset);
 	}
     }
 
@@ -170,7 +165,10 @@
     if (opt.remove->answer) {
 	const char *oldname;
 
-	Path[0] = '\0';
+	if (Path) {
+	    G_free(Path);
+	    Path = NULL;
+	}
 
 	/* read existing mapsets from SEARCH_PATH */
 	for (n = 0; (oldname = G__mapset_name(n)); n++) {
@@ -187,8 +185,7 @@
 	    }
 
 	    nchoices++;
-	    strcat(Path, oldname);
-	    strcat(Path, " ");
+	    append_mapset(&Path, oldname);
 	}
     }
 
@@ -249,3 +246,15 @@
 
     exit(EXIT_SUCCESS);
 }
+
+static void append_mapset(char **path, const char *mapset)
+{
+    int init = (*path == NULL);
+
+    *path = (char *)G_realloc(*path, (init ? 0 : strlen(*path)) + strlen(mapset) + 2);
+    if (init)
+        *path[0] = '\0';
+    strcat(*path, mapset);
+    strcat(*path, " ");
+    return;
+}



More information about the grass-commit mailing list