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);
#include <ucw/opt.h>
#include <stdio.h>
-
enum test_table_cols {
test_col0_str, test_col1_int, test_col2_uint, test_col3_bool, test_col4_double
};
[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
},
[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),
}
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;
}
}
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;
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;
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);
}
*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;
}
}
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);
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
}
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) {
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) {
[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
},
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
};
/**
/**
* 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
*
* <col-name> is a string that does not contain comma ',' or '[',']' brackets
*
- * <col-opt> is currently only one string.
+ * <col-opt> is currently only one string without commas. In the future the format can be <str1>,<str2>,... .
*
* FIXME In the future, we should allow <col-opt> to be a comma(,) separated list of identifiers
**/