+/** Default format string for global_list mode. */
+#define GLOBAL_LIST_DFLT_FMT "%(size:r:8) %(files:r:8) %(dirname)\n"
+/** Default format string for global_summary mode. */
+#define GLOBAL_SUMMARY_DFLT_FMT "#directories: %(dirs), #files: %(files), size: %(size)\n"
+/** Default format string for user_list mode. */
+#define USER_LIST_DFLT_FMT "%(size:r:5) %(files:r:5) %(dirname)\n"
+/** Default format string for user_summary mode. */
+#define USER_SUMMARY_DFLT_FMT "%(pw_name:l:16) %(uid:r:6) %(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);
+}
+
+/**
+ * Parse a given format string.
+ *
+ * \param string The format string to parse.
+ * \param params gengetopt parameters.
+ * \param admissible_uids The array of admissible uid ranges.
+ * \param fi The format info to be used with format_items().
+ *
+ * If \a string is not \p NULL, it is broken down into its components using
+ * \ref create_argv() and the resulting argument vector is passed together with
+ * \a params to gengetopt's command line parser. If --help or --detailed-help
+ * was specified in \a string, the corresponding help text is printed and the
+ * function returns zero.
+ *
+ * Otherwise, any --uid or --user options are parsed and transformed into an
+ * array of admissible uids which is returned via \a admissible_uids.
+ *
+ * Finally, the format string given by --format (or the default format string
+ * for the given select mode if no --format option was given in \a string) is
+ * parsed as well resulting in a format_info structure which is returned via
+ * \a fi. The caller uses the \a fi pointer later to format each output line.
+ *
+ * \return Negative on errors, zero if --help or --detailed-help was given,
+ * positive otherwise.
+ *
+ * \sa format_items().
+ */