]> mj.ucw.cz Git - libucw.git/commitdiff
tableprinter: hidding of column linked list internals
authorRobert Kessl <kesslr@centrum.cz>
Fri, 4 Jul 2014 08:06:49 +0000 (10:06 +0200)
committerRobert Kessl <kesslr@centrum.cz>
Fri, 4 Jul 2014 08:06:49 +0000 (10:06 +0200)
ucw/table-types.c
ucw/table.h

index 3d06f792a7c1d0b43a18eaee39aefb17fc4a1193..d465fab01c701fa18e4af88ecffcd7b4e913a041 100644 (file)
@@ -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)
 }
index 43d94f79b960181873660b3a4c84a10ca201e1d4..afe7b7d34b29080d18b8a673613a813fc54770fe 100644 (file)
@@ -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.