[Skiboot] [PATCH v3 3/4] external: simplify help output in xscom commands

Cédric Le Goater clg at fr.ibm.com
Wed Mar 9 23:30:35 AEDT 2016


This kills a few booleans used to output version and help.

Suggested-by: Vasant Hegde <hegdevasant at linux.vnet.ibm.com>
Signed-off-by: Cédric Le Goater <clg at fr.ibm.com>
---
 external/xscom-utils/getscom.c | 19 ++++++-------------
 external/xscom-utils/getsram.c | 22 ++++++----------------
 external/xscom-utils/putscom.c | 23 +++++++----------------
 3 files changed, 19 insertions(+), 45 deletions(-)

diff --git a/external/xscom-utils/getscom.c b/external/xscom-utils/getscom.c
index 45bdf2c2df92..96dcace433cd 100644
--- a/external/xscom-utils/getscom.c
+++ b/external/xscom-utils/getscom.c
@@ -28,6 +28,7 @@ static void print_usage(void)
 	printf("usage: getscom [-c|--chip chip-id] addr\n");
 	printf("       getscom -l|--list-chips\n");
 	printf("       getscom -v|--version\n");
+	exit(1);
 }
 
 static void print_chip_info(uint32_t chip_id)
@@ -81,9 +82,7 @@ int main(int argc, char *argv[])
 {
 	uint64_t val, addr = -1ull;
 	uint32_t def_chip, chip_id = 0xffffffff;
-	bool show_help = false;
 	bool list_chips = false;
-	bool show_version = false;
 	bool no_work = false;
 	int rc;
 
@@ -107,14 +106,14 @@ int main(int argc, char *argv[])
 			chip_id = strtoul(optarg, NULL, 0);
 			break;
 		case 'h':
-			show_help = true;
+			print_usage();
 			break;
 		case 'l':
 			list_chips = true;
 			break;
 		case 'v':
-			show_version = true;
-			break;
+			printf("xscom utils version %s\n", VERSION_STR);
+			exit(1);
 		default:
 			exit(1);
 		}
@@ -122,17 +121,11 @@ int main(int argc, char *argv[])
 	
 	if (addr == -1ull)
 		no_work = true;
-	if (no_work && !list_chips && !show_version && !show_help) {
+	if (no_work && !list_chips) {
 		fprintf(stderr, "Invalid or missing address\n");
 		print_usage();
-		exit(1);
 	}
-	if (show_version)
-		printf("xscom utils version %s\n", VERSION_STR);
-	if (show_help)
-		print_usage();
-	if (no_work && !list_chips)
-		return 0;
+
 	def_chip = xscom_init();
 	if (def_chip == 0xffffffff) {
 		fprintf(stderr, "No valid XSCOM chip found\n");
diff --git a/external/xscom-utils/getsram.c b/external/xscom-utils/getsram.c
index 6e85fc88a0e0..ea3d38badf8d 100644
--- a/external/xscom-utils/getsram.c
+++ b/external/xscom-utils/getsram.c
@@ -29,6 +29,7 @@ static void print_usage(void)
 	printf("usage: getsram [-c|--chip chip-id] addr\n");
 	printf("               [--occ-channel|n <chan>]\n");
 	printf("       getsram -v|--version\n");
+	exit(1);
 }
 
 #define VERSION_STR _str(VERSION)
@@ -39,9 +40,6 @@ int main(int argc, char *argv[])
 {
 	uint64_t val, addr = -1ull;
 	uint32_t def_chip, chip_id = 0xffffffff;
-	bool show_help = false;
-	bool show_version = false;
-	bool no_work = false;
 	int rc;
 	int occ_channel = 0;
 
@@ -72,29 +70,21 @@ int main(int argc, char *argv[])
 			}
 			break;
 		case 'h':
-			show_help = true;
+			print_usage();
 			break;
 		case 'v':
-			show_version = true;
-			break;
+			printf("xscom utils version %s\n", VERSION_STR);
+			exit(1);
 		default:
 			exit(1);
 		}
 	}
 
-	if (addr == -1ull)
-		no_work = true;
-	if (no_work && !show_version && !show_help) {
+	if (addr == -1ull) {
 		fprintf(stderr, "Invalid or missing address\n");
 		print_usage();
-		exit(1);
 	}
-	if (show_version)
-		printf("xscom utils version %s\n", VERSION_STR);
-	if (show_help)
-		print_usage();
-	if (no_work)
-		return 0;
+
 	def_chip = xscom_init();
 	if (def_chip == 0xffffffff) {
 		fprintf(stderr, "No valid XSCOM chip found\n");
diff --git a/external/xscom-utils/putscom.c b/external/xscom-utils/putscom.c
index 8c397fc0be57..be7b696186cb 100644
--- a/external/xscom-utils/putscom.c
+++ b/external/xscom-utils/putscom.c
@@ -27,6 +27,7 @@ static void print_usage(void)
 {
 	printf("usage: putscom [-c|--chip chip-id] addr value\n");
 	printf("       putscom -v|--version\n");
+	exit(1);
 }
 
 #define VERSION_STR _str(VERSION)
@@ -37,9 +38,7 @@ int main(int argc, char *argv[])
 {
 	uint64_t val = -1ull, addr = -1ull;
 	uint32_t def_chip, chip_id = 0xffffffff;
-	bool show_help = false, got_addr = false, got_val = false;
-	bool show_version = false;
-	bool no_work = false;
+	bool got_addr = false, got_val = false;
 	int rc;
 
 	while(1) {
@@ -67,29 +66,21 @@ int main(int argc, char *argv[])
 			chip_id = strtoul(optarg, NULL, 0);
 			break;
 		case 'v':
-			show_version = true;
-			break;
+			printf("xscom utils version %s\n", VERSION_STR);
+			exit(1);
 		case 'h':
-			show_help = true;
+			print_usage();
 			break;
 		default:
 			exit(1);
 		}
 	}
 	
-	if (!got_addr || !got_val)
-		no_work = true;
-	if (no_work && !show_version && !show_help) {
+	if (!got_addr || !got_val) {
 		fprintf(stderr, "Invalid or missing address/value\n");
 		print_usage();
-		exit(1);
 	}
-	if (show_version)
-		printf("xscom utils version %s\n", VERSION_STR);
-	if (show_help)
-		print_usage();
-	if (no_work)
-		return 0;
+
 	def_chip = xscom_init();
 	if (def_chip == 0xffffffff) {
 		fprintf(stderr, "No valid XSCOM chip found\n");
-- 
2.1.4



More information about the Skiboot mailing list