From 878fc3f835ed598ee30793d9088321f34291c5c2 Mon Sep 17 00:00:00 2001 From: Robert Kessl Date: Wed, 2 Jul 2014 10:47:05 +0200 Subject: [PATCH] tableprinter: code cleanup; doc update --- ucw/table-types.c | 11 +---------- ucw/table.c | 22 +++------------------- ucw/table.h | 9 +++++++++ 3 files changed, 13 insertions(+), 29 deletions(-) diff --git a/ucw/table-types.c b/ucw/table-types.c index c5aa96fa..75bf53bc 100644 --- a/ucw/table-types.c +++ b/ucw/table-types.c @@ -10,9 +10,6 @@ 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) { @@ -34,8 +31,6 @@ bool table_set_col_opt_ucw_types(struct table *tbl, int col_copy_idx, const char } 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) { @@ -48,11 +43,9 @@ bool table_set_col_opt_ucw_types(struct table *tbl, int col_copy_idx, const char 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); @@ -135,9 +128,7 @@ void table_col_timestamp(struct table *tbl, int col, u64 val) 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; } } - diff --git a/ucw/table.c b/ucw/table.c index 823f7e75..048d4589 100644 --- a/ucw/table.c +++ b/ucw/table.c @@ -121,7 +121,6 @@ const char * table_get_col_list(struct table *tbl) return tmp; } - static void table_update_ll(struct table *tbl) { int cols_to_output = tbl->cols_to_output; @@ -183,7 +182,7 @@ static char * table_parse_col_arg(char *col_def) } /** - * + * 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) { @@ -234,10 +233,8 @@ const char * table_set_col_order_by_name(struct table *tbl, const char *col_orde 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) { @@ -247,15 +244,13 @@ const char * table_set_col_order_by_name(struct table *tbl, const char *col_orde 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; } @@ -264,15 +259,6 @@ const char * table_set_col_order_by_name(struct table *tbl, const char *col_orde 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; @@ -285,8 +271,6 @@ static void table_set_all_cols_content(struct table *tbl, int col, char *col_con 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; @@ -484,7 +468,7 @@ const char *table_set_option_value(struct table *tbl, const char *key, const cha } 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) { diff --git a/ucw/table.h b/ucw/table.h index afdd0bef..14e84314 100644 --- a/ucw/table.h +++ b/ucw/table.h @@ -335,6 +335,15 @@ bool 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 * this function returns. + * + * The format of the col_order string is the following: + * := [,]* + * + * := '[' ']' + * is a string that does not contain comma ',' or '[',']' brackets + * is currently only one string. + * + * FIXME In the future, we should allow to be a comma(,) separated list of identifiers **/ const char *table_set_col_order_by_name(struct table *tbl, const char *col_order); -- 2.39.2