From 57c1eeda2b4741f06af46d429ae84026767eb249 Mon Sep 17 00:00:00 2001 From: Robert Kessl Date: Fri, 4 Jul 2014 10:06:49 +0200 Subject: [PATCH] tableprinter: hidding of column linked list internals --- ucw/table-types.c | 13 ++++--------- ucw/table.h | 3 +++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ucw/table-types.c b/ucw/table-types.c index 3d06f792..d465fab0 100644 --- a/ucw/table-types.c +++ b/ucw/table-types.c @@ -94,9 +94,7 @@ void table_col_size(struct table *tbl, int col, u64 val) [UNIT_TERABYTE] = "TB" }; - int curr_col = tbl->columns[col].first_column; - while(curr_col != -1) { - + TBL_COL_ITER_START(tbl, col, curr_col) { // FIXME: do some rounding? uint out_type = 0; if(tbl->column_order[curr_col].output_type == CELL_OUT_UNINITIALIZED) { @@ -108,8 +106,7 @@ void table_col_size(struct table *tbl, int col, u64 val) } tbl->column_order[curr_col].cell_content = mp_printf(tbl->pool, "%lu%s", val, unit_suffix[out_type]); - curr_col = tbl->column_order[curr_col].next_column; - } + } TBL_COL_ITER_END(tbl, curr_col) } @@ -131,8 +128,7 @@ void table_col_timestamp(struct table *tbl, int col, u64 val) time_t tmp_time = (time_t)val; struct tm t = *gmtime(&tmp_time); - int curr_col = tbl->columns[col].first_column; - while(curr_col != -1) { + TBL_COL_ITER_START(tbl, col, curr_col) { switch (tbl->column_order[curr_col].output_type) { case TIMESTAMP_EPOCH: case CELL_OUT_UNINITIALIZED: @@ -147,6 +143,5 @@ void table_col_timestamp(struct table *tbl, int col, u64 val) } tbl->column_order[curr_col].cell_content = mp_printf(tbl->pool, "%s", formatted_time_buf); - curr_col = tbl->column_order[curr_col].next_column; - } + } TBL_COL_ITER_END(tbl, curr_col) } diff --git a/ucw/table.h b/ucw/table.h index 43d94f79..afe7b7d3 100644 --- a/ucw/table.h +++ b/ucw/table.h @@ -215,6 +215,9 @@ struct table { #define TBL_OUTPUT_BLOCKLINE .formatter = &table_fmt_blockline #define TBL_OUTPUT_MACHINE_READABLE .formatter = &table_fmt_machine_readable +#define TBL_COL_ITER_START(_tbl, _colidx, _var) int _var = _tbl->columns[_colidx].first_column; while(_var != -1) { +#define TBL_COL_ITER_END(_tbl, _var) _var = _tbl->column_order[_var].next_column; } + /** * Initialize a table definition. The structure should already contain * the definitions of columns. -- 2.39.2