/* * _build_state_list - build a list of node states * IN str - comma separated list of job states * RET List of enum job_states values */ static List _build_state_list (char *state_str) { List state_ids; char *orig, *str, *state; if (state_str == NULL) return NULL; if (strcasecmp (state_str, "all") == 0 ) return _build_all_states_list (); orig = str = xstrdup (state_str); state_ids = list_create (NULL); while ((state = _next_tok (",", &str))) { int *id = xmalloc (sizeof (*id)); if ((*id = _node_state_id (state)) < 0) { error ("Bad state string: \"%s\"", state); return (NULL); } list_append (state_ids, id); } xfree (orig); return (state_ids); }
/* * _build_part_list - build a list of partition names * IN parts - comma separated list of partitions * RET List of partition names */ static List _build_part_list(char *parts) { List part_list; char *orig, *str, *part; orig = str = xstrdup(parts); part_list = list_create(NULL); while ((part = _next_tok (",", &str))) { char *tmp_part = xstrdup(part); list_append (part_list, tmp_part); } xfree(orig); return (part_list); }
List list_split_append (List l, char *sep, char *str) { char *tok; if (sep == NULL) sep = " \t"; while ((tok = _next_tok(sep, &str)) != NULL) { if (strlen(tok) > 0) { char *s = strdup(tok); if (!s || !list_append(l, s)) goto fail; } } return l; fail: list_destroy(l); return NULL; }