浏览代码

g.mapsets: clean up list_mapsets fns

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@42623 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 15 年之前
父节点
当前提交
ad49a009a7

+ 0 - 59
general/g.mapsets/dsply_maps.c

@@ -1,59 +0,0 @@
-#include <string.h>
-#include <stdio.h>
-#include <grass/glocale.h>
-#include "local_proto.h"
-
-static int display1(void);
-static int display2(const char *fs);
-
-int display_available_mapsets(const char* fs)
-{
-    if (!fs)
-	display1();
-    else
-	display2(fs);
-
-    return 0;
-}
-
-static int display1(void)
-{
-    int n;
-
-    fprintf(stdout, _("Available mapsets:"));
-    for (n = 0; n < nmapsets; n++) {
-	if (n % 4)
-	    fprintf(stdout, " ");
-	else
-	    fprintf(stdout, "\n");
-	fprintf(stdout, "%2d %-15s", n + 1, mapset_name[n]);
-    }
-    fprintf(stdout, "\n");
-    if (nmapsets == 0)
-	fprintf(stdout, _("** no mapsets **\n"));
-    fprintf(stdout, "\n");
-
-    return 0;
-}
-
-static int display2(const char *fs)
-{
-    int nleft, len, n;
-    char *name;
-
-    nleft = 78;
-    for (n = 0; n < nmapsets; n++) {
-	len = strlen(name = mapset_name[n]);
-	if (len > nleft) {
-	    fprintf(stdout, "\n");
-	    nleft = 78;
-	}
-	fprintf(stdout, "%s", name);
-	if (n < nmapsets-1)
-	    fprintf(stdout, "%s", fs);
-	nleft -= (len + 1);
-    }
-    fprintf(stdout, "\n");
-
-    return 0;
-}

+ 0 - 57
general/g.mapsets/dsply_path.c

@@ -1,57 +0,0 @@
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include "local_proto.h"
-
-int display_mapset_path(const char *fs)
-{
-    int n;
-    int map;			/* pointer into list of available mapsets */
-    int offset = 6;		/* accounts for " <x>, " */
-    const char *name;
-    int len;
-    int nleft;
-
-    if (!fs) {
-	/* account for largest mapset number in offset value */
-	for (n = nmapsets; n /= 10; offset++) ;
-
-	fprintf(stdout, _("Your mapset search list:\n"));
-    }
-
-    nleft = 78;
-    for (n = 0; (name = G__mapset_name(n)); n++) {
-	/* match each mapset to its numeric equivalent */
-	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"),
-			      name);
-	}
-
-	len = strlen(name);
-	if (len > nleft) {
-	    fprintf(stdout, "\n");
-	    nleft = 78;
-	}
-
-	if (!fs) {
-	    if (n)
-		fprintf(stdout, ", ");
-	    fprintf(stdout, "%s <%d>", name, map + 1);
-	    nleft -= (len + offset);
-	}
-	else {
-	    fprintf(stdout, "%s", name);
-	    if (G__mapset_name(n+1))
-		fprintf(stdout, "%s", fs);
-	    nleft -= (len + 1);
-	}
-    }
-    fprintf(stdout, "\n");
-    if (!fs)
-	fprintf(stdout, "\n");
-
-    return 0;
-}

+ 53 - 0
general/g.mapsets/list.c

@@ -0,0 +1,53 @@
+#include <string.h>
+#include <stdio.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
+
+void list_available_mapsets(const char* fs)
+{
+    int  n;
+    G_message(_("Available mapsets:"));
+    
+    for (n = 0; n < nmapsets; n++) {
+	fprintf(stdout, "%s", mapset_name[n]);
+	if (n < nmapsets-1) {
+	    if (strcmp(fs, "newline") == 0)
+		fprintf(stdout, "\n");
+	    else if (strcmp(fs, "space") == 0)
+		fprintf(stdout, " ");
+	    else if (strcmp(fs, "comma") == 0)
+		fprintf(stdout, ",");
+	    else if (strcmp(fs, "tab") == 0)
+		fprintf(stdout, "\t");
+	    else
+		fprintf(stdout, "%s", fs);
+	}
+    }
+    fprintf(stdout, "\n");
+}
+
+void list_accessible_mapsets(const char* fs)
+{
+    int n;
+    const char *name;
+    
+    G_message(_("Accessible mapsets:"));
+    for (n = 0; (name = G__mapset_name(n)); n++) {
+	/* match each mapset to its numeric equivalent */
+	fprintf(stdout, "%s", name);
+	if (G__mapset_name(n+1)) {
+	    if (strcmp(fs, "newline") == 0)
+		fprintf(stdout, "\n");
+	    else if (strcmp(fs, "space") == 0)
+		fprintf(stdout, " ");
+	    else if (strcmp(fs, "comma") == 0)
+		fprintf(stdout, ",");
+	    else if (strcmp(fs, "tab") == 0)
+		fprintf(stdout, "\t");
+	    else
+		fprintf(stdout, "%s", fs);
+	}
+    }
+    fprintf(stdout, "\n");
+}

