newly implemented functions are: extern int scols_table_is_namesort(struct libscols_table *tb); extern int scols_table_is_sizesort(struct libscols_table *tb); extern int scols_table_enable_namesort(struct libscols_table *tb, int enable); extern int scols_table_enable_sizesort(struct libscols_table *tb, int enable); Signed-off-by: Shakur Shams Mullick <shakursmullick@xxxxxxxxx> --- libsmartcols/src/table.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index d4c61ee..224e7b9 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -707,6 +707,51 @@ int scols_table_enable_raw(struct libscols_table *tb, int enable) tb->format = 0; return 0; } +/** + * scols_table_enable_namesort: + * @tb: table + * @enable: 1 or 0 + * + * Enable/disable sorted by name output format. + * + * Returns: 0 on success, negative number in case of an error. + */ + +int scols_table_enable_namesort(struct libscols_table *tb, int enable) +{ + assert(tb); + if (!tb) + return -EINVAL; + + if (enable) + tb->sort = SCOLS_SORT_NAME; + else if (tb->sort == SCOLS_SORT_NAME) + tb->sort = 0; + return 0; +} + +/** + * scols_table_enable_sizesort: + * @tb: table + * @enable: 1 or 0 + * + * Enable/disable sorted by size output format. + * + * Returns: 0 on success, negative number in case of an error. + */ + +int scols_table_enable_sizesort(struct libscols_table *tb, int enable) +{ + assert(tb); + if (!tb) + return -EINVAL; + + if (enable) + tb->sort = SCOLS_SORT_SIZE; + else if (tb->sort == SCOLS_SORT_SIZE) + tb->sort = 0; + return 0; +} /** * scols_table_enable_export: @@ -840,6 +885,29 @@ int scols_table_is_noheadings(struct libscols_table *tb) } /** + * scols_table_is_namesort: + * @tb: table + * + * Returns: 1 if sorted output by name is enabled. + */ +int scols_table_is_namesort(struct libscols_table *tb) +{ + assert(tb); + return tb && tb->sort == SCOLS_SORT_NAME; +} + +/** + * scols_table_is_sizesort: + * @tb: table + * + * Returns: 1 if sorted output by size is enabled. + */ +int scols_table_is_sizesort(struct libscols_table *tb) +{ + assert(tb); + return tb && tb->sort == SCOLS_SORT_SIZE; +} +/** * scols_table_is_export: * @tb: table * -- 1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html