summaryrefslogtreecommitdiff
path: root/libsmartcols
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2014-04-14 13:44:23 +0200
committerKarel Zak <kzak@redhat.com>2014-04-14 13:44:23 +0200
commit4baab7dfd36523ede61159c02744b5cf78928da0 (patch)
tree90755cbde0951e9952b4ecc79f6e9c4caada6145 /libsmartcols
parent873eb9105acd21d0fad4d46872fade8e0e8d9e9c (diff)
downloadutil-linux-4baab7dfd36523ede61159c02744b5cf78928da0.tar.gz
libsmartcols: improve line and cell separators
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols')
-rw-r--r--libsmartcols/src/libsmartcols.h.in4
-rw-r--r--libsmartcols/src/table.c30
-rw-r--r--libsmartcols/src/test.c5
3 files changed, 22 insertions, 17 deletions
diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in
index 1307013a1..9468226f2 100644
--- a/libsmartcols/src/libsmartcols.h.in
+++ b/libsmartcols/src/libsmartcols.h.in
@@ -174,8 +174,8 @@ extern int scols_table_enable_noheadings(struct libscols_table *tb, int enable);
extern int scols_table_enable_export(struct libscols_table *tb, int enable);
extern int scols_table_enable_maxout(struct libscols_table *tb, int enable);
-extern int scols_table_set_column_separator(struct libscols_table *tb, char *sep);
-extern int scols_table_set_line_separator(struct libscols_table *tb, char *sep);
+extern int scols_table_set_column_separator(struct libscols_table *tb, const char *sep);
+extern int scols_table_set_line_separator(struct libscols_table *tb, const char *sep);
extern struct libscols_table *scols_new_table(void);
extern void scols_ref_table(struct libscols_table *tb);
diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c
index 34b43b508..d4c61eea3 100644
--- a/libsmartcols/src/table.c
+++ b/libsmartcols/src/table.c
@@ -898,20 +898,23 @@ int scols_table_is_tree(struct libscols_table *tb)
*
* Returns: 0, a negative value in case of an error.
*/
-int scols_table_set_column_separator(struct libscols_table *tb, char *sep)
+int scols_table_set_column_separator(struct libscols_table *tb, const char *sep)
{
+ char *p = NULL;
+
assert (tb);
if (!tb)
return -EINVAL;
- sep = strdup(sep);
- if (!sep)
- return -ENOMEM;
+ if (sep) {
+ p = strdup(sep);
+ if (!p)
+ return -ENOMEM;
+ }
free(tb->colsep);
- tb->colsep = sep;
-
+ tb->colsep = p;
return 0;
}
@@ -924,20 +927,23 @@ int scols_table_set_column_separator(struct libscols_table *tb, char *sep)
*
* Returns: 0, a negative value in case of an error.
*/
-int scols_table_set_line_separator(struct libscols_table *tb, char *sep)
+int scols_table_set_line_separator(struct libscols_table *tb, const char *sep)
{
+ char *p = NULL;
+
assert (tb);
if (!tb)
return -EINVAL;
- sep = strdup(sep);
- if (!sep)
- return -ENOMEM;
+ if (sep) {
+ p = strdup(sep);
+ if (!p)
+ return -ENOMEM;
+ }
free(tb->linesep);
- tb->linesep = sep;
-
+ tb->linesep = p;
return 0;
}
diff --git a/libsmartcols/src/test.c b/libsmartcols/src/test.c
index eaff49e7e..98975b77a 100644
--- a/libsmartcols/src/test.c
+++ b/libsmartcols/src/test.c
@@ -215,10 +215,9 @@ int main(int argc, char *argv[])
notree = 1;
break;
case 'c':
- scols_table_set_line_separator(tb, ",");
- /* a column separator should always take up one cell */
- scols_table_set_column_separator(tb, ":");
+ scols_table_set_column_separator(tb, ",");
scols_table_enable_raw(tb, 1);
+ notree = 1;
break;
case 'C':
clonetb = 1;