util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Milan Broz <mbroz@redhat.com>
To: util-linux@vger.kernel.org
Cc: Milan Broz <mbroz@redhat.com>
Subject: [PATCH 1/5] Add string_add_to_idarray() - parse and add to id list.
Date: Thu, 26 Jul 2012 15:52:04 +0200	[thread overview]
Message-ID: <1343310728-16624-1-git-send-email-mbroz@redhat.com> (raw)
In-Reply-To: <1343304884-14297-1-git-send-email-mbroz@redhat.com>


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


  reply	other threads:[~2012-07-26 13:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2012-07-26 13:52   ` [PATCH 2/5] " 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

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=1343310728-16624-1-git-send-email-mbroz@redhat.com \
    --to=mbroz@redhat.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;
as well as URLs for NNTP newsgroup(s).