]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: add scols_table_move_column()
authorKarel Zak <kzak@redhat.com>
Wed, 29 Mar 2017 12:06:37 +0000 (14:06 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 7 Apr 2017 12:34:11 +0000 (14:34 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/docs/libsmartcols-sections.txt
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/libsmartcols.sym
libsmartcols/src/table.c

index 7e31cdda24fcf6046787e11b97c51eeeac41ea7e..4be9bf22be17c4a954147f6594bca8b939db82c3 100644 (file)
@@ -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
index e9df9333c8a281bfb3a670ee8b3300bf96558404..4b2a67284e93690ae62560ebd357c2d8174a89fa 100644 (file)
@@ -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);
index b8a3a5b4c956274d8cc17048a2ba988c5c15409b..917cca3d6aafd44152ad20a48284dcd78644a110 100644 (file)
@@ -162,4 +162,5 @@ global:
 SMARTCOLS_2.30 {
 global:
        scols_cell_get_alignment;
+       scols_table_move_column;
 } SMARTCOLS_2.29;
index f1ddacc9f8549a18437b15a75807a0e163b4e1d8..84c0f6a25b9465df3753dbac1c3f7e7d78cb10fe 100644 (file)
@@ -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