lib/tt: add TT_FL_FREEDATA
... to call free() for line data. Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
2719215751
commit
f234cc3b51
|
@ -27,7 +27,9 @@ enum {
|
||||||
TT_FL_TREE = (1 << 6), /* use tree "ascii art" */
|
TT_FL_TREE = (1 << 6), /* use tree "ascii art" */
|
||||||
TT_FL_RIGHT = (1 << 7), /* align to the right */
|
TT_FL_RIGHT = (1 << 7), /* align to the right */
|
||||||
TT_FL_STRICTWIDTH = (1 << 8), /* don't reduce width if column is empty */
|
TT_FL_STRICTWIDTH = (1 << 8), /* don't reduce width if column is empty */
|
||||||
TT_FL_NOEXTREMES = (1 << 9) /* ignore extreme fields when count column width*/
|
TT_FL_NOEXTREMES = (1 << 9), /* ignore extreme fields when count column width*/
|
||||||
|
|
||||||
|
TT_FL_FREEDATA = (1 << 10), /* free() data in tt_free_table() */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tt {
|
struct tt {
|
||||||
|
@ -61,7 +63,7 @@ struct tt_column {
|
||||||
|
|
||||||
struct tt_line {
|
struct tt_line {
|
||||||
struct tt *table;
|
struct tt *table;
|
||||||
char const **data;
|
char **data;
|
||||||
void *userdata;
|
void *userdata;
|
||||||
size_t data_sz; /* strlen of all data */
|
size_t data_sz; /* strlen of all data */
|
||||||
|
|
||||||
|
@ -85,7 +87,7 @@ 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 struct tt_line *tt_add_line(struct tt *tb, struct tt_line *parent);
|
||||||
|
|
||||||
extern int tt_line_set_data(struct tt_line *ln, int colnum, const char *data);
|
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);
|
extern int tt_line_set_userdata(struct tt_line *ln, void *data);
|
||||||
|
|
||||||
extern void tt_fputs_quoted(const char *data, FILE *out);
|
extern void tt_fputs_quoted(const char *data, FILE *out);
|
||||||
|
|
10
lib/tt.c
10
lib/tt.c
|
@ -221,9 +221,17 @@ void tt_remove_lines(struct tt *tb)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (!list_empty(&tb->tb_lines)) {
|
while (!list_empty(&tb->tb_lines)) {
|
||||||
|
struct list_head *p;
|
||||||
struct tt_line *ln = list_entry(tb->tb_lines.next,
|
struct tt_line *ln = list_entry(tb->tb_lines.next,
|
||||||
struct tt_line, ln_lines);
|
struct tt_line, ln_lines);
|
||||||
list_del(&ln->ln_lines);
|
list_del(&ln->ln_lines);
|
||||||
|
|
||||||
|
list_for_each(p, &tb->tb_columns) {
|
||||||
|
struct tt_column *cl =
|
||||||
|
list_entry(p, struct tt_column, cl_columns);
|
||||||
|
if ((cl->flags & TT_FL_FREEDATA) || (tb->flags & TT_FL_FREEDATA))
|
||||||
|
free(ln->data[cl->seqnum]);
|
||||||
|
}
|
||||||
free(ln->data);
|
free(ln->data);
|
||||||
free(ln);
|
free(ln);
|
||||||
}
|
}
|
||||||
|
@ -360,7 +368,7 @@ struct tt_column *tt_get_column(struct tt *tb, size_t colnum)
|
||||||
*
|
*
|
||||||
* Stores data that will be printed to the table cell.
|
* Stores data that will be printed to the table cell.
|
||||||
*/
|
*/
|
||||||
int tt_line_set_data(struct tt_line *ln, int colnum, const char *data)
|
int tt_line_set_data(struct tt_line *ln, int colnum, char *data)
|
||||||
{
|
{
|
||||||
struct tt_column *cl;
|
struct tt_column *cl;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue