]> mj.ucw.cz Git - libucw.git/commitdiff
tableprinter: renamed output_type -> fmt, changed bool default format
authorRobert Kessl <kesslr@centrum.cz>
Mon, 21 Jul 2014 12:07:10 +0000 (14:07 +0200)
committerRobert Kessl <kesslr@centrum.cz>
Mon, 21 Jul 2014 12:08:21 +0000 (14:08 +0200)
ucw/table-test-2.c
ucw/table-test-align.c
ucw/table-test.c
ucw/table-types.c
ucw/table.c
ucw/table.h

index 88fec5e22486c90e79806509ae674ac6d7ae9e02..35688734e5852e293c0528b81e9a98ab3bcf25a0 100644 (file)
@@ -37,25 +37,25 @@ static void do_test(void)
   table_col_timestamp(tbl, TEST_COL1_TS, test_time);
   table_end_row(tbl);
 
-  tbl->column_order[TEST_COL0_SIZE].output_type = SIZE_UNITS_FIXED | SIZE_UNIT_KILOBYTE;
+  tbl->column_order[TEST_COL0_SIZE].fmt = SIZE_UNITS_FIXED | SIZE_UNIT_KILOBYTE;
   table_col_size(tbl, TEST_COL0_SIZE, test_size);
   table_col_timestamp(tbl, TEST_COL1_TS, test_time);
   table_end_row(tbl);
 
-  tbl->column_order[TEST_COL0_SIZE].output_type = SIZE_UNITS_FIXED | SIZE_UNIT_MEGABYTE;
+  tbl->column_order[TEST_COL0_SIZE].fmt = SIZE_UNITS_FIXED | SIZE_UNIT_MEGABYTE;
   table_col_size(tbl, TEST_COL0_SIZE, test_size);
   table_col_timestamp(tbl, TEST_COL1_TS, test_time);
   table_end_row(tbl);
 
-  tbl->column_order[TEST_COL0_SIZE].output_type = SIZE_UNITS_FIXED | SIZE_UNIT_GIGABYTE;
-  tbl->column_order[TEST_COL1_TS].output_type = TIMESTAMP_DATETIME;
+  tbl->column_order[TEST_COL0_SIZE].fmt = SIZE_UNITS_FIXED | SIZE_UNIT_GIGABYTE;
+  tbl->column_order[TEST_COL1_TS].fmt = TIMESTAMP_DATETIME;
   table_col_size(tbl, TEST_COL0_SIZE, test_size);
   table_col_timestamp(tbl, TEST_COL1_TS, test_time);
   table_end_row(tbl);
 
   test_size = test_size * 1024LU;
-  tbl->column_order[TEST_COL0_SIZE].output_type = SIZE_UNITS_FIXED | SIZE_UNIT_TERABYTE;
-  tbl->column_order[TEST_COL1_TS].output_type = TIMESTAMP_DATETIME;
+  tbl->column_order[TEST_COL0_SIZE].fmt = SIZE_UNITS_FIXED | SIZE_UNIT_TERABYTE;
+  tbl->column_order[TEST_COL1_TS].fmt = TIMESTAMP_DATETIME;
   table_col_size(tbl, TEST_COL0_SIZE, test_size);
   table_col_timestamp(tbl, TEST_COL1_TS, test_time);
   table_end_row(tbl);
index b1d16a97dfe73172c7217f65e9113301e9f1f21d..8432449b21cc45a185107f63a499484787f1f900 100644 (file)
@@ -9,7 +9,6 @@
 #include <ucw/opt.h>
 #include <stdio.h>
 
-
 enum test_table_cols {
   test_col0_str, test_col1_int, test_col2_uint, test_col3_bool, test_col4_double
 };
@@ -19,7 +18,7 @@ static struct table_template test_tbl = {
     [test_col0_str] = TBL_COL_STR("col0_str", 30 | CELL_ALIGN_LEFT),
     [test_col1_int] = TBL_COL_INT("col1_int", 8),
     [test_col2_uint] = TBL_COL_UINT("col2_uint", 9),
-    [test_col3_bool] = TBL_COL_BOOL("col3_bool", 9 | CELL_ALIGN_LEFT),
+    [test_col3_bool] = TBL_COL_BOOL_FMT("col3_bool", 9 | CELL_ALIGN_LEFT, XTYPE_FMT_PRETTY),
     [test_col4_double] = TBL_COL_DOUBLE_FMT("col4_double", 11 | CELL_ALIGN_LEFT, XTYPE_FMT_DEFAULT),
     TBL_COL_END
   },
index 7b6e581d64417f93d3bd22265b6bb5bded460f50..480a7a33222936fa6c4b131aef9ef723ba218ff7 100644 (file)
@@ -21,7 +21,7 @@ static struct table_template test_tbl = {
     [TEST_COL0_STR] = TBL_COL_STR("col0_str", 20),
     [TEST_COL1_INT] = TBL_COL_INT("col1_int", 8),
     [TEST_COL2_UINT] = TBL_COL_UINT("col2_uint", 9),
-    [TEST_COL3_BOOL] = TBL_COL_BOOL("col3_bool", 9),
+    [TEST_COL3_BOOL] = TBL_COL_BOOL_FMT("col3_bool", 9, XTYPE_FMT_PRETTY),
     [TEST_COL4_DOUBLE] = TBL_COL_DOUBLE_FMT("col4_double", 11, XTYPE_FMT_PRETTY),
     [TEST_COL5_SIZE] = TBL_COL_SIZE("col5_size", 11),
     [TEST_COL6_TIME] = TBL_COL_TIMESTAMP("col6_timestamp", 20),
index e3d184cd787599be2fba3014f05ca465fd1de09a..f516f8f47ff617dceb2ca63300b2298f4ea158a3 100644 (file)
@@ -69,19 +69,19 @@ int table_set_col_opt_size(struct table *tbl, uint col_inst_idx, const char *col
   }
 
   if(strlen(col_arg) == 0 || strcasecmp(col_arg, "b") == 0 || strcasecmp(col_arg, "bytes") == 0) {
-    tbl->column_order[col_inst_idx].output_type = SIZE_UNIT_BYTE | SIZE_UNITS_FIXED;
+    tbl->column_order[col_inst_idx].fmt = SIZE_UNIT_BYTE | SIZE_UNITS_FIXED;
     *err = NULL;
     return TABLE_OPT_PROCESSED;
   }
 
-  tbl->column_order[col_inst_idx].output_type = XTYPE_FMT_DEFAULT; // CELL_OUT_UNINITIALIZED;
+  tbl->column_order[col_inst_idx].fmt = XTYPE_FMT_DEFAULT; // CELL_OUT_UNINITIALIZED;
   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 | SIZE_UNITS_FIXED;
+      tbl->column_order[col_inst_idx].fmt = i | SIZE_UNITS_FIXED;
     }
   }
 
-  if(tbl->column_order[col_inst_idx].output_type == XTYPE_FMT_DEFAULT) {
+  if(tbl->column_order[col_inst_idx].fmt == XTYPE_FMT_DEFAULT) {
     *err = mp_printf(tbl->pool, "Invalid column format option: '%s' for column %d (counted from 0)", col_arg, col_inst_idx);
     return TABLE_OPT_ERR;
   }
@@ -117,9 +117,9 @@ int table_set_col_opt_timestamp(struct table *tbl, uint col_inst_idx, const char
   }
 
   if(strcasecmp(col_arg, "timestamp") == 0 || strcasecmp(col_arg, "epoch") == 0) {
-    tbl->column_order[col_inst_idx].output_type = TIMESTAMP_EPOCH;
+    tbl->column_order[col_inst_idx].fmt = TIMESTAMP_EPOCH;
   } else if(strcasecmp(col_arg, "datetime") == 0) {
-    tbl->column_order[col_inst_idx].output_type = TIMESTAMP_DATETIME;
+    tbl->column_order[col_inst_idx].fmt = TIMESTAMP_DATETIME;
   } else {
     *err = mp_printf(tbl->pool, "Invalid column format option: '%s' for column %d.", col_arg, col_inst_idx);
     return TABLE_OPT_ERR;
index 4b41ae2089f82907767f3267164f20addc878fe1..cf9941775256a48d0d3ff57e7017f7e782e946b2 100644 (file)
@@ -55,7 +55,7 @@ static struct table *table_make_instance(const struct table_template *tbl_templa
       new_inst->column_order[i].cell_content = NULL;
       int col_idx = new_inst->column_order[i].idx;
       new_inst->column_order[i].col_def = new_inst->columns + col_idx;
-      new_inst->column_order[i].output_type = tbl_template->columns[col_idx].fmt;
+      new_inst->column_order[i].fmt = tbl_template->columns[col_idx].fmt;
     }
 
     new_inst->cols_to_output = tbl_template->cols_to_output;
@@ -191,7 +191,7 @@ void table_set_col_order(struct table *tbl, int *col_order, int cols_to_output)
     tbl->column_order[i].idx = col_idx;
     tbl->column_order[i].col_def = tbl->columns + col_idx;
     tbl->column_order[i].cell_content = NULL;
-    tbl->column_order[i].output_type = tbl->columns[col_idx].fmt;
+    tbl->column_order[i].fmt = tbl->columns[col_idx].fmt;
   }
   table_update_ll(tbl);
 }
@@ -229,7 +229,7 @@ int table_set_col_opt_default(struct table *tbl, int col_idx, const char *col_ar
       *err = mp_printf(tbl->pool, "An error occured while parsing precision: %s.", tmp_err);
       return false;
     }
-    tbl->column_order[col_idx].output_type = precision; // FIXME: shift the value of precision
+    tbl->column_order[col_idx].fmt = precision; // FIXME: shift the value of precision
     return true;
   }
 
