Refactor the top level menu, creating a sub-menu for devices
configuration.  Internals is also reworked to reduce code duplication.

Signed-off-by: Gabriel Krisman Bertazi <kris...@linux.vnet.ibm.com>
---
 iprconfig.c | 125 +++++++++++++++++++++---------------------------------------
 iprconfig.h |  25 +++++++++---
 2 files changed, 63 insertions(+), 87 deletions(-)

diff --git a/iprconfig.c b/iprconfig.c
index 3327bc4..771ec23 100644
--- a/iprconfig.c
+++ b/iprconfig.c
@@ -32,6 +32,8 @@
 
 char *tool_name = "iprconfig";
 
+#define MAX_CMD_LENGTH 1000
+
 struct devs_to_init_t {
        struct ipr_dev *dev;
        struct ipr_ioa *ioa;
@@ -1679,6 +1681,31 @@ static void processing()
        refresh();
 }
 
+int display_features_menu(i_container *i_con, s_node *menu)
+{
+       char cmnd[MAX_CMD_LENGTH];
+       int rc, loop;
+       struct stat file_stat;
+       struct screen_output *s_out;
+       int offset = 0;
+
+       for (loop = 0; loop < (menu->num_opts); loop++) {
+               menu->body = ipr_list_opts(menu->body,
+                                          menu->options[loop].key,
+                                          menu->options[loop].list_str);
+       }
+       menu->body = ipr_end_list(menu->body);
+
+       s_out = screen_driver(menu, 0, NULL);
+       free(menu->body);
+       menu->body = NULL;
+       rc = s_out->rc;
+       i_con = s_out->i_con;
+       i_con = free_i_con(i_con);
+       free(s_out);
+       return rc;
+}
+
 /**
  * main_menu - Main menu
  * @i_con:             i_container struct
@@ -1688,10 +1715,8 @@ static void processing()
  **/
 int main_menu(i_container *i_con)
 {
-       int rc;
        int j;
        struct ipr_ioa *ioa;
-       struct screen_output *s_out;
        struct scsi_dev_data *scsi_dev_data;
 
        processing();
@@ -1706,24 +1731,22 @@ int main_menu(i_container *i_con)
                }
        }
 
-       for (j = 0; j < n_main_menu.num_opts; j++) {
-               n_main_menu.body = ipr_list_opts(n_main_menu.body,
-                                                n_main_menu.options[j].key,
-                                                
n_main_menu.options[j].list_str);
-       }
-
-       n_main_menu.body = ipr_end_list(n_main_menu.body);
+       return display_features_menu(i_con, &n_main_menu);
+}
 
-       s_out = screen_driver(&n_main_menu, 0, NULL);
-       free(n_main_menu.body);
-       n_main_menu.body = NULL;
-       rc = s_out->rc;
-       i_con = s_out->i_con;
-       i_con = free_i_con(i_con);
-       free(s_out);
-       return rc;
+/**
+ * conf_menu - Config menu
+ * @i_con:             i_container struct
+ *
+ * Returns:
+ *   0 if success / non-zero on failure
+ **/
+int config_menu(i_container *i_con)
+{
+       return display_features_menu(i_con, &n_config_menu);
 }
 
