util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lsblk: support -o +<attr> for adding attribute to output fields.
@ 2012-07-26 12:14 Milan Broz
  2012-07-26 13:52 ` [PATCH 1/5] Add string_add_to_idarray() - parse and add to id list Milan Broz
  0 siblings, 1 reply; 11+ messages in thread
From: Milan Broz @ 2012-07-26 12:14 UTC (permalink / raw)
  To: util-linux; +Cc: Milan Broz

E.g. lsblk -o +model
(Maybe it would be nice to add this to other tools as well?)

Signed-off-by: Milan Broz <mbroz@redhat.com>
---
 misc-utils/lsblk.c |   22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index cb2b768..471f2d5 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -1213,6 +1213,7 @@ int main(int argc, char *argv[])
 	struct lsblk _ls;
 	int tt_flags = TT_FL_TREE;
 	int i, c, status = EXIT_FAILURE;
+	char *outarg = NULL;
 
 	enum {
 		EXCL_NONE,
@@ -1290,11 +1291,7 @@ int main(int argc, char *argv[])
 			tt_flags |= TT_FL_NOHEADINGS;
 			break;
 		case 'o':
-			ncolumns = string_to_idarray(optarg,
-						columns, ARRAY_SIZE(columns),
-						column_name_to_id);
-			if (ncolumns < 0)
-				return EXIT_FAILURE;
+			outarg = optarg;
 			break;
 		case 'P':
 			exclusive_option(&excl_rlP, EXCL_PAIRS, "--{raw,list,pairs}");
@@ -1363,6 +1360,21 @@ int main(int argc, char *argv[])
 		columns[ncolumns++] = COL_TARGET;
 	}
 
+	if (outarg) {
+		if (outarg[0] == '+')
+			outarg++;
+		else
+			ncolumns = 0;
+
+		c = string_to_idarray(outarg, &columns[ncolumns],
+					ARRAY_SIZE(columns) - ncolumns,
+					column_name_to_id);
+		if (c < 0)
+			return EXIT_FAILURE;
+
+		ncolumns += c;
+	}
+
 	if (nexcludes == 0 && nincludes == 0)
 		excludes[nexcludes++] = 1;	/* default: ignore RAM disks */
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 1/5] Add string_add_to_idarray() - parse and add to id list.
  2012-07-26 12:14 [PATCH] lsblk: support -o +<attr> for adding attribute to output fields Milan Broz
@ 2012-07-26 13:52 ` Milan Broz
  2012-07-26 13:52   ` [PATCH 2/5] lsblk: support -o +<attr> for adding attribute to output fields Milan Broz
                     ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Milan Broz @ 2012-07-26 13:52 UTC (permalink / raw)
  To: util-linux; +Cc: Milan Broz


Signed-off-by: Milan Broz <mbroz@redhat.com>
---
 include/strutils.h |    4 ++++
 lib/strutils.c     |   26 ++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/include/strutils.h b/include/strutils.h
index 57b13fd..123907f 100644
--- a/include/strutils.h
+++ b/include/strutils.h
@@ -59,6 +59,10 @@ extern char *size_to_human_string(int options, uint64_t bytes);
 
 extern int string_to_idarray(const char *list, int ary[], size_t arysz,
 			   int (name2id)(const char *, size_t));
+extern int string_add_to_idarray(const char *list, int ary[],
+				 size_t arysz, int *ary_pos,
+				 int (name2id)(const char *, size_t));
+
 extern int string_to_bitarray(const char *list, char *ary,
 			    int (*name2bit)(const char *, size_t));
 
diff --git a/lib/strutils.c b/lib/strutils.c
index 036ae06..df31682 100644
--- a/lib/strutils.c
+++ b/lib/strutils.c
@@ -479,6 +479,32 @@ int string_to_idarray(const char *list, int ary[], size_t arysz,
 }
 
 /*
+ * Parses the array like string_to_idarray but if format is "+aaa,bbb"
+ * it adds fields to array instead of replacing them.
+ */
+int string_add_to_idarray(const char *list, int ary[], size_t arysz,
+			int *ary_pos, int (name2id)(const char *, size_t))
+{
+	const char *list_add;
+	int r;
+
+	if (!list || !*list || !ary_pos || *ary_pos < 0 | *ary_pos > (int)arysz)
+		return -1;
+
+	if (list[0] == '+')
+		list_add = &list[1];
+	else {
+		list_add = list;
+		*ary_pos = 0;
+	}
+
+	r = string_to_idarray(list_add, &ary[*ary_pos], arysz - *ary_pos, name2id);
+	if (r > 0)
+		*ary_pos += r;
+	return r;
+}
+
+/*
  * LIST ::= <item> [, <item>]
  *
  * The <item> is translated to 'id' by name2id() function and the 'id' is used
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/5]  lsblk: support -o +<attr> for adding attribute to output fields.
  2012-07-26 13:52 ` [PATCH 1/5] Add string_add_to_idarray() - parse and add to id list Milan Broz
