From: Ondrej Oprala Date: Tue, 25 Mar 2014 09:24:13 +0000 (+0100) Subject: libsmartcols: move some code around X-Git-Tag: v2.25-rc1~368 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b72b824d06a03785494f026196241aa119e63c15;p=thirdparty%2Futil-linux.git libsmartcols: move some code around Signed-off-by: Ondrej Oprala --- diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in index 54a623c430..8130d62dcc 100644 --- a/libsmartcols/src/libsmartcols.h.in +++ b/libsmartcols/src/libsmartcols.h.in @@ -129,7 +129,7 @@ extern int scols_table_set_tree(struct libscols_table *tb, int enable); extern struct libscols_table *scols_new_table(struct libscols_symbols *syms); extern void scols_ref_table(struct libscols_table *tb); extern void scols_unref_table(struct libscols_table *tb); -extern int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl); +extern int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl, int flags); extern int scols_table_remove_column(struct libscols_table *tb, struct libscols_column *cl); extern int scols_table_remove_columns(struct libscols_table *tb); extern struct libscols_column *scols_table_new_column(struct libscols_table *tb, const char *name, double whint, int flags); diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index bbbd5a59de..6b4d9673eb 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -73,7 +73,7 @@ void scols_unref_table(struct libscols_table *tb) } } -int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl) +int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl, int flags) { assert(tb); assert(cl); @@ -81,6 +81,9 @@ int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl if (!tb || !cl || !list_empty(&tb->tb_lines)) return -EINVAL; + if (flags & SCOLS_FL_TREE) + scols_table_set_tree(tb, 1); + list_add_tail(&cl->cl_columns, &tb->tb_columns); cl->seqnum = tb->ncols++; scols_ref_column(cl); @@ -182,10 +185,7 @@ struct libscols_column *scols_table_new_column(struct libscols_table *tb, scols_column_set_whint(cl, whint); scols_column_set_flags(cl, flags); - if (flags & SCOLS_FL_TREE) - scols_table_set_tree(tb, 1); - - if (scols_table_add_column(tb, cl)) /* this increments column ref-counter */ + if (scols_table_add_column(tb, cl, flags)) /* this increments column ref-counter */ goto err; scols_unref_column(cl); @@ -453,7 +453,7 @@ struct libscols_table *scols_copy_table(struct libscols_table *tb) cl = scols_copy_column(cl); if (!cl) goto err; - if (scols_table_add_column(ret, cl)) + if (scols_table_add_column(ret, cl, tb->tree ? SCOLS_FL_TREE : 0)) goto err; scols_unref_column(cl); }