[GRASS-SVN] r51165 - grass/trunk/vector/v.external.out
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Mar 26 10:47:48 EDT 2012
Author: martinl
Date: 2012-03-26 07:47:48 -0700 (Mon, 26 Mar 2012)
New Revision: 51165
Modified:
grass/trunk/vector/v.external.out/args.c
grass/trunk/vector/v.external.out/link.c
grass/trunk/vector/v.external.out/list.c
grass/trunk/vector/v.external.out/local_proto.h
grass/trunk/vector/v.external.out/main.c
grass/trunk/vector/v.external.out/status.c
Log:
v.external.out: order formats by name also when listing formats (-f)
Modified: grass/trunk/vector/v.external.out/args.c
===================================================================
--- grass/trunk/vector/v.external.out/args.c 2012-03-26 14:20:38 UTC (rev 51164)
+++ grass/trunk/vector/v.external.out/args.c 2012-03-26 14:47:48 UTC (rev 51165)
@@ -24,7 +24,7 @@
options->format->description = _("Format for output vector data");
options->format->required = YES;
options->format->type = TYPE_STRING;
- options->format->options = format_list();
+ options->format->options = format_options();
#ifdef HAVE_OGR
options->format->answer = "ESRI_Shapefile";
#else
Modified: grass/trunk/vector/v.external.out/link.c
===================================================================
--- grass/trunk/vector/v.external.out/link.c 2012-03-26 14:20:38 UTC (rev 51164)
+++ grass/trunk/vector/v.external.out/link.c 2012-03-26 14:47:48 UTC (rev 51165)
@@ -7,12 +7,12 @@
static char *get_option_pg(char **, const char *);
static void check_option_on_off(const char *, char **);
-void make_link(const char *dsn,
+void make_link(const char *dsn_opt,
const char *format,
char *option_str, char **options)
{
int use_ogr;
- char *filename, *pg_schema, *pg_fid, *pg_geom_name;
+ char *filename, *pg_schema, *pg_fid, *pg_geom_name, *dsn;
char *pg_spatial_index, *pg_primary_key;
FILE *fp;
@@ -59,7 +59,22 @@
filename = "OGR";
G_remove("", "PG");
}
-
+
+ /* be friendly, ignored 'PG:' prefix for GRASS-PostGIS data driver */
+ if (!use_ogr && strcmp(format, "PostgreSQL") == 0 &&
+ G_strncasecmp(dsn_opt, "PG:", 3) == 0) {
+ int i, length;
+
+ length = strlen(dsn_opt);
+ dsn = (char *) G_malloc(length - 3);
+ for (i = 3; i < length; i++)
+ dsn[i-3] = dsn_opt[i];
+ dsn[length-3] = '\0';
+ }
+ else {
+ dsn = G_store(dsn_opt);
+ }
+
/* parse options for PG data format */
pg_schema = pg_fid = pg_geom_name = NULL;
pg_spatial_index = pg_primary_key = NULL;
Modified: grass/trunk/vector/v.external.out/list.c
===================================================================
--- grass/trunk/vector/v.external.out/list.c 2012-03-26 14:20:38 UTC (rev 51164)
+++ grass/trunk/vector/v.external.out/list.c 2012-03-26 14:47:48 UTC (rev 51165)
@@ -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 @@
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 @@
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;
+ list = format_list(&count, NULL);
+
+ for (i = 0; i < count; i++)
+ fprintf(stdout, "%s\n", list[i]);
+ fflush(stdout);
-
- 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
- fflush(stdout);
+ G_free(list);
}
Modified: grass/trunk/vector/v.external.out/local_proto.h
===================================================================
--- grass/trunk/vector/v.external.out/local_proto.h 2012-03-26 14:20:38 UTC (rev 51164)
+++ grass/trunk/vector/v.external.out/local_proto.h 2012-03-26 14:47:48 UTC (rev 51165)
@@ -21,7 +21,7 @@
const char *, const char *, char **);
/* list.c */
-char *format_list(void);
+char *format_options(void);
void list_formats(void);
/* status.c */
Modified: grass/trunk/vector/v.external.out/main.c
===================================================================
--- grass/trunk/vector/v.external.out/main.c 2012-03-26 14:20:38 UTC (rev 51164)
+++ grass/trunk/vector/v.external.out/main.c 2012-03-26 14:47:48 UTC (rev 51165)
@@ -70,24 +70,7 @@
}
if (options.dsn->answer) {
- char *dsn;
-
- /* be friendly, ignored 'PG:' prefix for PostGIS format */
- if (strcmp(format, "PostGIS") == 0 &&
- G_strncasecmp(options.dsn->answer, "PG:", 3) == 0) {
- int i, length;
-
- length = strlen(options.dsn->answer);
- dsn = (char *) G_malloc(length - 3);
- for (i = 3; i < length; i++)
- dsn[i-3] = options.dsn->answer[i];
- dsn[length-3] = '\0';
- }
- else {
- dsn = G_store(options.dsn->answer);
- }
-
- make_link(dsn, format,
+ make_link(options.dsn->answer, format,
options.opts->answer, options.opts->answers);
}
Modified: grass/trunk/vector/v.external.out/status.c
===================================================================
--- grass/trunk/vector/v.external.out/status.c 2012-03-26 14:20:38 UTC (rev 51164)
+++ grass/trunk/vector/v.external.out/status.c 2012-03-26 14:47:48 UTC (rev 51165)
@@ -72,7 +72,7 @@
print_key_value("conninfo", p, shell);
/* format (hardcoded) */
- print_key_value("format", "PostGIS", shell);
+ print_key_value("format", "PostgreSQL", shell);
/* schema */
p = G_find_key_value("schema", key_val);
More information about the grass-commit
mailing list