**/
const char * table_set_col_order_by_name(struct table *tbl, const char *col_order_str)
{
+ if(col_order_str[0] == '*') {
+ tbl->column_order = mp_alloc(tbl->pool, sizeof(int) * tbl->column_count);
+ tbl->cols_to_output = tbl->column_count;
+ for(uint i = 0; i < tbl->cols_to_output; i++) tbl->column_order[i] = i;
+
+ return NULL;
+ }
+
if(!col_order_str[0]) {
tbl->column_order = mp_alloc(tbl->pool, 0);
tbl->cols_to_output = 0;
} else if(strcmp(key, "fmt") == 0) {
if(strcmp(value, "human") == 0) table_set_formatter(tbl, &table_fmt_human_readable);
else if(strcmp(value, "machine") == 0) table_set_formatter(tbl, &table_fmt_machine_readable);
+ else if(strcmp(value, "blockline") == 0) table_set_formatter(tbl, &table_fmt_blockline);
else {
return "Tableprinter: invalid argument to output-type option.";
}
.table_start = table_start_machine_readable,
};
+
+/*** Blockline formatter ***/
+
+static void table_row_blockline_output(struct table *tbl)
+{
+ for(uint i = 0; i < tbl->cols_to_output; i++) {
+ int col_idx = tbl->column_order[i];
+ bprintf(tbl->out, "%s: %s\n", tbl->columns[col_idx].name, tbl->col_str_ptrs[col_idx]);
+ }
+ bputc(tbl->out, '\n');
+}
+
+static void table_start_blockline(struct table *tbl)
+{
+ if(tbl->col_delimiter == NULL) {
+ tbl->col_delimiter = " ";
+ }
+
+ if(tbl->append_delimiter == NULL) {
+ tbl->append_delimiter = ",";
+ }
+}
+
+struct table_formatter table_fmt_blockline = {
+ .row_output = table_row_blockline_output,
+ .table_start = table_start_blockline
+};
+
+
+
/*** Tests ***/
#ifdef TEST
#define TBL_APPEND_DELIMITER(_delimiter_) .append_delimiter = _delimiter_
#define TBL_OUTPUT_HUMAN_READABLE .formatter = &table_fmt_human_readable
+#define TBL_OUTPUT_BLOCKLINE .formatter = &table_fmt_blockline
#define TBL_OUTPUT_MACHINE_READABLE .formatter = &table_fmt_machine_readable
/***
// Standard formatters
extern struct table_formatter table_fmt_human_readable;
extern struct table_formatter table_fmt_machine_readable;
+extern struct table_formatter table_fmt_blockline;
/**
* Process the table one option and sets the values in @tbl according to the command-line parameters.