]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: remove dependence on libsmartcols
authorKarel Zak <kzak@redhat.com>
Wed, 13 Aug 2014 08:10:11 +0000 (10:10 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 13 Aug 2014 08:10:11 +0000 (10:10 +0200)
It's application business to convert libfdisk_table to string.

Signed-off-by: Karel Zak <kzak@redhat.com>
14 files changed:
configure.ac
disk-utils/Makemodule.am
disk-utils/cfdisk.c
disk-utils/fdisk.c
libfdisk/src/Makemodule.am
libfdisk/src/bsd.c
libfdisk/src/dos.c
libfdisk/src/fdiskP.h
libfdisk/src/gpt.c
libfdisk/src/label.c
libfdisk/src/libfdisk.h
libfdisk/src/sgi.c
libfdisk/src/sun.c
libfdisk/src/table.c

index dd61948492a638a523424f7588b7415753090db7..5b558ec11a27e15f562b1eeb2bdd084e425ef4e9 100644 (file)
@@ -823,11 +823,11 @@ dnl libfdisk is enabled at all times if possible
 dnl
 UL_BUILD_INIT([libfdisk], [check])
 UL_REQUIRES_BUILD([libfdisk], [libuuid])
-UL_REQUIRES_BUILD([libfdisk], [libsmartcols])
 AM_CONDITIONAL([BUILD_LIBFDISK], [test "x$build_libfdisk" = xyes])
 
 UL_BUILD_INIT([fdisk], [check])
 UL_REQUIRES_BUILD([fdisk], [libfdisk])
+UL_REQUIRES_BUILD([fdisk], [libsmartcols])
 AM_CONDITIONAL([BUILD_FDISK], [test "x$build_fdisk" = xyes])
 
 
index 995e085529907476b343e5261277652637c281e1..04118c73ba06ec84f318302915bacbc0d61a9b1e 100644 (file)
@@ -142,6 +142,11 @@ fdisk_CFLAGS += -I$(ul_libuuid_incdir)
 fdisk_LDADD += libuuid.la
 endif
 
+if BUILD_LIBSMARTCOLS
+fdisk_CFLAGS += -I$(ul_libsmartcols_incdir)
+fdisk_LDADD += libsmartcols.la
+endif
+
 if HAVE_STATIC_FDISK
 sbin_PROGRAMS += fdisk.static
 fdisk_static_SOURCES = $(fdisk_SOURCES)
index eff7933552527d5926b150a5e5c16f0abe6623bd..453eafab0a87f90e04e22b46226979cee57b26db 100644 (file)
@@ -235,9 +235,6 @@ static int partition_from_scols(struct fdisk_table *tb,
        return 0;
 }
 
-/* It would be possible to use fdisk_table_to_string(), but we want some
- * extension to the output format, so let's do it without libfdisk
- */
 static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb)
 {
        const struct fdisk_column *col;
@@ -283,10 +280,18 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb)
        for (i = 0; i < cf->ncols; i++) {
                col = fdisk_label_get_column(lb, cf->cols[i]);
                if (col) {
-                       int fl = col->scols_flags;
-                       if (tree && col->id == FDISK_COL_DEVICE)
+                       int fl = 0;
+
+                       if (fdisk_column_is_number(col))
+                               fl |= SCOLS_FL_RIGHT;
+                       if (fdisk_column_get_id(col) == FDISK_COL_TYPE)
+                               fl |= SCOLS_FL_TRUNC;
+                       if (tree && fdisk_column_get_id(col) == FDISK_COL_DEVICE)
                                fl |= SCOLS_FL_TREE;
-                       if (!scols_table_new_column(table, col->name, col->width, fl))
+
+                       if (!scols_table_new_column(table,
+                                       fdisk_column_get_name(col),
+                                       fdisk_column_get_width(col), fl))
                                goto done;
                }
        }
@@ -305,7 +310,8 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb)
                        col = fdisk_label_get_column(lb, cf->cols[i]);
                        if (!col)
                                continue;
