From: Sandro Santilli Date: Fri, 12 Oct 2012 15:20:44 +0000 (+0000) Subject: Exit with non-zero code when commandline is malformed X-Git-Tag: 2.1.0beta2~548 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3dee3684e4717ca470d83d12fd9d68b3e69300a;p=postgis Exit with non-zero code when commandline is malformed It still exists with zero code when user explictly asks for the help screen (with -? as documented and with no switch as popular habit [well, mine]) git-svn-id: http://svn.osgeo.org/postgis/trunk@10418 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/loader/pgsql2shp-cli.c b/loader/pgsql2shp-cli.c index 04c2ad045..89a5becb6 100644 --- a/loader/pgsql2shp-cli.c +++ b/loader/pgsql2shp-cli.c @@ -22,8 +22,10 @@ static void -usage() +usage(int status) { + /* TODO: if status != 0 print all to stderr */ + printf(_( "RELEASE: %s (r%d)\n" ), POSTGIS_LIB_VERSION, POSTGIS_SVN_REVISION); printf(_("USAGE: pgsql2shp [] [.]\n" " pgsql2shp [] \n" @@ -47,6 +49,7 @@ usage() " COLUMNNAME DBFFIELD1\n" " AVERYLONGCOLUMNNAME DBFFIELD2\n" )); printf(_(" -? Display this help screen.\n\n" )); + exit(status); } int @@ -60,8 +63,7 @@ main(int argc, char **argv) /* If no options are specified, display usage */ if (argc == 1) { - usage(); - exit(0); + usage(0); /* TODO: should this exit with error ? */ } /* Parse command line options and set configuration */ @@ -106,12 +108,8 @@ main(int argc, char **argv) case 'k': config->keep_fieldname_case = 1; break; - case '?': - usage(); - exit(0); default: - usage(); - exit(0); + usage(pgis_optopt == '?' ? 0 : 1); } } @@ -124,8 +122,7 @@ main(int argc, char **argv) } else { - usage(); - exit(0); + usage(1); }