Changeset: f1b421e5b21c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f1b421e5b21c
Modified Files:
        tools/mserver/mserver5.c
Branch: Oct2012
Log Message:

mserver5: fixed implementation (exit code) of usage()


diffs (67 lines):

diff --git a/tools/mserver/mserver5.c b/tools/mserver/mserver5.c
--- a/tools/mserver/mserver5.c
+++ b/tools/mserver/mserver5.c
@@ -76,11 +76,11 @@ mserver_abort()
 }
 #endif
 
-static void usage(char *prog)
+static void usage(char *prog, int xit)
 __attribute__((__noreturn__));
 
 static void
-usage(char *prog)
+usage(char *prog, int xit)
 {
        fprintf(stderr, "Usage: %s [options] [scripts]\n", prog);
        fprintf(stderr, "    --dbname=<database_name>  Specify database 
name\n");
@@ -109,7 +109,7 @@ usage(char *prog)
        fprintf(stderr, "     --forcemito\n");
        fprintf(stderr, "     --debug=<bitmask>\n");
 
-       exit(0);
+       exit(xit);
 }
 
 static void
@@ -277,7 +277,7 @@ main(int argc, char **av)
        binpath = get_bin_path();
 
        if (!(setlen = mo_builtin_settings(&set)))
-               usage(prog);
+               usage(prog, -1);
 
        for (;;) {
                int option_index = 0;
@@ -368,7 +368,7 @@ main(int argc, char **av)
                                grpdebug |= GRPheaps;
                                break;
                        }
-                       usage(prog);
+                       usage(prog, -1);
                /* not reached */
                case 'c':
                        setlen = mo_add_option(&set, setlen, opt_cmdline, 
"config", optarg);
@@ -401,16 +401,19 @@ main(int argc, char **av)
                        break;
                case 'h':
                case '?':
-                       usage(prog);
+                       /* a bit of a hack: look at the option that the
+                          current `c' is based on and see if we recognize
+                          it: if -? or --help, exit with 0, else with -1 */
+                       usage(prog, strcmp(av[optind - 1], "-?") == 0 || 
strcmp(av[optind - 1], "--help") == 0 ? 0 : -1);
                default:
                        fprintf(stderr, "ERROR: getopt returned character "
                                                        "code '%c' 0%o\n", c, 
c);
-                       usage(prog);
+                       usage(prog, -1);
                }
        }
 
        if (!(setlen = mo_system_config(&set, setlen)))
-               usage(prog);
+               usage(prog, -1);
 
        if (debug || grpdebug) {
                long_str buf;
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to