From ba63c40936d99652f5ffe7f57a34dd79c7c8a74d Mon Sep 17 00:00:00 2001 From: Robert Kessl Date: Thu, 26 Jun 2014 09:37:04 +0200 Subject: [PATCH] tableprinter: add of table_col_is_printed --- ucw/table.c | 10 ++++++++++ ucw/table.h | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ucw/table.c b/ucw/table.c index 0906ec75..95944f0c 100644 --- a/ucw/table.c +++ b/ucw/table.c @@ -127,6 +127,16 @@ void table_set_col_order(struct table *tbl, int *col_order, int cols_to_output) tbl->cols_to_output = cols_to_output; } + +int table_col_is_printed(struct table *tbl, uint col_idx) +{ + for(uint i = 0; i < tbl->cols_to_output; i++) { + if(tbl->column_order[i] == col_idx) return 1; + } + + return 0; +} + /** * TODO: This function deliberately leaks memory. When it is called multiple times, * previous column orders still remain allocated in the table's memory pool. diff --git a/ucw/table.h b/ucw/table.h index 3fd4e343..843c039f 100644 --- a/ucw/table.h +++ b/ucw/table.h @@ -322,6 +322,11 @@ const char *table_get_col_list(struct table *tbl); **/ void table_set_col_order(struct table *tbl, int *col_order, int col_order_size); +/** + * Returns 1 if col_idx will be printed, 0 otherwise. + **/ +int table_col_is_printed(struct table *tbl, uint col_idx); + /** * Sets the order in which the columns are printed. The specification is a string with comma-separated column * names. Returns NULL for success and an error message otherwise. The string is not referenced after @@ -371,7 +376,7 @@ const char *table_set_gary_options(struct table *tbl, char **gary_table_opts); * * A formatter is described by a structure, which contains pointers to several * call-back functions, which are called by the table printer at specific occasions. - + * * The formatter can keep its internal state in the `data` field of `struct table` * and allocate temporary data from the table's memory pool. Memory allocated in * the `row_output` call-back is freed before the next row begins. Memory allocated -- 2.39.2