diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 14:30:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 14:30:35 +0000 |
commit | 378c18e5f024ac5a8aef4cb40d7c9aa9633d144c (patch) | |
tree | 44dfb6ca500d32cabd450649b322a42e70a30683 /libsmartcols/samples/maxout.c | |
parent | Initial commit. (diff) | |
download | util-linux-378c18e5f024ac5a8aef4cb40d7c9aa9633d144c.tar.xz util-linux-378c18e5f024ac5a8aef4cb40d7c9aa9633d144c.zip |
Adding upstream version 2.38.1.upstream/2.38.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libsmartcols/samples/maxout.c')
-rw-r--r-- | libsmartcols/samples/maxout.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/libsmartcols/samples/maxout.c b/libsmartcols/samples/maxout.c new file mode 100644 index 0000000..263d4de --- /dev/null +++ b/libsmartcols/samples/maxout.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2016 Karel Zak <kzak@redhat.com> + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> +#include <getopt.h> + +#include "c.h" +#include "nls.h" +#include "libsmartcols.h" + +enum { COL_LEFT, COL_FOO, COL_RIGHT }; + +int main(int argc, char *argv[]) +{ + struct libscols_table *tb; + int rc = -1, nlines = 3; + + setlocale(LC_ALL, ""); /* just to have enable UTF8 chars */ + + scols_init_debug(0); + + tb = scols_new_table(); + if (!tb) + err(EXIT_FAILURE, "failed to create output table"); + + scols_table_enable_maxout(tb, TRUE); + if (!scols_table_new_column(tb, "LEFT", 0, 0)) + goto done; + if (!scols_table_new_column(tb, "FOO", 0, 0)) + goto done; + if (!scols_table_new_column(tb, "RIGHT", 0, SCOLS_FL_RIGHT)) + goto done; + + while (nlines--) { + struct libscols_line *ln = scols_table_new_line(tb, NULL); + int rc; + + rc = scols_line_set_data(ln, COL_LEFT, "A"); + if (!rc) + rc = scols_line_set_data(ln, COL_FOO, "B"); + if (!rc) + rc = scols_line_set_data(ln, COL_RIGHT, "C"); + if (rc) + err(EXIT_FAILURE, "failed to set line data"); + } + + scols_print_table(tb); + rc = 0; +done: + scols_unref_table(tb); + return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} |