From a4ac7a67867013cc2848e044f0220fe631946066 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 7 Aug 2013 11:05:57 +1000 Subject: [PATCH] scanner: support help and --help wayland-scanner without arguments prints out usage. With help or --help it waits for stdin to supply something which isn't quite as informative as printing out the help. This patch also moves the strcmp for args up to have all of them in one location. --- src/scanner.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/scanner.c b/src/scanner.c index 4aa70d1a..ace6633b 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -1158,9 +1158,22 @@ int main(int argc, char *argv[]) struct protocol protocol; int len; void *buf; + enum { + CLIENT_HEADER, + SERVER_HEADER, + CODE, + } mode; if (argc != 2) usage(EXIT_FAILURE); + else if (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "--help") == 0) + usage(EXIT_SUCCESS); + else if (strcmp(argv[1], "client-header") == 0) + mode = CLIENT_HEADER; + else if (strcmp(argv[1], "server-header") == 0) + mode = SERVER_HEADER; + else if (strcmp(argv[1], "code") == 0) + mode = CODE; wl_list_init(&protocol.interface_list); protocol.type_index = 0; @@ -1193,12 +1206,16 @@ int main(int argc, char *argv[]) XML_ParserFree(ctx.parser); - if (strcmp(argv[1], "client-header") == 0) { - emit_header(&protocol, 0); - } else if (strcmp(argv[1], "server-header") == 0) { - emit_header(&protocol, 1); - } else if (strcmp(argv[1], "code") == 0) { - emit_code(&protocol); + switch(mode) { + case CLIENT_HEADER: + emit_header(&protocol, 0); + break; + case SERVER_HEADER: + emit_header(&protocol, 1); + break; + case CODE: + emit_code(&protocol); + break; } return 0;