From: Igor Gnatenko Date: Sat, 16 Jan 2016 21:51:52 +0000 (+0100) Subject: libsmartcols: reflect changinging SCOLS_FL_TREE after adding to table X-Git-Tag: v2.28-rc1~194^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d10fa7e6dd2b936edcfc5e6ab78687e60e57b46a;p=thirdparty%2Futil-linux.git libsmartcols: reflect changinging SCOLS_FL_TREE after adding to table When scols_column_set_flags() is called we will compare before & after status of SCOLS_FL_TREE flag and appropriately handle tb->ntreecols. Reference: https://github.com/karelzak/util-linux/issues/254 Signed-off-by: Igor Gnatenko --- diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c index 269ceea0c8..b31b39063f 100644 --- a/libsmartcols/src/column.c +++ b/libsmartcols/src/column.c @@ -157,6 +157,13 @@ int scols_column_set_flags(struct libscols_column *cl, int flags) if (!cl) return -EINVAL; + if (cl->table) { + if (!(cl->flags & SCOLS_FL_TREE) && (flags & SCOLS_FL_TREE)) + cl->table->ntreecols++; + else if ((cl->flags & SCOLS_FL_TREE) && !(flags & SCOLS_FL_TREE)) + cl->table->ntreecols--; + } + cl->flags = flags; return 0; } diff --git a/libsmartcols/src/smartcolsP.h b/libsmartcols/src/smartcolsP.h index 163417707e..9f63c3ad1e 100644 --- a/libsmartcols/src/smartcolsP.h +++ b/libsmartcols/src/smartcolsP.h @@ -89,6 +89,8 @@ struct libscols_column { struct libscols_cell header; struct list_head cl_columns; + + struct libscols_table *table; }; /* diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index cb4cfae0d3..3360d525bc 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -141,6 +141,7 @@ int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl DBG(TAB, ul_debugobj(tb, "add column %p", cl)); list_add_tail(&cl->cl_columns, &tb->tb_columns); cl->seqnum = tb->ncols++; + cl->table = tb; scols_ref_column(cl); /* TODO: @@ -173,6 +174,7 @@ int scols_table_remove_column(struct libscols_table *tb, DBG(TAB, ul_debugobj(tb, "remove column %p", cl)); list_del_init(&cl->cl_columns); tb->ncols--; + cl->table = NULL; scols_unref_column(cl); return 0; }