/* Insert timer value <v> into tree <r>. A pre-allocated node must be passed * in <alloc>. It may be NULL, in which case the function will allocate it * itself. It will be reset to NULL once consumed. The caller is responsible * for freeing the node once not used anymore. The node where the value was * inserted is returned. */ struct timer *insert_timer(struct eb_root *r, struct timer **alloc, int v) { struct timer *t = *alloc; struct eb32_node *n; if (!t) { t = calloc(sizeof(*t), 1); if (unlikely(!t)) { fprintf(stderr, "%s: not enough memory\n", __FUNCTION__); exit(1); } } t->node.key = quantify(v, QBITS); // keep only the higher QBITS bits n = eb32i_insert(r, &t->node); if (n == &t->node) t = NULL; /* node inserted, will malloc next time */ *alloc = t; return container_of(n, struct timer, node); }
int iogen(int argc, char *argv[]) { int ch; int i, nr_proc = 1; struct stat sb; /* set defaults */ io_size = 64 * 1024; file_size = 1 * 1024 * 1024 * 1024; read_perc = 50; randomize = 0; interval = 60; strlcpy(target_dir, "./", sizeof target_dir); strlcpy(result_dir, "./", sizeof result_dir); while ((ch = getopt(argc, argv, "b:d:f:kn:p:rs:t:T:P:")) != -1) { switch (ch) { case 'b': io_size = atoll(optarg) * quantify(optarg[strlen(optarg) - 1]); if (io_size < MINIOSIZE) errx(1, "io block size too small"); if (io_size > MAXIOSIZE) errx(1, "io block size too large"); break; case 'd': if (stat(optarg, &sb) == -1) err(1, "stat failed"); else if (sb.st_mode & S_IFDIR) strlcpy(target_dir, optarg, sizeof target_dir); else errx(1, "invalid target path"); break; case 'f': if (stat(optarg, &sb) == -1) err(1, "stat failed"); else if (sb.st_mode & S_IFDIR) strlcpy(result_dir, optarg, sizeof result_dir); else errx(1, "invalid result path"); break; case 'k': killall(); /* NOTREACHED */ break; case 'n': nr_proc = atol(optarg); if (nr_proc < 1) errx(1, "invalid number of processes"); break; case 'p': read_perc = atol(optarg); if (read_perc < 10) errx(1, "read percentage size too small"); if (read_perc > 90) errx(1, "read percentage size too large"); break; case 'r': randomize = 1; break; case 's': file_size = atoll(optarg) * quantify(optarg[strlen(optarg) - 1]); if (file_size < MINFILESIZE) errx(1, "file size too small"); if (file_size > MAXFILESIZE) errx(1, "file size too large"); break; case 't': interval = atoi(optarg); if (interval < 1) errx(1, "time slice too small"); if (interval > 3600) errx(1, "time slice too large"); break; case 'T': timeout = atoi(optarg); if (timeout < 1) errx(1, "time slice too small"); if (timeout > 3600) errx(1, "time slice too large"); break; case 'P': if (optarg[0] == '?') { show_patterns(); exit(0); } pattern = atoi(optarg); if (pattern > IOGEN_PAT_TEXT) errx(1, "illegal pattern"); break; case 'h': default: usage(IOGEN_USAGE); /* NOTREACHED */ break; } } err_log(0, "%s test run commences with %u proc(s)", IOGEN_VERSION, nr_proc); err_log(0, "file size: %llu io size: %llu read percentage: %i random: %s " "target: %s result: %s update interval: %i", file_size, io_size, read_perc, randomize ? "yes" : "no", target_dir, result_dir, interval); for (i = 0; i < nr_proc; i++) fprintf(stderr, "child spawned %i\n", run_io()); return (0); }
NFAUNode * WCPattern::parse(const bool inParen, const bool inOr, NFAUNode ** end) { NFAUNode * start, *cur, *next = NULL; CMString t; int grc = groupCount++; bool inv, quo; bool ahead = 0, pos = 0, noncap = 0, indep = 0; unsigned long oldFlags = flags; if (inParen) { if (pattern[curInd] == '?') { ++curInd; --groupCount; if (pattern[curInd] == ':') { noncap = 1; ++curInd; grc = --nonCapGroupCount; } else if (pattern[curInd] == '=') { ++curInd; ahead = 1; pos = 1; } else if (pattern[curInd] == '!') { ++curInd; ahead = 1; pos = 0; } else if (pattern.Mid(curInd, 2) == L"<=") { curInd += 2; return parseBehind(1, end); } else if (pattern.Mid(curInd, 2) == L"<!") { curInd += 2; return parseBehind(0, end); } else if (pattern[curInd] == '>') { ++curInd; indep = 1; } else { bool negate = false, done = false; while (!done) { if (curInd >= pattern.GetLength()) { raiseError(); return NULL; } else if (negate) { switch (pattern[curInd]) { case 'i': flags &= ~WCPattern::CASE_INSENSITIVE; break; case 'd': flags &= ~WCPattern::UNIX_LINE_MODE; break; case 'm': flags &= ~WCPattern::MULTILINE_MATCHING; break; case 's': flags &= ~WCPattern::DOT_MATCHES_ALL; break; case ':': done = true; break; case ')': ++curInd; *end = registerNode(new NFALookBehindUNode(L"", true)); return *end; case '-': default: raiseError(); return NULL; } } else { switch (pattern[curInd]) { case 'i': flags |= WCPattern::CASE_INSENSITIVE; break; case 'd': flags |= WCPattern::UNIX_LINE_MODE; break; case 'm': flags |= WCPattern::MULTILINE_MATCHING; break; case 's': flags |= WCPattern::DOT_MATCHES_ALL; break; case ':': done = true; break; case '-': negate = true; break; case ')': ++curInd; *end = registerNode(new NFALookBehindUNode(L"", true)); return *end; default: raiseError(); return NULL; } } ++curInd; } noncap = 1; grc = --nonCapGroupCount; } if (noncap) cur = start = registerNode(new NFAGroupHeadUNode(grc)); else cur = start = registerNode(new NFASubStartUNode); } else cur = start = registerNode(new NFAGroupHeadUNode(grc)); } else cur = start = registerNode(new NFASubStartUNode); while (curInd < pattern.GetLength()) { wchar_t ch = pattern[curInd++]; next = NULL; if (error) return NULL; switch (ch) { case '^': if ((flags & WCPattern::MULTILINE_MATCHING) != 0) next = registerNode(new NFAStartOfLineUNode); else next = registerNode(new NFAStartOfInputUNode); break; case '$': if ((flags & WCPattern::MULTILINE_MATCHING) != 0) next = registerNode(new NFAEndOfLineUNode); else next = registerNode(new NFAEndOfInputUNode(0)); break; case '|': --groupCount; cur->next = registerNode(new NFAAcceptUNode); cur = start = registerNode(new NFAOrUNode(start, parse(inParen, 1))); break; case '\\': if (curInd < pattern.GetLength()) { bool eoi = 0; switch (pattern[curInd]) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': next = parseBackref(); break; case 'A': ++curInd; next = registerNode(new NFAStartOfInputUNode); break; case 'B': ++curInd; next = registerNode(new NFAWordBoundaryUNode(0)); break; case 'b': ++curInd; next = registerNode(new NFAWordBoundaryUNode(1)); break; case 'G': ++curInd; next = registerNode(new NFAEndOfMatchUNode); break; case 'Z': eoi = 1; case 'z': ++curInd; next = registerNode(new NFAEndOfInputUNode(eoi)); break; default: t = parseEscape(inv, quo); //printf("inv quo classes { %c %c %s }\n", inv ? 't' : 'f', quo ? 't' : 'f', t.c_str()); if (!quo) { if (t.GetLength() > 1 || inv) { if ((flags & WCPattern::CASE_INSENSITIVE) != 0) next = registerNode(new NFACIClassUNode(t, inv)); else next = registerNode(new NFAClassUNode(t, inv)); } else next = registerNode(new NFACharUNode(t[0])); } else next = parseQuote(); } } else raiseError(); break; case '[': if ((flags & WCPattern::CASE_INSENSITIVE) == 0) { NFAClassUNode * clazz = new NFAClassUNode(); CMString s = parseClass(); for (int i = 0; i < (int)s.GetLength(); ++i) clazz->vals[s[i]] = 1; next = registerNode(clazz); } else { NFACIClassUNode * clazz = new NFACIClassUNode(); CMString s = parseClass(); for (int i = 0; i < s.GetLength(); ++i) clazz->vals[to_lower(s[i])] = 1; next = registerNode(clazz); } break; case '.': { bool useN = 1, useR = 1; NFAClassUNode * clazz = new NFAClassUNode(1); if ((flags & WCPattern::UNIX_LINE_MODE) != 0) useR = 0; if ((flags & WCPattern::DOT_MATCHES_ALL) != 0) useN = useR = 0; if (useN) clazz->vals['\n'] = 1; if (useR) clazz->vals['\r'] = 1; next = registerNode(clazz); } break; case '(': { NFAUNode *end, *t1, *t2; t1 = parse(1, 0, &end); if (!t1) raiseError(); else if (t1->isGroupHeadNode() && (t2 = quantifyGroup(t1, end, grc)) != NULL) { cur->next = t2; cur = t2->next; } else { cur->next = t1; cur = end; } } break; case ')': if (!inParen) raiseError(); else if (inOr) { --curInd; cur = cur->next = registerNode(new NFAAcceptUNode); flags = oldFlags; return start; } else { if (ahead) { cur = cur->next = registerNode(new NFAAcceptUNode); flags = oldFlags; return *end = registerNode(new NFALookAheadUNode(start, pos)); } else if (indep) { cur = cur->next = registerNode(new NFAAcceptUNode); flags = oldFlags; return *end = registerNode(new NFAPossessiveQuantifierUNode(this, start, 1, 1)); } else { // capping or noncapping, it doesnt matter *end = cur = cur->next = registerNode(new NFAGroupTailUNode(grc)); next = quantifyGroup(start, *end, grc); if (next) { start = next; *end = next->next; } flags = oldFlags; return start; } } break; case '{': // registered pattern cur->next = parseRegisteredWCPattern(&next); if (cur->next) cur = next; break; case '*': case '+': case '?': // case '}': // case ']': raiseError(); break; default: if ((flags & WCPattern::CASE_INSENSITIVE) != 0) next = registerNode(new NFACICharUNode(ch)); else next = registerNode(new NFACharUNode(ch)); break; } if (next) cur = cur->next = quantify(next); } if (inParen) raiseError(); else { if (inOr) cur = cur->next = registerNode(new NFAAcceptUNode); if (end) *end = cur; } flags = oldFlags; if (error) return NULL; return start; }