From patchwork Mon Jun 4 09:07:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 924892 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40zpxW1rtHz9s0W for ; Mon, 4 Jun 2018 19:07:59 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="mp5DRlpf"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40zpxW0J8tzF0yB for ; Mon, 4 Jun 2018 19:07:59 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="mp5DRlpf"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40zpxR1yWbzF0tm for ; Mon, 4 Jun 2018 19:07:55 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="mp5DRlpf"; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 40zpxP1C9lz9s0w; Mon, 4 Jun 2018 19:07:52 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1528103275; bh=vCpThEBJiVaPbYN1zHtI1Gu1WSZ4i7NmdaG/RpPIzh8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mp5DRlpfbcIXEE/DxRYO+Go8fWgLUvnulP3zECM3V75HTqUOVnYgarM0tQSPhql8b QcLJK97qNqFToEjJxizL0/9Io+j5rOEyhl22Q+rEMPX5rx4kIJIrH1RUsFXV85EmIM l0OIT6QhgWebQensY/ESIAdfsVJi4OF1IgYeYVPUlp9aXQpt3p3D90UhohYem9u8DW bIpefPBcNVNv6yETCQEa0KPqc3GVYydhT/jTD6lPNgt7za+IHxoV0KBbIAZxnyjqXV mbAfQKK/ZHA07T7adK9zksSvD+rjaWIaP6aqGJEMGomXMjCfV+2geRkNJOUXjk/mpw CJU+KQ8/xqzVQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Mon, 4 Jun 2018 19:07:20 +1000 Message-Id: <20180604090721.18744-3-amitay@ozlabs.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180604090721.18744-1-amitay@ozlabs.org> References: <20180604090721.18744-1-amitay@ozlabs.org> Subject: [Pdbg] [PATCH v3 2/3] main: Print specific errors for invalid arguments X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" This avoids the large usage message obscuring the actual errors from parsing options. Print usage only if an option is invalid. Signed-off-by: Amitay Isaacs --- src/main.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main.c b/src/main.c index 6c7c7be..2234d48 100644 --- a/src/main.c +++ b/src/main.c @@ -237,7 +237,7 @@ static bool parse_list(const char *arg, int max, int *list, int *count) static bool parse_options(int argc, char *argv[]) { int c; - bool opt_error = true; + bool opt_error = false; int p_list[MAX_PROCESSORS]; int c_list[MAX_CHIPS]; int t_list[MAX_THREADS]; @@ -265,8 +265,6 @@ static bool parse_options(int argc, char *argv[]) switch(c) { case 'a': - opt_error = false; - if (p_count == 0) { p_count = MAX_PROCESSORS; for (i = 0; i < MAX_PROCESSORS; i++) @@ -287,28 +285,27 @@ static bool parse_options(int argc, char *argv[]) break; case 'p': - if (!parse_list(optarg, MAX_PROCESSORS, p_list, &p_count)) + if (!parse_list(optarg, MAX_PROCESSORS, p_list, &p_count)) { fprintf(stderr, "Failed to parse '-p %s'\n", optarg); - else - opt_error = false; + opt_error = true; + } break; case 'c': - if (!parse_list(optarg, MAX_CHIPS, c_list, &c_count)) + if (!parse_list(optarg, MAX_CHIPS, c_list, &c_count)) { fprintf(stderr, "Failed to parse '-c %s'\n", optarg); - else - opt_error = false; + opt_error = true; + } break; case 't': - if (!parse_list(optarg, MAX_THREADS, t_list, &t_count)) + if (!parse_list(optarg, MAX_THREADS, t_list, &t_count)) { fprintf(stderr, "Failed to parse '-t %s'\n", optarg); - else - opt_error = false; + opt_error = true; + } break; case 'b': - opt_error = false; if (strcmp(optarg, "fsi") == 0) { backend = FSI; device_node = "p9w"; @@ -322,12 +319,13 @@ static bool parse_options(int argc, char *argv[]) backend = FAKE; } else if (strcmp(optarg, "host") == 0) { backend = HOST; - } else + } else { + fprintf(stderr, "Invalid backend '%s'\n", optarg); opt_error = true; + } break; case 'd': - opt_error = false; device_node = optarg; break; @@ -335,6 +333,8 @@ static bool parse_options(int argc, char *argv[]) errno = 0; i2c_addr = strtoull(optarg, &endptr, 0); opt_error = (errno || *endptr != '\0'); + if (opt_error) + fprintf(stderr, "Invalid slave address '%s'\n", optarg); break; case 'D': @@ -349,12 +349,12 @@ static bool parse_options(int argc, char *argv[]) case '?': case 'h': opt_error = true; + print_usage(basename(argv[0])); break; } } while (c != EOF && !opt_error); if (opt_error) { - print_usage(basename(argv[0])); return false; }