8 #define bitsperlong (8 * sizeof(unsigned long))
11 #define howmany(x, y) (((x)+((y)-1))/(y))
14 #define longsperbits(n) howmany(n, bitsperlong)
16 #define max(a, b) ((a) > (b) ? (a) : (b))
27 bmp =
malloc(
sizeof(*bmp));
32 if (bmp->
maskp == 0) {
45 bmp->
maskp = (
unsigned long *)0xdeadcdef;
61 static unsigned int _getbit(
const struct bitmask *bmp,
unsigned int n)
70 static void _setbit(
struct bitmask *bmp,
unsigned int n,
unsigned int v)
98 static int scan_was_ok(
int sret,
char nextc,
const char *ok_next_chars)
101 (sret == 2 &&
strchr(ok_next_chars, nextc) !=
NULL);
104 static const char *nexttoken(
const char *
q,
int sep)
124 for (i = 0; i < bmp->
size; i++)
133 for (i = 0; i < bmp->
size; i++)
142 for (i = 0; i < bmp->
size; i++)
151 return _getbit(bmp, i);
164 unsigned int m = bmp->
size;
165 for (i = 0; i < bmp->
size; i++)
175 for (n = i; n < bmp->
size; n++)
198 while (p = q, q = nexttoken(q,
','), p) {
206 sret =
sscanf(p,
"%u%c", &a, &nextc);
207 if (!scan_was_ok(sret, nextc,
",-"))
211 c1 = nexttoken(p,
'-');
212 c2 = nexttoken(p,
',');
213 if (c1 !=
NULL && (c2 ==
NULL || c1 < c2)) {
214 sret =
sscanf(c1,
"%u%c", &b, &nextc);
215 if (!scan_was_ok(sret, nextc,
",:"))
217 c1 = nexttoken(c1,
':');
218 if (c1 !=
NULL && (c2 ==
NULL || c1 < c2)) {
219 sret =
sscanf(c1,
"%u%c", &s, &nextc);
220 if (!scan_was_ok(sret, nextc,
","))
248 static inline int emit(
char *
buf,
int buflen,
int rbot,
int rtop,
int len)
251 len +=
snprintf(buf + len,
max(buflen - len, 0),
",");
253 len +=
snprintf(buf + len,
max(buflen - len, 0),
"%d", rbot);
255 len +=
snprintf(buf + len,
max(buflen - len, 0),
"%d-%d",
278 unsigned int cur, rbot, rtop;
283 while (cur < bmp->size) {
286 if (cur >= bmp->
size || cur > rtop + 1) {
287 len =
emit(buf, buflen, rbot, rtop, len);