@ 2012-07-26 13:52   ` Milan Broz
  2012-07-26 14:47     ` Karel Zak
  2012-07-26 13:52   ` [PATCH 3/5] partx: " Milan Broz
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Milan Broz @ 2012-07-26 13:52 UTC (permalink / raw)
  To: util-linux; +Cc: Milan Broz


Signed-off-by: Milan Broz <mbroz@redhat.com>
---
 misc-utils/lsblk.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index cb2b768..19c8edd 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -1213,6 +1213,7 @@ int main(int argc, char *argv[])
 	struct lsblk _ls;
 	int tt_flags = TT_FL_TREE;
 	int i, c, status = EXIT_FAILURE;
+	char *outarg = NULL;
 
 	enum {
 		EXCL_NONE,
@@ -1290,11 +1291,7 @@ int main(int argc, char *argv[])
 			tt_flags |= TT_FL_NOHEADINGS;
 			break;
 		case 'o':
-			ncolumns = string_to_idarray(optarg,
-						columns, ARRAY_SIZE(columns),
-						column_name_to_id);
-			if (ncolumns < 0)
-				return EXIT_FAILURE;
+			outarg = optarg;
 			break;
 		case 'P':
 			exclusive_option(&excl_rlP, EXCL_PAIRS, "--{raw,list,pairs}");
@@ -1363,6 +1360,10 @@ int main(int argc, char *argv[])
 		columns[ncolumns++] = COL_TARGET;
 	}
 
+	if (outarg && string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
+					 &ncolumns, column_name_to_id) < 0)
+		return EXIT_FAILURE;
+
 	if (nexcludes == 0 && nincludes == 0)
 		excludes[nexcludes++] = 1;	/* default: ignore RAM disks */
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/5] partx: support -o +<attr> for adding attribute to output fields.
  2012-07-26 13:52 ` [PATCH 1/5] Add string_add_to_idarray() - parse and add to id list Milan Broz
  2012-07-26 13:52   ` [PATCH 2/5] lsblk: support -o +<attr> for adding attribute to output fields Milan Broz
@ 2012-07-26 13:52   ` Milan Broz
  2012-07-26 14:47     ` Karel Zak
  2012-07-26 13:52   ` [PATCH 4/5] findmnt: " Milan Broz
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Milan Broz @ 2012-07-26 13:52 UTC (permalink / raw)
  To: util-linux; +Cc: Milan Broz


Signed-off-by: Milan Broz <mbroz@redhat.com>
---
 disk-utils/partx.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/disk-utils/partx.c b/disk-utils/partx.c
index 69c559d..8af33ab 100644
--- a/disk-utils/partx.c
+++ b/disk-utils/partx.c
@@ -643,6 +643,7 @@ int main(int argc, char **argv)
 	char *type = NULL;
 	char *device = NULL; /* pointer to argv[], ie: /dev/sda1 */
 	char *wholedisk = NULL; /* allocated, ie: /dev/sda */
+	char *outarg = NULL;
 	dev_t disk_devno = 0, part_devno = 0;
 
 	static const struct option long_opts[] = {
@@ -691,11 +692,7 @@ int main(int argc, char **argv)
 				errx(EXIT_FAILURE, _("failed to parse --nr <M-N> range"));
 			break;
 		case 'o':
-			ncolumns = string_to_idarray(optarg,
-						columns, ARRAY_SIZE(columns),
-						column_name_to_id);
-			if (ncolumns < 0)
-				return EXIT_FAILURE;
+			outarg = optarg;
 			exclusive_option(&what, ACT_SHOW, ACT_ERROR);
 			break;
 		case 'P':
@@ -740,6 +737,11 @@ int main(int argc, char **argv)
 		columns[ncolumns++] = COL_UUID;
 	}
 