-                       if (fdisk_partition_to_string(pa, cf->cxt, col->id, &cdata))
+                       if (fdisk_partition_to_string(pa, cf->cxt,
+                                       fdisk_column_get_id(col), &cdata))
                                continue;
                        scols_line_refer_data(ln, i, cdata);
                }
index fed7a5745edb4c6993b2ac47753fa7dfb1754152..1e6b45d3c0fee85fcd1c80c6c84854fb7a3cb871 100644 (file)
@@ -21,6 +21,7 @@
 #include <sys/time.h>
 #include <time.h>
 #include <limits.h>
+#include <libsmartcols.h>
 
 #include "c.h"
 #include "xalloc.h"
@@ -539,45 +540,105 @@ void list_disklabel(struct fdisk_context *cxt)
 {
        struct fdisk_table *tb = NULL;
        struct fdisk_partition *pa = NULL;
-       struct fdisk_iter *itr;
-
-       char *str;
+       struct fdisk_iter *itr = NULL;
+       struct libscols_table *out = NULL;
+       const char *bold = NULL;
+       int *cols = NULL;
+       size_t  ncols = 0, i;
 
        /* print label specific stuff by libfdisk FDISK_ASK_INFO API */
        fdisk_list_disklabel(cxt);
 
-       /* print partitions */
-       if (fdisk_get_partitions(cxt, &tb))
-               return;
-       if (fdisk_table_to_string(tb, cxt, NULL, 0, &str) == 0) {
-               fputc('\n', stdout);
-               if (str) {
-                       char *p = str;
-                       char *next = strchr(str, '\n');
-                       if (next && colors_wanted()) {
-                               *next = '\0';
-                               color_scheme_enable("header", UL_COLOR_BOLD);
-                               fputs(p, stdout);
-                               color_disable();
-                               fputc('\n', stdout);
-                               p = ++next;
-                       }
-                       fputs(p, stdout);
-                       free(str);
+       /* get partitions and generate output */
+       if (fdisk_get_partitions(cxt, &tb) || fdisk_table_get_nents(tb) <= 0)
+               goto done;
+
+       if (fdisk_get_columns(cxt, 0, &cols, &ncols))
+               goto done;
+
+       itr = fdisk_new_iter(FDISK_ITER_FORWARD);
+       if (!itr) {
+               fdisk_warn(cxt, _("faild to allocate iterator"));
+               goto done;
+       }
+
+       out = scols_new_table();
+       if (!out) {
+               fdisk_warn(cxt, _("faild to allocate output table"));
+               goto done;
+       }
+
+       if (colors_wanted()) {
+               scols_table_enable_colors(out, 1);
+               bold = color_scheme_get_sequence("header", UL_COLOR_BOLD);
+       }
+
+       /* define output table columns */
+       for (i = 0; i < ncols; i++) {
+               int fl = 0;
+               struct libscols_column *co;
+               const struct fdisk_column *col =
+                               fdisk_label_get_column(cxt->label, cols[i]);
+               if (!col)
+                       goto done;
+               if (fdisk_column_is_number(col))
+                       fl |= SCOLS_FL_RIGHT;
+               if (fdisk_column_get_id(col) == FDISK_COL_TYPE)
+                       fl |= SCOLS_FL_TRUNC;
+
+               co = scols_table_new_column(out,
+                               fdisk_column_get_name(col),
+                               fdisk_column_get_width(col), fl);
+               if (!co)
+                       goto done;
+
+               /* set colum header color */
+               if (bold)
+                       scols_cell_set_color(scols_column_get_header(co), bold);
+       }
+
+       /* fill-in output table */
+       while (fdisk_table_next_partition(tb, itr, &pa) == 0) {
+               struct libscols_line *ln = scols_table_new_line(out, NULL);
+
+               if (!ln) {
+                       fdisk_warn(cxt, _("faild to allocate output line"));
+                       goto done;
+               }
+
+               for (i = 0; i < ncols; i++) {
+                       char *data = NULL;
+
+                       const struct fdisk_column *col =
+                               fdisk_label_get_column(cxt->label, cols[i]);
+
+                       if (fdisk_partition_to_string(pa, cxt,
+                                       fdisk_column_get_id(col),
+                                       &data))
+                               continue;
+                       scols_line_refer_data(ln, i, data);
                }
        }
 
-       fputc('\n', stdout);
+       /* print */
+       if (!scols_table_is_empty(out)) {
+               fputc('\n', stdout);
+               scols_print_table(out);
+       }
 
-       itr = fdisk_new_iter(FDISK_ITER_FORWARD);
 
+       fputc('\n', stdout);
+
+       /* print warnings */
        while (itr && fdisk_table_next_partition(tb, itr, &pa) == 0)
                fdisk_warn_alignment(cxt, fdisk_partition_get_start(pa),
                                          fdisk_partition_get_partno(pa) + 1);
 
        if (fdisk_table_wrong_order(tb))
                fdisk_info(cxt, _("Partition table entries are not in disk order."));
-
+done:
+       free(cols);
+       scols_unref_table(out);
        fdisk_unref_table(tb);
        fdisk_free_iter(itr);
 }
index 99bddb2dad191c589abf03a65f12d85bbeabbace..d8cbffbe37df3798f89c99c0d6d6c953e5a182fc 100644 (file)
@@ -49,12 +49,6 @@ libfdisk_la_DEPENDENCIES += libuuid.la
 libfdisk_la_CFLAGS += -I$(ul_libuuid_incdir)
 endif
 
-if BUILD_LIBSMARTCOLS
-libfdisk_la_LIBADD += libsmartcols.la
-libfdisk_la_DEPENDENCIES += libsmartcols.la
-libfdisk_la_CFLAGS += -I$(ul_libsmartcols_incdir)
-endif
-
 check_PROGRAMS += \
        test_fdisk_ask \
        test_fdisk_utils
@@ -71,10 +65,6 @@ if BUILD_LIBUUID
 libfdisk_tests_ldflags += libuuid.la
 endif
 
-if BUILD_LIBSMARTCOLS
-libfdisk_tests_ldflags += libsmartcols.la
-endif
-
 test_fdisk_ask_SOURCES = libfdisk/src/ask.c
 test_fdisk_ask_CFLAGS = $(libfdisk_tests_cflags)
 test_fdisk_ask_LDFLAGS = $(libfdisk_tests_ldflags)
index 0a03338f70e128f3e48f93d2119d32e0fda71954..d6dc4b7f9598f2338c71223f805d210519131193 100644 (file)
@@ -15,7 +15,6 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <sys/param.h>
-#include <libsmartcols.h>
 
 #include "nls.h"
 #include "blkdev.h"
@@ -882,15 +881,15 @@ static const struct fdisk_label_operations bsd_operations =
 static const struct fdisk_column bsd_columns[] =
 {
        { FDISK_COL_DEVICE,     N_("Slice"),      1,    0 },
-       { FDISK_COL_START,      N_("Start"),      5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_END,        N_("End"),        5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_SECTORS,    N_("Sectors"),    5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_CYLINDERS,  N_("Cylinders"),  5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_SIZE,       N_("Size"),       5,    SCOLS_FL_RIGHT },
+       { FDISK_COL_START,      N_("Start"),      5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_END,        N_("End"),        5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_SECTORS,    N_("Sectors"),    5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_CYLINDERS,  N_("Cylinders"),  5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_SIZE,       N_("Size"),       5,    FDISK_COLFL_NUMBER },
        { FDISK_COL_TYPE,       N_("Type"),       8,    0 },
-       { FDISK_COL_FSIZE,      N_("Fsize"),      5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_BSIZE,      N_("Bsize"),      5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_CPG,        N_("Cpg"),        5,    SCOLS_FL_RIGHT }
+       { FDISK_COL_FSIZE,      N_("Fsize"),      5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_BSIZE,      N_("Bsize"),      5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_CPG,        N_("Cpg"),        5,    FDISK_COLFL_NUMBER }
 };
 
 /*
index 58ddec8561f7a16aec8dfad43c02bad6e14a5203..fc4ac7a8013c80228243eb6210f823fe5e9463ab 100644 (file)
@@ -15,7 +15,6 @@
 #include "fdiskP.h"
 
 #include <ctype.h>
-#include <libsmartcols.h>
 
 #define MAXIMUM_PARTS  60
 #define ACTIVE_FLAG     0x80
@@ -1987,18 +1986,18 @@ static const struct fdisk_column dos_columns[] =
        /* basic */
        { FDISK_COL_DEVICE,     N_("Device"),    10,    0 },
        { FDISK_COL_BOOT,       N_("Boot"),       1,    0 },
-       { FDISK_COL_START,      N_("Start"),      5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_END,        N_("End"),        5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_SECTORS,    N_("Sectors"),    5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_CYLINDERS,  N_("Cylinders"),  5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_SIZE,       N_("Size"),       5,    SCOLS_FL_RIGHT, FDISK_COLFL_EYECANDY },
-       { FDISK_COL_TYPEID,     N_("Id"),         2,    SCOLS_FL_RIGHT },
-       { FDISK_COL_TYPE,       N_("Type"),     0.1,    SCOLS_FL_TRUNC },
+       { FDISK_COL_START,      N_("Start"),      5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_END,        N_("End"),        5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_SECTORS,    N_("Sectors"),    5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_CYLINDERS,  N_("Cylinders"),  5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_SIZE,       N_("Size"),       5,    FDISK_COLFL_NUMBER | FDISK_COLFL_EYECANDY },
+       { FDISK_COL_TYPEID,     N_("Id"),         2,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_TYPE,       N_("Type"),     0.1,    0 },
 
        /* expert mode */
-       { FDISK_COL_SADDR,      N_("Start-C/H/S"), 1,   SCOLS_FL_RIGHT, FDISK_COLFL_DETAIL },
-       { FDISK_COL_EADDR,      N_("End-C/H/S"),   1,   SCOLS_FL_RIGHT, FDISK_COLFL_DETAIL },
-       { FDISK_COL_ATTR,       N_("Attrs"),       2,   SCOLS_FL_RIGHT, FDISK_COLFL_DETAIL }
+       { FDISK_COL_SADDR,      N_("Start-C/H/S"), 1,   FDISK_COLFL_NUMBER | FDISK_COLFL_DETAIL },
+       { FDISK_COL_EADDR,      N_("End-C/H/S"),   1,   FDISK_COLFL_NUMBER | FDISK_COLFL_DETAIL },
+       { FDISK_COL_ATTR,       N_("Attrs"),       2,   FDISK_COLFL_NUMBER | FDISK_COLFL_DETAIL }
 
 };
 
index ea6e291b1c81e50bd23e98b932581c14f67287a7..0e5f234d8f9add7cf7f4d169f791b4905499288d 100644 (file)
@@ -235,8 +235,6 @@ struct fdisk_column {
        int             id;             /* FDISK_COL_* */
        const char      *name;          /* column header */
        double          width;
-       int             scols_flags;    /* SCOLS_FL_* */
-
        int             flags;          /* FDISK_COLFL_* */
 };
 
@@ -244,6 +242,7 @@ struct fdisk_column {
 enum {
        FDISK_COLFL_DETAIL      = (1 << 1),     /* only display if fdisk_context_display_details() */
        FDISK_COLFL_EYECANDY    = (1 << 2),     /* don't display if fdisk_context_display_details() */
+       FDISK_COLFL_NUMBER      = (1 << 3),     /* column display numbers */
 };
 
 /*
index d5acf95d046af75e0921d2b1412ac2ab600f4a0e..8ebb915df1c16058f5d0ed2dd82b281ce8a3a599 100644 (file)
@@ -18,7 +18,6 @@
 #include <errno.h>
 #include <ctype.h>
 #include <uuid.h>
-#include <libsmartcols.h>
 
 #include "fdiskP.h"
 
@@ -2400,17 +2399,17 @@ static const struct fdisk_column gpt_columns[] =
 {
        /* basic */
        { FDISK_COL_DEVICE,     N_("Device"),    10,    0 },
-       { FDISK_COL_START,      N_("Start"),      5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_END,        N_("End"),        5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_SECTORS,    N_("Sectors"),    5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_CYLINDERS,  N_("Cylinders"),  5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_SIZE,       N_("Size"),       5,    SCOLS_FL_RIGHT, FDISK_COLFL_EYECANDY },
-       { FDISK_COL_TYPE,       N_("Type"),     0.1,    SCOLS_FL_TRUNC, FDISK_COLFL_EYECANDY },
+       { FDISK_COL_START,      N_("Start"),      5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_END,        N_("End"),        5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_SECTORS,    N_("Sectors"),    5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_CYLINDERS,  N_("Cylinders"),  5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_SIZE,       N_("Size"),       5,    FDISK_COLFL_NUMBER | FDISK_COLFL_EYECANDY },
+       { FDISK_COL_TYPE,       N_("Type"),     0.1,    FDISK_COLFL_EYECANDY },
        /* expert */
-       { FDISK_COL_TYPEID,     N_("Type-UUID"), 36,    0,           FDISK_COLFL_DETAIL },
-       { FDISK_COL_UUID,       N_("UUID"),      36,    0,           FDISK_COLFL_DETAIL },
-       { FDISK_COL_NAME,       N_("Name"),     0.2,    SCOLS_FL_TRUNC, FDISK_COLFL_DETAIL },
-       { FDISK_COL_ATTR,       N_("Attrs"),      0,    0,           FDISK_COLFL_DETAIL }
+       { FDISK_COL_TYPEID,     N_("Type-UUID"), 36,    FDISK_COLFL_DETAIL },
+       { FDISK_COL_UUID,       N_("UUID"),      36,    FDISK_COLFL_DETAIL },
+       { FDISK_COL_NAME,       N_("Name"),     0.2,    FDISK_COLFL_DETAIL },
+       { FDISK_COL_ATTR,       N_("Attrs"),      0,    FDISK_COLFL_DETAIL }
 };
 
 /*
index f2cc255cdd4e670f1b4df028b6498f7d1ecda952..f6bef31d1ded2f4eec7fdadca6605e378d67f051 100644 (file)
@@ -113,10 +113,9 @@ int fdisk_missing_geometry(struct fdisk_context *cxt)
  * @cols: returns allocated array with FDISK_COL_* IDs
  * @ncols: returns number of items in cols
  *
- * This function returns the default or all columns for the current label.  The
- * library uses the columns for list operations (see fdisk_list_disklabel() and
- * fdisk_list_partitions()). Note that the set of the default columns depends
- * on fdisk_context_enable_details() function. If the details are eanable then
+ * This function returns the default or all columns for the current label.
+ * Note that the set of the default columns depends on
+ * fdisk_context_enable_details() function. If the details are enabled then
  * this function usually returns more columns.
  *
  * Returns 0 on success, otherwise, a corresponding error.
@@ -176,6 +175,26 @@ const struct fdisk_column *fdisk_label_get_column(
        return NULL;
 }
 
+int fdisk_column_get_id(const struct fdisk_column *col)
+{
+       return col ? col->id : -EINVAL;
+}
+
+const char *fdisk_column_get_name(const struct fdisk_column *col)
+{
+       return col ? col->name : NULL;
+}
+
+double fdisk_column_get_width(const struct fdisk_column *col)
+{
+       return col ? col->width : -EINVAL;
+}
+
+int fdisk_column_is_number(const struct fdisk_column *col)
+{
+       return col->flags ? col->flags & FDISK_COLFL_NUMBER : 0;
+}
+
 /**
  * fdisk_verify_disklabel:
  * @cxt: fdisk context
index a717f4ea3e4cbbf2fbf608b1f3f3124743c66e96..e7bc84338722fc9c1d379bb597c5af92019198ae 100644 (file)
@@ -35,6 +35,7 @@ struct fdisk_partition;
 struct fdisk_ask;
 struct fdisk_iter;
 struct fdisk_table;
+struct fdisk_column;
 
 /*
  * Supported partition table types (labels)
@@ -168,6 +169,11 @@ extern int fdisk_set_partition_type(struct fdisk_context *cxt, size_t partnum,
 
 extern int fdisk_get_columns(struct fdisk_context *cxt, int all, int **cols, size_t *ncols);
 
+extern int fdisk_column_get_id(const struct fdisk_column *col);
+extern const char *fdisk_column_get_name(const struct fdisk_column *col);
+extern double fdisk_column_get_width(const struct fdisk_column *col);
+extern int fdisk_column_is_number(const struct fdisk_column *col);
+
 extern void fdisk_label_set_changed(struct fdisk_label *lb, int changed);
 extern int fdisk_label_is_changed(struct fdisk_label *lb);
 
@@ -245,10 +251,6 @@ extern int fdisk_table_sort_partitions(struct fdisk_table *tb,
                        int (*cmp)(struct fdisk_partition *,
                                   struct fdisk_partition *));
 
-extern int fdisk_table_to_string(struct fdisk_table *tb,
-                         struct fdisk_context *cxt,
-                         int *cols, size_t ncols,  char **data);
-
 extern int fdisk_table_next_partition(
                        struct fdisk_table *tb,
                        struct fdisk_iter *itr,
index b191176d2610fe7d3a8d0955872b593d29d936d6..8e8d3208e1357f47be6c0c7418d4f243917f4a50 100644 (file)
@@ -11,7 +11,6 @@
  *               Phillip Kesling <pkesling@sgi.com>, Mar 2003.
  */
 
-#include <libsmartcols.h>
 #include "c.h"
 #include "nls.h"
 #include "all-io.h"
@@ -1084,14 +1083,14 @@ static int sgi_toggle_partition_flag(struct fdisk_context *cxt, size_t i, unsign
 static const struct fdisk_column sgi_columns[] =
 {
        { FDISK_COL_DEVICE,     N_("Device"),    10,    0 },
-       { FDISK_COL_START,      N_("Start"),      5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_END,        N_("End"),        5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_SECTORS,    N_("Sectors"),    5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_CYLINDERS,  N_("Cylinders"),  5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_SIZE,       N_("Size"),       5,    SCOLS_FL_RIGHT, FDISK_COLFL_EYECANDY },
-       { FDISK_COL_TYPEID,     N_("Id"),         2,    SCOLS_FL_RIGHT },
-       { FDISK_COL_TYPE,       N_("Type"),     0.1,    SCOLS_FL_TRUNC, FDISK_COLFL_EYECANDY },
-       { FDISK_COL_ATTR,       N_("Attrs"),      0,    SCOLS_FL_RIGHT }
+       { FDISK_COL_START,      N_("Start"),      5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_END,        N_("End"),        5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_SECTORS,    N_("Sectors"),    5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_CYLINDERS,  N_("Cylinders"),  5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_SIZE,       N_("Size"),       5,    FDISK_COLFL_NUMBER | FDISK_COLFL_EYECANDY },
+       { FDISK_COL_TYPEID,     N_("Id"),         2,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_TYPE,       N_("Type"),     0.1,    FDISK_COLFL_EYECANDY },
+       { FDISK_COL_ATTR,       N_("Attrs"),      0,    FDISK_COLFL_NUMBER }
 };
 
 static const struct fdisk_label_operations sgi_operations =
index 50bdf8668a211afd597aa75868dcdd5f8ce416f9..a4af4761b6bf93a18a5a9b1b8abe0656a334f169 100644 (file)
@@ -12,8 +12,6 @@
 #include <unistd.h>            /* write */
 #include <sys/ioctl.h>         /* ioctl */
 
-#include <libsmartcols.h>
-
 #include "nls.h"
 #include "blkdev.h"
 #include "bitops.h"
@@ -998,14 +996,14 @@ static int sun_partition_is_used(
 static const struct fdisk_column sun_columns[] =
 {
        { FDISK_COL_DEVICE,     N_("Device"),    10,    0 },
-       { FDISK_COL_START,      N_("Start"),      5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_END,        N_("End"),        5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_SECTORS,    N_("Sectors"),    5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_CYLINDERS,  N_("Cylinders"),  5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_SIZE,       N_("Size"),       5,    SCOLS_FL_RIGHT },
-       { FDISK_COL_TYPEID,     N_("Id"),         2,    SCOLS_FL_RIGHT },
-       { FDISK_COL_TYPE,       N_("Type"),     0.1,    SCOLS_FL_TRUNC },
-       { FDISK_COL_ATTR,       N_("Flags"),      0,    SCOLS_FL_RIGHT }
+       { FDISK_COL_START,      N_("Start"),      5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_END,        N_("End"),        5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_SECTORS,    N_("Sectors"),    5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_CYLINDERS,  N_("Cylinders"),  5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_SIZE,       N_("Size"),       5,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_TYPEID,     N_("Id"),         2,    FDISK_COLFL_NUMBER },
+       { FDISK_COL_TYPE,       N_("Type"),     0.1,    0 },
+       { FDISK_COL_ATTR,       N_("Flags"),      0,    FDISK_COLFL_NUMBER }
 };
 
 const struct fdisk_label_operations sun_operations =
index acdb365d09d13c4d5cfae3c07b664312fcc12e45..61876d0efaa3aa4f1d6905c08be73319f3b33cb4 100644 (file)
@@ -1,5 +1,4 @@
 
-#include <libsmartcols.h>
 #include "fdiskP.h"
 
 /**
@@ -547,96 +546,3 @@ int fdisk_table_wrong_order(struct fdisk_table *tb)
        }
        return 0;
 }
-
-/**
- * fdisk_table_to_string
- * @tb: table
- * @cxt: fdisk context
- * @cols: array with wanted FDISK_COL_* columns
- * @ncols: number of items in the cols array
- * @data: returns table as a newlly allocated string or NULL for empty PT
- *
- * If no @cols are specified then the default is printed (see
- * fdisk_get_columns() for the default columns).
-
- * Returns 0 on success, otherwise, a corresponding error.
- */
-int fdisk_table_to_string(struct fdisk_table *tb,
-                         struct fdisk_context *cxt,
-                         int *cols,
-                         size_t ncols,
-                         char **data)
-{
-       int *org_cols = cols, rc = 0;
-       struct libscols_table *table = NULL;
-       const struct fdisk_column *col;
-       struct fdisk_partition *pa = NULL;
-       struct fdisk_iter itr;
-       size_t j;
-
-       if (!cxt || !tb || !data)
-               return -EINVAL;
-
-       DBG(TAB, ul_debugobj(tb, "generate string"));
-       *data = NULL;
-
-       if (!fdisk_table_get_nents(tb))
-               return 0;
-
-       if (!cols || !ncols) {
-               rc = fdisk_get_columns(cxt, 0, &cols, &ncols);
-               if (rc)
-                       return rc;
-       }
-
-       table = scols_new_table();
-       if (!table) {
-               rc = -ENOMEM;
-               goto done;
-       }
-
-       /* define columns */
-       for (j = 0; j < ncols; j++) {
-               col = fdisk_label_get_column(cxt->label, cols[j]);
-               if (col)
-                       if (!scols_table_new_column(table, col->name, col->width, col->scols_flags))
-                               goto done;
-       }
-
-       fdisk_reset_iter(&itr, FDISK_ITER_FORWARD);
-
-       /* convert partition to string and add to table */
-       while (fdisk_table_next_partition(tb, &itr, &pa) == 0) {
-               struct libscols_line *ln = scols_table_new_line(table, NULL);
-               if (!ln) {
-                       rc = -ENOMEM;
-                       goto done;
-               }
-
-               DBG(TAB, ul_debugobj(tb, "  string from part #%zu [%p]",
-                                       pa->partno + 1, pa));
-
-               /* set data for the columns */
-               for (j = 0; j < ncols; j++) {
-                       char *cdata = NULL;
-
-                       col = fdisk_label_get_column(cxt->label, cols[j]);
-                       if (!col)
-                               continue;
-                       if (fdisk_partition_to_string(pa, cxt, col->id, &cdata))
-                               continue;
-                       scols_line_refer_data(ln, j, cdata);
-               }
-       }
-
-       rc = 0;
-       if (!scols_table_is_empty(table))
-               rc = scols_print_table_to_string(table, data);
-       else
-               DBG(TAB, ul_debugobj(tb, "table empty"));
-done:
-       if (org_cols != cols)
-               free(cols);
-       scols_unref_table(table);
-       return rc;
-}