refactoring
parent
20a7234dac
commit
0987bfff92
31
main.cc
31
main.cc
|
@ -23,6 +23,7 @@ using cscript::cs_value;
|
||||||
using cscript::cs_stacked_value;
|
using cscript::cs_stacked_value;
|
||||||
using cscript::cs_bcode_ref;
|
using cscript::cs_bcode_ref;
|
||||||
using cscript::cs_bcode;
|
using cscript::cs_bcode;
|
||||||
|
using cscript::util::list_parser;
|
||||||
|
|
||||||
namespace fs = ostd::fs;
|
namespace fs = ostd::fs;
|
||||||
namespace build = ostd::build;
|
namespace build = ostd::build;
|
||||||
|
@ -32,12 +33,12 @@ static void rule_add(
|
||||||
string_range target, string_range depends,
|
string_range target, string_range depends,
|
||||||
cs_bcode *body, bool action = false
|
cs_bcode *body, bool action = false
|
||||||
) {
|
) {
|
||||||
cscript::util::list_parser p{cs, target};
|
list_parser p{cs, target};
|
||||||
while (p.parse()) {
|
for (auto tr: p.iter()) {
|
||||||
auto &rl = mk.rule(p.get_item()).action(action);
|
auto &rl = mk.rule(tr).action(action);
|
||||||
cscript::util::list_parser lp{cs, depends};
|
list_parser lp{cs, depends};
|
||||||
while (lp.parse()) {
|
for (auto dp: lp.iter()) {
|
||||||
rl.depend(lp.get_item());
|
rl.depend(dp);
|
||||||
}
|
}
|
||||||
if (cscript::cs_code_is_empty(body)) {
|
if (cscript::cs_code_is_empty(body)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -134,8 +135,9 @@ static void init_pathlib(cs_state &cs) {
|
||||||
string_range oldext = args[1].get_strr();
|
string_range oldext = args[1].get_strr();
|
||||||
string_range newext = args[2].get_strr();
|
string_range newext = args[2].get_strr();
|
||||||
std::string ret;
|
std::string ret;
|
||||||
for (cscript::util::list_parser p{cs, args[0].get_strr()}; p.parse();) {
|
list_parser p{cs, args[0].get_strr()};
|
||||||
ostd::path np{p.get_item()};
|
for (auto ps: p.iter()) {
|
||||||
|
ostd::path np{ps};
|
||||||
if (!ret.empty()) {
|
if (!ret.empty()) {
|
||||||
ret += ' ';
|
ret += ' ';
|
||||||
}
|
}
|
||||||
|
@ -147,13 +149,14 @@ static void init_pathlib(cs_state &cs) {
|
||||||
});
|
});
|
||||||
|
|
||||||
cs.new_command("glob", "C", [](auto &cs, auto args, auto &res) {
|
cs.new_command("glob", "C", [](auto &cs, auto args, auto &res) {
|
||||||
auto ret = ostd::appender<std::string>();
|
auto app = ostd::appender<std::vector<path>>();
|
||||||
auto app = ostd::appender<std::vector<path>>();;
|
list_parser p{cs, args[0].get_strr()};
|
||||||
for (cscript::util::list_parser p{cs, args[0].get_strr()}; p.parse();) {
|
for (auto ps: p.iter()) {
|
||||||
fs::glob_match(app, p.get_item());
|
fs::glob_match(app, ps);
|
||||||
}
|
}
|
||||||
ostd::format(ret, "%(%s %)", app.get());
|
res.set_str(ostd::format(
|
||||||
res.set_str(std::move(ret.get()));
|
ostd::appender<std::string>(), "%(%s %)", app.get()
|
||||||
|
).get());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue