diff mbox series

[ndctl,07/37] cxl/list: Support comma separated lists

Message ID 164298554612.3021641.3315920699556984273.stgit@dwillia2-desk3.amr.corp.intel.com
State New, archived
Headers show
Series cxl: Full topology enumeration | expand

Commit Message

Dan Williams Jan. 24, 2022, 12:52 a.m. UTC
In addition to supporting a syntax like:

   cxl list -m "0 1 2"

...support:

   cxl list -m 0,1,2

Reported-by: Vishal Verma <vishal.l.verma@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 cxl/filter.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/cxl/filter.c b/cxl/filter.c
index efafaf5a3197..405b653d80b2 100644
--- a/cxl/filter.c
+++ b/cxl/filter.c
@@ -6,6 +6,15 @@ 
 #include <cxl/libcxl.h>
 #include "filter.h"
 
+static const char *which_sep(const char *filter)
+{
+	if (strchr(filter, ' '))
+		return " ";
+	if (strchr(filter, ','))
+		return ",";
+	return " ";
+}
+
 struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
 					  const char *__ident)
 {
@@ -20,8 +29,8 @@  struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
 	if (!ident)
 		return NULL;
 
-	for (name = strtok_r(ident, " ", &save); name;
-	     name = strtok_r(NULL, " ", &save)) {
+	for (name = strtok_r(ident, which_sep(__ident), &save); name;
+	     name = strtok_r(NULL, which_sep(__ident), &save)) {
 		if (strcmp(name, "all") == 0)
 			break;