+
 /**
  * print_standalone_disks - 
  * @ioa:               ipr ioa struct
@@ -2749,31 +2772,11 @@ int device_details(i_container *i_con)
 **/
 int hot_spare_screen(i_container *i_con)
 {
-       int rc;
-       struct screen_output *s_out;
-       int loop;
-
-       free_raid_cmds();
-
-       for (loop = 0; loop < n_hot_spare_screen.num_opts; loop++) {
-               n_hot_spare_screen.body =
-                       ipr_list_opts(n_hot_spare_screen.body,
-                                     n_hot_spare_screen.options[loop].key,
-                                     
n_hot_spare_screen.options[loop].list_str);
-       }
-
-       n_hot_spare_screen.body = ipr_end_list(n_hot_spare_screen.body);
-
-       s_out = screen_driver(&n_hot_spare_screen, 0, NULL);
-       free(n_hot_spare_screen.body);
-       n_hot_spare_screen.body = NULL;
-       rc = s_out->rc;
-       free(s_out);
-       return rc;
+       return display_features_menu(i_con, &n_hot_spare_screen);
 }
 
 /**
-* raid_screen - 
+* raid_screen -
 * @i_con:            i_container struct
 *
 * Returns:
@@ -2781,27 +2784,7 @@ int hot_spare_screen(i_container *i_con)
 **/
 int raid_screen(i_container *i_con)
 {
-       int rc;
-       struct screen_output *s_out;
-       int loop;
-
-       free_raid_cmds();
-
-       for (loop = 0; loop < n_raid_screen.num_opts; loop++) {
-               n_raid_screen.body =
-                       ipr_list_opts(n_raid_screen.body,
-                                     n_raid_screen.options[loop].key,
-                                     n_raid_screen.options[loop].list_str);
-       }
-
-       n_raid_screen.body = ipr_end_list(n_raid_screen.body);
-
-       s_out = screen_driver(&n_raid_screen, 0, NULL);
-       free(n_raid_screen.body);
-       n_raid_screen.body = NULL;
-       rc = s_out->rc;
-       free(s_out);
-       return rc;
+       return display_features_menu(i_con, &n_raid_screen);
 }
 
 /**
@@ -11845,29 +11828,9 @@ int choose_ucode(i_container * i_con)
 **/
 int ucode_screen(i_container *i_con)
 {
-       int rc;
-       struct screen_output *s_out;
-       int loop;
-
-       for (loop = 0; loop < n_ucode_screen.num_opts; loop++) {
-               n_ucode_screen.body =
-                       ipr_list_opts(n_ucode_screen.body,
-                                     n_ucode_screen.options[loop].key,
-                                     n_ucode_screen.options[loop].list_str);
-       }
-
-       n_ucode_screen.body = ipr_end_list(n_ucode_screen.body);
-
-       s_out = screen_driver(&n_ucode_screen, 0, NULL);
-       free(n_ucode_screen.body);
-       n_ucode_screen.body = NULL;
-       rc = s_out->rc;
-       free(s_out);
-       return rc;
+       return display_features_menu(i_con, &n_ucode_screen);
 }
 
-#define MAX_CMD_LENGTH 1000
-
 /**
 * log_menu -
 * @i_con:            i_container struct
diff --git a/iprconfig.h b/iprconfig.h
index b3cf22d..54309d4 100644
--- a/iprconfig.h
+++ b/iprconfig.h
@@ -65,6 +65,7 @@ struct function_output {
 };
 
 int main_menu(i_container * i_con);
+int config_menu(i_container *i_con);
 
 int disk_status(i_container * i_con);
 int device_details(i_container * i_con);
@@ -192,12 +193,9 @@ struct screen_opts main_menu_opt[] = {
        {disk_status,        "1", __("Display hardware status")},
        {raid_screen,        "2", __("Work with disk arrays")},
        {disk_unit_recovery, "3", __("Work with disk unit recovery")},
-       {bus_config,         "4", __("Work with SCSI bus configuration")},
-       {driver_config,      "5", __("Work with driver configuration")},
-       {disk_config,        "6", __("Work with disk configuration")},
-       {ioa_config,         "7", __("Work with adapter configuration")},
-       {ucode_screen,       "8", __("Work with microcode updates")},
-       {log_menu,           "9", __("Analyze log")},
+       {config_menu,        "4", __("Work with configuration options")},
+       {ucode_screen,       "5", __("Work with microcode updates")},
+       {log_menu,           "6", __("Analyze log")},
 };
 
 s_node n_main_menu = {
@@ -208,6 +206,21 @@ s_node n_main_menu = {
        .title    =  __("IBM Power RAID Configuration Utility")
 };
 
+struct screen_opts config_menu_opt[] = {
+       {bus_config,         "1", __("Work with SCSI bus configuration")},
+       {driver_config,      "2", __("Work with driver configuration")},
+       {disk_config,        "3", __("Work with disk configuration")},
+       {ioa_config,         "4", __("Work with adapter configuration")},
+};
+
+s_node n_config_menu = {
+       .rc_flags = (EXIT_FLAG | CANCEL_FLAG | REFRESH_FLAG),
+       .f_flags  = (EXIT_FLAG | CANCEL_FLAG),
+       .num_opts = NUM_OPTS(config_menu_opt),
+       .options  = &config_menu_opt[0],
+       .title    =  __("IBM Power RAID Configuration Utility")
+};
+
 struct screen_opts disk_status_opt[] = {
        {device_details, "\n"}
 };
-- 
2.1.0


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Iprdd-devel mailing list
Iprdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iprdd-devel

Reply via email to