bool table_set_col_opt_ucw_types(struct table *tbl, int col_copy_idx, const char *col_arg, char **err)
{
- fprintf(stdout, "col_copy_idx: %d, col_arg: %s\n", col_copy_idx, col_arg);
- fflush(stdout);
-
int col_type_idx = tbl->column_order[col_copy_idx].idx;
if(tbl->columns[col_type_idx].type == COL_TYPE_SIZE) {
if(strcasecmp(col_arg, "b") == 0 || strcasecmp(col_arg, "bytes") == 0) {
}
if(tbl->columns[col_type_idx].type == COL_TYPE_TIMESTAMP) {
- fprintf(stdout, "setting timestamp format, col_arg: '%s'\n", col_arg);
- fflush(stdout);
if(strcasecmp(col_arg, "timestamp") == 0 || strcasecmp(col_arg, "epoch") == 0) {
tbl->column_order[col_copy_idx].output_type = TIMESTAMP_EPOCH;
} else if(strcasecmp(col_arg, "datetime") == 0) {
return true;
}
- *err = mp_printf(tbl->pool, "Tableprinter: invalid column format option: '%s' for column %d.", col_arg, col_copy_idx);
- return false;
+ return table_set_col_opt_default(tbl, col_copy_idx, col_arg, err);
}
-
void table_col_size_name(struct table *tbl, const char *col_name, u64 val)
{
int col = table_get_col_idx(tbl, col_name);
break;
}
- //table_col_printf(tbl, col, "%s", formatted_time_buf);
tbl->column_order[curr_col].cell_content = mp_printf(tbl->pool, "%s", formatted_time_buf);
curr_col = tbl->column_order[curr_col].next_column;
}
}
-
return tmp;
}
-
static void table_update_ll(struct table *tbl)
{
int cols_to_output = tbl->cols_to_output;
}
/**
- *
+ * Setting options for basic table types (as defined in table.h)
**/
bool table_set_col_opt_default(struct table *tbl, int col_copy_idx, const char *col_arg, char **err)
{
tbl->cols_to_output = col_count;
tbl->column_order = mp_alloc_zero(tbl->pool, sizeof(struct table_col_info) * col_count);
- //int *col_order_int = alloca(sizeof(int) * col_count);
int curr_col_idx = 0;
char *name_start = tmp_col_order;
- //int curr_col_instance = 0;
while(name_start) {
char *next = strchr(name_start, ',');
if(next) {
char *arg = table_parse_col_arg(name_start); // this sets 0 on the '['
int col_idx = table_get_col_idx(tbl, name_start);
if(col_idx == -1) {
- return mp_printf(tbl->pool, "Unknown table column '%s'", name_start);
+ return mp_printf(tbl->pool, "Unknown table column '%s', possible column names are: %s.", name_start, table_get_col_list(tbl));
}
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 = CELL_OUT_UNINITIALIZED;
- fprintf(stdout, "formatter: %p, set_col_instance_option: %p\n", tbl->formatter, tbl->formatter->set_col_instance_option);
if(tbl->formatter && tbl->formatter->set_col_instance_option) {
char *err = NULL;
- fprintf(stdout, "calling: %p\n", tbl->formatter->set_col_instance_option);
tbl->formatter->set_col_instance_option(tbl, curr_col_idx, arg, &err);
if(err) return err;
}
curr_col_idx++;
}
- //table_set_col_order(tbl, col_order_int, curr_col_order_int);
- //tbl->cols_to_output = cols_to_output;
- //tbl->column_order = mp_alloc_zero(tbl->pool, sizeof(struct table_col_info) * cols_to_output);
- //for(int i = 0; i < cols_to_output; i++) {
- //int col_idx = col_order[i];
- //tbl->column_order[i].idx = col_idx;
- //tbl->column_order[i].cell_content = NULL;
- //tbl->column_order[i].output_type = CELL_OUT_UNINITIALIZED;
- //}
table_update_ll(tbl);
return NULL;
int curr_col = tbl->columns[col].first_column;
while(curr_col != -1) {
if(override == 0 && tbl->column_order[curr_col].output_type != CELL_OUT_UNINITIALIZED ) {
- fprintf(stdout, "curr_col: %d\n", curr_col);
- fflush(stdout);
die("Error while setting content of all cells of a single type column, cell format should not be overriden.");
}
tbl->column_order[curr_col].cell_content = col_content;
} else if(strcmp(key, "cols") == 0) {
const char *err = table_set_col_order_by_name(tbl, value);
if(err != NULL) {
- return mp_printf(tbl->pool, "%s, possible column names are: %s.", err, table_get_col_list(tbl));
+ return err;
}
return NULL;
} else if(strcmp(key, "fmt") == 0) {
* 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
* this function returns.
+ *
+ * The format of the col_order string is the following:
+ * <col-order-string> := <col-def>[,<col-def>]*
+ *
+ * <col-def> := <col-name> '[' <col-opt> ']'
+ * <col-name> is a string that does not contain comma ',' or '[',']' brackets
+ * <col-opt> is currently only one string.
+ *
+ * FIXME In the future, we should allow <col-opt> to be a comma(,) separated list of identifiers
**/
const char *table_set_col_order_by_name(struct table *tbl, const char *col_order);