@@ -282,8 +282,7 @@ const char * table_set_col_order_by_name(struct table *tbl, const char *col_orde
     }
     tbl->column_order[curr_col_idx].col_def = tbl->columns + col_idx;
     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 = tbl->columns[col_idx].fmt;
+    tbl->column_order[curr_col_idx].fmt = tbl->columns[col_idx].fmt;
     if(tbl->columns[col_idx].type_def && tbl->columns[col_idx].set_col_instance_option) {
       char *err = NULL;
       tbl->columns[col_idx].set_col_instance_option(tbl, curr_col_idx, arg, &err);
@@ -315,7 +314,7 @@ void table_col_generic_format(struct table *tbl, int col, void *value, const str
   tbl->last_printed_col = col;
   tbl->row_printing_started = 1;
   TBL_COL_ITER_START(tbl, col, curr_col, curr_col_idx) {
-    enum xtype_fmt fmt = curr_col->output_type;
+    enum xtype_fmt fmt = curr_col->fmt;
     curr_col->cell_content = expected_type->format(value, fmt, tbl->pool);
   } TBL_COL_ITER_END
 }
@@ -414,7 +413,7 @@ const char *table_set_option_value(struct table *tbl, const char *key, const cha
       const char *err = xtype_parse_fmt(NULL, value, &fmt, tbl->pool);
       if(err) return mp_printf(tbl->pool, "Invalid cell format: '%s'.", err);
       for(uint i = 0; i < tbl->cols_to_output; i++) {
-        tbl->column_order[i].output_type = fmt;
+        tbl->column_order[i].fmt = fmt;
       }
       return NULL;
     } else if(strcmp(key, "raw") == 0 || strcmp(key, "pretty") == 0) {
@@ -422,7 +421,7 @@ const char *table_set_option_value(struct table *tbl, const char *key, const cha
       const char *err = xtype_parse_fmt(NULL, key, &fmt, tbl->pool);
       if(err) return mp_printf(tbl->pool, "Invalid cell format: '%s'.", err);
       for(uint i = 0; i < tbl->cols_to_output; i++) {
-        tbl->column_order[i].output_type = fmt;
+        tbl->column_order[i].fmt = fmt;
       }
       return NULL;
     } else if(strcmp(key, "col-delim") == 0) {
@@ -586,7 +585,7 @@ static struct table_template test_tbl = {
     [TEST_COL0_STR] = TBL_COL_STR("col0_str", 20),
     [TEST_COL1_INT] = TBL_COL_INT("col1_int", 8),
     [TEST_COL2_UINT] = TBL_COL_UINT("col2_uint", 9),
-    [TEST_COL3_BOOL] = TBL_COL_BOOL("col3_bool", 9),
+    [TEST_COL3_BOOL] = TBL_COL_BOOL_FMT("col3_bool", 9, XTYPE_FMT_PRETTY),
     [TEST_COL4_DOUBLE] = TBL_COL_DOUBLE("col4_double", 11),
     TBL_COL_END
   },
index be459687b6c9c3899c3282b0ff3bdf3843dcc9e7..576404775bb4ce3457dfc595bdef548af20a6c52 100644 (file)
@@ -121,7 +121,7 @@ struct table_col_instance {
   const struct table_column *col_def;  // this is pointer to the column definition, located in the array struct table::columns
   const char *cell_content;            // content of the cell of the current row
   int next_column;                     // index of next column in linked list of columns of the same type
-  uint output_type;                    // format of this column
+  uint fmt;                    // format of this column
 };
 
 /**
@@ -218,8 +218,8 @@ struct table {
 /**
  * These macros are used for definition of column order
  **/
-#define TBL_COL(_idx) { .idx = _idx, .output_type = XTYPE_FMT_DEFAULT, .next_column = -1 }
-#define TBL_COL_FMT(_idx, _fmt) { .idx = _idx, .output_type = _fmt, .next_column = -1 }
+#define TBL_COL(_idx) { .idx = _idx, .fmt = XTYPE_FMT_DEFAULT, .next_column = -1 }
+#define TBL_COL_FMT(_idx, _fmt) { .idx = _idx, .fmt = _fmt, .next_column = -1 }
 
 #define TBL_FMT_HUMAN_READABLE     .formatter = &table_fmt_human_readable
 #define TBL_FMT_BLOCKLINE          .formatter = &table_fmt_blockline
@@ -378,7 +378,7 @@ bool table_col_is_printed(struct table *tbl, uint col_idx);
  *
  * <col-name> is a string that does not contain comma ',' or '[',']' brackets
  *
- * <col-opt> is currently only one string.
+ * <col-opt> is currently only one string without commas. In the future the format can be <str1>,<str2>,... .
  *
  * FIXME In the future, we should allow <col-opt> to be a comma(,) separated list of identifiers
  **/