From 322ce333fb09ceb39b55a77eceff3ac0cbaf1522 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 6 Nov 2008 21:16:30 +0100 Subject: [PATCH] Move code for setting up the format string to an own function. --- select.c | 68 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/select.c b/select.c index 3ec359e..c26b548 100644 --- 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; -- 2.39.5