Ticket #3547: mc-3547-cleanup-setup.c-reduce-function-scope.patch

File mc-3547-cleanup-setup.c-reduce-function-scope.patch, 8.3 KB (added by and, 7 years ago)
  • src/setup.c

    From 3dcd02cb635ad43c557656df149235976d16abc8 Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Sun, 17 Jan 2016 14:43:10 +0000
    Subject: [PATCH] cleanup setup.c reduce function scope
    
    reduce scope for
        void save_config (void);
        void save_layout (void);
        void panels_load_options (void);
        void panels_save_options (void);
    and move code to file scope section
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     src/setup.c | 167 +++++++++++++++++++++++++++++++-----------------------------
     src/setup.h |   6 ---
     2 files changed, 85 insertions(+), 88 deletions(-)
    
    diff --git a/src/setup.c b/src/setup.c
    index 3f6a38e..4a1e293 100644
    a b panel_save_type (const char *section, panel_view_mode_t type) 
    822822 
    823823/* --------------------------------------------------------------------------------------------- */ 
    824824 
     825/** 
     826  Load panels options from [Panels] section. 
     827*/ 
     828static void 
     829panels_load_options (void) 
     830{ 
     831    if (mc_config_has_group (mc_main_config, CONFIG_PANELS_SECTION)) 
     832    { 
     833        size_t i; 
     834        int qmode; 
     835 
     836        for (i = 0; panels_ini_options[i].opt_name != NULL; i++) 
     837            *panels_ini_options[i].opt_addr = 
     838                mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION, 
     839                                    panels_ini_options[i].opt_name, 
     840                                    *panels_ini_options[i].opt_addr); 
     841 
     842        qmode = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION, 
     843                                   "quick_search_mode", (int) panels_options.qsearch_mode); 
     844        if (qmode < 0) 
     845            panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE; 
     846        else if (qmode >= QSEARCH_NUM) 
     847            panels_options.qsearch_mode = QSEARCH_PANEL_CASE; 
     848        else 
     849            panels_options.qsearch_mode = (qsearch_mode_t) qmode; 
     850 
     851        panels_options.select_flags = 
     852            mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION, "select_flags", 
     853                               (int) panels_options.select_flags); 
     854    } 
     855} 
     856 
     857/* --------------------------------------------------------------------------------------------- */ 
     858 
     859/** 
     860  Save panels options in [Panels] section. 
     861*/ 
     862static void 
     863panels_save_options (void) 
     864{ 
     865    size_t i; 
     866 
     867    for (i = 0; panels_ini_options[i].opt_name != NULL; i++) 
     868        mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION, 
     869                            panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr); 
     870 
     871    mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION, 
     872                       "quick_search_mode", (int) panels_options.qsearch_mode); 
     873    mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION, 
     874                       "select_flags", (int) panels_options.select_flags); 
     875} 
     876 
     877/* --------------------------------------------------------------------------------------------- */ 
     878 
     879static void 
     880save_config (void) 
     881{ 
     882    size_t i; 
     883 
     884    /* Save integer options */ 
     885    for (i = 0; int_options[i].opt_name != NULL; i++) 
     886        mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, 
     887                           *int_options[i].opt_addr); 
     888 
     889    /* Save string options */ 
     890    for (i = 0; str_options[i].opt_name != NULL; i++) 
     891        mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, 
     892                              *str_options[i].opt_addr); 
     893} 
     894 
     895/* --------------------------------------------------------------------------------------------- */ 
     896 
     897static void 
     898save_layout (void) 
     899{ 
     900    size_t i; 
     901 
     902    /* Save integer options */ 
     903    for (i = 0; layout[i].opt_name != NULL; i++) 
     904        mc_config_set_int (mc_main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name, 
     905                           *layout[i].opt_addr); 
     906} 
     907 
     908/* --------------------------------------------------------------------------------------------- */ 
     909 
    825910/* save panels.ini */ 
    826911static void 
    827912save_panel_types (void) 
    done_setup (void) 
    11481233#endif /* HAVE_ASPELL */ 
    11491234} 
    11501235 
    1151 /* --------------------------------------------------------------------------------------------- */ 
    1152  
    1153 void 
    1154 save_config (void) 
    1155 { 
    1156     size_t i; 
    1157  
    1158     /* Save integer options */ 
    1159     for (i = 0; int_options[i].opt_name != NULL; i++) 
    1160         mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name, 
    1161                            *int_options[i].opt_addr); 
    1162  
    1163     /* Save string options */ 
    1164     for (i = 0; str_options[i].opt_name != NULL; i++) 
    1165         mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name, 
    1166                               *str_options[i].opt_addr); 
    1167 } 
    11681236 
    11691237/* --------------------------------------------------------------------------------------------- */ 
    11701238 
    setup_save_config_show_error (const char *filename, GError ** mcerror) 
    11791247    } 
    11801248} 
    11811249 
    1182 /* --------------------------------------------------------------------------------------------- */ 
    1183  
    1184 void 
    1185 save_layout (void) 
    1186 { 
    1187     size_t i; 
    1188  
    1189     /* Save integer options */ 
    1190     for (i = 0; layout[i].opt_name != NULL; i++) 
    1191         mc_config_set_int (mc_main_config, CONFIG_LAYOUT_SECTION, layout[i].opt_name, 
    1192                            *layout[i].opt_addr); 
    1193 } 
    11941250 
    11951251/* --------------------------------------------------------------------------------------------- */ 
    11961252 
    panel_save_setup (WPanel * panel, const char *section) 
    14331489    mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status); 
    14341490} 
    14351491 
    1436 /* --------------------------------------------------------------------------------------------- */ 
    1437  
    1438 /** 
    1439   Load panels options from [Panels] section. 
    1440 */ 
    1441 void 
    1442 panels_load_options (void) 
    1443 { 
    1444     if (mc_config_has_group (mc_main_config, CONFIG_PANELS_SECTION)) 
    1445     { 
    1446         size_t i; 
    1447         int qmode; 
    1448  
    1449         for (i = 0; panels_ini_options[i].opt_name != NULL; i++) 
    1450             *panels_ini_options[i].opt_addr = 
    1451                 mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION, 
    1452                                     panels_ini_options[i].opt_name, 
    1453                                     *panels_ini_options[i].opt_addr); 
    1454  
    1455         qmode = mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION, 
    1456                                    "quick_search_mode", (int) panels_options.qsearch_mode); 
    1457         if (qmode < 0) 
    1458             panels_options.qsearch_mode = QSEARCH_CASE_INSENSITIVE; 
    1459         else if (qmode >= QSEARCH_NUM) 
    1460             panels_options.qsearch_mode = QSEARCH_PANEL_CASE; 
    1461         else 
    1462             panels_options.qsearch_mode = (qsearch_mode_t) qmode; 
    1463  
    1464         panels_options.select_flags = 
    1465             mc_config_get_int (mc_main_config, CONFIG_PANELS_SECTION, "select_flags", 
    1466                                (int) panels_options.select_flags); 
    1467     } 
    1468 } 
    1469  
    1470 /* --------------------------------------------------------------------------------------------- */ 
    1471  
    1472 /** 
    1473   Save panels options in [Panels] section. 
    1474 */ 
    1475 void 
    1476 panels_save_options (void) 
    1477 { 
    1478     size_t i; 
    1479  
    1480     for (i = 0; panels_ini_options[i].opt_name != NULL; i++) 
    1481         mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION, 
    1482                             panels_ini_options[i].opt_name, *panels_ini_options[i].opt_addr); 
    1483  
    1484     mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION, 
    1485                        "quick_search_mode", (int) panels_options.qsearch_mode); 
    1486     mc_config_set_int (mc_main_config, CONFIG_PANELS_SECTION, 
    1487                        "select_flags", (int) panels_options.select_flags); 
    1488 } 
    14891492 
    14901493/* --------------------------------------------------------------------------------------------- */ 
  • src/setup.h

    diff --git a/src/setup.h b/src/setup.h
    index 169c635..47ad560 100644
    a b const char *setup_init (void); 
    144144void load_setup (void); 
    145145gboolean save_setup (gboolean save_options, gboolean save_panel_options); 
    146146void done_setup (void); 
    147 void save_config (void); 
    148147void setup_save_config_show_error (const char *filename, GError ** mcerror); 
    149148 
    150 void save_layout (void); 
    151  
    152149void load_key_defs (void); 
    153150#ifdef ENABLE_VFS_FTP 
    154151char *load_anon_passwd (void); 
    void free_keymap_defs (void); 
    160157void panel_load_setup (WPanel * panel, const char *section); 
    161158void panel_save_setup (WPanel * panel, const char *section); 
    162159 
    163 void panels_load_options (void); 
    164 void panels_save_options (void); 
    165  
    166160/*** inline functions ****************************************************************************/ 
    167161 
    168162#endif /* MC__SETUP_H */