From: Karel Zak Date: Mon, 14 Apr 2014 11:44:23 +0000 (+0200) Subject: libsmartcols: improve line and cell separators X-Git-Tag: v2.25-rc1~288 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4baab7dfd36523ede61159c02744b5cf78928da0;p=thirdparty%2Futil-linux.git libsmartcols: improve line and cell separators Signed-off-by: Karel Zak --- diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in index 1307013a18..9468226f24 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 34b43b508a..d4c61eea33 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 eaff49e7e1..98975b77a0 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;