[PATCH wayland] scanner: simplify the getopt logic
Bryce Harrington
bryce at osg.samsung.com
Fri May 8 14:22:52 PDT 2015
On Thu, Apr 30, 2015 at 03:28:35PM +0300, Pekka Paalanen wrote:
> From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
>
> Use the same retvals for both short and long options.
>
> Whitespace fixes.
>
> Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
Reviewed-by: Bryce Harrington <bryce at osg.samsung.com>
Pushed:
8877a34..d08c079 master -> master
> ---
> src/scanner.c | 44 ++++++++++++++------------------------------
> 1 file changed, 14 insertions(+), 30 deletions(-)
>
> diff --git a/src/scanner.c b/src/scanner.c
> index 75322f7..5812176 100644
> --- a/src/scanner.c
> +++ b/src/scanner.c
> @@ -1302,7 +1302,7 @@ int main(int argc, char *argv[])
> void *buf;
> bool help = false, core_headers = false;
> bool fail = false;
> - int opt, option_index = 0;
> + int opt;
> enum {
> CLIENT_HEADER,
> SERVER_HEADER,
> @@ -1310,43 +1310,27 @@ int main(int argc, char *argv[])
> } mode;
>
> static const struct option options[] = {
> - {"help", no_argument, 0, 0 },
> - {"include-core-only", no_argument, 0, 0 },
> - {0, 0, 0, 0 }
> + { "help", no_argument, NULL, 'h' },
> + { "include-core-only", no_argument, NULL, 'c' },
> + { 0, 0, NULL, 0 }
> };
>
> while (1) {
> - opt = getopt_long(argc, argv, "hc",
> - options, &option_index);
> + opt = getopt_long(argc, argv, "hc", options, NULL);
>
> if (opt == -1)
> break;
>
> - if (opt == 0) {
> - switch (option_index) {
> - case 0:
> - help = true;
> - break;
> - case 1:
> - core_headers = true;
> - break;
> - default:
> - fail = true;
> - break;
> - }
> - continue;
> - }
> -
> switch (opt) {
> - case 'h':
> - help = true;
> - break;
> - case 'c':
> - core_headers = true;
> - break;
> - default:
> - fail = true;
> - break;
> + case 'h':
> + help = true;
> + break;
> + case 'c':
> + core_headers = true;
> + break;
> + default:
> + fail = true;
> + break;
> }
> }
>
> --
> 2.0.5
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list