master
Daniel Kolesa 2015-09-01 18:50:00 +01:00
parent 9c1ce90bfe
commit e817b51e5a
1 changed files with 11 additions and 9 deletions

20
main.cc
View File

@ -14,12 +14,14 @@
using ostd::ConstCharRange; using ostd::ConstCharRange;
using ostd::Vector; using ostd::Vector;
using ostd::String; using ostd::String;
using ostd::Uint32;
using ostd::slice_until;
/* represents a rule definition, possibly with a function */ /* represents a rule definition, possibly with a function */
struct Rule { struct Rule {
String target; String target;
Vector<String> deps; Vector<String> deps;
ostd::Uint32 *func; Uint32 *func;
Rule(): target(), deps(), func(nullptr) {} Rule(): target(), deps(), func(nullptr) {}
Rule(const Rule &r): target(r.target), deps(r.deps), func(r.func) { Rule(const Rule &r): target(r.target), deps(r.deps), func(r.func) {
@ -118,7 +120,7 @@ static ConstCharRange ob_compare_subst(ConstCharRange expanded,
if (rep.empty()) if (rep.empty())
return nullptr; return nullptr;
/* get the part before % */ /* get the part before % */
auto fp = ostd::slice_until(toexpand, rep); auto fp = slice_until(toexpand, rep);
/* part before % does not compare, so ignore */ /* part before % does not compare, so ignore */
if (expanded.size() <= fp.size()) if (expanded.size() <= fp.size())
return nullptr; return nullptr;
@ -144,9 +146,9 @@ static ConstCharRange ob_compare_subst(ConstCharRange expanded,
/* expand globs */ /* expand globs */
static void ob_get_path_parts(Vector<ConstCharRange> &parts, static void ob_get_path_parts(Vector<ConstCharRange> &parts,
ConstCharRange elem) { ConstCharRange elem) {
ostd::ConstCharRange star = ostd::find(elem, '*'); ConstCharRange star = ostd::find(elem, '*');
while (!star.empty()) { while (!star.empty()) {
ostd::ConstCharRange ep = ostd::slice_until(elem, star); ConstCharRange ep = slice_until(elem, star);
if (!ep.empty()) if (!ep.empty())
parts.push(ep); parts.push(ep);
parts.push("*"); parts.push("*");
@ -249,7 +251,7 @@ static bool ob_expand_glob(String &ret, ConstCharRange src, bool ne) {
return false; return false;
} }
/* part before star */ /* part before star */
ConstCharRange prestar = ostd::slice_until(src, star); ConstCharRange prestar = slice_until(src, star);
/* try finding slash before star */ /* try finding slash before star */
ConstCharRange slash = ostd::find_last(prestar, '/'); ConstCharRange slash = ostd::find_last(prestar, '/');
/* directory to scan */ /* directory to scan */
@ -258,7 +260,7 @@ static bool ob_expand_glob(String &ret, ConstCharRange src, bool ne) {
ConstCharRange fnpre = prestar; ConstCharRange fnpre = prestar;
if (!slash.empty()) { if (!slash.empty()) {
/* there was slash, adjust directory + prefix accordingly */ /* there was slash, adjust directory + prefix accordingly */
dir = ostd::slice_until(src, slash); dir = slice_until(src, slash);
fnpre = slash; fnpre = slash;
fnpre.pop_front(); fnpre.pop_front();
} }
@ -268,7 +270,7 @@ static bool ob_expand_glob(String &ret, ConstCharRange src, bool ne) {
/* if a slash follows, adjust */ /* if a slash follows, adjust */
ConstCharRange nslash = ostd::find(fnpost, '/'); ConstCharRange nslash = ostd::find(fnpost, '/');
if (!nslash.empty()) if (!nslash.empty())
fnpost = ostd::slice_until(fnpost, nslash); fnpost = slice_until(fnpost, nslash);
/* retrieve the single element with whatever stars in it, chop it up */ /* retrieve the single element with whatever stars in it, chop it up */
Vector<ConstCharRange> parts; Vector<ConstCharRange> parts;
ob_get_path_parts(parts, ConstCharRange(&fnpre[0], &fnpost[fnpost.size()])); ob_get_path_parts(parts, ConstCharRange(&fnpre[0], &fnpost[fnpost.size()]));
@ -315,7 +317,7 @@ struct ObState {
repd.clear(); repd.clear();
auto lp = ostd::find(atgt, '%'); auto lp = ostd::find(atgt, '%');
if (!lp.empty()) { if (!lp.empty()) {
repd.append(ostd::slice_until(atgt, lp)); repd.append(slice_until(atgt, lp));
repd.append(sr.sub); repd.append(sr.sub);
lp.pop_front(); lp.pop_front();
if (!lp.empty()) repd.append(lp); if (!lp.empty()) repd.append(lp);
@ -338,7 +340,7 @@ struct ObState {
return r; return r;
} }
if (ob_check_exec(tname, subdeps)) { if (ob_check_exec(tname, subdeps)) {
ostd::Uint32 *func = nullptr; Uint32 *func = nullptr;
for (auto &sr: rlist.iter()) { for (auto &sr: rlist.iter()) {
Rule &r = *sr.rule; Rule &r = *sr.rule;
if (!r.func) if (!r.func)