We use libstrutil parse_range() function to parse the node ranges in xp_nodeset_parse_noderange.
Signed-off-by: Abhishek Kulkarni <
kulk...@lanl.gov>
Index: libxcpu/node.c
===================================================================
--- libxcpu/node.c (revision 752)
+++ libxcpu/node.c (working copy)
@@ -260,73 +260,43 @@
static int
xp_nodeset_parse_noderange(Xpnodeset *nds, char *noderange)
{
- int i, b, e;
- char *s, *t, *p, *ss;
+ int i, n;
+ char *s, **nodes = NULL;
/* we allow two kinds of description here -- abcd123 and abcd[2-56] */
s = noderange;
- while (isalpha(*s))
- s++;
-
- if (isdigit(*s) || *s == '\0' || *s == '!') {
- while (isdigit(*s) || *s == '.' || *s == '-' || isalpha(*s))
+ n = parse_range(noderange, &nodes);
+ if (n < 0)
+ goto error;
+ else if (n == 1) { /* Not a range */
+ s = nodes[0];
+ while (isalpha(*s))
s++;
- if (*s == '!') {
- s++;
- while (isdigit(*s))
+ if (isdigit(*s) || *s == '\0' || *s == '!') {
+ while (isdigit(*s) || *s == '.' || *s == '-' || isalpha(*s))
s++;
- }
-
- if (*s != '\0')
- goto error;
-
- if (xp_nodeset_create_node(nds, noderange) < 0)
- return -1;
- } else if (*s == '[') {
- t = strchr(s, ']');
- if (!t)
- goto error;
-
- if (*(t+1) != '\0')
- goto error;
-
- *t = '\0';
- t = strchr(s, '-');
- if (!t)
- goto error;
-
- *t = '\0';
- t++;
-
- b = strtol(s + 1, &ss, 10);
- if (*ss != '\0')
- goto error;
-
- e = strtol(t, &ss, 10);
- if (*ss != '\0')
- goto error;
-
- p = sp_malloc((s-noderange) + 32);
- if (!p)
- return -1;
-
- memmove(p, noderange, (s-noderange));
- s = p + (s - noderange);
- for(i = b; i <= e; i++) {
- sprintf(s, "%d", i);
- if (xp_nodeset_create_node(nds, p) < 0) {
- free(p);
- return -1;
+
+ if (*s == '!') {
+ s++;
+ while (isdigit(*s))
+ s++;
}
+
+ if (*s != '\0')
+ goto error;
}
-
- free(p);
}
+ for (i = 0; i < n; i++) {
+ if (xp_nodeset_create_node(nds, nodes[i]) < 0)
+ goto error;
+ }
+ free(nodes);
return 0;
error:
+ free(nodes);
sp_werror("syntax error: '%s' not a valid node description", EIO, noderange);
return -1;
}