]> mj.ucw.cz Git - libucw.git/commitdiff
tableprinter: bugfix in table_set_col_opt_size, incorrect handling of argument
authorRobert Kessl <kesslr@centrum.cz>
Fri, 4 Jul 2014 14:22:50 +0000 (16:22 +0200)
committerRobert Kessl <kesslr@centrum.cz>
Fri, 4 Jul 2014 14:22:50 +0000 (16:22 +0200)
ucw/table-types.c

index ab2e5b696ab9f0542b72924f1d4159379d0f7cff..25576d3e55563347957d85518f0c10fde93e095f 100644 (file)
@@ -24,15 +24,12 @@ static bool table_set_col_opt_size(struct table *tbl, uint col_copy_idx, const c
     return false;
   }
 
-  if(col_arg == NULL) {
+  if(col_arg == NULL || strcasecmp(col_arg, "b") == 0 || strcasecmp(col_arg, "bytes") == 0) {
+    tbl->column_order[col_copy_idx].output_type = UNIT_BYTE;
     *err = NULL;
     return true;
   }
 
-  if(strcasecmp(col_arg, "b") == 0 || strcasecmp(col_arg, "bytes") == 0) {
-    tbl->column_order[col_copy_idx].output_type = UNIT_BYTE;
-  }
-
   tbl->column_order[col_copy_idx].output_type = CELL_OUT_UNINITIALIZED;
   for(uint i = 0; i < ARRAY_SIZE(unit_suffix); i++) {
     if(strcasecmp(col_arg, unit_suffix[i]) == 0) {
@@ -110,15 +107,16 @@ void table_col_size(struct table *tbl, int col, u64 val)
   TBL_COL_ITER(tbl, col, curr_col, curr_col_idx) {
     // FIXME: do some rounding?
     uint out_type = 0;
+    u64 curr_val = val;
     if(curr_col->output_type == CELL_OUT_UNINITIALIZED) {
-      val = val / unit_div[UNIT_BYTE];
+      curr_val = curr_val / unit_div[UNIT_BYTE];
       out_type = 0;
     } else {
-      val = val / unit_div[curr_col->output_type];
+      curr_val = curr_val / unit_div[curr_col->output_type];
       out_type = curr_col->output_type;
     }
 
-    curr_col->cell_content = mp_printf(tbl->pool, "%lu%s", val, unit_suffix[out_type]);
+    curr_col->cell_content = mp_printf(tbl->pool, "%lu%s", curr_val, unit_suffix[out_type]);
   }
 }