2 #include <ucw/config.h>
3 #include <ucw/table-types.h>
4 #include <ucw/fastbuf.h>
5 #include <ucw/config.h>
10 void table_col_size_name(struct table *tbl, const char *col_name, u64 val)
12 int col = table_get_col_idx(tbl, col_name);
13 table_col_size(tbl, col, val);
16 void table_col_size(struct table *tbl, int col, u64 val)
18 ASSERT_MSG(col < tbl->column_count && col >= 0, "Table column %d does not exist.", col);
19 ASSERT(tbl->columns[col].type == COL_TYPE_ANY || COL_TYPE_SIZE == tbl->columns[col].type);
21 tbl->last_printed_col = col;
22 tbl->row_printing_started = 1;
24 static u64 unit_div[] = {
25 [UNIT_BYTE] = (u64) 1,
26 [UNIT_KILOBYTE] = (u64) 1024LU,
27 [UNIT_MEGABYTE] = (u64) (1024LU * 1024LU),
28 [UNIT_GIGABYTE] = (u64) (1024LU * 1024LU * 1024LU),
29 [UNIT_TERABYTE] = (u64) (1024LU * 1024LU * 1024LU * 1024LU)
32 static const char *unit_suffix[] = {
34 [UNIT_KILOBYTE] = "KB",
35 [UNIT_MEGABYTE] = "MB",
36 [UNIT_GIGABYTE] = "GB",
37 [UNIT_TERABYTE] = "TB"
40 // FIXME: do some rounding?
41 val = val / unit_div[tbl->column_order[col].output_type];
43 //tbl->col_str_ptrs[col] = mp_printf(tbl->pool, "%lu%s", val, unit_suffix[tbl->column_order[col].output_type]);
44 table_col_printf(tbl, col, "%lu%s", val, unit_suffix[tbl->column_order[col].output_type]);
47 #define FORMAT_TIME_SIZE 20 // Minimum buffer size
49 void table_col_timestamp_name(struct table *tbl, const char * col_name, u64 val)
51 int col = table_get_col_idx(tbl, col_name);
52 table_col_size(tbl, col, val);
55 void table_col_timestamp(struct table *tbl, int col, u64 val)
57 ASSERT_MSG(col < tbl->column_count && col >= 0, "Table column %d does not exist.", col);
58 ASSERT(tbl->columns[col].type == COL_TYPE_ANY || COL_TYPE_TIMESTAMP == tbl->columns[col].type);
59 //ASSERT(fmt != NULL);
61 char formatted_time_buf[FORMAT_TIME_SIZE];
63 time_t tmp_time = (time_t)val;
64 struct tm t = *gmtime(&tmp_time);
66 switch (tbl->column_order[col].output_type) {
68 sprintf(formatted_time_buf, "%u", (uint) val);
70 case TIMESTAMP_DATETIME:
71 strftime(formatted_time_buf, FORMAT_TIME_SIZE, "%F %T", &t);
76 //tbl->col_str_ptrs[col] = mp_printf(tbl->pool, "%s", formatted_time_buf);
77 table_col_printf(tbl, col, "%s", formatted_time_buf);