]> granicus.if.org Git - postgis/commitdiff
Exit with non-zero code when commandline is malformed
authorSandro Santilli <strk@keybit.net>
Fri, 12 Oct 2012 15:20:44 +0000 (15:20 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 12 Oct 2012 15:20:44 +0000 (15:20 +0000)
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

loader/pgsql2shp-cli.c

index 04c2ad0459725d3a8fd377c27a4b0192a365d18a..89a5becb6381c9fddf002d8dd6515ef6163ab462 100644 (file)
 
 
 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 [<options>] <database> [<schema>.]<table>\n"
                 "       pgsql2shp [<options>] <database> <query>\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);
        }