From 5187a385870950d779b6434b2d2982914367f638 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 9 Jul 2012 17:14:16 +1000 Subject: [PATCH] Help: use an array to choose which help matches which mode. Looks cleaner than a big switch statement. Signed-off-by: NeilBrown --- ReadMe.c | 11 +++++++++++ mdadm.c | 15 ++++----------- mdadm.h | 2 ++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ReadMe.c b/ReadMe.c index fa71ec94..b6aac0b3 100644 --- a/ReadMe.c +++ b/ReadMe.c @@ -600,3 +600,14 @@ char Help_config[] = "\n" ; +char *mode_help[mode_count] = { + [0] = Help, + [ASSEMBLE] = Help_assemble, + [BUILD] = Help_build, + [CREATE] = Help_create, + [MANAGE] = Help_manage, + [MISC] = Help_misc, + [MONITOR] = Help_monitor, + [GROW] = Help_grow, + [INCREMENTAL] = Help_incr, +}; diff --git a/mdadm.c b/mdadm.c index 6a632e9e..1d050e4d 100644 --- a/mdadm.c +++ b/mdadm.c @@ -1136,20 +1136,13 @@ int main(int argc, char *argv[]) } if (print_help) { - char *help_text = Help; + char *help_text; if (print_help == 2) help_text = OptionHelp; else - switch (mode) { - case ASSEMBLE : help_text = Help_assemble; break; - case BUILD : help_text = Help_build; break; - case CREATE : help_text = Help_create; break; - case MANAGE : help_text = Help_manage; break; - case MISC : help_text = Help_misc; break; - case MONITOR : help_text = Help_monitor; break; - case GROW : help_text = Help_grow; break; - case INCREMENTAL:help_text= Help_incr; break; - } + help_text = mode_help[mode]; + if (help_text == NULL) + help_text = Help; fputs(help_text,stdout); exit(0); } diff --git a/mdadm.h b/mdadm.h index bda557db..98ea472d 100644 --- a/mdadm.h +++ b/mdadm.h @@ -264,6 +264,7 @@ enum mode { GROW, INCREMENTAL, AUTODETECT, + mode_count }; extern char short_options[]; @@ -271,6 +272,7 @@ extern char short_bitmap_options[]; extern char short_bitmap_auto_options[]; extern struct option long_options[]; extern char Version[], Usage[], Help[], OptionHelp[], + *mode_help[], Help_create[], Help_build[], Help_assemble[], Help_grow[], Help_incr[], Help_manage[], Help_misc[], Help_monitor[], Help_config[]; -- 2.39.2