From: Shakur Shams Mullick <shakursmullick@gmail.com>
To: util-linux@vger.kernel.org
Cc: Shakur Shams Mullick <shakursmullick@gmail.com>
Subject: [PATCH v3 5/5] libsmartcols/src/table_print.c: add sorting for table
Date: Wed, 14 May 2014 11:10:00 +0600 [thread overview]
Message-ID: <1400044200-9196-5-git-send-email-shakursmullick@gmail.com> (raw)
In-Reply-To: <1400044200-9196-1-git-send-email-shakursmullick@gmail.com>
Signed-off-by: Shakur Shams Mullick <shakursmullick@gmail.com>
---
libsmartcols/src/table_print.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c
index 24b73f9..fed0305 100644
--- a/libsmartcols/src/table_print.c
+++ b/libsmartcols/src/table_print.c
@@ -694,7 +694,28 @@ static size_t strlen_line(struct libscols_line *ln)
return sz;
}
+int comparison_func(struct list_head *a, struct list_head *b, void *data)
+{
+ struct libscols_column *cl;
+ struct libscols_line *ra, *rb;
+ struct libscols_cell *ca, *cb;
+
+ cl = (struct libscols_column *)(data);
+
+ ra = list_entry(a, struct libscols_line, ln_lines);
+ rb = list_entry(b, struct libscols_line, ln_lines);
+
+ ca = scols_line_get_cell(ra, cl->seqnum);
+ cb = scols_line_get_cell(rb, cl->seqnum);
+
+ return cl->compare_data(ca, cb, NULL);
+}
+void scols_sort_table(struct libscols_table *tb, struct libscols_column *cl)
+{
+ assert(tb);
+ list_sort(&tb->tb_lines, comparison_func, cl);
+}
/**
* scols_print_table:
--
1.8.3.2
next prev parent reply other threads:[~2014-05-14 5:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-14 5:09 [PATCH v3 1/5] libsmartcols/src/libsmartcols.h.in: add function Shakur Shams Mullick
2014-05-14 5:09 ` [PATCH v3 2/5] libsmartcols/src/libsmartcols.sym: add function symbol Shakur Shams Mullick
2014-05-14 5:09 ` [PATCH v3 3/5] libsmartcols/src/smartcolsP.h: add field to struct libscols_column Shakur Shams Mullick
2014-05-14 5:09 ` [PATCH v3 4/5] misc-utils/lsblk.c: add sorting support for lsblk command Shakur Shams Mullick
2014-05-14 5:10 ` Shakur Shams Mullick [this message]
2014-05-20 13:16 ` [PATCH v3 1/5] libsmartcols/src/libsmartcols.h.in: add function Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1400044200-9196-5-git-send-email-shakursmullick@gmail.com \
--to=shakursmullick@gmail.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox