From patchwork Wed Jun 22 09:27:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 2155 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id EBC5223F4D for ; Wed, 22 Jun 2011 09:32:22 +0000 (UTC) Received: from mail-vw0-f52.google.com (mail-vw0-f52.google.com [209.85.212.52]) by fiordland.canonical.com (Postfix) with ESMTP id B24EEA184E6 for ; Wed, 22 Jun 2011 09:32:22 +0000 (UTC) Received: by vws16 with SMTP id 16so688955vws.11 for ; Wed, 22 Jun 2011 02:32:22 -0700 (PDT) Received: by 10.52.161.65 with SMTP id xq1mr609366vdb.167.1308735141979; Wed, 22 Jun 2011 02:32:21 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs124945vdc; Wed, 22 Jun 2011 02:32:21 -0700 (PDT) Received: by 10.227.13.135 with SMTP id c7mr483303wba.111.1308735139921; Wed, 22 Jun 2011 02:32:19 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id n11si936884wbh.27.2011.06.22.02.32.19; Wed, 22 Jun 2011 02:32:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QZJnF-00034m-1g for ; Wed, 22 Jun 2011 09:32:17 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id C6DF82E8CBA for ; Wed, 22 Jun 2011 09:27:19 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glcompbench X-Launchpad-Branch: ~glcompbench-dev/glcompbench/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 25 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glcompbench-dev/glcompbench/trunk] Rev 25: Improve robustness of command line option parsing. Message-Id: <20110622092719.30588.13980.launchpad@loganberry.canonical.com> Date: Wed, 22 Jun 2011 09:27:19 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13265"; Instance="initZopeless config overlay" X-Launchpad-Hash: 2901a05f85dbdd6f1022790744e29af10db38b98 ------------------------------------------------------------ revno: 25 committer: Alexandros Frantzis 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 === 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 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 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_ids;