diff options
author | Ondrej Oprala | 2014-04-09 16:58:28 +0200 |
---|---|---|
committer | Ondrej Oprala | 2014-04-14 12:37:21 +0200 |
commit | d1b4d14f4da1a6ac10f0d038c20bd80185b99bdc (patch) | |
tree | c22532d0cf01c53645c209a8c5647fffb0cf886b /libsmartcols/src/table.c | |
parent | build-sys: fix fstrim systemd stuff (diff) | |
download | kernel-qcow2-util-linux-d1b4d14f4da1a6ac10f0d038c20bd80185b99bdc.tar.gz kernel-qcow2-util-linux-d1b4d14f4da1a6ac10f0d038c20bd80185b99bdc.tar.xz kernel-qcow2-util-linux-d1b4d14f4da1a6ac10f0d038c20bd80185b99bdc.zip |
libsmartcols: add separator getters/setters
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Diffstat (limited to 'libsmartcols/src/table.c')
-rw-r--r-- | libsmartcols/src/table.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index 914cc2ed9..34b43b508 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -84,6 +84,8 @@ void scols_unref_table(struct libscols_table *tb) scols_table_remove_lines(tb); scols_table_remove_columns(tb); scols_unref_symbols(tb->symbols); + free(tb->linesep); + free(tb->colsep); free(tb); } } @@ -609,6 +611,11 @@ struct libscols_table *scols_copy_table(struct libscols_table *tb) scols_unref_line(newln); } + /* separators */ + if (scols_table_set_column_separator(ret, tb->colsep) || + scols_table_set_line_separator(ret, tb->linesep)) + goto err; + return ret; err: scols_unref_table(ret); @@ -880,3 +887,87 @@ int scols_table_is_tree(struct libscols_table *tb) assert(tb); return tb && tb->ntreecols > 0; } + +/** + * scols_table_set_column_separator: + * @tb: table + * @sep: separator + * + * Sets the column separator of @tb to @sep. + * Please note that @sep should always take up a single cell in the output. + * + * Returns: 0, a negative value in case of an error. + */ +int scols_table_set_column_separator(struct libscols_table *tb, char *sep) +{ + assert (tb); + + if (!tb) + return -EINVAL; + + sep = strdup(sep); + if (!sep) + return -ENOMEM; + + free(tb->colsep); + tb->colsep = sep; + + return 0; +} + +/** + * scols_table_set_line_separator: + * @tb: table + * @sep: separator + * + * Sets the line separator of @tb to @sep. + * + * Returns: 0, a negative value in case of an error. + */ +int scols_table_set_line_separator(struct libscols_table *tb, char *sep) +{ + assert (tb); + + if (!tb) + return -EINVAL; + + sep = strdup(sep); + if (!sep) + return -ENOMEM; + + free(tb->linesep); + tb->linesep = sep; + + return 0; +} + +/** + * scols_table_get_column_separator: + * @tb: table + * + * Returns: @tb column separator, NULL in case of an error + */ +char *scols_table_get_column_separator(struct libscols_table *tb) +{ + assert (tb); + + if (!tb) + return NULL; + return tb->colsep; +} + +/** + * scols_table_get_line_separator: + * @tb: table + * + * Returns: @tb line separator, NULL in case of an error + */ +char *scols_table_get_line_separator(struct libscols_table *tb) +{ + assert (tb); + + if (!tb) + return NULL; + return tb->linesep; + +} |