static void test_option_parser(struct table *tbl)
{
- tbl->formatter->process_option = user_defined_option;
+ struct table_formatter test_option_fmtr = table_fmt_human_readable;
+ test_option_fmtr.process_option = user_defined_option;
+
+ const struct table_formatter *tmp_fmtr = tbl->formatter;
+ tbl->formatter = &test_option_fmtr;
+
const char *rv = table_set_option(tbl, "invalid:option");
if(rv) printf("Tableprinter option parser returned error: \"%s\".\n", rv);
rv = table_set_option(tbl, "valuekey:value");
if(rv) printf("Tableprinter option parser returned error: \"%s\".\n", rv);
+
+ tbl->formatter = tmp_fmtr;
}
int main(int argc UNUSED, char **argv)
/*** Configuration ***/
-void table_set_formatter(struct table *tbl, struct table_formatter *fmt)
+void table_set_formatter(struct table *tbl, const struct table_formatter *fmt)
{
tbl->formatter = fmt;
}
}
}
-struct table_formatter table_fmt_human_readable = {
+const struct table_formatter table_fmt_human_readable = {
.row_output = table_row_human_readable,
.table_start = table_start_human_readable,
};
}
}
-struct table_formatter table_fmt_machine_readable = {
+const struct table_formatter table_fmt_machine_readable = {
.row_output = table_row_machine_readable,
.table_start = table_start_machine_readable,
};
}
}
-struct table_formatter table_fmt_blockline = {
+const struct table_formatter table_fmt_blockline = {
.row_output = table_row_blockline_output,
.table_start = table_start_blockline
};
// FIXME: update documentation according to the changes made in recent commits!
-/** Types of columns. These are seldom used explicitly, using a column definition macro is preferred. **/
+/** The COL_TYPE_ANY macro specifies a column type which can be filled with arbitrary type. **/
#define COL_TYPE_ANY NULL
uint cols_to_output; // [*] Number of columns that are printed
const char *col_delimiter; // [*] Delimiter that is placed between columns
// Back-end used for table formatting and its private data
- struct table_formatter *formatter; // FIXME: should be const?
+ const struct table_formatter *formatter; // FIXME: should be const?
};
/**
int col_out; // Index of the column that is currently printed using fb_col_out
// Back-end used for table formatting and its private data
- struct table_formatter *formatter;
+ const struct table_formatter *formatter;
void *data;
};
/**
* Sets table formatter. See below for the list of formatters.
**/
-void table_set_formatter(struct table *tbl, struct table_formatter *fmt);
+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,
};
/** Standard formatter for human-readable output. **/
-extern struct table_formatter table_fmt_human_readable;
+extern const struct table_formatter table_fmt_human_readable;
/** Standard formatter for machine-readable output (tab-separated values). **/
-extern struct table_formatter table_fmt_machine_readable;
+extern const struct table_formatter table_fmt_machine_readable;
/**
* Standard formatter for block output. Each cell is output on its own line
* of the form `column_name: value`. Rows are separated by blank lines.
**/
-extern struct table_formatter table_fmt_blockline;
+extern const struct table_formatter table_fmt_blockline;
#endif