|
@@ -6,22 +6,21 @@
|
|
|
#ifdef HAVE_OGR
|
|
|
#include "ogr_api.h"
|
|
|
|
|
|
-int cmp(const void *a, const void *b)
|
|
|
+static int cmp(const void *a, const void *b)
|
|
|
{
|
|
|
return (strcmp(*(char **)a, *(char **)b));
|
|
|
}
|
|
|
#endif /* HAVE_OGR */
|
|
|
|
|
|
-char *format_list(void)
|
|
|
+static char **format_list(int *count, size_t *len)
|
|
|
{
|
|
|
- int i, count;
|
|
|
- size_t len;
|
|
|
-
|
|
|
- char **list, *ret;
|
|
|
+ int i;
|
|
|
+ char **list;
|
|
|
|
|
|
list = NULL;
|
|
|
- count = len = 0;
|
|
|
- ret = NULL;
|
|
|
+ *count = 0;
|
|
|
+ if (len)
|
|
|
+ *len = 0;
|
|
|
|
|
|
#ifdef HAVE_OGR
|
|
|
char buf[2000];
|
|
@@ -40,22 +39,38 @@ char *format_list(void)
|
|
|
G_debug(2, "driver %d/%d : %s", i, OGRGetDriverCount(),
|
|
|
OGR_Dr_GetName(Ogr_driver));
|
|
|
|
|
|
- list = G_realloc(list, (count + 1) * sizeof(char *));
|
|
|
+ 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, ' ', '_');
|
|
|
- list[count++] = G_store(buf);
|
|
|
- len += strlen(buf) + 1; /* + ',' */
|
|
|
+ list[(*count)++] = G_store(buf);
|
|
|
+ if (len)
|
|
|
+ *len += strlen(buf) + 1; /* + ',' */
|
|
|
}
|
|
|
|
|
|
- qsort(list, count, sizeof(char *), cmp);
|
|
|
+ /* order formats by name */
|
|
|
+ qsort(list, *count, sizeof(char *), cmp);
|
|
|
#endif
|
|
|
#if defined HAVE_POSTGRES && !defined HAVE_OGR
|
|
|
- list = G_realloc(list, (count + 1) * sizeof(char *));
|
|
|
- list[count++] = G_store("PostgreSQL");
|
|
|
- len += strlen("PostgreSQL") + 1;
|
|
|
+ list = G_realloc(list, ((*count) + 1) * sizeof(char *));
|
|
|
+ list[(*count)++] = G_store("PostgreSQL");
|
|
|
+ if (len)
|
|
|
+ *len += strlen("PostgreSQL") + 1;
|
|
|
#endif
|
|
|
+
|
|
|
+ return list;
|
|
|
+}
|
|
|
+
|
|
|
+char *format_options()
|
|
|
+{
|
|
|
+ int i, count;
|
|
|
+ char **list, *ret;
|
|
|
+ size_t len;
|
|
|
+
|
|
|
+ ret = NULL;
|
|
|
+ list = format_list(&count, &len);
|
|
|
+
|
|
|
if (len > 0) {
|
|
|
ret = G_malloc((len + 1) * sizeof(char)); /* \0 */
|
|
|
*ret = '\0';
|
|
@@ -78,29 +93,16 @@ char *format_list(void)
|
|
|
|
|
|
void list_formats(void)
|
|
|
{
|
|
|
+ int i, count;
|
|
|
+ char **list;
|
|
|
+
|
|
|
G_message(_("List of supported formats:"));
|
|
|
|
|
|
-#ifdef HAVE_OGR
|
|
|
- /* -------------------------------------------------------------------- */
|
|
|
- /* List supported formats and exit. */
|
|
|
- /* code from GDAL 1.2.5 gcore/gdal_misc.cpp */
|
|
|
- /* Copyright (c) 1999, Frank Warmerdam */
|
|
|
- /* -------------------------------------------------------------------- */
|
|
|
- int iDr;
|
|
|
- OGRSFDriverH driver;
|
|
|
-
|
|
|
-
|
|
|
- for (iDr = 0; iDr < OGRGetDriverCount(); iDr++) {
|
|
|
- driver = OGRGetDriver(iDr);
|
|
|
-
|
|
|
- if (!OGR_Dr_TestCapability(driver, ODrCCreateDataSource))
|
|
|
- continue;
|
|
|
-
|
|
|
- fprintf(stdout, "%s\n", OGR_Dr_GetName(driver));
|
|
|
- }
|
|
|
-#endif
|
|
|
-#ifdef HAVE_POSTGRES
|
|
|
- fprintf(stdout, "PostGIS\n");
|
|
|
-#endif
|
|
|
+ list = format_list(&count, NULL);
|
|
|
+
|
|
|
+ for (i = 0; i < count; i++)
|
|
|
+ fprintf(stdout, "%s\n", list[i]);
|
|
|
fflush(stdout);
|
|
|
+
|
|
|
+ G_free(list);
|
|
|
}
|