This source file includes following definitions.
- pmix_util_parse_range_options
- pmix_util_get_ranges
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #include "pmix_config.h"
24 #include "pmix_common.h"
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #ifdef HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
32 #ifdef HAVE_SYS_TYPES_H
33 #include <sys/types.h>
34 #endif
35
36 #include "src/util/argv.h"
37 #include "src/util/output.h"
38
39 #include "src/util/parse_options.h"
40
41 void pmix_util_parse_range_options(char *inp, char ***output)
42 {
43 char **r1=NULL, **r2=NULL;
44 int i, vint;
45 int start, end, n;
46 char nstr[32];
47 char *input, *bang;
48 bool bang_option=false;
49
50
51 if (NULL == inp) {
52 return;
53 }
54
55
56 input = strdup(inp);
57
58
59 if (NULL != (bang = strchr(input, '!'))) {
60 bang_option = true;
61 *bang = '\0';
62 }
63
64
65 r1 = pmix_argv_split(input, ',');
66
67 for (i=0; i < pmix_argv_count(r1); i++) {
68 r2 = pmix_argv_split(r1[i], '-');
69 if (1 < pmix_argv_count(r2)) {
70
71 start = strtol(r2[0], NULL, 10);
72 end = strtol(r2[1], NULL, 10);
73 } else {
74
75
76
77 vint = strtol(r1[i], NULL, 10);
78 if (-1 == vint) {
79 pmix_argv_free(*output);
80 *output = NULL;
81 pmix_argv_append_nosize(output, "-1");
82 pmix_argv_free(r2);
83 goto cleanup;
84 }
85 start = strtol(r2[0], NULL, 10);
86 end = start;
87 }
88 for (n = start; n <= end; n++) {
89 snprintf(nstr, 32, "%d", n);
90 pmix_argv_append_nosize(output, nstr);
91 }
92 pmix_argv_free(r2);
93 }
94
95 cleanup:
96 if (bang_option) {
97 pmix_argv_append_nosize(output, "BANG");
98 }
99 free(input);
100 pmix_argv_free(r1);
101
102 }
103
104 void pmix_util_get_ranges(char *inp, char ***startpts, char ***endpts)
105 {
106 char **r1=NULL, **r2=NULL;
107 int i;
108 char *input;
109
110
111 if (NULL == inp) {
112 return;
113 }
114
115
116 input = strdup(inp);
117
118
119 r1 = pmix_argv_split(input, ',');
120
121 for (i=0; i < pmix_argv_count(r1); i++) {
122 r2 = pmix_argv_split(r1[i], '-');
123 if (2 == pmix_argv_count(r2)) {
124
125 pmix_argv_append_nosize(startpts, r2[0]);
126 pmix_argv_append_nosize(endpts, r2[1]);
127 } else if (1 == pmix_argv_count(r2)) {
128
129
130
131 pmix_argv_append_nosize(startpts, r2[0]);
132 pmix_argv_append_nosize(endpts, r2[0]);
133 } else {
134
135 pmix_output(0, "Unknown parse error on string: %s(%s)", inp, r1[i]);
136 }
137 pmix_argv_free(r2);
138 }
139
140 free(input);
141 pmix_argv_free(r1);
142
143 }