diff mbox

[Branch,~glcompbench-dev/glcompbench/trunk] Rev 25: Improve robustness of command line option parsing.

Message ID 20110622092719.30588.13980.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org June 22, 2011, 9:27 a.m. UTC
------------------------------------------------------------
revno: 25
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
branch nick: trunk
timestamp: Wed 2011-06-22 12:26:51 +0300
message:
  Improve robustness of command line option parsing.
modified:
  src/glcompbench.cc
  src/options.cc
  src/options.h


--
lp:glcompbench
https://code.launchpad.net/~glcompbench-dev/glcompbench/trunk

You are subscribed to branch lp:glcompbench.
To unsubscribe from this branch go to https://code.launchpad.net/~glcompbench-dev/glcompbench/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'src/glcompbench.cc'
--- src/glcompbench.cc	2011-03-14 22:54:03 +0000
+++ src/glcompbench.cc	2011-06-22 09:26:51 +0000
@@ -43,7 +43,8 @@ 
 
     std::list<CompositeTest*> tests;
 
-    Options::parse_args(argc, argv);
+    if (!Options::parse_args(argc, argv))
+        return 1;
 
     if (Options::show_help) {
         Options::print_help();

=== modified file 'src/options.cc'
--- src/options.cc	2011-04-27 18:10:23 +0000
+++ src/options.cc	2011-06-22 09:26:51 +0000
@@ -98,20 +98,23 @@ 
            "  --help             Display help\n");
 }
 
-void
+bool
 Options::parse_args(int argc, char **argv)
 {
     while (1) {
-        int option_index = 0;
+        int option_index = -1;
         int c;
-        const char *optname;
+        const char *optname = "";
 
         c = getopt_long(argc, argv, "",
                         long_options, &option_index);
         if (c == -1)
             break;
+        if (c == ':' || c == '?')
+            return false;
 
-       optname = long_options[option_index].name;
+        if (option_index != -1)
+            optname = long_options[option_index].name;
 
        if (!strcmp(optname, "ids"))
            parse_window_ids(optarg, Options::window_ids);
@@ -140,4 +143,6 @@ 
        else if (!strcmp(optname, "help"))
            Options::show_help = true;
     }
+
+    return true;
 }

=== modified file 'src/options.h'
--- src/options.h	2011-04-27 18:10:23 +0000
+++ src/options.h	2011-06-22 09:26:51 +0000
@@ -28,7 +28,7 @@ 
 #include <list>
 
 struct Options {
-    static void parse_args(int argc, char **argv);
+    static bool parse_args(int argc, char **argv);
     static void print_help();
 
     static std::list<Window> window_ids;