libsmartcols: add scols_table_move_column()
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
52f35f1ecc
commit
7bdefc7fc0
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -162,4 +162,5 @@ global:
|
|||
SMARTCOLS_2.30 {
|
||||
global:
|
||||
scols_cell_get_alignment;
|
||||
scols_table_move_column;
|
||||
} SMARTCOLS_2.29;
|
||||
|
|
|
@ -251,6 +251,38 @@ int scols_table_remove_columns(struct libscols_table *tb)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
Loading…
Reference in New Issue