]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: improve line and cell separators
authorKarel Zak <kzak@redhat.com>
Mon, 14 Apr 2014 11:44:23 +0000 (13:44 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 14 Apr 2014 11:44:23 +0000 (13:44 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/table.c
libsmartcols/src/test.c

index 1307013a18e6d22159c7bf14fed275123b3cc75a..9468226f24191630d95175a903275a5c99883d0f 100644 (file)
@@ -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);
index 34b43b508a8137b782029c1aefafd7819846a1c0..d4c61eea339e8e5f07c3f34c9dd22925faeb2e32 100644 (file)
@@ -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;
 }
 
index eaff49e7e12c23b0830ce38db872a9174511b789..98975b77a018f7bc742736a5ef13e48e0ffe5576 100644 (file)
@@ -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;