[GRASS-SVN] r48937 - grass/trunk/vector/v.out.ogr
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Oct 25 14:12:55 EDT 2011
Author: martinl
Date: 2011-10-25 11:12:55 -0700 (Tue, 25 Oct 2011)
New Revision: 48937
Modified:
grass/trunk/vector/v.out.ogr/list.c
Log:
v.out.ogr: sort formats
Modified: grass/trunk/vector/v.out.ogr/list.c
===================================================================
--- grass/trunk/vector/v.out.ogr/list.c 2011-10-25 15:00:08 UTC (rev 48936)
+++ grass/trunk/vector/v.out.ogr/list.c 2011-10-25 18:12:55 UTC (rev 48937)
@@ -1,38 +1,64 @@
#include "local_proto.h"
+static int cmp(const void *, const void *);
+
/* to print available drivers in help text */
char *OGR_list_write_drivers(void)
{
- int drn, i;
+ int i, count;
+ size_t len;
OGRSFDriverH Ogr_driver;
char buf[2000];
+
+ char **list, *ret;
- char OGRdrivers[2000];
-
- OGRdrivers[0] = '\0';
-
+ list = NULL;
+ count = len = 0;
+
/* Open OGR DSN */
OGRRegisterAll();
G_debug(2, "driver count = %d", OGRGetDriverCount());
- drn = 0;
for (i = 0; i < OGRGetDriverCount(); i++) {
/* only fetch read/write drivers */
if (!OGR_Dr_TestCapability(OGRGetDriver(i), ODrCCreateDataSource))
continue;
- if (drn)
- strcat(OGRdrivers, ",");
-
Ogr_driver = OGRGetDriver(i);
G_debug(2, "driver %d/%d : %s", i, OGRGetDriverCount(),
OGR_Dr_GetName(Ogr_driver));
+
+ list = G_realloc(list, (count + 1) * sizeof(char *));
+
/* chg white space to underscore in OGR driver names */
sprintf(buf, "%s", OGR_Dr_GetName(Ogr_driver));
G_strchg(buf, ' ', '_');
- strcat(OGRdrivers, buf);
- drn++;
+ list[count++] = G_store(buf);
+ len += strlen(buf) + 1; /* + ',' */
}
- G_debug(2, "all drivers: %s", OGRdrivers);
- return G_store(OGRdrivers);
+ qsort(list, count, sizeof(char *), cmp);
+
+ if (len > 0) {
+ ret = G_malloc((len + 1) * sizeof(char)); /* \0 */
+ *ret = '\0';
+ for (i = 0; i < count; i++) {
+ if (i > 0)
+ strcat(ret, ",");
+ strcat(ret, list[i]);
+ G_free(list[i]);
+ }
+ G_free(list);
+ }
+ else {
+ ret = G_store("");
+ }
+
+ G_debug(2, "all drivers: %s", ret);
+
+ return ret;
}
+
+int cmp(const void *a, const void *b)
+{
+ return (strcmp(*(char **)a, *(char **)b));
+}
More information about the grass-commit
mailing list