out = bfdopen_shared(1, 4096);
struct table *tbl = table_init(&test_tbl2);
table_set_col_order_by_name(tbl, "");
- const char *err = table_set_option_value(tbl, "cols", "size[KB],size[MB],size[GB],size[TB],ts[datetime],ts[timestamp]");
+ const char *err = table_set_option_value(tbl, "cols", "size[KB],size[MB],size[GB],size[TB],size[auto],ts[datetime],ts[timestamp]");
if(err) {
opt_failure("err in table_set_option_value: '%s'.", err);
abort();
table_start(tbl, out);
u64 test_time = 1403685533;
- s64 test_size = 4LU*(1024LU * 1024LU * 1024LU);
+ s64 test_size = 4LU*(1024LU * 1024LU);
table_col_size(tbl, TEST_COL0_SIZE, test_size);
table_col_timestamp(tbl, TEST_COL1_TS, test_time);
table_end_row(tbl);
+ test_size = test_size * 1024LU;
+
table_col_size(tbl, TEST_COL0_SIZE, test_size);
table_col_timestamp(tbl, TEST_COL1_TS, test_time);
table_end_row(tbl);
4096MB 1403685533
4GB 2014-06-25 08:38:53
4TB 2014-06-25 08:38:53
- size size size size ts ts
- 4194304KB 4096MB 4GB 0TB 2014-06-25 08:38:53 1403685533
- 4194304KB 4096MB 4GB 0TB 2014-06-25 08:38:53 1403685533
- 4294967296KB 4194304MB 4096GB 4TB 2014-06-25 08:38:53 1403685533
+ size size size size size ts ts
+ 4096KB 4MB 0GB 0TB 4MB 2014-06-25 08:38:53 1403685533
+ 4194304KB 4096MB 4GB 0TB 4GB 2014-06-25 08:38:53 1403685533
+ 4294967296KB 4194304MB 4096GB 4TB 4TB 2014-06-25 08:38:53 1403685533
EOF
{ 0, 0, 0 }
};
+static enum size_units xt_size_auto_units(u64 sz)
+{
+ if(sz >= xtype_units_size[SIZE_UNIT_TERABYTE].num) {
+ return SIZE_UNIT_TERABYTE;
+ } else if(sz >= xtype_units_size[SIZE_UNIT_GIGABYTE].num) {
+ return SIZE_UNIT_GIGABYTE;
+ } else if(sz >= xtype_units_size[SIZE_UNIT_MEGABYTE].num) {
+ return SIZE_UNIT_MEGABYTE;
+ } else if(sz >= xtype_units_size[SIZE_UNIT_KILOBYTE].num) {
+ return SIZE_UNIT_KILOBYTE;
+ }
+
+ return SIZE_UNIT_BYTE;
+}
+
static const char *xt_size_format(void *src, u32 fmt, struct mempool *pool)
{
u64 curr_val = *(u64*) src;
curr_val = curr_val;
out_units = SIZE_UNIT_BYTE;
} else if(fmt == XTYPE_FMT_PRETTY) {
- curr_val = curr_val;
- out_units = SIZE_UNIT_BYTE;
+ // the same as SIZE_UNIT_AUTO
+ out_units = xt_size_auto_units(curr_val);
+ curr_val = curr_val / xtype_units_size[out_units].num;
+ } else if((fmt & SIZE_UNITS_FIXED) != 0 && (fmt & SIZE_UNIT_AUTO) == SIZE_UNIT_AUTO) {
+ // the same as XTYPE_FMT_PRETTY
+ out_units = xt_size_auto_units(curr_val);
+ curr_val = curr_val / xtype_units_size[out_units].num;
} else if((fmt & SIZE_UNITS_FIXED) != 0) {
curr_val = curr_val / xtype_units_size[fmt & ~SIZE_UNITS_FIXED].num;
out_units = fmt & ~SIZE_UNITS_FIXED;
return NULL;
}
+ if(strcmp(opt_str, "auto") == 0) {
+ *dest = SIZE_UNIT_AUTO | SIZE_UNITS_FIXED;
+ return NULL;
+ }
+
int unit_idx = xtype_unit_parser(opt_str, xtype_units_size);
if(unit_idx == -1) {
return mp_printf(pool, "Unknown option '%s'", opt_str);