Browse Source

https://trac.osgeo.org/grass/ticket/983 (sort g.mapsets -l output)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@44620 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 14 years ago
parent
commit
5f9aea133c
2 changed files with 14 additions and 2 deletions
  1. 12 0
      general/g.mapsets/get_maps.c
  2. 2 2
      general/g.mapsets/main.c

+ 12 - 0
general/g.mapsets/get_maps.c

@@ -1,7 +1,11 @@
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <grass/gis.h>
 #include "local_proto.h"
 
+static int cmp(const void *, const void *);
+
 int get_available_mapsets(void)
 {
     char **ms;
@@ -14,5 +18,13 @@ int get_available_mapsets(void)
     for(i = 0; i < nmapsets; i++)
 	mapset_name[i] = G_store(ms[i]);
 
+    /* sort mapsets */
+    qsort(mapset_name, nmapsets, sizeof(char *), cmp);
+
     return 0;
 }
+
+static int cmp(const void *a, const void *b) 
+{
+    return (strcmp(*(char **)a, *(char **)b));
+}

+ 2 - 2
general/g.mapsets/main.c

@@ -94,12 +94,12 @@ int main(int argc, char *argv[])
     
     opt.list = G_define_flag();
     opt.list->key = 'l';
-    opt.list->description = _("List all available mapsets");
+    opt.list->description = _("List all available mapsets in alphabetical order");
     opt.list->guisection = _("Print");
 
     opt.print = G_define_flag();
     opt.print->key = 'p';
-    opt.print->description = _("Print current mapset search path");
+    opt.print->description = _("Print mapsets in current search path");
     opt.print->guisection = _("Print");
 
     opt.dialog = G_define_flag();