From: Robert Kessl Date: Wed, 9 Jul 2014 15:23:46 +0000 (+0200) Subject: tableprinter: renamed size units; update of doc X-Git-Tag: v6.1~3^2~105 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=9118f7ef58958057d5eec0a63748ce2ff0e2c053;p=libucw.git tableprinter: renamed size units; update of doc --- diff --git a/ucw/table-types.c b/ucw/table-types.c index bdcf63b1..72666b5b 100644 --- a/ucw/table-types.c +++ b/ucw/table-types.c @@ -7,11 +7,11 @@ #include static const char *unit_suffix[] = { - [UNIT_SIZE_BYTE] = "", - [UNIT_SIZE_KILOBYTE] = "KB", - [UNIT_SIZE_MEGABYTE] = "MB", - [UNIT_SIZE_GIGABYTE] = "GB", - [UNIT_SIZE_TERABYTE] = "TB" + [SIZE_UNIT_BYTE] = "", + [SIZE_UNIT_KILOBYTE] = "KB", + [SIZE_UNIT_MEGABYTE] = "MB", + [SIZE_UNIT_GIGABYTE] = "GB", + [SIZE_UNIT_TERABYTE] = "TB" }; static bool table_set_col_opt_size(struct table *tbl, uint col_inst_idx, const char *col_arg, char **err) @@ -23,13 +23,13 @@ static bool table_set_col_opt_size(struct table *tbl, uint col_inst_idx, const c } if(col_arg == NULL || strcasecmp(col_arg, "b") == 0 || strcasecmp(col_arg, "bytes") == 0) { - tbl->column_order[col_inst_idx].output_type = UNIT_SIZE_BYTE; + tbl->column_order[col_inst_idx].output_type = SIZE_UNIT_BYTE; *err = NULL; return true; } tbl->column_order[col_inst_idx].output_type = CELL_OUT_UNINITIALIZED; - for(uint i = UNIT_SIZE_BYTE; i <= UNIT_SIZE_TERABYTE; i++) { + 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; } @@ -95,11 +95,11 @@ void table_col_size(struct table *tbl, int col, u64 val) tbl->row_printing_started = 1; static u64 unit_div[] = { - [UNIT_SIZE_BYTE] = (u64) 1, - [UNIT_SIZE_KILOBYTE] = (u64) 1024LLU, - [UNIT_SIZE_MEGABYTE] = (u64) (1024LLU * 1024LLU), - [UNIT_SIZE_GIGABYTE] = (u64) (1024LLU * 1024LLU * 1024LLU), - [UNIT_SIZE_TERABYTE] = (u64) (1024LLU * 1024LLU * 1024LLU * 1024LLU) + [SIZE_UNIT_BYTE] = (u64) 1, + [SIZE_UNIT_KILOBYTE] = (u64) 1024LLU, + [SIZE_UNIT_MEGABYTE] = (u64) (1024LLU * 1024LLU), + [SIZE_UNIT_GIGABYTE] = (u64) (1024LLU * 1024LLU * 1024LLU), + [SIZE_UNIT_TERABYTE] = (u64) (1024LLU * 1024LLU * 1024LLU * 1024LLU) }; TBL_COL_ITER_START(tbl, col, curr_col, curr_col_idx) { @@ -107,8 +107,8 @@ void table_col_size(struct table *tbl, int col, u64 val) uint out_type = 0; u64 curr_val = val; if(curr_col->output_type == CELL_OUT_UNINITIALIZED) { - curr_val = curr_val / unit_div[UNIT_SIZE_BYTE]; - out_type = UNIT_SIZE_BYTE; + curr_val = curr_val / unit_div[SIZE_UNIT_BYTE]; + out_type = SIZE_UNIT_BYTE; } else { curr_val = curr_val / unit_div[curr_col->output_type]; out_type = curr_col->output_type; diff --git a/ucw/table-types.h b/ucw/table-types.h index a5bfd61e..e6b542a9 100644 --- a/ucw/table-types.h +++ b/ucw/table-types.h @@ -10,12 +10,12 @@ #include enum size_units { - UNIT_SIZE_BYTE = CELL_OUT_USER_DEF_START, - UNIT_SIZE_KILOBYTE, - UNIT_SIZE_MEGABYTE, - UNIT_SIZE_GIGABYTE, - UNIT_SIZE_TERABYTE, - UNIT_SIZE_AUTO + SIZE_UNIT_BYTE = CELL_OUT_USER_DEF_START, + SIZE_UNIT_KILOBYTE, + SIZE_UNIT_MEGABYTE, + SIZE_UNIT_GIGABYTE, + SIZE_UNIT_TERABYTE, + SIZE_UNIT_AUTO }; enum timestamp_format { diff --git a/ucw/table.c b/ucw/table.c index a8749a51..cdd735f9 100644 --- a/ucw/table.c +++ b/ucw/table.c @@ -22,7 +22,7 @@ static void table_update_ll(struct table *tbl); static struct table *table_make_instance(const struct table_template *tbl_template) { - struct table *new_inst = xmalloc_zero(sizeof(struct table)); + struct table *new_inst = xmalloc_zero(sizeof(struct table)); // FIXME: update allocation to the weird schema made by pchar and mj? new_inst->pool = mp_new(4096); if(tbl_template->column_order) { diff --git a/ucw/table.h b/ucw/table.h index cb295bad..488c4833 100644 --- a/ucw/table.h +++ b/ucw/table.h @@ -374,7 +374,9 @@ 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. * * FIXME In the future, we should allow to be a comma(,) separated list of identifiers