2 * UCW Library -- Table printer
4 * (c) 2014 Robert Kessl <robert.kessl@economia.cz>
8 #include <ucw/string.h>
9 #include <ucw/stkstring.h>
11 #include <ucw/table.h>
12 #include <ucw/strtonum.h>
17 /* Forward declarations */
19 static void table_update_ll(struct table *tbl);
21 /*** Management of tables ***/
23 void table_init(struct table *tbl)
25 int col_count = 0; // count the number of columns in the struct table
28 if(tbl->columns[col_count].name == NULL &&
29 tbl->columns[col_count].fmt == NULL &&
30 tbl->columns[col_count].width == 0 &&
31 tbl->columns[col_count].type == COL_TYPE_LAST)
33 ASSERT(tbl->columns[col_count].name != NULL);
34 ASSERT(tbl->columns[col_count].type == COL_TYPE_ANY || tbl->columns[col_count].fmt != NULL);
35 ASSERT(tbl->columns[col_count].width != 0);
39 tbl->pool = mp_new(4096);
41 tbl->column_count = col_count;
44 tbl->formatter = &table_fmt_human_readable;
47 tbl->print_header = 1; // by default, print header
50 void table_cleanup(struct table *tbl)
53 memset(tbl, 0, sizeof(struct table));
56 // TODO: test default column order
57 static void table_make_default_column_order(struct table *tbl)
59 int *col_order_int = mp_alloc_zero(tbl->pool, sizeof(int) * tbl->column_count);
60 for(int i = 0; i < tbl->column_count; i++) {
63 table_set_col_order(tbl, col_order_int, tbl->column_count);
66 void table_start(struct table *tbl, struct fastbuf *out)
68 tbl->last_printed_col = -1;
69 tbl->row_printing_started = 0;
72 ASSERT_MSG(tbl->out, "Output fastbuf not specified.");
74 if(tbl->column_order == NULL) table_make_default_column_order(tbl);
76 // update linked lists
79 if(tbl->formatter->table_start != NULL) tbl->formatter->table_start(tbl);
81 mp_save(tbl->pool, &tbl->pool_state);
83 ASSERT_MSG(tbl->col_delimiter, "In-between column delimiter not specified.");
86 void table_end(struct table *tbl)
88 tbl->last_printed_col = -1;
89 tbl->row_printing_started = 0;
91 mp_restore(tbl->pool, &tbl->pool_state);
93 if(tbl->formatter->table_end) tbl->formatter->table_end(tbl);
96 /*** Configuration ***/
98 void table_set_formatter(struct table *tbl, struct table_formatter *fmt)
100 tbl->formatter = fmt;
103 int table_get_col_idx(struct table *tbl, const char *col_name)
105 for(int i = 0; i < tbl->column_count; i++) {
106 if(strcmp(tbl->columns[i].name, col_name) == 0) return i;
111 const char * table_get_col_list(struct table *tbl)
113 if(tbl->column_count == 0) return "";
115 char *tmp = mp_strdup(tbl->pool, tbl->columns[0].name);
117 for(int i = 1; i < tbl->column_count; i++) {
118 tmp = mp_printf_append(tbl->pool, tmp, ", %s", tbl->columns[i].name);
124 static void table_update_ll(struct table *tbl)
126 int cols_to_output = tbl->cols_to_output;
128 for(int i = 0; i < tbl->column_count; i++) {
129 tbl->columns[i].first_column = -1;
130 tbl->columns[i].last_column = -1;
133 for(int i = 0; i < cols_to_output; i++) {
134 int col_idx = tbl->column_order[i].idx;
135 int last = tbl->columns[col_idx].last_column;
137 tbl->columns[col_idx].last_column = i;
138 tbl->column_order[last].next_column = i;
140 tbl->columns[col_idx].last_column = i;
141 tbl->columns[col_idx].first_column = i;
143 tbl->column_order[i].next_column = -1;
147 void table_set_col_order(struct table *tbl, int *col_order, int cols_to_output)
149 for(int i = 0; i < cols_to_output; i++) {
150 ASSERT_MSG(col_order[i] >= 0 && col_order[i] < tbl->column_count, "Column %d does not exist (column number should be between 0 and %d)", col_order[i], tbl->column_count - 1);
153 tbl->cols_to_output = cols_to_output;
154 tbl->column_order = mp_alloc_zero(tbl->pool, sizeof(struct table_col_info) * cols_to_output);
155 for(int i = 0; i < cols_to_output; i++) {
156 int col_idx = col_order[i];
157 tbl->column_order[i].idx = col_idx;
158 tbl->column_order[i].cell_content = NULL;
159 tbl->column_order[i].output_type = CELL_OUT_UNINITIALIZED;
161 table_update_ll(tbl);
164 bool table_col_is_printed(struct table *tbl, uint col_idx)
166 if(tbl->columns[col_idx].first_column == -1) return 0;
171 static char * table_parse_col_arg(char *col_def)
173 // FIXME: should be switched to str_sepsplit
174 char * left_br = strchr(col_def, '[');
175 if(left_br == NULL) return NULL;
178 char *right_br = strchr(left_br, ']');
185 * Setting options for basic table types (as defined in table.h)
187 bool table_set_col_opt_default(struct table *tbl, int col_copy_idx, const char *col_arg, char **err)
189 int col_type_idx = tbl->column_order[col_copy_idx].idx;
191 if(tbl->columns[col_type_idx].type == COL_TYPE_DOUBLE) {
193 str_to_uint(&precision, col_arg, NULL, 0);
194 tbl->column_order[col_type_idx].output_type = precision;
198 *err = mp_printf(tbl->pool, "Tableprinter: invalid column format option: '%s' for column %d.", col_arg, col_copy_idx);
203 * TODO: This function deliberately leaks memory. When it is called multiple times,
204 * previous column orders still remain allocated in the table's memory pool.
206 const char * table_set_col_order_by_name(struct table *tbl, const char *col_order_str)
208 if(col_order_str[0] == '*') {
209 int *col_order_int = alloca(sizeof(int) * tbl->column_count);
210 for(int i = 0; i < tbl->column_count; i++) {
211 col_order_int[i] = i;
213 table_set_col_order(tbl, col_order_int, tbl->column_count);
218 if(!col_order_str[0]) {
219 tbl->column_order = mp_alloc(tbl->pool, 0);
220 tbl->cols_to_output = 0;
224 char *tmp_col_order = stk_strdup(col_order_str);
227 for(int i = 0; col_order_str[i] != 0; i++) {
228 if(col_order_str[i] == ',') {
233 tbl->cols_to_output = col_count;
234 tbl->column_order = mp_alloc_zero(tbl->pool, sizeof(struct table_col_info) * col_count);
236 int curr_col_idx = 0;
237 char *name_start = tmp_col_order;
239 char *next = strchr(name_start, ',');
244 char *arg = table_parse_col_arg(name_start); // this sets 0 on the '['
245 int col_idx = table_get_col_idx(tbl, name_start);
247 return mp_printf(tbl->pool, "Unknown table column '%s', possible column names are: %s.", name_start, table_get_col_list(tbl));
249 tbl->column_order[curr_col_idx].idx = col_idx;
250 tbl->column_order[curr_col_idx].cell_content = NULL;
251 tbl->column_order[curr_col_idx].output_type = CELL_OUT_UNINITIALIZED;
252 if(tbl->formatter && tbl->formatter->set_col_instance_option) {
254 tbl->formatter->set_col_instance_option(tbl, curr_col_idx, arg, &err);
262 table_update_ll(tbl);
267 /*** Table cells ***/
269 static void table_set_all_cols_content(struct table *tbl, int col, char *col_content, int override)
271 int curr_col = tbl->columns[col].first_column;
272 while(curr_col != -1) {
273 if(override == 0 && tbl->column_order[curr_col].output_type != CELL_OUT_UNINITIALIZED ) {
274 die("Error while setting content of all cells of a single type column, cell format should not be overriden.");
276 tbl->column_order[curr_col].cell_content = col_content;
277 curr_col = tbl->column_order[curr_col].next_column;
281 void table_col_printf(struct table *tbl, int col, const char *fmt, ...)
283 ASSERT_MSG(col < tbl->column_count && col >= 0, "Table column %d does not exist.", col);
284 tbl->last_printed_col = col;
285 tbl->row_printing_started = 1;
288 char *cell_content = mp_vprintf(tbl->pool, fmt, args);
289 table_set_all_cols_content(tbl, col, cell_content, 1);
293 static const char *table_col_default_fmts[] = {
294 [COL_TYPE_STR] = "%s",
295 [COL_TYPE_INT] = "%d",
296 [COL_TYPE_S64] = "%lld",
297 [COL_TYPE_INTMAX] = "%jd",
298 [COL_TYPE_UINT] = "%u",
299 [COL_TYPE_U64] = "%llu",
300 [COL_TYPE_UINTMAX] = "%ju",
301 [COL_TYPE_BOOL] = "%d",
302 [COL_TYPE_DOUBLE] = "%.2lf",
303 [COL_TYPE_ANY] = NULL,
304 [COL_TYPE_LAST] = NULL
307 #define TABLE_COL(_name_, _type_, _typeconst_) void table_col_##_name_(struct table *tbl, int col, _type_ val)\
309 const char *fmt = tbl->columns[col].fmt;\
310 if(tbl->columns[col].type == COL_TYPE_ANY) {\
311 fmt = table_col_default_fmts[_typeconst_];\
313 table_col_##_name_##_fmt(tbl, col, fmt, val);\
316 #define TABLE_COL_STR(_name_, _type_, _typeconst_) void table_col_##_name_##_name(struct table *tbl, const char *col_name, _type_ val)\
318 int col = table_get_col_idx(tbl, col_name);\
319 table_col_##_name_(tbl, col, val);\
322 #define TABLE_COL_FMT(_name_, _type_, _typeconst_) void table_col_##_name_##_fmt(struct table *tbl, int col, const char *fmt, _type_ val)\
324 ASSERT_MSG(col < tbl->column_count && col >= 0, "Table column %d does not exist.", col);\
325 ASSERT(tbl->columns[col].type == COL_TYPE_ANY || _typeconst_ == tbl->columns[col].type);\
326 ASSERT(fmt != NULL);\
327 tbl->last_printed_col = col;\
328 tbl->row_printing_started = 1;\
329 char *cell_content = mp_printf(tbl->pool, fmt, val);\
330 table_set_all_cols_content(tbl, col, cell_content, 0);\
333 #define TABLE_COL_BODIES(_name_, _type_, _typeconst_) TABLE_COL(_name_, _type_, _typeconst_);\
334 TABLE_COL_STR(_name_, _type_, _typeconst_);\
335 TABLE_COL_FMT(_name_, _type_, _typeconst_);
337 TABLE_COL_BODIES(int, int, COL_TYPE_INT)
338 TABLE_COL_BODIES(uint, uint, COL_TYPE_UINT)
339 TABLE_COL_BODIES(str, const char *, COL_TYPE_STR)
340 TABLE_COL_BODIES(intmax, intmax_t, COL_TYPE_INTMAX)
341 TABLE_COL_BODIES(uintmax, uintmax_t, COL_TYPE_UINTMAX)
342 TABLE_COL_BODIES(s64, s64, COL_TYPE_S64)
343 TABLE_COL_BODIES(u64, u64, COL_TYPE_U64)
345 // column type double is a special case
346 TABLE_COL(double, double, COL_TYPE_DOUBLE);
347 TABLE_COL_STR(double, double, COL_TYPE_DOUBLE);
351 #undef TABLE_COL_BODIES
353 void table_col_double_fmt(struct table *tbl, int col, const char *fmt, double val)
355 ASSERT_MSG(col < tbl->column_count && col >= 0, "Table column %d does not exist.", col);
356 ASSERT(tbl->columns[col].type == COL_TYPE_ANY || COL_TYPE_DOUBLE == tbl->columns[col].type);
358 tbl->last_printed_col = col;
359 tbl->row_printing_started = 1;
360 char *cell_content = mp_printf(tbl->pool, fmt, val);
361 int curr_col = tbl->columns[col].first_column;
362 while(curr_col != -1) {
363 if(tbl->column_order[curr_col].output_type < 0) tbl->column_order[curr_col].cell_content = cell_content;
365 char *cell_content_tmp = mp_printf(tbl->pool, "%.*lf", tbl->column_order[curr_col].output_type, val);
366 tbl->column_order[curr_col].cell_content = cell_content_tmp;
368 curr_col = tbl->column_order[curr_col].next_column;
372 void table_col_bool(struct table *tbl, int col, uint val)
374 table_col_bool_fmt(tbl, col, tbl->columns[col].fmt, val);
377 void table_col_bool_name(struct table *tbl, const char *col_name, uint val)
379 int col = table_get_col_idx(tbl, col_name);
380 table_col_bool(tbl, col, val);
383 void table_col_bool_fmt(struct table *tbl, int col, const char *fmt, uint val)
385 ASSERT_MSG(col < tbl->column_count && col >= 0, "Table column %d does not exist.", col);
386 ASSERT(COL_TYPE_BOOL == tbl->columns[col].type);
388 tbl->last_printed_col = col;
389 tbl->row_printing_started = 1;
391 int curr_col = tbl->columns[col].first_column;
392 while(curr_col != -1) {
393 switch(tbl->column_order[curr_col].output_type) {
394 case CELL_OUT_HUMAN_READABLE:
395 case CELL_OUT_UNINITIALIZED:
396 tbl->column_order[curr_col].cell_content = mp_printf(tbl->pool, fmt, val ? "true" : "false");
398 case CELL_OUT_MACHINE_READABLE:
399 // FIXME: this is just an example of printing in different formats
400 tbl->column_order[curr_col].cell_content = mp_printf(tbl->pool, fmt, val ? "1" : "0");
403 die("Unsupported output type.");
405 curr_col = tbl->column_order[curr_col].next_column;
408 // FIXME: add to printing of all columns
411 void table_reset_row(struct table *tbl)
413 for(uint i = 0; i < tbl->cols_to_output; i++) {
414 tbl->column_order[i].cell_content = NULL;
416 mp_restore(tbl->pool, &tbl->pool_state);
417 tbl->last_printed_col = -1;
418 tbl->row_printing_started = 0;
421 void table_end_row(struct table *tbl)
423 ASSERT(tbl->formatter->row_output);
424 if(tbl->row_printing_started == 0) return;
425 tbl->formatter->row_output(tbl);
426 table_reset_row(tbl);
429 /* Construction of a cell using a fastbuf */
431 struct fastbuf *table_col_fbstart(struct table *tbl, int col)
433 fbpool_init(&tbl->fb_col_out);
434 fbpool_start(&tbl->fb_col_out, tbl->pool, 1);
436 return &tbl->fb_col_out.fb;
439 void table_col_fbend(struct table *tbl)
441 char *cell_content = fbpool_end(&tbl->fb_col_out);
442 table_set_all_cols_content(tbl, tbl->col_out, cell_content, 1);
446 /*** Option parsing ***/
448 const char *table_set_option_value(struct table *tbl, const char *key, const char *value)
450 // Options with no value
451 if(value == NULL || (value != NULL && strlen(value) == 0)) {
452 if(strcmp(key, "noheader") == 0) {
453 tbl->print_header = 0;
458 // Options with a value
460 if(strcmp(key, "header") == 0) {
462 return mp_printf(tbl->pool, "Tableprinter: invalid option: '%s' has invalid value: '%s'.", key, value);
463 uint tmp = value[0] - '0';
465 return mp_printf(tbl->pool, "Tableprinter: invalid option: '%s' has invalid value: '%s'.", key, value);
466 tbl->print_header = tmp;
468 } else if(strcmp(key, "cols") == 0) {
469 const char *err = table_set_col_order_by_name(tbl, value);
474 } else if(strcmp(key, "fmt") == 0) {
475 if(strcmp(value, "human") == 0) table_set_formatter(tbl, &table_fmt_human_readable);
476 else if(strcmp(value, "machine") == 0) table_set_formatter(tbl, &table_fmt_machine_readable);
477 else if(strcmp(value, "blockline") == 0) table_set_formatter(tbl, &table_fmt_blockline);
479 return "Tableprinter: invalid argument to output-type option.";
482 } else if(strcmp(key, "col-delim") == 0) {
483 char * d = mp_printf(tbl->pool, "%s", value);
484 tbl->col_delimiter = d;
490 if(tbl->formatter && tbl->formatter->process_option) {
491 const char *err = NULL;
492 if(tbl->formatter->process_option(tbl, key, value, &err)) {
497 // Unrecognized option
498 return mp_printf(tbl->pool, "Tableprinter: invalid option: '%s%s%s'.", key, (value ? ":" : ""), (value ? : ""));
501 const char *table_set_option(struct table *tbl, const char *opt)
503 char *key = stk_strdup(opt);
504 char *value = strchr(key, ':');
508 return table_set_option_value(tbl, key, value);
511 const char *table_set_gary_options(struct table *tbl, char **gary_table_opts)
513 for (uint i = 0; i < GARY_SIZE(gary_table_opts); i++) {
514 const char *rv = table_set_option(tbl, gary_table_opts[i]);
522 /*** Default formatter for human-readable output ***/
524 static void table_row_human_readable(struct table *tbl)
526 for(uint i = 0; i < tbl->cols_to_output; i++) {
527 int col_idx = tbl->column_order[i].idx;
529 bputs(tbl->out, tbl->col_delimiter);
531 int col_width = tbl->columns[col_idx].width & CELL_WIDTH_MASK;
532 if(tbl->columns[col_idx].width & CELL_ALIGN_LEFT) col_width = -1 * col_width;
533 bprintf(tbl->out, "%*s", col_width, tbl->column_order[i].cell_content);
535 bputc(tbl->out, '\n');
538 static void table_write_header(struct table *tbl)
540 for(uint i = 0; i < tbl->cols_to_output; i++) {
541 int col_idx = tbl->column_order[i].idx;
543 bputs(tbl->out, tbl->col_delimiter);
545 int col_width = tbl->columns[col_idx].width & CELL_WIDTH_MASK;
546 if(tbl->columns[col_idx].width & CELL_ALIGN_LEFT) col_width = -1 * col_width;
547 bprintf(tbl->out, "%*s", col_width, tbl->columns[col_idx].name);
549 bputc(tbl->out, '\n');
552 static void table_start_human_readable(struct table *tbl)
554 if(tbl->col_delimiter == NULL) {
555 tbl->col_delimiter = " ";
558 if(tbl->print_header != 0) {
559 table_write_header(tbl);
563 struct table_formatter table_fmt_human_readable = {
564 .row_output = table_row_human_readable,
565 .table_start = table_start_human_readable,
568 /*** Default formatter for machine-readable output ***/
570 static void table_row_machine_readable(struct table *tbl)
572 for(uint i = 0; i < tbl->cols_to_output; i++) {
574 bputs(tbl->out, tbl->col_delimiter);
576 bputs(tbl->out, tbl->column_order[i].cell_content);
578 bputc(tbl->out, '\n');
581 static void table_start_machine_readable(struct table *tbl)
583 if(tbl->col_delimiter == NULL) {
584 tbl->col_delimiter = "\t";
587 if(tbl->print_header != 0) {
588 uint col_idx = tbl->column_order[0].idx;
589 bputs(tbl->out, tbl->columns[col_idx].name);
590 for(uint i = 1; i < tbl->cols_to_output; i++) {
591 col_idx = tbl->column_order[i].idx;
592 bputs(tbl->out, tbl->col_delimiter);
593 bputs(tbl->out, tbl->columns[col_idx].name);
595 bputc(tbl->out, '\n');
599 struct table_formatter table_fmt_machine_readable = {
600 .row_output = table_row_machine_readable,
601 .table_start = table_start_machine_readable,
605 /*** Blockline formatter ***/
607 static void table_row_blockline_output(struct table *tbl)
609 for(uint i = 0; i < tbl->cols_to_output; i++) {
610 int col_idx = tbl->column_order[i].idx;
611 bprintf(tbl->out, "%s: %s\n", tbl->columns[col_idx].name, tbl->column_order[i].cell_content);
613 bputc(tbl->out, '\n');
616 static void table_start_blockline(struct table *tbl)
618 if(tbl->col_delimiter == NULL) {
619 tbl->col_delimiter = "\n";
623 struct table_formatter table_fmt_blockline = {
624 .row_output = table_row_blockline_output,
625 .table_start = table_start_blockline
636 enum test_table_cols {
637 test_col0_str, test_col1_int, test_col2_uint, test_col3_bool, test_col4_double
640 static struct table_col_info test_column_order[] = { TBL_COL(test_col3_bool), TBL_COL(test_col4_double), TBL_COL(test_col2_uint), TBL_COL(test_col1_int), TBL_COL(test_col0_str) };
642 static struct table test_tbl = {
644 [test_col0_str] = TBL_COL_STR("col0_str", 20),
645 [test_col1_int] = TBL_COL_INT("col1_int", 8),
646 [test_col2_uint] = TBL_COL_UINT("col2_uint", 9),
647 [test_col3_bool] = TBL_COL_BOOL("col3_bool", 9),
648 [test_col4_double] = TBL_COL_DOUBLE("col4_double", 11, 2),
651 TBL_COL_ORDER(test_column_order),
652 TBL_OUTPUT_HUMAN_READABLE,
653 TBL_COL_DELIMITER("\t"),
657 * tests: table_set_nt, table_set_uint, table_set_bool, table_set_double, table_set_printf
659 static void do_print1(struct table *test_tbl)
661 table_col_str(test_tbl, test_col0_str, "sdsdf");
662 table_col_int(test_tbl, test_col1_int, -10);
663 table_col_int(test_tbl, test_col1_int, 10000);
664 table_col_uint(test_tbl, test_col2_uint, 10);
665 table_col_printf(test_tbl, test_col2_uint, "XXX-%u", 22222);
666 table_col_bool(test_tbl, test_col3_bool, 1);
667 table_col_double(test_tbl, test_col4_double, 1.5);
668 table_col_printf(test_tbl, test_col4_double, "AAA");
669 table_end_row(test_tbl);
671 table_col_str(test_tbl, test_col0_str, "test");
672 table_col_int(test_tbl, test_col1_int, -100);
673 table_col_uint(test_tbl, test_col2_uint, 100);
674 table_col_bool(test_tbl, test_col3_bool, 0);
675 table_col_printf(test_tbl, test_col4_double, "%.2lf", 1.5);
676 table_end_row(test_tbl);
679 static void test_simple1(struct fastbuf *out)
681 table_init(&test_tbl);
683 // print table with header
684 table_set_col_order_by_name(&test_tbl, "col3_bool");
685 table_start(&test_tbl, out);
686 do_print1(&test_tbl);
687 table_end(&test_tbl);
689 // print the same table as in the previous case without header
690 table_set_col_order_by_name(&test_tbl, "col0_str,col2_uint,col1_int,col3_bool");
691 table_start(&test_tbl, out);
692 do_print1(&test_tbl);
693 table_end(&test_tbl);
695 // this also tests whether there is need to call table_set_col_order_by_name after table_end was called
696 test_tbl.print_header = 0;
697 table_start(&test_tbl, out);
698 do_print1(&test_tbl);
699 table_end(&test_tbl);
700 test_tbl.print_header = 1;
702 table_set_col_order_by_name(&test_tbl, "col3_bool");
703 table_start(&test_tbl, out);
704 do_print1(&test_tbl);
705 table_end(&test_tbl);
707 table_set_col_order_by_name(&test_tbl, "col3_bool,col0_str");
708 table_start(&test_tbl, out);
709 do_print1(&test_tbl);
710 table_end(&test_tbl);
712 table_set_col_order_by_name(&test_tbl, "col0_str,col3_bool,col2_uint");
713 table_start(&test_tbl, out);
714 do_print1(&test_tbl);
715 table_end(&test_tbl);
717 table_set_col_order_by_name(&test_tbl, "col0_str,col3_bool,col2_uint,col0_str,col3_bool,col2_uint,col0_str,col3_bool,col2_uint");
718 table_start(&test_tbl, out);
719 do_print1(&test_tbl);
720 table_end(&test_tbl);
722 table_set_col_order_by_name(&test_tbl, "col0_str,col1_int,col2_uint,col3_bool,col4_double");
723 table_start(&test_tbl, out);
724 do_print1(&test_tbl);
725 table_end(&test_tbl);
727 table_cleanup(&test_tbl);
730 enum test_any_table_cols {
731 test_any_col0_int, test_any_col1_any
734 static struct table_col_info test_any_column_order[] = { TBL_COL(test_any_col0_int), TBL_COL(test_any_col1_any) };
736 static struct table test_any_tbl = {
738 [test_any_col0_int] = TBL_COL_INT("col0_int", 8),
739 [test_any_col1_any] = TBL_COL_ANY("col1_any", 9),
742 TBL_COL_ORDER(test_any_column_order),
743 TBL_OUTPUT_HUMAN_READABLE,
744 TBL_COL_DELIMITER("\t"),
747 static void test_any_type(struct fastbuf *out)
749 table_init(&test_any_tbl);
751 table_start(&test_any_tbl, out);
753 table_col_int(&test_any_tbl, test_any_col0_int, -10);
754 table_col_int(&test_any_tbl, test_any_col1_any, 10000);
755 table_end_row(&test_any_tbl);
757 table_col_int(&test_any_tbl, test_any_col0_int, -10);
758 table_col_double(&test_any_tbl, test_any_col1_any, 1.4);
759 table_end_row(&test_any_tbl);
761 table_col_printf(&test_any_tbl, test_any_col0_int, "%d", 10);
762 table_col_double(&test_any_tbl, test_any_col1_any, 1.4);
763 table_end_row(&test_any_tbl);
765 table_end(&test_any_tbl);
766 table_cleanup(&test_any_tbl);
769 int main(int argc UNUSED, char **argv UNUSED)
772 out = bfdopen_shared(1, 4096);