// instance to which the @col_opt is set. Return value is the error string.
};
+/**
+ * Definition of a column instance. The table_col_instance belongs to a struct table. col_def is
+ * pointing to a definition of the column in struct table::columns. The user can fill only the @idx
+ * and @fmt. The @col_def, @cell_content, @next_column are private fields.
+ *
+ * Please use only fields marked with `[*]`.
+ **/
struct table_col_instance {
- uint idx; // idx is a index into struct table::columns
+ uint idx; // [*] idx is a index into struct table::columns
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
};
/**
* * `TBL_COL_`'type'`_FMT(name, width, fmt)` defines a column with a custom format string
* * `TBL_COL_END` ends the column definitions
* * `TBL_COL_ORDER` specifies custom ordering of columns in the output
- * * `TBL_COL_DELIMITER` and `TBL_APPEND_DELIMITER` override default delimiters
+ * * `TBL_COL_DELIMITER` overrides the default delimiter
* * `TBL_FMT_HUMAN_READABLE` requests human-readable formatting (this is the default)
* * `TBL_FMT_MACHINE_READABLE` requests machine-readable TSV output
* * `TBL_FMT_BLOCKLINE` requests block formatting (each cell printed a pair of a key and value on its own line)
**/
#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_COL_ORDER_END { .col_def = 0, .idx = (uint) ~0, .fmt = 0, .next_column = -1 }
+#define TBL_COL_ORDER_END { .col_def = 0, .idx = ~0U, .fmt = 0, .next_column = -1 }
/**
* These macros are aliases to various kinds of table formats.
* to the `value`
***/
-
#define TABLE_COL_PROTO(_name, _type) void table_col_##_name(struct table *tbl, int col, _type val);
TABLE_COL_PROTO(int, int)
int table_get_col_idx(struct table *tbl, const char *col_name);
/**
- * Sets a string option to an instance of a column 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.
+ * Sets a string option on a column instance.
+ *
+ * By default, the option is parsed as a formatting mode of the corresponding <<xtypes:,xtype>>
+ * using <<xtypes:fun_xtype_parse_fmt,`xtype_parse_fmt()`>>.
*
- * Each struct table_column has a pointer to a customized version of table_set_col_opt (called
- * set_col_opt). The hook set_call_opt should be always called through @table_set_col_opt. The hook
- * and @table_set_col_opt has the same prototype, but @table_set_col_opt should never be used as the
- * table_set_opt hook.
+ * As special cases might require special handling (e.g., column decoration, post-processing, etc.),
+ * a column can define a `set_col_opt` hook, which takes over option parsing. (Beware, the hook must
+ * not be called directly and it must not call this function.)
+ *
+ * See <<ucw-tableprinter.5:,the list of options>> for more.
**/
const char *table_set_col_opt(struct table *tbl, uint col_inst_idx, const char *col_opt);
* names. Returns NULL for success and an error message otherwise. The string is not referenced after
* this function returns.
*
- * The format of the col_order string is the following:
- * <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 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
+ * See <<ucw-tableprinter.5:,the list of options>> for full syntax.
**/
const char *table_set_col_order_by_name(struct table *tbl, const char *col_order);
/**
- * Returns true if col_idx will be printed, false otherwise.
+ * Returns true if @col_def_idx will be printed, false otherwise.
**/
bool table_col_is_printed(struct table *tbl, uint col_def_idx);
void table_set_formatter(struct table *tbl, const struct table_formatter *fmt);
/**
- * Set a table option. All options have a key and a value. Currently,
- * the following keys are defined (other keys can be accepted by formatters):
- *
- * [options="header"]
- * |===================================================================================================
- * | key | value | meaning
- * | `header` | 0 or 1 | set whether a table header should be printed
- * | `noheader` | 'none' | equivalent to `header`=0
- * | `cols` | comma-separated column list | set order of columns
- * | `fmt` | `human`/`machine`/`block` | set table formatter to one of the built-in formatters
- * | `col-delim`| string | set column delimiter
- * | `cells` | string | set column format mode
- * | `raw` | 'none' | set column format to raw data
- * | `pretty` | 'none' | set column format to pretty-printing
- * |===================================================================================================
+ * Set a table option. All options have a key and a value.
+ * See <<ucw-tableprinter.5:,the list of options>>.
**/
const char *table_set_option_value(struct table *tbl, const char *key, const char *value);