* [PATCH 2/8] libsmartcols/src/libsmartcols.sym: add function symbol
2014-05-03 17:41 [PATCH 1/8] libsmartcols/src/libsmartcols.h.in: add function name Shakur Shams Mullick
@ 2014-05-03 17:41 ` Shakur Shams Mullick
2014-05-03 17:41 ` [PATCH 3/8] libsmartcols/src/smartcolsP.h: add sort flag and related enum Shakur Shams Mullick
` (6 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Shakur Shams Mullick @ 2014-05-03 17:41 UTC (permalink / raw)
To: util-linux; +Cc: Shakur Shams Mullick
Signed-off-by: Shakur Shams Mullick <shakursmullick@gmail.com>
---
libsmartcols/src/libsmartcols.sym | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libsmartcols/src/libsmartcols.sym b/libsmartcols/src/libsmartcols.sym
index 4b64f28..fe7f36c 100644
--- a/libsmartcols/src/libsmartcols.sym
+++ b/libsmartcols/src/libsmartcols.sym
@@ -70,6 +70,8 @@ global:
scols_table_enable_maxout;
scols_table_enable_noheadings;
scols_table_enable_raw;
+ scols_table_enable_namesort;
+ scols_table_enable_sizesort;
scols_table_get_column;
scols_table_get_column_separator;
scols_table_get_line;
@@ -84,6 +86,8 @@ global:
scols_table_is_noheadings;
scols_table_is_raw;
scols_table_is_tree;
+ scols_table_is_namesort;
+ scols_table_is_sizesort;
scols_table_new_column;
scols_table_new_line;
scols_table_next_column;
--
1.8.3.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 3/8] libsmartcols/src/smartcolsP.h: add sort flag and related enum
2014-05-03 17:41 [PATCH 1/8] libsmartcols/src/libsmartcols.h.in: add function name Shakur Shams Mullick
2014-05-03 17:41 ` [PATCH 2/8] libsmartcols/src/libsmartcols.sym: add function symbol Shakur Shams Mullick
@ 2014-05-03 17:41 ` Shakur Shams Mullick
2014-05-03 17:41 ` [PATCH 4/8] libsmartcols/src/table.c: implementation of 4 newly added functions Shakur Shams Mullick
` (5 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Shakur Shams Mullick @ 2014-05-03 17:41 UTC (permalink / raw)
To: util-linux; +Cc: Shakur Shams Mullick
Signed-off-by: Shakur Shams Mullick <shakursmullick@gmail.com>
---
libsmartcols/src/smartcolsP.h | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/libsmartcols/src/smartcolsP.h b/libsmartcols/src/smartcolsP.h
index ebdc929..d7b9982 100644
--- a/libsmartcols/src/smartcolsP.h
+++ b/libsmartcols/src/smartcolsP.h
@@ -44,7 +44,7 @@ UL_DEBUG_DECLARE_MASK(libsmartcols);
struct libscols_iter {
struct list_head *p; /* current position */
struct list_head *head; /* start position */
- int direction; /* SCOLS_ITER_{FOR,BACK}WARD */
+ int direction; /* SCOLS_ITER_{FOR,BACK}WARD */
};
/*
@@ -108,11 +108,16 @@ struct libscols_line {
};
enum {
- SCOLS_FMT_HUMAN = 0, /* default, human readable */
+ SCOLS_FMT_HUMAN = 0, /* default, human readable */
SCOLS_FMT_RAW, /* space separated */
SCOLS_FMT_EXPORT /* COLNAME="data" ... */
};
+enum{
+ SCOLS_SORT_NAME = 0, /* sort by name */
+ SCOLS_SORT_SIZE /* sort by size */
+};
+
/*
* The table
*/
@@ -133,13 +138,15 @@ struct libscols_table {
struct libscols_symbols *symbols;
int format; /* SCOLS_FMT_* */
-
+
+ int sort; /* SCOLS_SORT_* */
+
/* flags */
unsigned int ascii :1, /* don't use unicode */
- colors_wanted :1, /* enable colors */
- is_term :1, /* isatty() */
- maxout :1, /* maximalize output */
- no_headings :1; /* don't print header */
+ colors_wanted :1, /* enable colors */
+ is_term :1, /* isatty() */
+ maxout :1, /* maximalize output */
+ no_headings :1; /* don't print header */
};
#define IS_ITER_FORWARD(_i) ((_i)->direction == SCOLS_ITER_FORWARD)
--
1.8.3.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 4/8] libsmartcols/src/table.c: implementation of 4 newly added functions
2014-05-03 17:41 [PATCH 1/8] libsmartcols/src/libsmartcols.h.in: add function name Shakur Shams Mullick
2014-05-03 17:41 ` [PATCH 2/8] libsmartcols/src/libsmartcols.sym: add function symbol Shakur Shams Mullick
2014-05-03 17:41 ` [PATCH 3/8] libsmartcols/src/smartcolsP.h: add sort flag and related enum Shakur Shams Mullick
@ 2014-05-03 17:41 ` Shakur Shams Mullick
2014-05-03 17:41 ` [PATCH 5/8] libsmartcols/src/table_print.c: sort table before printing Shakur Shams Mullick
` (4 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Shakur Shams Mullick @ 2014-05-03 17:41 UTC (permalink / raw)
To: util-linux; +Cc: Shakur Shams Mullick
newly implemented functions are:
extern int scols_table_is_namesort(struct libscols_table *tb);
extern int scols_table_is_sizesort(struct libscols_table *tb);
extern int scols_table_enable_namesort(struct libscols_table *tb, int enable);
extern int scols_table_enable_sizesort(struct libscols_table *tb, int enable);
Signed-off-by: Shakur Shams Mullick <shakursmullick@gmail.com>
---
libsmartcols/src/table.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c
index d4c61ee..224e7b9 100644
--- a/libsmartcols/src/table.c
+++ b/libsmartcols/src/table.c
@@ -707,6 +707,51 @@ int scols_table_enable_raw(struct libscols_table *tb, int enable)
tb->format = 0;
return 0;
}
+/**
+ * scols_table_enable_namesort:
+ * @tb: table
+ * @enable: 1 or 0
+ *
+ * Enable/disable sorted by name output format.
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+
+int scols_table_enable_namesort(struct libscols_table *tb, int enable)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+
+ if (enable)
+ tb->sort = SCOLS_SORT_NAME;
+ else if (tb->sort == SCOLS_SORT_NAME)
+ tb->sort = 0;
+ return 0;
+}
+
+/**
+ * scols_table_enable_sizesort:
+ * @tb: table
+ * @enable: 1 or 0
+ *
+ * Enable/disable sorted by size output format.
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+
+int scols_table_enable_sizesort(struct libscols_table *tb, int enable)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+
+ if (enable)
+ tb->sort = SCOLS_SORT_SIZE;
+ else if (tb->sort == SCOLS_SORT_SIZE)
+ tb->sort = 0;
+ return 0;
+}
/**
* scols_table_enable_export:
@@ -840,6 +885,29 @@ int scols_table_is_noheadings(struct libscols_table *tb)
}
/**
+ * scols_table_is_namesort:
+ * @tb: table
+ *
+ * Returns: 1 if sorted output by name is enabled.
+ */
+int scols_table_is_namesort(struct libscols_table *tb)
+{
+ assert(tb);
+ return tb && tb->sort == SCOLS_SORT_NAME;
+}
+
+/**
+ * scols_table_is_sizesort:
+ * @tb: table
+ *
+ * Returns: 1 if sorted output by size is enabled.
+ */
+int scols_table_is_sizesort(struct libscols_table *tb)
+{
+ assert(tb);
+ return tb && tb->sort == SCOLS_SORT_SIZE;
+}
+/**
* scols_table_is_export:
* @tb: table
*
--
1.8.3.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 5/8] libsmartcols/src/table_print.c: sort table before printing
2014-05-03 17:41 [PATCH 1/8] libsmartcols/src/libsmartcols.h.in: add function name Shakur Shams Mullick
` (2 preceding siblings ...)
2014-05-03 17:41 ` [PATCH 4/8] libsmartcols/src/table.c: implementation of 4 newly added functions Shakur Shams Mullick
@ 2014-05-03 17:41 ` Shakur Shams Mullick
2014-05-03 17:41 ` [PATCH 6/8] misc-utils/lsblk.c: add sorting support for lsblk command Shakur Shams Mullick
` (3 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Shakur Shams Mullick @ 2014-05-03 17:41 UTC (permalink / raw)
To: util-linux; +Cc: Shakur Shams Mullick
It fascilitates sorting before printing the table. Sorting can be done by size or name.
Signed-off-by: Shakur Shams Mullick <shakursmullick@gmail.com>
---
libsmartcols/src/table_print.c | 60 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 59 insertions(+), 1 deletion(-)
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c
index 2942053..b256198 100644
--- a/libsmartcols/src/table_print.c
+++ b/libsmartcols/src/table_print.c
@@ -20,6 +20,7 @@
#include <string.h>
#include <termios.h>
#include <ctype.h>
+#include <list.h>
#include "nls.h"
#include "mbsalign.h"
@@ -27,6 +28,7 @@
#include "ttyutils.h"
#include "carefulputc.h"
#include "smartcolsP.h"
+#include "strutils.h"
/* This is private struct to work with output data */
struct libscols_buffer {
@@ -38,6 +40,8 @@ struct libscols_buffer {
size_t art_idx; /* begin of the tree ascii art or zero */
};
+static uint sq;
+
static struct libscols_buffer *new_buffer(size_t sz)
{
struct libscols_buffer *buf = malloc(sz + sizeof(struct libscols_buffer));
@@ -694,7 +698,35 @@ static size_t strlen_line(struct libscols_line *ln)
return sz;
}
+int size_comparison(struct list_head *a, struct list_head *b, void *data)
+{
+ struct libscols_line *ra, *rb;
+ uint64_t n, m;
+
+ ra = list_entry(a, struct libscols_line, ln_lines);
+ rb = list_entry(b, struct libscols_line, ln_lines);
+
+ strtosize(ra->cells[sq].data, &n);
+ strtosize(rb->cells[sq].data, &m);
+
+ if (n >= m)
+ return 1;
+ return -1;
+}
+int name_comparison(struct list_head *a, struct list_head *b, void *data)
+{
+ struct libscols_line *ra, *rb;
+ int n, m;
+
+ ra = list_entry(a, struct libscols_line, ln_lines);
+ rb = list_entry(b, struct libscols_line, ln_lines);
+
+ n = strlen(ra->cells[sq].data);
+ m = strlen(rb->cells[sq].data);
+
+ return strncmp(ra->cells[sq].data, rb->cells[sq].data, (n>=m ? n : m));
+}
/**
* scols_print_table:
@@ -711,7 +743,9 @@ int scols_print_table(struct libscols_table *tb)
struct libscols_line *ln;
struct libscols_iter itr;
struct libscols_buffer *buf;
-
+ struct list_head *p;
+ char *sdata;
+
assert(tb);
if (!tb)
return -1;
@@ -743,6 +777,30 @@ int scols_print_table(struct libscols_table *tb)
if (scols_table_is_tree(tb))
rc = print_tree(tb, buf);
+ else if (scols_table_is_namesort(tb))
+ {
+ list_for_each(p, &tb->tb_columns) {
+ struct libscols_column *cl = list_entry(p, struct libscols_column, cl_columns);
+ if(strncmp(cl->header.data, "NAME", 4) == 0){
+ sq = cl->seqnum;
+ break;
+ }
+ }
+ list_sort(&tb->tb_lines, name_comparison, NULL);
+ print_table(tb, buf);
+ }
+ else if (scols_table_is_sizesort(tb))
+ {
+ list_for_each(p, &tb->tb_columns) {
+ struct libscols_column *cl = list_entry(p, struct libscols_column, cl_columns);
+ if(strncmp(cl->header.data, "SIZE", 4) == 0){
+ sq = cl->seqnum;
+ break;
+ }
+ }
+ list_sort(&tb->tb_lines, size_comparison, NULL);
+ print_table(tb, buf);
+ }
else
rc = print_table(tb, buf);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 6/8] misc-utils/lsblk.c: add sorting support for lsblk command
2014-05-03 17:41 [PATCH 1/8] libsmartcols/src/libsmartcols.h.in: add function name Shakur Shams Mullick
` (3 preceding siblings ...)
2014-05-03 17:41 ` [PATCH 5/8] libsmartcols/src/table_print.c: sort table before printing Shakur Shams Mullick
@ 2014-05-03 17:41 ` Shakur Shams Mullick
2014-05-06 10:43 ` Karel Zak
2014-05-03 17:41 ` [PATCH 7/8] misc-utils/lslocks.c: add sorting support for lslocks command Shakur Shams Mullick
` (2 subsequent siblings)
7 siblings, 1 reply; 10+ messages in thread
From: Shakur Shams Mullick @ 2014-05-03 17:41 UTC (permalink / raw)
To: util-linux; +Cc: Shakur Shams Mullick
It adds support for sorting in lsblk command. sorting can be done by name(-c) or size(-z). For longoptions use --sort name or --sort size
e.g. lsblk -c
lsblk -q name
lsblk --sort size
Signed-off-by: Shakur Shams Mullick <shakursmullick@gmail.com>
---
misc-utils/lsblk.c | 43 +++++++++++++++++++++++++++++++++++++------
1 file changed, 37 insertions(+), 6 deletions(-)
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index 2efb2ec..2d9c9c7 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -110,11 +110,13 @@ enum {
/* basic table settings */
enum {
- LSBLK_ASCII = (1 << 0),
- LSBLK_RAW = (1 << 1),
- LSBLK_NOHEADINGS = (1 << 2),
- LSBLK_EXPORT = (1 << 3),
- LSBLK_TREE = (1 << 4),
+ LSBLK_ASCII = (1 << 0),
+ LSBLK_RAW = (1 << 1),
+ LSBLK_NOHEADINGS = (1 << 2),
+ LSBLK_EXPORT = (1 << 3),
+ LSBLK_TREE = (1 << 4),
+ LSBLK_NSORTED = (1 << 5), /* sort by name */
+ LSBLK_SZSORTED = (1 << 6), /* sort by size */
};
/* column names */
@@ -1355,6 +1357,10 @@ static void __attribute__((__noreturn__)) help(FILE *out)
fputs(_(" -i, --ascii use ascii characters only\n"), out);
fputs(_(" -I, --include <list> show only devices with specified major numbers\n"), out);
fputs(_(" -l, --list use list format output\n"), out);
+ fputs(_(" -z, show list sorted by size\n"), out);
+ fputs(_(" -c, show list sorted by name\n"), out);
+ fputs(_(" -q --sort WORD sort by WORD: size -z, name -c\n"), out);
+ fputs(_(" e.g. --sort size\n"), out);
fputs(_(" -m, --perms output info about permissions\n"), out);
fputs(_(" -n, --noheadings don't print headings\n"), out);
fputs(_(" -o, --output <list> output columns\n"), out);
@@ -1413,6 +1419,9 @@ int main(int argc, char *argv[])
{ "pairs", 0, 0, 'P' },
{ "scsi", 0, 0, 'S' },
{ "version", 0, 0, 'V' },
+ { "sort", 1, 0, 'q' },
+ { NULL, 0, 0, 'z' },
+ { NULL, 0, 0, 'c' },
{ NULL, 0, 0, 0 },
};
@@ -1432,7 +1441,7 @@ int main(int argc, char *argv[])
memset(lsblk, 0, sizeof(*lsblk));
while((c = getopt_long(argc, argv,
- "abdDe:fhlnmo:pPiI:rstVS", longopts, NULL)) != -1) {
+ "abdDe:fhlnmo:pPiI:rstVSq:zc", longopts, NULL)) != -1) {
err_exclusive_options(c, longopts, excl, excl_st);
@@ -1462,6 +1471,26 @@ int main(int argc, char *argv[])
case 'l':
scols_flags &= ~LSBLK_TREE; /* disable the default */
break;
+ case 'q':
+ if(strncasecmp(optarg, "size", 4) == 0)
+ {
+ scols_flags |= LSBLK_SZSORTED;
+ scols_flags &= ~LSBLK_TREE; /* disable the default */
+ }
+ else if(strncasecmp(optarg, "name", 4) == 0)
+ {
+ scols_flags |= LSBLK_NSORTED;
+ scols_flags &= ~LSBLK_TREE; /* disable the default */
+ }
+ break;
+ case 'c':
+ scols_flags |= LSBLK_NSORTED;
+ scols_flags &= ~LSBLK_TREE; /* disable the default */
+ break;
+ case 'z':
+ scols_flags |= LSBLK_SZSORTED;
+ scols_flags &= ~LSBLK_TREE; /* disable the default */
+ break;
case 'n':
scols_flags |= LSBLK_NOHEADINGS;
break;
@@ -1564,6 +1593,8 @@ int main(int argc, char *argv[])
scols_table_enable_export(lsblk->table, !!(scols_flags & LSBLK_EXPORT));
scols_table_enable_ascii(lsblk->table, !!(scols_flags & LSBLK_ASCII));
scols_table_enable_noheadings(lsblk->table, !!(scols_flags & LSBLK_NOHEADINGS));
+ scols_table_enable_namesort(lsblk->table, !!(scols_flags & LSBLK_NSORTED));
+ scols_table_enable_sizesort(lsblk->table, !!(scols_flags & LSBLK_SZSORTED));
for (i = 0; i < ncolumns; i++) {
struct colinfo *ci = get_column_info(i);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 6/8] misc-utils/lsblk.c: add sorting support for lsblk command
2014-05-03 17:41 ` [PATCH 6/8] misc-utils/lsblk.c: add sorting support for lsblk command Shakur Shams Mullick
@ 2014-05-06 10:43 ` Karel Zak
0 siblings, 0 replies; 10+ messages in thread
From: Karel Zak @ 2014-05-06 10:43 UTC (permalink / raw)
To: Shakur Shams Mullick; +Cc: util-linux
On Sat, May 03, 2014 at 11:41:26PM +0600, Shakur Shams Mullick wrote:
> It adds support for sorting in lsblk command. sorting can be done by name(-c) or size(-z). For longoptions use --sort name or --sort size
>
> e.g. lsblk -c
> lsblk -q name
> lsblk --sort size
IMHO it would be better to have a generic option
lsblk --order-by <column>
and maybe sort-cuts --order-by-size and --order-by-name to sort by NAME
and SIZE columns. (or s/order/sort/ ...)
It will probably necessary to add info about compare function type
(number or string) to lsblk "struct colinfo".
Maybe we can also add scols_cmpstr_cells() and scols_cmpnum_cells() to
the library to avoid duplicate code.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 7/8] misc-utils/lslocks.c: add sorting support for lslocks command
2014-05-03 17:41 [PATCH 1/8] libsmartcols/src/libsmartcols.h.in: add function name Shakur Shams Mullick
` (4 preceding siblings ...)
2014-05-03 17:41 ` [PATCH 6/8] misc-utils/lsblk.c: add sorting support for lsblk command Shakur Shams Mullick
@ 2014-05-03 17:41 ` Shakur Shams Mullick
2014-05-03 17:41 ` [PATCH 8/8] disk-utils/partx.c: add sorting support for partx command Shakur Shams Mullick
2014-05-06 10:33 ` [PATCH 1/8] libsmartcols/src/libsmartcols.h.in: add function name Karel Zak
7 siblings, 0 replies; 10+ messages in thread
From: Shakur Shams Mullick @ 2014-05-03 17:41 UTC (permalink / raw)
To: util-linux; +Cc: Shakur Shams Mullick
usage is similar to that of lsblk.
Signed-off-by: Shakur Shams Mullick <shakursmullick@gmail.com>
---
misc-utils/lslocks.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/misc-utils/lslocks.c b/misc-utils/lslocks.c
index 1495bd4..0d6aa16 100644
--- a/misc-utils/lslocks.c
+++ b/misc-utils/lslocks.c
@@ -89,6 +89,8 @@ static struct libmnt_table *tab; /* /proc/self/mountinfo */
/* basic output flags */
static int no_headings;
static int raw;
+static int nsort;
+static int szsort;
struct lock {
struct list_head locks;
@@ -462,6 +464,8 @@ static int show_locks(struct list_head *locks)
}
scols_table_enable_raw(table, raw);
scols_table_enable_noheadings(table, no_headings);
+ scols_table_enable_namesort(table, nsort);
+ scols_table_enable_sizesort(table, szsort);
for (i = 0; i < ncolumns; i++) {
struct colinfo *col = get_column_info(i);
@@ -511,6 +515,10 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
" -n, --noheadings don't print headings\n"
" -r, --raw use the raw output format\n"
" -u, --notruncate don't truncate text in columns\n"
+ " -z, show list sorted by size\n"
+ " -c, show list sorted by name\n"
+ " -q --sort WORD sort by WORD: size -z, name -c\n"
+ " e.g. --sort size\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n"), out);
@@ -534,6 +542,9 @@ int main(int argc, char *argv[])
{ "help", no_argument, NULL, 'h' },
{ "output", required_argument, NULL, 'o' },
{ "notruncate", no_argument, NULL, 'u' },
+ { "sort", 1, NULL, 'q' },
+ { NULL, no_argument, NULL, 'z' },
+ { NULL, no_argument, NULL, 'c' },
{ "version", no_argument, NULL, 'V' },
{ "noheadings", no_argument, NULL, 'n' },
{ "raw", no_argument, NULL, 'r' },
@@ -546,7 +557,7 @@ int main(int argc, char *argv[])
atexit(close_stdout);
while ((c = getopt_long(argc, argv,
- "p:o:nruhV", long_opts, NULL)) != -1) {
+ "p:o:nruhVq:zc", long_opts, NULL)) != -1) {
switch(c) {
case 'p':
@@ -566,6 +577,18 @@ int main(int argc, char *argv[])
case 'r':
raw = 1;
break;
+ case 'q':
+ if(strncasecmp(optarg, "size", 4) == 0)
+ szsort = 1;
+ else if(strncasecmp(optarg, "name", 4) == 0)
+ nsort = 1;
+ break;
+ case 'c':
+ nsort = 1;
+ break;
+ case 'z':
+ szsort = 1;
+ break;
case 'u':
disable_columns_truncate();
break;
--
1.8.3.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 8/8] disk-utils/partx.c: add sorting support for partx command
2014-05-03 17:41 [PATCH 1/8] libsmartcols/src/libsmartcols.h.in: add function name Shakur Shams Mullick
` (5 preceding siblings ...)
2014-05-03 17:41 ` [PATCH 7/8] misc-utils/lslocks.c: add sorting support for lslocks command Shakur Shams Mullick
@ 2014-05-03 17:41 ` Shakur Shams Mullick
2014-05-06 10:33 ` [PATCH 1/8] libsmartcols/src/libsmartcols.h.in: add function name Karel Zak
7 siblings, 0 replies; 10+ messages in thread
From: Shakur Shams Mullick @ 2014-05-03 17:41 UTC (permalink / raw)
To: util-linux; +Cc: Shakur Shams Mullick
usage is similar to that of lsblk
Signed-off-by: Shakur Shams Mullick <shakursmullick@gmail.com>
---
disk-utils/partx.c | 35 +++++++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/disk-utils/partx.c b/disk-utils/partx.c
index 830af1f..ef7872d 100644
--- a/disk-utils/partx.c
+++ b/disk-utils/partx.c
@@ -41,9 +41,11 @@
/* basic table settings */
enum {
- PARTX_RAW = (1 << 0),
+ PARTX_RAW = (1 << 0),
PARTX_NOHEADINGS = (1 << 1),
PARTX_EXPORT = (1 << 2),
+ PARTX_NSORTED = (1 << 3),
+ PARTX_SZSORTED = (1 << 4),
};
/* all the columns (-o option) */
@@ -634,6 +636,8 @@ static int show_parts(blkid_partlist ls, int scols_flags, int lower, int upper)
scols_table_enable_raw(table, !!(scols_flags & PARTX_RAW));
scols_table_enable_export(table, !!(scols_flags & PARTX_EXPORT));
scols_table_enable_noheadings(table, !!(scols_flags & PARTX_NOHEADINGS));
+ scols_table_enable_namesort(table, !!(scols_flags & PARTX_NSORTED));
+ scols_table_enable_sizesort(table, !!(scols_flags & PARTX_SZSORTED));
for (i = 0; i < ncolumns; i++) {
struct colinfo *col = get_column_info(i);
@@ -717,6 +721,10 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(_(" -d, --delete delete specified partitions or all of them\n"), out);
fputs(_(" -u, --update update specified partitions or all of them\n"), out);
fputs(_(" -s, --show list partitions\n\n"), out);
+ fputs(_(" -z, show list sorted by size\n"), out);
+ fputs(_(" -c, show list sorted by name\n"), out);
+ fputs(_(" -q --sort WORD sort by WORD: size -z, name -c\n"), out);
+ fputs(_(" e.g. --sort size\n"), out);
fputs(_(" -b, --bytes print SIZE in bytes rather than in human readable format\n"), out);
fputs(_(" -g, --noheadings don't print headings for --show\n"), out);
fputs(_(" -n, --nr <n:m> specify the range of partitions (e.g. --nr 2:4)\n"), out);
@@ -766,6 +774,9 @@ int main(int argc, char **argv)
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ "verbose", no_argument, NULL, 'v' },
+ { "sort", 1, NULL, 'q' },
+ { NULL, no_argument, NULL, 'z' },
+ { NULL, no_argument, NULL, 'c' },
{ NULL, 0, NULL, 0 }
};
@@ -781,7 +792,7 @@ int main(int argc, char **argv)
atexit(close_stdout);
while ((c = getopt_long(argc, argv,
- "abdglrsuvn:t:o:PhV", long_opts, NULL)) != -1) {
+ "abdglrsuvn:t:o:PhVq:zc", long_opts, NULL)) != -1) {
err_exclusive_options(c, long_opts, excl, excl_st);
@@ -801,6 +812,26 @@ int main(int argc, char **argv)
case 'l':
what = ACT_LIST;
break;
+ case 'q':
+ if(strncasecmp(optarg, "size", 4) == 0)
+ {
+ what = ACT_SHOW;
+ scols_flags |= PARTX_SZSORTED;
+ }
+ else if(strncasecmp(optarg, "name", 4) == 0)
+ {
+ what = ACT_SHOW;
+ scols_flags |= PARTX_NSORTED;
+ }
+ break;
+ case 'z':
+ what = ACT_SHOW;
+ scols_flags |= PARTX_SZSORTED;
+ break;
+ case 'c':
+ what = ACT_SHOW;
+ scols_flags |= PARTX_NSORTED;
+ break;
case 'n':
if (parse_range(optarg, &lower, &upper, 0))
errx(EXIT_FAILURE, _("failed to parse --nr <M-N> range"));
--
1.8.3.2
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 1/8] libsmartcols/src/libsmartcols.h.in: add function name
2014-05-03 17:41 [PATCH 1/8] libsmartcols/src/libsmartcols.h.in: add function name Shakur Shams Mullick
` (6 preceding siblings ...)
2014-05-03 17:41 ` [PATCH 8/8] disk-utils/partx.c: add sorting support for partx command Shakur Shams Mullick
@ 2014-05-06 10:33 ` Karel Zak
7 siblings, 0 replies; 10+ messages in thread
From: Karel Zak @ 2014-05-06 10:33 UTC (permalink / raw)
To: Shakur Shams Mullick; +Cc: util-linux
On Sat, May 03, 2014 at 11:41:21PM +0600, Shakur Shams Mullick wrote:
> libsmartcols/src/libsmartcols.h.in | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
Thanks Shakur,
> +extern int scols_table_is_namesort(struct libscols_table *tb);
> +extern int scols_table_is_sizesort(struct libscols_table *tb);
unfortunately it seems more like a hack to have sorted output from
lsblk(8) than a real extension to the API.
It's shared library, we should not force developers to use our
hardcoded point of view. It would be better to have API to specify
custom compare function.
scols_column_set_sortcmp(struct libscols_column *cl,
int (*compar)(struct libscols_cell *, struct libscols_cell *, void *),
void *data)
it means function to compare two cells. This function should be called
from struct list_head compare function.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 10+ messages in thread