From 85fa6ee15aaae7e4becbef99d8d49199a7b5f1ff Mon Sep 17 00:00:00 2001 From: Robert Kessl Date: Tue, 22 Jul 2014 12:12:19 +0200 Subject: [PATCH] tableprinter: updated setting of column option --- ucw/table-types.h | 9 ++++----- ucw/table.c | 12 ++++++------ ucw/table.h | 10 ++++++---- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ucw/table-types.h b/ucw/table-types.h index 79b9e19e..004a237b 100644 --- a/ucw/table-types.h +++ b/ucw/table-types.h @@ -26,12 +26,11 @@ enum size_units { extern const struct xtype xt_size; extern const struct xtype xt_timestamp; -#define TBL_COL_SIZE(_name, _width) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_size, .set_col_instance_option = table_set_col_opt_default } -#define TBL_COL_TIMESTAMP(_name, _width) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_timestamp, .set_col_instance_option = table_set_col_opt_default } - -#define TBL_COL_SIZE_FMT(_name, _width, _units) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_size, .set_col_instance_option = table_set_col_opt_default } -#define TBL_COL_TIMESTAMP_FMT(_name, _width, _fmt) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_timestamp, .set_col_instance_option = table_set_col_opt_default} +#define TBL_COL_SIZE(_name, _width) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_size, .set_col_opt = table_set_col_opt } +#define TBL_COL_TIMESTAMP(_name, _width) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_timestamp, .set_col_opt = table_set_col_opt } +#define TBL_COL_SIZE_FMT(_name, _width, _units) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_size, .set_col_opt = table_set_col_opt } +#define TBL_COL_TIMESTAMP_FMT(_name, _width, _fmt) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_timestamp, .set_col_opt = table_set_col_opt} TABLE_COL_PROTO(size, u64) TABLE_COL_PROTO(timestamp, u64) diff --git a/ucw/table.c b/ucw/table.c index 90988d21..3d468a44 100644 --- a/ucw/table.c +++ b/ucw/table.c @@ -215,12 +215,12 @@ static char * table_parse_col_arg(char *col_def) return left_br; } -/** - * Setting options for basic table types (as defined in table.h) - **/ -const char *table_set_col_opt_default(struct table *tbl, uint col_idx, const char *col_opt) +const char *table_set_col_opt(struct table *tbl, uint col_idx, const char *col_opt) { const struct table_column *col_def = tbl->column_order[col_idx].col_def; + if(col_def && col_def->set_col_opt && col_def->set_col_opt != table_set_col_opt) { + return col_def->set_col_opt(tbl, col_idx, col_opt); + } if(col_def && col_def->type_def && col_def->type_def->parse_fmt) { uint fmt = 0; @@ -279,9 +279,9 @@ const char * table_set_col_order_by_name(struct table *tbl, const char *col_orde tbl->column_order[curr_col_idx].col_def = tbl->columns + col_idx; tbl->column_order[curr_col_idx].idx = col_idx; tbl->column_order[curr_col_idx].fmt = tbl->columns[col_idx].fmt; - if(tbl->columns[col_idx].type_def && tbl->columns[col_idx].set_col_instance_option) { + if(tbl->columns[col_idx].type_def && tbl->columns[col_idx].set_col_opt) { const char *err = NULL; - err = tbl->columns[col_idx].set_col_instance_option(tbl, curr_col_idx, arg); + err = tbl->columns[col_idx].set_col_opt(tbl, curr_col_idx, arg); if(err) return mp_printf(tbl->pool, "Error occured while setting column option: %s.", err); } diff --git a/ucw/table.h b/ucw/table.h index 4f63e827..0813a8ea 100644 --- a/ucw/table.h +++ b/ucw/table.h @@ -104,7 +104,7 @@ struct table_column { uint fmt; // [*] default format of the column const struct xtype *type_def; // [*] pointer to xtype of this column - const char * (*set_col_instance_option)(struct table *tbl, uint col, const char *value); + const char * (*set_col_opt)(struct table *tbl, uint col, const char *value); // [*] process table option for a column instance }; @@ -115,7 +115,7 @@ struct table_col_instance { const struct table_column *col_def; // this is pointer to the column definition, located in the array struct table::columns const char *cell_content; // content of the cell of the current row int next_column; // index of next column in linked list of columns of the same type - uint fmt; // format of this column + uint fmt; // format of this column }; /** @@ -338,9 +338,11 @@ int table_get_col_idx(struct table *tbl, const char *col_name); /** - * Sets a string argument to a column instance + * Sets a string option to an instance of a columnt type. This is the default version that checks + * whether the xtype::parse_fmt can be called and calls it. However, there are situation in which + * the xtype::parse_fmt is not sufficient, e.g., column decoration, post-processing, etc. **/ -const char *table_set_col_opt_default(struct table *tbl, uint col_idx, const char *col_opt); +const char *table_set_col_opt(struct table *tbl, uint col_idx, const char *col_opt); /** * Returns a comma-and-space-separated list of column names, allocated from table's internal -- 2.39.2