[PATCH] libxcpu: use parse_range to parse node ranges.

0 views
Skip to first unread message

Abhishek Kulkarni

unread,
Dec 17, 2008, 8:51:33 PM12/17/08
to xc...@googlegroups.com

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;
 }

Latchesar Ionkov

unread,
Dec 18, 2008, 10:53:17 AM12/18/08
to xc...@googlegroups.com
Acked-by: Latchesar Ionkov <lu...@ionkov.net>
Reply all
Reply to author
Forward
0 new messages