Move code for setting up the format string to an own function.
authorAndre Noll <maan@systemlinux.org>
Thu, 6 Nov 2008 20:16:30 +0000 (21:16 +0100)
committerAndre Noll <maan@systemlinux.org>
Thu, 6 Nov 2008 20:16:30 +0000 (21:16 +0100)
select.c

index 3ec359e..c26b548 100644 (file)
--- a/select.c
+++ b/select.c
@@ -652,6 +652,41 @@ out:
 #define USER_LIST_DFLT_FMT "%(size:r:5) %(files:r:5) %(dirname)\n"
 #define USER_SUMMARY_DFLT_FMT "%(pw_name:l:16) %(uid:r:5) %(dirs:r:5) %(files:r:5) %(size:r:5)\n"
 
+static int setup_format_string(char *fmt, struct format_info **fi)
+{
+       struct atom *atoms;
+
+       if (!fmt)
+               INFO_LOG("using default format string\n");
+       switch (select_conf.select_mode_arg) {
+       case select_mode_arg_global_list:
+               if (!fmt)
+                       fmt = GLOBAL_LIST_DFLT_FMT;
+               atoms = global_list_atoms;
+               break;
+       case select_mode_arg_global_summary:
+               if (!fmt)
+                       fmt = GLOBAL_SUMMARY_DFLT_FMT;
+               atoms = global_summary_atoms;
+               break;
+       case select_mode_arg_user_list:
+               if (!fmt)
+                       fmt = USER_LIST_DFLT_FMT;
+               atoms = user_list_atoms;
+               break;
+       case select_mode_arg_user_summary:
+               if (!fmt)
+                       fmt = USER_SUMMARY_DFLT_FMT;
+               atoms = user_summary_atoms;
+               break;
+       default:
+               ERROR_LOG("bad select mode\n");
+               return -ERRNO_TO_ERROR(-EINVAL);
+       };
+       INFO_LOG("format string: %s\n", fmt);
+       return parse_format_string(fmt, atoms, fi);
+}
+
 /* return: < 0: error, >0: OK, == 0: help given */
 int parse_select_options(char *string, struct select_cmdline_parser_params *params,
                struct uid_range **admissible_uids, struct format_info **fi)
@@ -659,7 +694,6 @@ int parse_select_options(char *string, struct select_cmdline_parser_params *para
        int ret;
        const char **line;
        char *fmt = NULL;
-       struct atom *atoms;
 
        if (string) {
                int argc;
@@ -676,41 +710,11 @@ int parse_select_options(char *string, struct select_cmdline_parser_params *para
                if (select_conf.help_given || select_conf.detailed_help_given)
                        goto help;
                fmt = select_conf.format_arg;
-
        }
        ret = parse_uid_arg(select_conf.uid_arg, admissible_uids);
        if (ret < 0)
                return ret;
-
-       if (!fmt)
-               INFO_LOG("using default format string\n");
-       switch (select_conf.select_mode_arg) {
-               case select_mode_arg_global_list:
-                       if (!fmt)
-                               fmt = GLOBAL_LIST_DFLT_FMT;
-                       atoms = global_list_atoms;
-                       break;
-               case select_mode_arg_global_summary:
-                       if (!fmt)
-                               fmt = GLOBAL_SUMMARY_DFLT_FMT;
-                       atoms = global_summary_atoms;
-                       break;
-               case select_mode_arg_user_list:
-                       if (!fmt)
-                               fmt = USER_LIST_DFLT_FMT;
-                       atoms = user_list_atoms;
-                       break;
-               case select_mode_arg_user_summary:
-                       if (!fmt)
-                               fmt = USER_SUMMARY_DFLT_FMT;
-                       atoms = user_summary_atoms;
-                       break;
-               default:
-                       ERROR_LOG("bad select mode\n");
-                       return -ERRNO_TO_ERROR(-EINVAL);
-       };
-       INFO_LOG("format string: %s\n", fmt);
-       return parse_format_string(fmt, atoms, fi);
+       return setup_format_string(fmt, fi);
 help:
        line = select_conf.detailed_help_given?
                select_args_info_detailed_help : select_args_info_help;