]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
partx: use libsmartcols
authorOndrej Oprala <ooprala@redhat.com>
Thu, 27 Mar 2014 14:18:20 +0000 (15:18 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 3 Apr 2014 10:29:18 +0000 (12:29 +0200)
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
disk-utils/Makemodule.am
disk-utils/partx.c

index 8780df6444ffa1331beb3832ac078e2e3311f2d1..bb1b28389812e935cf7e86f206919d0d53c7e271 100644 (file)
@@ -216,7 +216,7 @@ resizepart_LDADD = $(LDADD) libcommon.la
 partx_SOURCES = \
        disk-utils/partx.c \
        disk-utils/partx.h
-partx_CFLAGS = -I$(ul_libblkid_incdir)
-partx_LDADD = $(LDADD) libblkid.la libcommon.la
+partx_CFLAGS = -I$(ul_libblkid_incdir) -I$(ul_libsmartcols_incdir)
+partx_LDADD = $(LDADD) libblkid.la libcommon.la libsmartcols.la
 
 endif # BUILD_PARTX
index 44d38fd0eaf0f1c2ca72e6ae44bba8322604442f..d8d056f4065171fdf072f6cf6b55230566fe7558 100644 (file)
 #include <dirent.h>
 
 #include <blkid.h>
+#include <libsmartcols.h>
 
 #include "c.h"
 #include "pathnames.h"
 #include "nls.h"
-#include "tt.h"
 #include "blkdev.h"
 #include "strutils.h"
 #include "xalloc.h"
 /* this is the default upper limit, could be modified by --nr */
 #define SLICES_MAX     256
 
+/* basic table settings */
+enum {
+       PARTX_RAW =             (1 << 0),
+       PARTX_NOHEADINGS =      (1 << 1),
+       PARTX_EXPORT =          (1 << 2),
+};
+
 /* all the columns (-o option) */
 enum {
        COL_PARTNO,
@@ -71,22 +78,22 @@ enum {
 struct colinfo {
        const char      *name;  /* header */
        double          whint;  /* width hint (N < 1 is in percent of termwidth) */
-       int             flags;  /* TT_FL_* */
+       int             flags;  /* SCOLS_FL_* */
        const char      *help;
 };
 
 /* columns descriptions */
 struct colinfo infos[] = {
-       [COL_PARTNO]   = { "NR",    0.25, TT_FL_RIGHT, N_("partition number") },
-       [COL_START]    = { "START",   0.30, TT_FL_RIGHT, N_("start of the partition in sectors") },
-       [COL_END]      = { "END",     0.30, TT_FL_RIGHT, N_("end of the partition in sectors") },
-       [COL_SECTORS]  = { "SECTORS", 0.30, TT_FL_RIGHT, N_("number of sectors") },
-       [COL_SIZE]     = { "SIZE",    0.30, TT_FL_RIGHT, N_("human readable size") },
-       [COL_NAME]     = { "NAME",    0.30, TT_FL_TRUNC, N_("partition name") },
+       [COL_PARTNO]   = { "NR",    0.25, SCOLS_FL_RIGHT, N_("partition number") },
+       [COL_START]    = { "START",   0.30, SCOLS_FL_RIGHT, N_("start of the partition in sectors") },
+       [COL_END]      = { "END",     0.30, SCOLS_FL_RIGHT, N_("end of the partition in sectors") },
+       [COL_SECTORS]  = { "SECTORS", 0.30, SCOLS_FL_RIGHT, N_("number of sectors") },
+       [COL_SIZE]     = { "SIZE",    0.30, SCOLS_FL_RIGHT, N_("human readable size") },
+       [COL_NAME]     = { "NAME",    0.30, SCOLS_FL_TRUNC, N_("partition name") },
        [COL_UUID]     = { "UUID",    36, 0, N_("partition UUID")},
-       [COL_SCHEME]   = { "SCHEME",  0.1, TT_FL_TRUNC, N_("partition table type (dos, gpt, ...)")},
-       [COL_FLAGS]    = { "FLAGS",   0.1, TT_FL_TRUNC, N_("partition flags")},
-       [COL_TYPE]     = { "TYPE",    1, TT_FL_RIGHT, N_("partition type (a string, a UUID, or hex)")},
+       [COL_SCHEME]   = { "SCHEME",  0.1, SCOLS_FL_TRUNC, N_("partition table type (dos, gpt, ...)")},
+       [COL_FLAGS]    = { "FLAGS",   0.1, SCOLS_FL_TRUNC, N_("partition flags")},
+       [COL_TYPE]     = { "TYPE",    1, SCOLS_FL_RIGHT, N_("partition type (a string, a UUID, or hex)")},
 };
 
 #define NCOLS ARRAY_SIZE(infos)
@@ -526,15 +533,15 @@ static int list_parts(blkid_partlist ls, int lower, int upper)
        return 0;
 }
 
-static void add_tt_line(struct tt *tt, blkid_partition par)
+static void add_scols_line(struct libscols_table *table, blkid_partition par)
 {
-       struct tt_line *line;
+       struct libscols_line *line;
        int i;
 
-       assert(tt);
+       assert(table);
        assert(par);
 
-       line = tt_add_line(tt, NULL);
+       line = scols_table_new_line(table, NULL);
        if (!line) {
                warn(_("failed to add line to output"));
                return;
@@ -594,14 +601,14 @@ static void add_tt_line(struct tt *tt, blkid_partition par)
                }
 
                if (str)
-                       tt_line_set_data(line, i, str);
+                       scols_line_set_data(line, i, str);
        }
 }
 
-static int show_parts(blkid_partlist ls, int tt_flags, int lower, int upper)
+static int show_parts(blkid_partlist ls, int scols_flags, int lower, int upper)
 {
        int i, rc = -1;
-       struct tt *tt;
+       struct libscols_table *table;
        int nparts;
 
        assert(ls);
@@ -610,16 +617,19 @@ static int show_parts(blkid_partlist ls, int tt_flags, int lower, int upper)
        if (!nparts)
                return 0;
 
-       tt = tt_new_table(tt_flags | TT_FL_FREEDATA);
-       if (!tt) {
+       table = scols_new_table(NULL);
+       if (!table) {
                warn(_("failed to initialize output table"));
                return -1;
        }
+       scols_table_set_raw(table, !!(scols_flags & PARTX_RAW));
+       scols_table_set_export(table, !!(scols_flags & PARTX_EXPORT));
+       scols_table_set_no_headings(table, !!(scols_flags & PARTX_NOHEADINGS));
 
        for (i = 0; i < ncolumns; i++) {
                struct colinfo *col = get_column_info(i);
 
-               if (!tt_define_column(tt, col->name, col->whint, col->flags)) {
+               if (!scols_table_new_column(table, col->name, col->whint, col->flags)) {
                        warnx(_("failed to initialize output column"));
                        goto done;
                }
@@ -634,13 +644,13 @@ static int show_parts(blkid_partlist ls, int tt_flags, int lower, int upper)
                if (upper && n > upper)
                        continue;
 
-               add_tt_line(tt, par);
+               add_scols_line(table, par);
        }
 
        rc = 0;
-       tt_print_table(tt);
+       scols_print_table(table);
 done:
-       tt_free_table(tt);
+       scols_unref_table(table);
        return rc;
 }
 
@@ -722,7 +732,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 int main(int argc, char **argv)
 {
        int fd, c, what = ACT_NONE, lower = 0, upper = 0, rc = 0;
-       int tt_flags = 0;
+       int scols_flags = 0;
        char *type = NULL;
        char *device = NULL; /* pointer to argv[], ie: /dev/sda1 */
        char *wholedisk = NULL; /* allocated, ie: /dev/sda */
@@ -775,7 +785,7 @@ int main(int argc, char **argv)
                        what = ACT_DELETE;
                        break;
                case 'g':
-                       tt_flags |= TT_FL_NOHEADINGS;
+                       scols_flags |= PARTX_NOHEADINGS;
                        break;
                case 'l':
                        what = ACT_LIST;
@@ -788,11 +798,11 @@ int main(int argc, char **argv)
                        outarg = optarg;
                        break;
                case 'P':
-                       tt_flags |= TT_FL_EXPORT;
+                       scols_flags |= PARTX_EXPORT;
                        what = ACT_SHOW;
                        break;
                case 'r':
-                       tt_flags |= TT_FL_RAW;
+                       scols_flags |= PARTX_RAW;
                        what = ACT_SHOW;
                        break;
                case 's':
@@ -953,7 +963,7 @@ int main(int argc, char **argv)
 
                        switch (what) {
                        case ACT_SHOW:
-                               rc = show_parts(ls, tt_flags, lower, upper);
+                               rc = show_parts(ls, scols_flags, lower, upper);
                                break;
                        case ACT_LIST:
                                rc = list_parts(ls, lower, upper);