/** The decimal representation of an uint64_t never exceeds that size. */
#define FORMATED_VALUE_SIZE 25
+#define GLOBAL_SUMMARY_ATOMS \
+ ATOM(dirs, COUNT) \
+ ATOM(files, COUNT) \
+ ATOM(size, SIZE)
+
+#define ATOM(x, y) { .name = #x, .type = AT_ ## y},
+struct atom global_summary_atoms[] = {
+ GLOBAL_SUMMARY_ATOMS
+ {.name = NULL}
+};
+#undef ATOM
+#define ATOM(x, y) gsa_ ## x,
+enum global_summary_atoms {GLOBAL_SUMMARY_ATOMS};
+#undef ATOM
+
#define USER_SUMMARY_ATOMS \
ATOM(pw_name, STRING) \
ATOM(uid, ID) \
enum user_summary_atoms {USER_SUMMARY_ATOMS};
#undef ATOM
+
/* these get filled in by the select command. */
static char count_unit_buf[4] = "( )", size_unit_buf[4] = "( )";
return check_loop_return(ret, *loop_ret, *loop_osl_errno);
}
-static int print_global_summary(void)
+static int print_global_summary(struct format_info *fi)
{
- char d[FORMATED_VALUE_SIZE], f[FORMATED_VALUE_SIZE],
- s[FORMATED_VALUE_SIZE];
- enum enum_count_unit ud, uf;
- enum enum_size_unit us;
int ret;
+ char *buf;
+ union atom_value values[] = {
+ [gsa_dirs] = {.num_value = (long long unsigned)num_dirs},
+ [gsa_files] = {.num_value = (long long unsigned)num_files},
+ [gsa_size] = {.num_value = (long long unsigned)num_bytes}
+ };
if (select_conf.no_global_summary_given)
return 1;
- ud = format_count_value(select_conf.count_unit_arg, num_dirs, 0, d);
- uf = format_count_value(select_conf.count_unit_arg, num_files, 0, f);
- us = format_size_value(select_conf.size_unit_arg, num_bytes, 0, s);
-
if (!select_conf.no_headers_given) {
- ret = output("Global summary "
- "(dirs(%c)/files(%c)/size(%c))\n",
- count_unit_abbrevs[ud],
- count_unit_abbrevs[uf],
- size_unit_abbrevs[us]
- );
+ ret = output("Global summary\n");
if (ret < 0)
return ret;
}
- return output("\t%s\t%s\t%s\n\n", d, f, s);
+ buf = format_items(fi, values);
+ ret = output("%s", buf);
+ free(buf);
+ return ret;
}
static int print_user_summary_line(struct user_info *ui, __a_unused void *data)
[usa_size] = {.num_value = (long long unsigned)ui->bytes}
};
char *buf = format_items(fi, values);
- return output("%s", buf);
+ int ret = output("%s", buf);
+
+ free(buf);
+ return ret;
}
static int name_comp(const void *a, const void *b)
ret = print_global_lists();
if (ret < 0)
return ret;
- ret = print_global_summary();
+ ret = print_global_summary(sli->global_summary_fi);
+ free_format_info(sli->global_summary_fi);
if (ret < 0)
return ret;
ret = print_user_lists();
if (ret < 0)
return ret;
ret = print_user_summary(sli->user_summary_fi);
+ free_format_info(sli->user_summary_fi);
if (ret < 0)
return ret;
return 1;
user_summary_atoms, &sfi->user_summary_fi);
if (ret < 0)
return ret;
+ ret = parse_format_string(select_conf.global_summary_format_arg,
+ global_summary_atoms, &sfi->global_summary_fi);
+ if (ret < 0) {
+ free_format_info(sfi->user_summary_fi);
+ return ret;
+ }
return 1;
help:
line = select_conf.detailed_help_given?