]> mj.ucw.cz Git - libucw.git/commitdiff
tableprinter: updated setting of column option
authorRobert Kessl <kesslr@centrum.cz>
Tue, 22 Jul 2014 10:12:19 +0000 (12:12 +0200)
committerRobert Kessl <kesslr@centrum.cz>
Tue, 22 Jul 2014 10:12:19 +0000 (12:12 +0200)
ucw/table-types.h
ucw/table.c
ucw/table.h

index 79b9e19e8261582a5ff34d7ea0f4da61d0f7d330..004a237bf6cf02b001744def143e2a6d0323e3a1 100644 (file)
@@ -26,12 +26,11 @@ enum size_units {
 extern const struct xtype xt_size;
 extern const struct xtype xt_timestamp;
 
-#define TBL_COL_SIZE(_name, _width)       { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_size, .set_col_instance_option = table_set_col_opt_default }
-#define TBL_COL_TIMESTAMP(_name, _width)  { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_timestamp, .set_col_instance_option = table_set_col_opt_default }
-
-#define TBL_COL_SIZE_FMT(_name, _width, _units)    { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_size, .set_col_instance_option = table_set_col_opt_default }
-#define TBL_COL_TIMESTAMP_FMT(_name, _width, _fmt) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_timestamp, .set_col_instance_option = table_set_col_opt_default}
+#define TBL_COL_SIZE(_name, _width)       { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_size, .set_col_opt = table_set_col_opt }
+#define TBL_COL_TIMESTAMP(_name, _width)  { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_timestamp, .set_col_opt = table_set_col_opt }
 
+#define TBL_COL_SIZE_FMT(_name, _width, _units)    { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_size, .set_col_opt = table_set_col_opt }
+#define TBL_COL_TIMESTAMP_FMT(_name, _width, _fmt) { .name = _name, .width = _width, .fmt = XTYPE_FMT_DEFAULT, .type_def = &xt_timestamp, .set_col_opt = table_set_col_opt}
 
 TABLE_COL_PROTO(size, u64)
 TABLE_COL_PROTO(timestamp, u64)
index 90988d21e4f2684c17f6b4595c6a02015115a809..3d468a44cdb64c2114e958ae34bde0ed2fc30aee 100644 (file)
@@ -215,12 +215,12 @@ static char * table_parse_col_arg(char *col_def)
   return left_br;
 }
 
-/**
- * Setting options for basic table types (as defined in table.h)
- **/
-const char *table_set_col_opt_default(struct table *tbl, uint col_idx, const char *col_opt)
+const char *table_set_col_opt(struct table *tbl, uint col_idx, const char *col_opt)
 {
   const struct table_column *col_def = tbl->column_order[col_idx].col_def;
+  if(col_def && col_def->set_col_opt && col_def->set_col_opt != table_set_col_opt) {
+    return col_def->set_col_opt(tbl, col_idx, col_opt);
+  }
 
   if(col_def && col_def->type_def && col_def->type_def->parse_fmt) {
     uint fmt = 0;
@@ -279,9 +279,9 @@ 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].fmt = tbl->columns[col_idx].fmt;
-    if(tbl->columns[col_idx].type_def && tbl->columns[col_idx].set_col_instance_option) {
+    if(tbl->columns[col_idx].type_def && tbl->columns[col_idx].set_col_opt) {
       const char *err = NULL;
-      err = tbl->columns[col_idx].set_col_instance_option(tbl, curr_col_idx, arg);
+      err = tbl->columns[col_idx].set_col_opt(tbl, curr_col_idx, arg);
       if(err) return mp_printf(tbl->pool, "Error occured while setting column option: %s.", err);
     }
 
index 4f63e827f226b0537092a97de7946f0838891147..0813a8ea38c41d1867a1e9c2cdf0f59e8de6c290 100644 (file)
@@ -104,7 +104,7 @@ struct table_column {
   uint fmt;                     // [*] default format of the column
   const struct xtype *type_def; // [*] pointer to xtype of this column
 
-  const char * (*set_col_instance_option)(struct table *tbl, uint col, const char *value);
+  const char * (*set_col_opt)(struct table *tbl, uint col, const char *value);
        // [*] process table option for a column instance
 };
 
@@ -115,7 +115,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 fmt;                    // format of this column
+  uint fmt;                            // format of this column
 };
 
 /**
@@ -338,9 +338,11 @@ int table_get_col_idx(struct table *tbl, const char *col_name);
 
 
 /**
- * Sets a string argument to a column instance
+ * Sets a string option to an instance of a columnt type. This is the default version that checks
+ * whether the xtype::parse_fmt can be called and calls it. However, there are situation in which
+ * the xtype::parse_fmt is not sufficient, e.g., column decoration, post-processing, etc.
  **/
-const char *table_set_col_opt_default(struct table *tbl, uint col_idx, const char *col_opt);
+const char *table_set_col_opt(struct table *tbl, uint col_idx, const char *col_opt);
 
 /**
  * Returns a comma-and-space-separated list of column names, allocated from table's internal