From: Shakur Shams Mullick <shakursmullick@gmail.com>
To: util-linux@vger.kernel.org
Cc: Shakur Shams Mullick <shakursmullick@gmail.com>
Subject: [PATCH 4/8] libsmartcols/src/cell.c: add two functions to compare number and string cells
Date: Sun, 11 May 2014 14:20:34 +0600 [thread overview]
Message-ID: <1399796438-5495-4-git-send-email-shakursmullick@gmail.com> (raw)
In-Reply-To: <1399796438-5495-1-git-send-email-shakursmullick@gmail.com>
scols_cmpstr_cells and scols_cmpnum_cells compare string and number cells.
When comparing data of two cells for the purpose of sorting, it is not
necessary to use these two library functions. Developers can use their
own implementation of cell comparison function.
Furthermore these two functions can be extended to fascilitate sorting
in reverse order.
These two functions could be modified to fascilitate sorting in reverse order.
---
libsmartcols/src/cell.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/libsmartcols/src/cell.c b/libsmartcols/src/cell.c
index 491b8a1..9304d2a 100644
--- a/libsmartcols/src/cell.c
+++ b/libsmartcols/src/cell.c
@@ -25,6 +25,7 @@
#include <ctype.h>
#include "smartcolsP.h"
+#include "strutils.h"
/*
* The cell has no ref-counting, free() and new() functions. All is
@@ -181,3 +182,33 @@ int scols_cell_copy_content(struct libscols_cell *dest,
rc = scols_cell_set_color(dest, scols_cell_get_color(src));
return rc;
}
+
+int scols_cmpstr_cells(struct libscols_cell *a, struct libscols_cell *b, void *data)
+{
+ int n, m;
+ const char *adata, *bdata;
+
+ adata = scols_cell_get_data(a);
+ bdata = scols_cell_get_data(b);
+
+ n = strlen(adata);
+ m = strlen(bdata);
+
+ return strncmp(adata, bdata, (n>=m ? n : m));
+}
+
+int scols_cmpnum_cells(struct libscols_cell *a, struct libscols_cell *b, void *data)
+{
+ uint64_t n, m;
+ const char *adata, *bdata;
+
+ adata = scols_cell_get_data(a);
+ bdata = scols_cell_get_data(b);
+
+ strtosize(adata, &n);
+ strtosize(bdata, &m);
+
+ if (n >= m)
+ return 1;
+ return -1;
+}
--
1.8.3.2
next prev parent reply other threads:[~2014-05-11 8:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-11 8:20 [PATCH v2 1/8] libsmartcols/src/libsmartcols.h.in: add library functions Shakur Shams Mullick
2014-05-11 8:20 ` [PATCH v2 2/8] libsmartcols/src/libsmartcols.sym: add symbols Shakur Shams Mullick
2014-05-11 8:20 ` [PATCH v2 3/8] libsmartcols/src/smartcolsP.h: add new field to struct libscols_table Shakur Shams Mullick
2014-05-11 8:20 ` Shakur Shams Mullick [this message]
2014-05-12 12:37 ` [PATCH 4/8] libsmartcols/src/cell.c: add two functions to compare number and string cells Karel Zak
2014-05-11 8:20 ` [PATCH 5/8] libsmartcols/src/column.c: add function to set comparison function scols_column_set_sortcmp() sets the cell comparison function to use Shakur Shams Mullick
2014-05-11 8:20 ` [PATCH v2 6/8] libsmartcols/src/table.c: set and get key column to use for sorting scols_table_set_key_column() sets the column to use scols_table_get_key_column() returns the column being used Shakur Shams Mullick
2014-05-11 8:20 ` [PATCH v2 7/8] libsmartcols/src/table_print.c: sort the list before printing Shakur Shams Mullick
2014-05-12 12:43 ` Karel Zak
2014-05-12 17:22 ` shams
2014-05-11 8:20 ` [PATCH v2 8/8] misc-utils/lsblk.c: adds sorting support for lsblk Shakur Shams Mullick
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=1399796438-5495-4-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