]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: use libsmartcols
authorOndrej Oprala <ooprala@redhat.com>
Thu, 27 Mar 2014 16:06:52 +0000 (17:06 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 3 Apr 2014 10:29:19 +0000 (12:29 +0200)
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
sys-utils/Makemodule.am
sys-utils/lscpu.c

index a1bdd83f58e9fb59e5b3f118ac29468805544b62..1d4f2d454fcb1a7581950c4c98a71a5e2fb32758 100644 (file)
@@ -247,7 +247,8 @@ lscpu_SOURCES = \
        sys-utils/lscpu.c \
        sys-utils/lscpu.h \
        sys-utils/lscpu-dmi.c
-lscpu_LDADD = $(LDADD) libcommon.la
+lscpu_LDADD = $(LDADD) libcommon.la libsmartcols.la
+lscpu_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir)
 dist_man_MANS += sys-utils/lscpu.1
 endif
 
index a42ee8e37654ee45d80230f155a4aa6404abe64f..8a5a9c693ad643e5875defb790290e3f43bfaf4c 100644 (file)
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#include <libsmartcols.h>
+
 #include "cpuset.h"
 #include "nls.h"
 #include "xalloc.h"
 #include "c.h"
 #include "strutils.h"
 #include "bitops.h"
-#include "tt.h"
 #include "path.h"
 #include "closestream.h"
 #include "optutils.h"
@@ -1226,19 +1227,20 @@ print_readable(struct lscpu_desc *desc, int cols[], int ncols,
 {
        int i;
        char buf[BUFSIZ], *data;
-       struct tt *tt = tt_new_table(TT_FL_FREEDATA);
+       struct libscols_table *table = scols_new_table(NULL);
 
-       if (!tt)
+       if (!table)
                 err(EXIT_FAILURE, _("failed to initialize output table"));
 
        for (i = 0; i < ncols; i++) {
                data = get_cell_header(desc, cols[i], mod, buf, sizeof(buf));
-               tt_define_column(tt, xstrdup(data), 0, 0);
+               if (!scols_table_new_column(table, xstrdup(data), 0, 0))
+                       return;
        }
 
        for (i = 0; i < desc->ncpuspos; i++) {
                int c;
-               struct tt_line *line;
+               struct libscols_line *line;
                int cpu = real_cpu_num(desc, i);
 
                if (!mod->offline && desc->online && !is_cpu_online(desc, cpu))
@@ -1248,18 +1250,23 @@ print_readable(struct lscpu_desc *desc, int cols[], int ncols,
                if (desc->present && !is_cpu_present(desc, cpu))
                        continue;
 
-               line = tt_add_line(tt, NULL);
+               line = scols_table_new_line(table, NULL);
+               if (!line) {
+                       scols_unref_table(table);
+                       return;
+               }
+
 
                for (c = 0; c < ncols; c++) {
                        data = get_cell_data(desc, i, cols[c], mod,
                                             buf, sizeof(buf));
-                       tt_line_set_data(line, c,
+                       scols_line_set_data(line, c,
                                        xstrdup(data && *data ? data : "-"));
                }
        }
 
-       tt_print_table(tt);
-       tt_free_table(tt);
+       scols_print_table(table);
+       scols_unref_table(table);
 }
 
 /* output formats "<key>  <value>"*/