diff mbox series

[2/4] mmc-utils: Simplify and streamline print_help function

Message ID 20250428122951.317055-3-avri.altman@sandisk.com
State New
Headers show
Series mmc-utils: Reuse the 'help' section for command usage handling | expand

Commit Message

Avri Altman April 28, 2025, 12:29 p.m. UTC
The print_help function uses a character-by-character processing of the
help string.  Replaced the loop with a single printf statement to print
the usage message in a cleaner and more efficient manner.

While at it, removed the redundant programname parameter from print
help, as it was no longer needed.

Signed-off-by: Avri Altman <avri.altman@sandisk.com>
---
 mmc.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/mmc.c b/mmc.c
index 2b58162..6e834ca 100644
--- a/mmc.c
+++ b/mmc.c
@@ -316,31 +316,21 @@  static char *get_prgname(char *programname)
 	return np;
 }
 
-static void print_help(char *programname, struct Command *cmd)
+static void print_help(struct Command *cmd)
 {
-	char	*pc;
-
-	printf("\t%s %s ", programname, cmd->verb );
-
-	for(pc = cmd->help; *pc; pc++){
-		putchar(*pc);
-		if(*pc == '\n')
-			printf("\t\t");
-	}
-
-	putchar('\n');
+        printf("------------------------------------------------\n");
+        printf("Usage for command\t%s %s\n", cmd->verb, cmd->help);
 }
 
 static void help(char *np)
 {
 	struct Command *cp;
 
-	printf("Usage:\n");
 	for( cp = commands; cp->verb; cp++ )
-		print_help(np, cp);
+		print_help(cp);
 
-	printf("\n\t%s help|--help|-h\n\t\tShow the help.\n",np);
-	printf("\n\t%s <cmd> --help\n\t\tShow detailed help for a command or subset of commands.\n",np);
+	printf("\n\t%s help|--help|-h\n\t\tShow the help.\n", np);
+	printf("\n\t%s <cmd> --help\n\t\tShow detailed help for a command or subset of commands.\n", np);
 	printf("\n%s\n", VERSION);
 }
 
@@ -504,7 +494,7 @@  static int parse_args(int argc, char **argv,
 		if(argc>i+1 && !strcmp(argv[i+1],"--help")){
 			if(!helprequested)
 				printf("Usage:\n");
-			print_help(prgname, cp);
+			print_help(cp);
 			helprequested=1;
 			continue;
 		}