From 259bd1f50237d3fd31ebbc8112b07819312d95d7 Mon Sep 17 00:00:00 2001 From: Mark Cave-Ayland Date: Fri, 8 Jun 2012 14:04:26 +0000 Subject: [PATCH] Rename references to -r to -s in shp2pgsql-cli.c and also move argument combination validation to a separate phase. This is based upon a report from Lauri Kajan who was having issues using -D and -s TO_SRID on Windows. git-svn-id: http://svn.osgeo.org/postgis/trunk@9868 b70326c6-7e19-0410-871a-916f4a2858ee --- loader/shp2pgsql-cli.c | 47 ++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/loader/shp2pgsql-cli.c b/loader/shp2pgsql-cli.c index d6021cb14..d2687b272 100644 --- a/loader/shp2pgsql-cli.c +++ b/loader/shp2pgsql-cli.c @@ -102,16 +102,6 @@ main (int argc, char **argv) case 'D': config->dump_format = 1; - if (!config->usetransaction) - { - fprintf(stderr, "Cannot use both -D and -e.\n"); - exit(1); - } - if (config->shp_sr_id != SRID_UNKNOWN) - { - fprintf(stderr, "Cannot use both -D and -r.\n"); - exit(1); - } break; case 'G': @@ -126,27 +116,22 @@ main (int argc, char **argv) if (pgis_optarg) { char *ptr = strchr(pgis_optarg, ':'); - if ( ptr ) + if (ptr) { - if (config->dump_format) - { - fprintf(stderr, "Cannot use both -D and -r.\n"); - exit(1); - } *ptr++ = '\0'; - sscanf(pgis_optarg, "%d", &(config->shp_sr_id)); - if ( ! *ptr ) { printf("No ptr?\n"); usage(); exit(1); } - sscanf(ptr, "%d", &(config->sr_id)); + sscanf(pgis_optarg, "%d", &config->shp_sr_id); + sscanf(ptr, "%d", &config->sr_id); } else { - sscanf(pgis_optarg, "%d", &(config->sr_id)); + /* Only TO_SRID specified */ + sscanf(pgis_optarg, "%d", &config->sr_id); } } else { - /* With -s, user must specify SRID or FROM_SRID:TO_SRID */ - usage(); + /* With -s, user must specify TO_SRID or FROM_SRID:TO_SRID */ + fprintf(stderr, "The -s parameter must be specified in the form [FROM_SRID:]TO_SRID\n"); exit(1); } break; @@ -230,11 +215,6 @@ main (int argc, char **argv) case 'e': config->usetransaction = 0; - if (config->dump_format) - { - fprintf(stderr, "Cannot use both -D and -e.\n"); - exit(1); - } break; case '?': @@ -247,6 +227,19 @@ main (int argc, char **argv) } } + /* Once we have parsed the arguments, make sure certain combinations are valid */ + if (config->dump_format && !config->usetransaction) + { + fprintf(stderr, "Invalid argument combination - cannot use both -D and -e\n"); + exit(1); + } + + if (config->dump_format && config->shp_sr_id != SRID_UNKNOWN) + { + fprintf(stderr, "Invalid argument combination - cannot use -D with -s FROM_SRID:TO_SRID\n"); + exit(1); + } + /* Determine the shapefile name from the next argument, if no shape file, exit. */ if (pgis_optind < argc) { -- 2.40.0