]> mj.ucw.cz Git - libucw.git/commitdiff
tableprinter: renamed size units; update of doc
authorRobert Kessl <kesslr@centrum.cz>
Wed, 9 Jul 2014 15:23:46 +0000 (17:23 +0200)
committerRobert Kessl <kesslr@centrum.cz>
Wed, 9 Jul 2014 15:23:46 +0000 (17:23 +0200)
ucw/table-types.c
ucw/table-types.h
ucw/table.c
ucw/table.h

index bdcf63b1ce43d5c056ef37ed538af47dd3712bb1..72666b5b16812bfa811b391c43fa54ce40b5f8aa 100644 (file)
@@ -7,11 +7,11 @@
 #include <stdlib.h>
 
 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;
index a5bfd61ebdcf3d5af375159ca04cd1928e26164b..e6b542a9aaeef21ddfc1c74dad83ddea607e87cc 100644 (file)
 #include <ucw/table.h>
 
 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 {
index a8749a511082f1f11caf057fb369f724c12e8ee9..cdd735f9348784a727b3235f8636c8c480aed3a7 100644 (file)
@@ -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) {
index cb295badc3da5094e87cc7d09aa91d8a739a8e17..488c483358856dd686cda56334f7e4310e5c5e63 100644 (file)
@@ -374,7 +374,9 @@ bool table_col_is_printed(struct table *tbl, uint col_idx);
  * <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