diff options
author | Karel Zak | 2017-03-29 14:06:37 +0200 |
---|---|---|
committer | Karel Zak | 2017-04-07 14:34:11 +0200 |
commit | 7bdefc7fc0c3c321363f8074f3ab1e2faaca6b2d (patch) | |
tree | f74e138427c06e029e414cfd4cd9bb20d977681c /libsmartcols | |
parent | libfdisk: (gpt) fix ents zeroize (diff) | |
download | kernel-qcow2-util-linux-7bdefc7fc0c3c321363f8074f3ab1e2faaca6b2d.tar.gz kernel-qcow2-util-linux-7bdefc7fc0c3c321363f8074f3ab1e2faaca6b2d.tar.xz kernel-qcow2-util-linux-7bdefc7fc0c3c321363f8074f3ab1e2faaca6b2d.zip |
libsmartcols: add scols_table_move_column()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols')
-rw-r--r-- | libsmartcols/docs/libsmartcols-sections.txt | 1 | ||||
-rw-r--r-- | libsmartcols/src/libsmartcols.h.in | 1 | ||||
-rw-r--r-- | libsmartcols/src/libsmartcols.sym | 1 | ||||
-rw-r--r-- | libsmartcols/src/table.c | 32 |
4 files changed, 35 insertions, 0 deletions
diff --git a/libsmartcols/docs/libsmartcols-sections.txt b/libsmartcols/docs/libsmartcols-sections.txt index 7e31cdda2..4be9bf22b 100644 --- a/libsmartcols/docs/libsmartcols-sections.txt +++ b/libsmartcols/docs/libsmartcols-sections.txt @@ -139,6 +139,7 @@ scols_table_is_nolinesep scols_table_is_nowrap scols_table_is_raw scols_table_is_tree +scols_table_move_column scols_table_new_column scols_table_new_line scols_table_next_column diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in index e9df9333c..4b2a67284 100644 --- a/libsmartcols/src/libsmartcols.h.in +++ b/libsmartcols/src/libsmartcols.h.in @@ -244,6 +244,7 @@ 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_remove_column(struct libscols_table *tb, struct libscols_column *cl); extern int scols_table_remove_columns(struct libscols_table *tb); +extern int scols_table_move_column(struct libscols_table *tb, struct libscols_column *pre, struct libscols_column *cl); extern struct libscols_column *scols_table_new_column(struct libscols_table *tb, const char *name, double whint, int flags); extern int scols_table_next_column(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_column **cl); extern const char *scols_table_get_column_separator(const struct libscols_table *tb); diff --git a/libsmartcols/src/libsmartcols.sym b/libsmartcols/src/libsmartcols.sym index b8a3a5b4c..917cca3d6 100644 --- a/libsmartcols/src/libsmartcols.sym +++ b/libsmartcols/src/libsmartcols.sym @@ -162,4 +162,5 @@ global: SMARTCOLS_2.30 { global: scols_cell_get_alignment; + scols_table_move_column; } SMARTCOLS_2.29; diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index f1ddacc9f..84c0f6a25 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -252,6 +252,38 @@ int scols_table_remove_columns(struct libscols_table *tb) } /** + * scols_table_move_column: + * @tb: table + * @pre: column before the column + * @cl: colum to move + * + * Move the @cl behind @pre. The the @pre is NULL then the @col is the fist + * column in the table. + * + * Returns: 0, a negative number in case of an error. + */ +int scols_table_move_column(struct libscols_table *tb, + struct libscols_column *pre, + struct libscols_column *cl) +{ + struct list_head *head; + struct libscols_iter itr; + size_t n = 0; + + list_del_init(&cl->cl_columns); /* remove from old position */ + + head = pre ? &pre->cl_columns : &tb->tb_columns; + list_add(&cl->cl_columns, head); /* add to the new place */ + + /* fix seq. numbers */ + scols_reset_iter(&itr, SCOLS_ITER_FORWARD); + while (scols_table_next_column(tb, &itr, &cl) == 0) + cl->seqnum = n++; + + return 0; +} + +/** * scols_table_new_column: * @tb: table * @name: column header |