From 7d1a2f577f59fb74533640dbfcd013d949da90ec Mon Sep 17 00:00:00 2001 From: Robert Kessl Date: Mon, 21 Jul 2014 14:07:10 +0200 Subject: [PATCH] tableprinter: renamed output_type -> fmt, changed bool default format --- ucw/table-test-2.c | 12 ++++++------ ucw/table-test-align.c | 3 +-- ucw/table-test.c | 2 +- ucw/table-types.c | 12 ++++++------ ucw/table.c | 17 ++++++++--------- ucw/table.h | 8 ++++---- 6 files changed, 26 insertions(+), 28 deletions(-) diff --git a/ucw/table-test-2.c b/ucw/table-test-2.c index 88fec5e2..35688734 100644 --- a/ucw/table-test-2.c +++ b/ucw/table-test-2.c @@ -37,25 +37,25 @@ static void do_test(void) table_col_timestamp(tbl, TEST_COL1_TS, test_time); table_end_row(tbl); - tbl->column_order[TEST_COL0_SIZE].output_type = SIZE_UNITS_FIXED | SIZE_UNIT_KILOBYTE; + tbl->column_order[TEST_COL0_SIZE].fmt = SIZE_UNITS_FIXED | SIZE_UNIT_KILOBYTE; table_col_size(tbl, TEST_COL0_SIZE, test_size); table_col_timestamp(tbl, TEST_COL1_TS, test_time); table_end_row(tbl); - tbl->column_order[TEST_COL0_SIZE].output_type = SIZE_UNITS_FIXED | SIZE_UNIT_MEGABYTE; + tbl->column_order[TEST_COL0_SIZE].fmt = SIZE_UNITS_FIXED | SIZE_UNIT_MEGABYTE; table_col_size(tbl, TEST_COL0_SIZE, test_size); table_col_timestamp(tbl, TEST_COL1_TS, test_time); table_end_row(tbl); - tbl->column_order[TEST_COL0_SIZE].output_type = SIZE_UNITS_FIXED | SIZE_UNIT_GIGABYTE; - tbl->column_order[TEST_COL1_TS].output_type = TIMESTAMP_DATETIME; + tbl->column_order[TEST_COL0_SIZE].fmt = SIZE_UNITS_FIXED | SIZE_UNIT_GIGABYTE; + tbl->column_order[TEST_COL1_TS].fmt = TIMESTAMP_DATETIME; table_col_size(tbl, TEST_COL0_SIZE, test_size); table_col_timestamp(tbl, TEST_COL1_TS, test_time); table_end_row(tbl); test_size = test_size * 1024LU; - tbl->column_order[TEST_COL0_SIZE].output_type = SIZE_UNITS_FIXED | SIZE_UNIT_TERABYTE; - tbl->column_order[TEST_COL1_TS].output_type = TIMESTAMP_DATETIME; + tbl->column_order[TEST_COL0_SIZE].fmt = SIZE_UNITS_FIXED | SIZE_UNIT_TERABYTE; + tbl->column_order[TEST_COL1_TS].fmt = TIMESTAMP_DATETIME; table_col_size(tbl, TEST_COL0_SIZE, test_size); table_col_timestamp(tbl, TEST_COL1_TS, test_time); table_end_row(tbl); diff --git a/ucw/table-test-align.c b/ucw/table-test-align.c index b1d16a97..8432449b 100644 --- a/ucw/table-test-align.c +++ b/ucw/table-test-align.c @@ -9,7 +9,6 @@ #include #include - enum test_table_cols { test_col0_str, test_col1_int, test_col2_uint, test_col3_bool, test_col4_double }; @@ -19,7 +18,7 @@ static struct table_template test_tbl = { [test_col0_str] = TBL_COL_STR("col0_str", 30 | CELL_ALIGN_LEFT), [test_col1_int] = TBL_COL_INT("col1_int", 8), [test_col2_uint] = TBL_COL_UINT("col2_uint", 9), - [test_col3_bool] = TBL_COL_BOOL("col3_bool", 9 | CELL_ALIGN_LEFT), + [test_col3_bool] = TBL_COL_BOOL_FMT("col3_bool", 9 | CELL_ALIGN_LEFT, XTYPE_FMT_PRETTY), [test_col4_double] = TBL_COL_DOUBLE_FMT("col4_double", 11 | CELL_ALIGN_LEFT, XTYPE_FMT_DEFAULT), TBL_COL_END }, diff --git a/ucw/table-test.c b/ucw/table-test.c index 7b6e581d..480a7a33 100644 --- a/ucw/table-test.c +++ b/ucw/table-test.c @@ -21,7 +21,7 @@ static struct table_template test_tbl = { [TEST_COL0_STR] = TBL_COL_STR("col0_str", 20), [TEST_COL1_INT] = TBL_COL_INT("col1_int", 8), [TEST_COL2_UINT] = TBL_COL_UINT("col2_uint", 9), - [TEST_COL3_BOOL] = TBL_COL_BOOL("col3_bool", 9), + [TEST_COL3_BOOL] = TBL_COL_BOOL_FMT("col3_bool", 9, XTYPE_FMT_PRETTY), [TEST_COL4_DOUBLE] = TBL_COL_DOUBLE_FMT("col4_double", 11, XTYPE_FMT_PRETTY), [TEST_COL5_SIZE] = TBL_COL_SIZE("col5_size", 11), [TEST_COL6_TIME] = TBL_COL_TIMESTAMP("col6_timestamp", 20), diff --git a/ucw/table-types.c b/ucw/table-types.c index e3d184cd..f516f8f4 100644 --- a/ucw/table-types.c +++ b/ucw/table-types.c @@ -69,19 +69,19 @@ int table_set_col_opt_size(struct table *tbl, uint col_inst_idx, const char *col } if(strlen(col_arg) == 0 || strcasecmp(col_arg, "b") == 0 || strcasecmp(col_arg, "bytes") == 0) { - tbl->column_order[col_inst_idx].output_type = SIZE_UNIT_BYTE | SIZE_UNITS_FIXED; + tbl->column_order[col_inst_idx].fmt = SIZE_UNIT_BYTE | SIZE_UNITS_FIXED; *err = NULL; return TABLE_OPT_PROCESSED; } - tbl->column_order[col_inst_idx].output_type = XTYPE_FMT_DEFAULT; // CELL_OUT_UNINITIALIZED; + tbl->column_order[col_inst_idx].fmt = XTYPE_FMT_DEFAULT; // CELL_OUT_UNINITIALIZED; for(uint i = SIZE_UNIT_BYTE; i <= SIZE_UNIT_TERABYTE; i++) { if(strcasecmp(col_arg, unit_suffix[i]) == 0) { - tbl->column_order[col_inst_idx].output_type = i | SIZE_UNITS_FIXED; + tbl->column_order[col_inst_idx].fmt = i | SIZE_UNITS_FIXED; } } - if(tbl->column_order[col_inst_idx].output_type == XTYPE_FMT_DEFAULT) { + if(tbl->column_order[col_inst_idx].fmt == XTYPE_FMT_DEFAULT) { *err = mp_printf(tbl->pool, "Invalid column format option: '%s' for column %d (counted from 0)", col_arg, col_inst_idx); return TABLE_OPT_ERR; } @@ -117,9 +117,9 @@ int table_set_col_opt_timestamp(struct table *tbl, uint col_inst_idx, const char } if(strcasecmp(col_arg, "timestamp") == 0 || strcasecmp(col_arg, "epoch") == 0) { - tbl->column_order[col_inst_idx].output_type = TIMESTAMP_EPOCH; + tbl->column_order[col_inst_idx].fmt = TIMESTAMP_EPOCH; } else if(strcasecmp(col_arg, "datetime") == 0) { - tbl->column_order[col_inst_idx].output_type = TIMESTAMP_DATETIME; + tbl->column_order[col_inst_idx].fmt = TIMESTAMP_DATETIME; } else { *err = mp_printf(tbl->pool, "Invalid column format option: '%s' for column %d.", col_arg, col_inst_idx); return TABLE_OPT_ERR; diff --git a/ucw/table.c b/ucw/table.c index 4b41ae20..cf994177 100644 --- a/ucw/table.c +++ b/ucw/table.c @@ -55,7 +55,7 @@ static struct table *table_make_instance(const struct table_template *tbl_templa new_inst->column_order[i].cell_content = NULL; int col_idx = new_inst->column_order[i].idx; new_inst->column_order[i].col_def = new_inst->columns + col_idx; - new_inst->column_order[i].output_type = tbl_template->columns[col_idx].fmt; + new_inst->column_order[i].fmt = tbl_template->columns[col_idx].fmt; } new_inst->cols_to_output = tbl_template->cols_to_output; @@ -191,7 +191,7 @@ void table_set_col_order(struct table *tbl, int *col_order, int cols_to_output) tbl->column_order[i].idx = col_idx; tbl->column_order[i].col_def = tbl->columns + col_idx; tbl->column_order[i].cell_content = NULL; - tbl->column_order[i].output_type = tbl->columns[col_idx].fmt; + tbl->column_order[i].fmt = tbl->columns[col_idx].fmt; } table_update_ll(tbl); } @@ -229,7 +229,7 @@ int table_set_col_opt_default(struct table *tbl, int col_idx, const char *col_ar *err = mp_printf(tbl->pool, "An error occured while parsing precision: %s.", tmp_err); return false; } - tbl->column_order[col_idx].output_type = precision; // FIXME: shift the value of precision + tbl->column_order[col_idx].fmt = precision; // FIXME: shift the value of precision return true; } @@ -282,8 +282,7 @@ 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].cell_content = NULL; - tbl->column_order[curr_col_idx].output_type = tbl->columns[col_idx].fmt; + 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) { char *err = NULL; tbl->columns[col_idx].set_col_instance_option(tbl, curr_col_idx, arg, &err); @@ -315,7 +314,7 @@ void table_col_generic_format(struct table *tbl, int col, void *value, const str tbl->last_printed_col = col; tbl->row_printing_started = 1; TBL_COL_ITER_START(tbl, col, curr_col, curr_col_idx) { - enum xtype_fmt fmt = curr_col->output_type; + enum xtype_fmt fmt = curr_col->fmt; curr_col->cell_content = expected_type->format(value, fmt, tbl->pool); } TBL_COL_ITER_END } @@ -414,7 +413,7 @@ const char *table_set_option_value(struct table *tbl, const char *key, const cha const char *err = xtype_parse_fmt(NULL, value, &fmt, tbl->pool); if(err) return mp_printf(tbl->pool, "Invalid cell format: '%s'.", err); for(uint i = 0; i < tbl->cols_to_output; i++) { - tbl->column_order[i].output_type = fmt; + tbl->column_order[i].fmt = fmt; } return NULL; } else if(strcmp(key, "raw") == 0 || strcmp(key, "pretty") == 0) { @@ -422,7 +421,7 @@ const char *table_set_option_value(struct table *tbl, const char *key, const cha const char *err = xtype_parse_fmt(NULL, key, &fmt, tbl->pool); if(err) return mp_printf(tbl->pool, "Invalid cell format: '%s'.", err); for(uint i = 0; i < tbl->cols_to_output; i++) { - tbl->column_order[i].output_type = fmt; + tbl->column_order[i].fmt = fmt; } return NULL; } else if(strcmp(key, "col-delim") == 0) { @@ -586,7 +585,7 @@ static struct table_template test_tbl = { [TEST_COL0_STR] = TBL_COL_STR("col0_str", 20), [TEST_COL1_INT] = TBL_COL_INT("col1_int", 8), [TEST_COL2_UINT] = TBL_COL_UINT("col2_uint", 9), - [TEST_COL3_BOOL] = TBL_COL_BOOL("col3_bool", 9), + [TEST_COL3_BOOL] = TBL_COL_BOOL_FMT("col3_bool", 9, XTYPE_FMT_PRETTY), [TEST_COL4_DOUBLE] = TBL_COL_DOUBLE("col4_double", 11), TBL_COL_END }, diff --git a/ucw/table.h b/ucw/table.h index be459687..57640477 100644 --- a/ucw/table.h +++ b/ucw/table.h @@ -121,7 +121,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 output_type; // format of this column + uint fmt; // format of this column }; /** @@ -218,8 +218,8 @@ struct table { /** * These macros are used for definition of column order **/ -#define TBL_COL(_idx) { .idx = _idx, .output_type = XTYPE_FMT_DEFAULT, .next_column = -1 } -#define TBL_COL_FMT(_idx, _fmt) { .idx = _idx, .output_type = _fmt, .next_column = -1 } +#define TBL_COL(_idx) { .idx = _idx, .fmt = XTYPE_FMT_DEFAULT, .next_column = -1 } +#define TBL_COL_FMT(_idx, _fmt) { .idx = _idx, .fmt = _fmt, .next_column = -1 } #define TBL_FMT_HUMAN_READABLE .formatter = &table_fmt_human_readable #define TBL_FMT_BLOCKLINE .formatter = &table_fmt_blockline @@ -378,7 +378,7 @@ bool table_col_is_printed(struct table *tbl, uint col_idx); * * is a string that does not contain comma ',' or '[',']' brackets * - * is currently only one string. + * is currently only one string without commas. In the future the format can be ,,... . * * FIXME In the future, we should allow to be a comma(,) separated list of identifiers **/ -- 2.39.5