]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: add cells
authorOndrej Oprala <ooprala@redhat.com>
Mon, 17 Mar 2014 12:00:52 +0000 (13:00 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 3 Apr 2014 10:29:16 +0000 (12:29 +0200)
[kzak@redhat.com: - remove copy, free -- all have to be handled by lines]

Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/Makemodule.am
libsmartcols/src/cell.c [new file with mode: 0644]
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/smartcolsP.h

index 5f8d180126f525ba1422c15b6951ad5e5fa05d37..7ee70093080bac3b3b3b856f478a330343a12f3a 100644 (file)
@@ -11,6 +11,7 @@ libsmartcols_la_SOURCES= \
        libsmartcols/src/smartcolsP.h \
        libsmartcols/src/iter.c \
        libsmartcols/src/symbols.c \
+       libsmartcols/src/cell.c \
        $(smartcolsinc_HEADERS)
 
 nodist_libsmartcols_la_SOURCES = libsmartcols/src/smartcolsP.h
diff --git a/libsmartcols/src/cell.c b/libsmartcols/src/cell.c
new file mode 100644 (file)
index 0000000..0a4999f
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * cell.c - functions for table handling at the cell level
+ *
+ * Copyright (C) 2014 Ondrej Oprala <ooprala@redhat.com>
+ * Copyright (C) 2014 Karel Zak <kzak@redhat.com>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "smartcolsP.h"
+
+/*
+ * The cell has no ref-counting, free() and new() functions. All is
+ * handled by libscols_line.
+ */
+
+int scols_cell_set_data(struct libscols_cell *ce, const char *str)
+{
+       char *p = NULL;
+
+       assert(ce);
+
+       if (!ce)
+               return -EINVAL;
+       if (str) {
+               p = strdup(str);
+               if (!p)
+                       return -ENOMEM;
+       }
+       free(ce->data);
+       ce->data = p;
+       return 0;
+}
+
+const char *scols_cell_get_data(const struct libscols_cell *ce)
+{
+       assert(ce);
+       return ce ? ce->data : NULL;
+}
+
+int scols_cell_set_color(struct libscols_cell *ce, const char *color)
+{
+       char *p = NULL;
+
+       assert(ce);
+
+       if (!ce)
+               return -EINVAL;
+       if (color) {
+               p = strdup(color);
+               if (!p)
+                       return -ENOMEM;
+       }
+       free(ce->color);
+       ce->color = p;
+       return 0;
+}
+
+const char *scols_cell_get_color(const struct libscols_cell *ce)
+{
+       assert(ce);
+       return ce ? ce->color : NULL;
+}
+
index eefac6c63a72ff8c0eeef4c4aa5bf6b898a123ab..7b3d4d837d609536ff20528c796c512fb8d706b8 100644 (file)
@@ -21,6 +21,7 @@ extern "C" {
 
 struct libscols_iter;
 struct libscols_symbols;
+struct libscols_cell;
 
 
 /* iter.c */
@@ -43,6 +44,12 @@ extern int scols_symbols_set_branch(struct libscols_symbols *sb, const char *str
 extern int scols_symbols_set_vertical(struct libscols_symbols *sb, const char *str);
 extern int scols_symbols_set_right(struct libscols_symbols *sb, const char *str);
 
+/* cell.c */
+extern int scols_cell_set_data(struct libscols_cell *ce, const char *str);
+extern const char *scols_cell_get_data(const struct libscols_cell *ce);
+extern int scols_cell_set_color(struct libscols_cell *ce, const char *color);
+extern const char *scols_cell_get_color(const struct libscols_cell *ce);
+
 #ifdef __cplusplus
 }
 #endif
index ca662a20478786966d443a303a2d851e6935ec50..6cb712a46cec62e7bc8fefb93eaceb9367992710 100644 (file)
@@ -42,4 +42,12 @@ struct libscols_symbols {
        char *right;
 };
 
+/*
+ * Table cells
+ */
+struct libscols_cell {
+       char    *data;
+       char    *color;
+};
+
 #endif /* _LIBSMARTCOLS_PRIVATE_H */