+	if (what == ACT_SHOW && outarg &&
+	    string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
+				   &ncolumns, column_name_to_id) < 0)
+		return EXIT_FAILURE;
+
 	/*
 	 * Note that 'partx /dev/sda1' == 'partx /dev/sda1 /dev/sda'
 	 * so assume that the device and/or disk are always the last
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/5] findmnt: support -o +<attr> for adding attribute to output fields.
  2012-07-26 13:52 ` [PATCH 1/5] Add string_add_to_idarray() - parse and add to id list Milan Broz
  2012-07-26 13:52   ` [PATCH 2/5] lsblk: support -o +<attr> for adding attribute to output fields Milan Broz
  2012-07-26 13:52   ` [PATCH 3/5] partx: " Milan Broz
@ 2012-07-26 13:52   ` Milan Broz
  2012-07-26 14:47     ` Karel Zak
  2012-07-26 13:52   ` [PATCH 5/5] wdctl: " Milan Broz
  2012-07-26 14:46   ` [PATCH 1/5] Add string_add_to_idarray() - parse and add to id list Karel Zak
  4 siblings, 1 reply; 11+ messages in thread
From: Milan Broz @ 2012-07-26 13:52 UTC (permalink / raw)
  To: util-linux; +Cc: Milan Broz


Signed-off-by: Milan Broz <mbroz@redhat.com>
---
 misc-utils/findmnt.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index 6df2f06..482466b 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -1041,6 +1041,7 @@ int main(int argc, char *argv[])
 	int direction = MNT_ITER_FORWARD;
 	int i, c, rc = -1, timeout = -1;
 	int ntabfiles = 0, tabtype = 0;
+	char *outarg = NULL;
 
 	enum {
 		EXCL_NONE,
@@ -1150,11 +1151,7 @@ int main(int argc, char *argv[])
 			disable_columns_truncate();
 			break;
 		case 'o':
-			ncolumns = string_to_idarray(optarg,
-						columns, ARRAY_SIZE(columns),
-						column_name_to_id);
-			if (ncolumns < 0)
-				exit(EXIT_FAILURE);
+			outarg = optarg;
 			break;
 		case 'O':
 			set_match(COL_OPTIONS, optarg);
@@ -1260,6 +1257,10 @@ int main(int argc, char *argv[])
 		columns[ncolumns++] = COL_OPTIONS;
 	}
 
+	if (outarg && string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
+					 &ncolumns, column_name_to_id) < 0)
+		return EXIT_FAILURE;
+
 	if (!tabtype)
 		tabtype = TABTYPE_KERNEL;
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/5] wdctl: support -o +<attr> for adding attribute to output fields.
  2012-07-26 13:52 ` [PATCH 1/5] Add string_add_to_idarray() - parse and add to id list Milan Broz
                     ` (2 preceding siblings ...)
  2012-07-26 13:52   ` [PATCH 4/5] findmnt: " Milan Broz
@ 2012-07-26 13:52   ` Milan Broz
  2012-07-26 14:48     ` Karel Zak
  2012-07-26 14:46   ` [PATCH 1/5] Add string_add_to_idarray() - parse and add to id list Karel Zak
  4 siblings, 1 reply; 11+ messages in thread
From: Milan Broz @ 2012-07-26 13:52 UTC (permalink / raw)
  To: util-linux; +Cc: Milan Broz


Signed-off-by: Milan Broz <mbroz@redhat.com>
---
 sys-utils/wdctl.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/sys-utils/wdctl.c b/sys-utils/wdctl.c
index ebe55b4..6367130 100644
--- a/sys-utils/wdctl.c
+++ b/sys-utils/wdctl.c
@@ -381,6 +381,7 @@ int main(int argc, char *argv[])
 	int c, tt_flags = 0, res = EXIT_SUCCESS, count = 0;
 	char noflags = 0, noident = 0, notimeouts = 0, oneline = 0;
 	uint32_t wanted = 0;
+	char *outarg = NULL;
 
 	enum {
 		EXCL_NONE,
@@ -413,11 +414,7 @@ int main(int argc, char *argv[])
 				"d:f:hFnITo:OrVx", long_opts, NULL)) != -1) {
 		switch(c) {
 		case 'o':
-			ncolumns = string_to_idarray(optarg,
-						     columns, ARRAY_SIZE(columns),
-						     column2id);
-			if (ncolumns < 0)
-				return EXIT_FAILURE;
+			outarg = optarg;
 			break;
 		case 'f':
 			exclusive_option(&excl_flag, EXCL_FLAGS, "--{flags,noflags}");
@@ -467,6 +464,10 @@ int main(int argc, char *argv[])
 		columns[ncolumns++] = COL_BSTATUS;
 	}
 
+	if (outarg && string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
+					 &ncolumns, column2id) < 0)
+		return EXIT_FAILURE;
+
 	do {
 		int rc;
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] Add string_add_to_idarray() - parse and add to id list.
  2012-07-26 13:52 ` [PATCH 1/5] Add string_add_to_idarray() - parse and add to id list Milan Broz
                     ` (3 preceding siblings ...)
  2012-07-26 13:52   ` [PATCH 5/5] wdctl: " Milan Broz
@ 2012-07-26 14:46   ` Karel Zak
  4 siblings, 0 replies; 11+ messages in thread
From: Karel Zak @ 2012-07-26 14:46 UTC (permalink / raw)
  To: Milan Broz; +Cc: util-linux

On Thu, Jul 26, 2012 at 03:52:04PM +0200, Milan Broz wrote:
>  include/strutils.h |    4 ++++
>  lib/strutils.c     |   26 ++++++++++++++++++++++++++
>  2 files changed, 30 insertions(+)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/5]  lsblk: support -o +<attr> for adding attribute to output fields.
  2012-07-26 13:52   ` [PATCH 2/5] lsblk: support -o +<attr> for adding attribute to output fields Milan Broz
@ 2012-07-26 14:47     ` Karel Zak
  0 siblings, 0 replies; 11+ messages in thread
From: Karel Zak @ 2012-07-26 14:47 UTC (permalink / raw)
  To: Milan Broz; +Cc: util-linux

On Thu, Jul 26, 2012 at 03:52:05PM +0200, Milan Broz wrote:
>  misc-utils/lsblk.c |   11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/5] partx: support -o +<attr> for adding attribute to output fields.
  2012-07-26 13:52   ` [PATCH 3/5] partx: " Milan Broz
@ 2012-07-26 14:47     ` Karel Zak
  0 siblings, 0 replies; 11+ messages in thread
From: Karel Zak @ 2012-07-26 14:47 UTC (permalink / raw)
  To: Milan Broz; +Cc: util-linux

On Thu, Jul 26, 2012 at 03:52:06PM +0200, Milan Broz wrote:
>  disk-utils/partx.c |   12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/5] findmnt: support -o +<attr> for adding attribute to output fields.
  2012-07-26 13:52   ` [PATCH 4/5] findmnt: " Milan Broz
@ 2012-07-26 14:47     ` Karel Zak
  0 siblings, 0 replies; 11+ messages in thread
From: Karel Zak @ 2012-07-26 14:47 UTC (permalink / raw)
  To: Milan Broz; +Cc: util-linux

On Thu, Jul 26, 2012 at 03:52:07PM +0200, Milan Broz wrote:
>  misc-utils/findmnt.c |   11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 5/5] wdctl: support -o +<attr> for adding attribute to output fields.
  2012-07-26 13:52   ` [PATCH 5/5] wdctl: " Milan Broz
@ 2012-07-26 14:48     ` Karel Zak
  0 siblings, 0 replies; 11+ messages in thread
From: Karel Zak @ 2012-07-26 14:48 UTC (permalink / raw)
  To: Milan Broz; +Cc: util-linux

On Thu, Jul 26, 2012 at 03:52:08PM +0200, Milan Broz wrote:
>  sys-utils/wdctl.c |   11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-07-26 14:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-26 12:14 [PATCH] lsblk: support -o +<attr> for adding attribute to output fields Milan Broz
2012-07-26 13:52 ` [PATCH 1/5] Add string_add_to_idarray() - parse and add to id list Milan Broz
2012-07-26 13:52   ` [PATCH 2/5] lsblk: support -o +<attr> for adding attribute to output fields Milan Broz
2012-07-26 14:47     ` Karel Zak
2012-07-26 13:52   ` [PATCH 3/5] partx: " Milan Broz
2012-07-26 14:47     ` Karel Zak
2012-07-26 13:52   ` [PATCH 4/5] findmnt: " Milan Broz
2012-07-26 14:47     ` Karel Zak
2012-07-26 13:52   ` [PATCH 5/5] wdctl: " Milan Broz
2012-07-26 14:48     ` Karel Zak
2012-07-26 14:46   ` [PATCH 1/5] Add string_add_to_idarray() - parse and add to id list Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).