summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2016-01-25 13:42:51 +0100
committerKarel Zak2016-01-25 13:42:51 +0100
commit107ca34a4ce8ae26b2e18f41489cc5756bc0b27b (patch)
treeb47b80813db6020f3736386c4ab3f34e2cc55c53
parentlibsmartcols: add samples directory (diff)
downloadkernel-qcow2-util-linux-107ca34a4ce8ae26b2e18f41489cc5756bc0b27b.tar.gz
kernel-qcow2-util-linux-107ca34a4ce8ae26b2e18f41489cc5756bc0b27b.tar.xz
kernel-qcow2-util-linux-107ca34a4ce8ae26b2e18f41489cc5756bc0b27b.zip
libsmartcols: fix samples build, add title.c
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--.gitignore5
-rw-r--r--libsmartcols/samples/Makemodule.am12
-rw-r--r--libsmartcols/samples/title.c94
3 files changed, 107 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 27aa3f6a9..a00874010 100644
--- a/.gitignore
+++ b/.gitignore
@@ -146,10 +146,7 @@ update.log
/rev
/rtcwake
/runuser
-/sample-mkfs
-/sample-partitions
-/sample-superblocks
-/sample-topology
+/sample-*
/script
/scriptreplay
/setarch
diff --git a/libsmartcols/samples/Makemodule.am b/libsmartcols/samples/Makemodule.am
new file mode 100644
index 000000000..990e00c14
--- /dev/null
+++ b/libsmartcols/samples/Makemodule.am
@@ -0,0 +1,12 @@
+
+check_PROGRAMS += \
+ sample-scols-tree \
+ sample-scols-title
+
+sample_scols_tree_SOURCES = libsmartcols/samples/tree.c
+sample_scols_tree_LDADD = libsmartcols.la libcommon.la
+sample_scols_tree_CFLAGS = -I$(ul_libsmartcols_incdir)
+
+sample_scols_title_SOURCES = libsmartcols/samples/title.c
+sample_scols_title_LDADD = libsmartcols.la
+sample_scols_title_CFLAGS = -I$(ul_libsmartcols_incdir)
diff --git a/libsmartcols/samples/title.c b/libsmartcols/samples/title.c
new file mode 100644
index 000000000..9bc955fe8
--- /dev/null
+++ b/libsmartcols/samples/title.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2010-2014 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 "strutils.h"
+#include "xalloc.h"
+
+#include "libsmartcols.h"
+
+
+enum { COL_NAME, COL_DATA };
+
+/* add columns to the @tb */
+static void setup_columns(struct libscols_table *tb)
+{
+ if (!scols_table_new_column(tb, "NAME", 0, 0))
+ goto fail;
+ if (!scols_table_new_column(tb, "DATA", 0, 0))
+ goto fail;
+ return;
+fail:
+ scols_unref_table(tb);
+ err(EXIT_FAILURE, "faild to create output columns");
+}
+
+static void add_line(struct libscols_table *tb, const char *name, const char *data)
+{
+ struct libscols_line *ln = scols_table_new_line(tb, NULL);
+ if (!ln)
+ err(EXIT_FAILURE, "failed to create output line");
+
+ if (scols_line_set_data(ln, COL_NAME, name))
+ goto fail;
+ if (scols_line_set_data(ln, COL_NAME, data))
+ goto fail;
+ return;
+fail:
+ scols_unref_table(tb);
+ err(EXIT_FAILURE, "faild to create output line");
+}
+
+int main(int argc, char *argv[])
+{
+ struct libscols_table *tb;
+ struct libscols_symbols *sy;
+
+ setlocale(LC_ALL, ""); /* just to have enable UTF8 chars */
+
+ scols_init_debug(0);
+
+ tb = scols_new_table();
+ if (!tb)
+ err(EXIT_FAILURE, "faild to create output table");
+
+ scols_table_enable_colors(tb, 1);
+ setup_columns(tb);
+ add_line(tb, "foo", "bla bla bla");
+ add_line(tb, "bar", "alb alb alb");
+
+ /* right */
+ scols_table_set_title(tb, "This is right title", SCOLS_TITLE_RIGHT, "red");
+ scols_print_table(tb);
+
+ /* center */
+ sy = scols_new_symbols();
+ if (!sy)
+ err_oom();
+ scols_table_set_symbols(tb, sy);
+
+ scols_symbols_set_title_padding(sy, "=");
+ scols_table_set_title(tb, "This is center title (with padding)", SCOLS_TITLE_CENTER, "green");
+ scols_print_table(tb);
+
+ /* left */
+ scols_symbols_set_title_padding(sy, "-");
+ scols_table_set_title(tb, "This is left title (with padding)", SCOLS_TITLE_LEFT, "blue");
+ scols_print_table(tb);
+
+ scols_unref_table(tb);
+ return EXIT_SUCCESS;
+}