+ 3 - 21
general/g.mapsets/local_proto.h

@@ -7,27 +7,9 @@
 GLOBAL char **mapset_name;
 GLOBAL char **mapset_name;
 GLOBAL int nmapsets;
 GLOBAL int nmapsets;
 
 
-/* dsply_maps.c */
-int display_available_mapsets(const char *);
-
-/* dsply_path.c */
-int display_mapset_path(const char *);
-
 /* get_maps.c */
 /* get_maps.c */
 int get_available_mapsets(void);
 int get_available_mapsets(void);
 
 
-/* get_path.c */
-int get_mapset_path(void);
-int delete_choices(void);
-
-/* main_cmd.c */
-int main(int, char *[]);
-
-/* main_inter.c */
-int main(int, char **);
-
-/* scan_int.c */
-int scan_int(char *, int *);
-
-/* set_path.c */
-int set_mapset_path(void);
+/* list.c */
+void list_available_mapsets(const char *);
+void list_accessible_mapsets(const char *);

+ 4 - 3
general/g.mapsets/main.c

@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
 	_("Name(s) of existing mapset(s) to remove from search list");
 	_("Name(s) of existing mapset(s) to remove from search list");
     
     
     opt.fs = G_define_standard_option(G_OPT_F_SEP);
     opt.fs = G_define_standard_option(G_OPT_F_SEP);
-    opt.fs->answer = " ";
+    opt.fs->answer = "space";
     
     
     opt.list = G_define_flag();
     opt.list = G_define_flag();
     opt.list->key = 'l';
     opt.list->key = 'l';
@@ -110,10 +110,11 @@ int main(int argc, char *argv[])
 
 
     if (opt.list->answer) {
     if (opt.list->answer) {
 	get_available_mapsets();
 	get_available_mapsets();
-	display_available_mapsets(opt.fs->answer);
+	list_available_mapsets(opt.fs->answer);
     }
     }
 
 
     if (opt.dialog->answer) {
     if (opt.dialog->answer) {
+	putenv("GRASS_VERBOSE=0");
 	sprintf(path, "%s/etc/gui/scripts/g.mapsets_picker.py", G_gisbase());
 	sprintf(path, "%s/etc/gui/scripts/g.mapsets_picker.py", G_gisbase());
 	G_spawn(getenv("GRASS_PYTHON"), "g.mapsets_picker.py", path, NULL);
 	G_spawn(getenv("GRASS_PYTHON"), "g.mapsets_picker.py", path, NULL);
     }
     }
@@ -195,7 +196,7 @@ int main(int argc, char *argv[])
 
 
     if (nchoices == 0) {
     if (nchoices == 0) {
 	if (opt.print->answer)
 	if (opt.print->answer)
-	    display_mapset_path(opt.fs->answer);
+	    list_accessible_mapsets(opt.fs->answer);
 
 
 	if (Path)
 	if (Path)
 	    G_free(Path);
 	    G_free(Path);

+ 2 - 1
lib/gis/parser_standard_options.c

@@ -441,7 +441,8 @@ struct Option *G_define_standard_option(int opt)
 	Opt->key_desc = "character";
 	Opt->key_desc = "character";
 	Opt->required = NO;
 	Opt->required = NO;
 	Opt->answer = "|";
 	Opt->answer = "|";
-	Opt->description = _("Field separator");
+	Opt->label = _("Field separator");
+	Opt->description = _("Special characters: newline, space, comma, tab");
 	break;
 	break;
 
 
 	/* colors */
 	/* colors */