diff options
author | Ondrej Oprala | 2014-03-17 13:00:52 +0100 |
---|---|---|
committer | Karel Zak | 2014-04-03 12:29:16 +0200 |
commit | 6d1072696ce3e4ae9dc8b4a37805fb00bfc1d4e1 (patch) | |
tree | a2e8db0e0a00fa7c6d5b520afe5d5ca8e8228f9c /libsmartcols/src/cell.c | |
parent | libsmartcols: add symbols (diff) | |
download | kernel-qcow2-util-linux-6d1072696ce3e4ae9dc8b4a37805fb00bfc1d4e1.tar.gz kernel-qcow2-util-linux-6d1072696ce3e4ae9dc8b4a37805fb00bfc1d4e1.tar.xz kernel-qcow2-util-linux-6d1072696ce3e4ae9dc8b4a37805fb00bfc1d4e1.zip |
libsmartcols: add cells
[kzak@redhat.com: - remove copy, free -- all have to be handled by lines]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols/src/cell.c')
-rw-r--r-- | libsmartcols/src/cell.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/libsmartcols/src/cell.c b/libsmartcols/src/cell.c new file mode 100644 index 000000000..0a4999ff2 --- /dev/null +++ b/libsmartcols/src/cell.c @@ -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; +} + |