int first_run;
struct list_head tb_columns;
- struct list_head tb_lines;
+ struct list_head tb_lines; /* lines as specified by user */
+ struct list_head tb_output; /* lines in output order */
const struct tt_symbols *symbols;
};
size_t data_sz; /* strlen of all data */
struct list_head ln_lines; /* table lines */
+ struct list_head ln_output; /* lines in output order */
struct list_head ln_branch; /* begin of branch (head of ln_children) */
struct list_head ln_children;
extern struct tt_column *tt_get_column(struct tt *tb, size_t colnum);
extern struct tt_line *tt_add_line(struct tt *tb, struct tt_line *parent);
+extern int tt_get_output_line(struct tt *tb, int i, struct tt_line **ln);
extern int tt_line_set_data(struct tt_line *ln, int colnum, char *data);
extern int tt_line_set_userdata(struct tt_line *ln, void *data);
tb->flags = flags;
tb->out = stdout;
INIT_LIST_HEAD(&tb->tb_lines);
+ INIT_LIST_HEAD(&tb->tb_output);
INIT_LIST_HEAD(&tb->tb_columns);
#if defined(HAVE_WIDECHAR)
ln->table = tb;
ln->parent = parent;
INIT_LIST_HEAD(&ln->ln_lines);
+ INIT_LIST_HEAD(&ln->ln_output);
INIT_LIST_HEAD(&ln->ln_children);
INIT_LIST_HEAD(&ln->ln_branch);
static void print_line(struct tt_line *ln, char *buf, size_t bufsz)
{
struct list_head *p;
+ struct tt *tb = ln->table;
/* set width according to the size of data
*/
print_data(ln->table, cl, line_get_data(ln, cl, buf, bufsz));
}
- fputc('\n', ln->table->out);
+ fputc('\n', tb->out);
+ list_add_tail(&ln->ln_output, &tb->tb_output);
}
static void print_header(struct tt *tb, char *buf, size_t bufsz)
return 0;
}
+int tt_get_output_line(struct tt *tb, int i, struct tt_line **ln)
+{
+ struct list_head *p;
+
+ if (!tb || !ln)
+ return -EINVAL;
+
+ list_for_each(p, &tb->tb_output) {
+ *ln = list_entry(p, struct tt_line, ln_output);
+ if (i-- == 0)
+ return 0;
+ }
+
+ return -1;
+}
/*
* @tb: table