[GRASS-SVN] r36713 - grass/branches/develbranch_6/general/g.mapsets
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Apr 13 03:51:14 EDT 2009
Author: hcho
Date: 2009-04-13 03:51:14 -0400 (Mon, 13 Apr 2009)
New Revision: 36713
Removed:
grass/branches/develbranch_6/general/g.mapsets/externs.h
Modified:
grass/branches/develbranch_6/general/g.mapsets/Makefile
grass/branches/develbranch_6/general/g.mapsets/dsply_maps.c
grass/branches/develbranch_6/general/g.mapsets/dsply_path.c
grass/branches/develbranch_6/general/g.mapsets/get_maps.c
grass/branches/develbranch_6/general/g.mapsets/local_proto.h
grass/branches/develbranch_6/general/g.mapsets/main.c
Log:
removed unused code; dynamic buffer for large databases.
Modified: grass/branches/develbranch_6/general/g.mapsets/Makefile
===================================================================
--- grass/branches/develbranch_6/general/g.mapsets/Makefile 2009-04-13 06:32:36 UTC (rev 36712)
+++ grass/branches/develbranch_6/general/g.mapsets/Makefile 2009-04-13 07:51:14 UTC (rev 36713)
@@ -1,4 +1,3 @@
-
MODULE_TOPDIR = ../..
PGM = g.mapsets
Modified: grass/branches/develbranch_6/general/g.mapsets/dsply_maps.c
===================================================================
--- grass/branches/develbranch_6/general/g.mapsets/dsply_maps.c 2009-04-13 06:32:36 UTC (rev 36712)
+++ grass/branches/develbranch_6/general/g.mapsets/dsply_maps.c 2009-04-13 07:51:14 UTC (rev 36713)
@@ -1,16 +1,17 @@
#include <string.h>
#include <stdio.h>
-#include "externs.h"
+#include <grass/glocale.h>
+#include "local_proto.h"
static int display1(void);
-static int display2(void);
+static int display2(const char *fs);
-int display_available_mapsets(int verbose)
+int display_available_mapsets(const char* fs)
{
- if (verbose)
+ if (!fs)
display1();
else
- display2();
+ display2(fs);
return 0;
}
@@ -19,7 +20,7 @@
{
int n;
- fprintf(stdout, "Available mapsets:");
+ fprintf(stdout, _("Available mapsets:"));
for (n = 0; n < nmapsets; n++) {
if (n % 4)
fprintf(stdout, " ");
@@ -29,13 +30,13 @@
}
fprintf(stdout, "\n");
if (nmapsets == 0)
- fprintf(stdout, "** no mapsets **\n");
+ fprintf(stdout, _("** no mapsets **\n"));
fprintf(stdout, "\n");
return 0;
}
-static int display2(void)
+static int display2(const char *fs)
{
int nleft, len, n;
char *name;
@@ -47,7 +48,9 @@
fprintf(stdout, "\n");
nleft = 78;
}
- fprintf(stdout, "%s ", name);
+ fprintf(stdout, "%s", name);
+ if (n < nmapsets-1)
+ fprintf(stdout, "%s", fs);
nleft -= (len + 1);
}
fprintf(stdout, "\n");
Modified: grass/branches/develbranch_6/general/g.mapsets/dsply_path.c
===================================================================
--- grass/branches/develbranch_6/general/g.mapsets/dsply_path.c 2009-04-13 06:32:36 UTC (rev 36712)
+++ grass/branches/develbranch_6/general/g.mapsets/dsply_path.c 2009-04-13 07:51:14 UTC (rev 36713)
@@ -1,32 +1,32 @@
#include <string.h>
-#include "externs.h"
#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
-int display_mapset_path(int verbose)
+int display_mapset_path(const char *fs)
{
int n;
int map; /* pointer into list of available mapsets */
int offset = 6; /* accounts for " <x>, " */
- char *name;
+ const char *name;
int len;
int nleft;
- if (verbose) {
+ if (!fs) {
/* account for largest mapset number in offset value */
for (n = nmapsets; n /= 10; offset++) ;
- fprintf(stdout, "Your mapset search list:\n");
- ncurr_mapsets = 0;
+ fprintf(stdout, _("Your mapset search list:\n"));
}
nleft = 78;
- for (n = 0; name = G__mapset_name(n); n++) {
+ for (n = 0; (name = G__mapset_name(n)); n++) {
/* match each mapset to its numeric equivalent */
- if (verbose) {
+ if (!fs) {
for (map = 0; map < nmapsets && strcmp(mapset_name[map], name);
map++) ;
if (map == nmapsets)
- G_fatal_error("%s not found in mapset list: call greg",
+ G_fatal_error(_("<%s> not found in mapset list"),
name);
}
@@ -36,21 +36,21 @@
nleft = 78;
}
- if (verbose) {
+ if (!fs) {
if (n)
fprintf(stdout, ", ");
fprintf(stdout, "%s <%d>", name, map + 1);
nleft -= (len + offset);
- curr_mapset[n] = map;
- ++ncurr_mapsets;
}
else {
- fprintf(stdout, "%s ", name);
+ fprintf(stdout, "%s", name);
+ if (G__mapset_name(n+1))
+ fprintf(stdout, "%s", fs);
nleft -= (len + 1);
}
}
fprintf(stdout, "\n");
- if (verbose)
+ if (!fs)
fprintf(stdout, "\n");
return 0;
Deleted: grass/branches/develbranch_6/general/g.mapsets/externs.h
===================================================================
--- grass/branches/develbranch_6/general/g.mapsets/externs.h 2009-04-13 06:32:36 UTC (rev 36712)
+++ grass/branches/develbranch_6/general/g.mapsets/externs.h 2009-04-13 07:51:14 UTC (rev 36713)
@@ -1,19 +0,0 @@
-#ifdef MAIN
-char *mapset_name[GMAPSET_MAX];
-int nmapsets;
-int choice[GMAPSET_MAX];
-int nchoices;
-int curr_mapset[GMAPSET_MAX];
-int ncurr_mapsets;
-#else
-extern char *mapset_name[];
-extern int nmapsets;
-extern int choice[];
-extern int nchoices;
-extern int curr_mapset[];
-extern int ncurr_mapsets;
-#endif
-
-#define REPLACE 0
-#define ADD 1
-#define DELETE 2
Modified: grass/branches/develbranch_6/general/g.mapsets/get_maps.c
===================================================================
--- grass/branches/develbranch_6/general/g.mapsets/get_maps.c 2009-04-13 06:32:36 UTC (rev 36712)
+++ grass/branches/develbranch_6/general/g.mapsets/get_maps.c 2009-04-13 07:51:14 UTC (rev 36713)
@@ -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/branches/develbranch_6/general/g.mapsets/local_proto.h
===================================================================
--- grass/branches/develbranch_6/general/g.mapsets/local_proto.h 2009-04-13 06:32:36 UTC (rev 36712)
+++ grass/branches/develbranch_6/general/g.mapsets/local_proto.h 2009-04-13 07:51:14 UTC (rev 36713)
@@ -1,8 +1,17 @@
+#ifdef _MAIN_C_
+#define GLOBAL
+#else
+#define GLOBAL extern
+#endif
+
+GLOBAL char **mapset_name;
+GLOBAL int nmapsets;
+
/* dsply_maps.c */
-int display_available_mapsets(int);
+int display_available_mapsets(const char *);
/* dsply_path.c */
-int display_mapset_path(int);
+int display_mapset_path(const char *);
/* get_maps.c */
int get_available_mapsets(void);
Modified: grass/branches/develbranch_6/general/g.mapsets/main.c
===================================================================
--- grass/branches/develbranch_6/general/g.mapsets/main.c 2009-04-13 06:32:36 UTC (rev 36712)
+++ grass/branches/develbranch_6/general/g.mapsets/main.c 2009-04-13 07:51:14 UTC (rev 36713)
@@ -7,9 +7,11 @@
* Glynn Clements <glynn gclements.plus.com>
* Hamish Bowman <hamish_nospam yahoo.com>,
* Markus Neteler <neteler itc.it>,
- * Moritz Lennert <mlennert club.worldonline.be>
+ * 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-2008 by the GRASS Development Team
+ * COPYRIGHT: (C) 1994-2009 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
@@ -17,7 +19,7 @@
*
*****************************************************************************/
-#define MAIN
+#define _MAIN_C_
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
@@ -25,27 +27,32 @@
#include <grass/spawn.h>
#include <grass/glocale.h>
#include "local_proto.h"
-#include "externs.h"
-static char Path[GPATH_MAX];
+static void append_mapset(char **, const char *);
int main(int argc, char *argv[])
{
int n;
int i;
int skip;
- char *cur_mapset;
+ const char *cur_mapset;
char **ptr;
char **tokens;
int no_tokens;
FILE *fp;
char path[GPATH_MAX];
- struct GModule *module;
- struct Option *opt1, *opt2, *opt3;
- struct Flag *print;
- struct Flag *list;
- struct Flag *tcl;
+ char *Path;
+ int nchoices;
+ struct GModule *module;
+ struct _opt {
+ struct Option *mapset, *add, *remove;
+ struct Option *fs;
+ struct Flag *print;
+ struct Flag *list;
+ struct Flag *dialog;
+ } opt;
+
G_gisinit(argv[0]);
module = G_define_module();
@@ -55,84 +62,88 @@
"search path, affecting the user's access to data existing "
"under the other GRASS mapsets in the current location.");
- opt1 = G_define_option();
- opt1->key = "mapset";
- opt1->type = TYPE_STRING;
- opt1->required = NO;
- opt1->multiple = YES;
- opt1->description = _("Name(s) of existing mapset(s)");
+ opt.mapset = G_define_option();
+ opt.mapset->key = "mapset";
+ opt.mapset->type = TYPE_STRING;
+ opt.mapset->required = NO;
+ opt.mapset->multiple = YES;
+ opt.mapset->description = _("Name(s) of existing mapset(s)");
- opt2 = G_define_option();
- opt2->key = "addmapset";
- opt2->type = TYPE_STRING;
- opt2->required = NO;
- opt2->multiple = YES;
- opt2->description =
+ opt.add = G_define_option();
+ opt.add->key = "addmapset";
+ opt.add->type = TYPE_STRING;
+ opt.add->required = NO;
+ opt.add->multiple = YES;
+ opt.add->description =
_("Name(s) of existing mapset(s) to add to search list");
- opt3 = G_define_option();
- opt3->key = "removemapset";
- opt3->type = TYPE_STRING;
- opt3->required = NO;
- opt3->multiple = YES;
- opt3->description =
+ opt.remove = G_define_option();
+ opt.remove->key = "removemapset";
+ opt.remove->type = TYPE_STRING;
+ opt.remove->required = NO;
+ opt.remove->multiple = YES;
+ opt.remove->description =
_("Name(s) of existing mapset(s) to remove from search list");
+
+ opt.fs = G_define_standard_option(G_OPT_F_SEP);
+ opt.fs->answer = " ";
+
+ opt.list = G_define_flag();
+ opt.list->key = 'l';
+ opt.list->description = _("List all available mapsets");
- list = G_define_flag();
- list->key = 'l';
- list->description = _("List all available mapsets");
+ opt.print = G_define_flag();
+ opt.print->key = 'p';
+ opt.print->description = _("Print current mapset search path");
- print = G_define_flag();
- print->key = 'p';
- print->description = _("Print current mapset search path");
+ opt.dialog = G_define_flag();
+ opt.dialog->key = 's';
+ opt.dialog->description = _("Show mapset selection dialog");
- tcl = G_define_flag();
- tcl->key = 's';
- tcl->description = _("Show mapset selection dialog");
-
- Path[0] = '\0';
+ Path = NULL;
+ nmapsets = 0;
nchoices = 0;
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
- if (list->answer) {
+ if (opt.list->answer) {
get_available_mapsets();
- display_available_mapsets(0);
+ display_available_mapsets(opt.fs->answer);
}
- if (tcl->answer) {
+ if (opt.dialog->answer) {
sprintf(path, "%s/etc/g.mapsets.tcl", G_gisbase());
G_spawn(path, "g.mapsets.tcl", NULL);
}
- if (opt1->answer) {
- for (ptr = opt1->answers; *ptr != NULL; ptr++) {
- char *mapset;
+ if (opt.mapset->answer) {
+ for (ptr = opt.mapset->answers; *ptr != NULL; ptr++) {
+ const char *mapset;
mapset = *ptr;
if (G__mapset_permissions(mapset) < 0)
G_fatal_error(_("Mapset <%s> not found"), mapset);
nchoices++;
- strcat(Path, mapset);
- strcat(Path, " ");
+ append_mapset(&Path, mapset);
}
}
/* add to existing search path */
- if (opt2->answer) {
- char *oldname;
+ 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 = opt2->answers; *ptr != NULL; ptr++) {
+ for (ptr = opt.add->answers; *ptr != NULL; ptr++) {
char *mapset;
mapset = *ptr;
@@ -147,22 +158,24 @@
mapset);
nchoices++;
- strcat(Path, mapset);
- strcat(Path, " ");
+ append_mapset(&Path, mapset);
}
}
/* remove from existing search path */
- if (opt3->answer) {
- char *oldname;
+ 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++) {
int found = 0;
- for (ptr = opt3->answers; *ptr; ptr++)
+ for (ptr = opt.remove->answers; *ptr; ptr++)
if (strcmp(oldname, *ptr) == 0)
found = 1;
@@ -173,15 +186,26 @@
}
nchoices++;
- strcat(Path, oldname);
- strcat(Path, " ");
+ append_mapset(&Path, oldname);
}
}
/* stuffem sets nchoices */
if (nchoices == 0) {
- goto DISPLAY;
+ if (opt.print->answer)
+ display_mapset_path(opt.fs->answer);
+
+ if (Path)
+ G_free(Path);
+
+ if (nmapsets) {
+ for(nmapsets--; nmapsets >= 0; nmapsets--)
+ G_free(mapset_name[nmapsets]);
+ G_free(mapset_name);
+ }
+
+ exit(EXIT_SUCCESS);
}
/* note I'm assuming that mapsets cannot have ' 's in them */
@@ -230,9 +254,26 @@
fclose(fp);
G_free_tokens(tokens);
- DISPLAY:
- if (print->answer)
- display_mapset_path(0);
+ if (Path)
+ G_free(Path);
+ if (nmapsets) {
+ for(nmapsets--; nmapsets >= 0; nmapsets--)
+ G_free(mapset_name[nmapsets]);
+ G_free(mapset_name);
+ }
+
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