master
Daniel Kolesa 2016-10-16 22:00:07 +02:00
parent a12bb3fbe2
commit c1743ef262
1 changed files with 10 additions and 28 deletions

38
main.cc
View File

@ -544,29 +544,21 @@ struct ObState: CsState {
} }
void register_rulecmds() { void register_rulecmds() {
new_command("rule", "sse", [this]( new_command("rule", "sse", [this](auto &cs, auto args, auto &) {
CsState &cs, CsValueRange args, CsValue &
) {
rule_add( rule_add(
cs, args[0].get_strr(), args[1].get_strr(), args[2].get_code() cs, args[0].get_strr(), args[1].get_strr(), args[2].get_code()
); );
}); });
new_command("action", "se", [this]( new_command("action", "se", [this](auto &cs, auto args, auto &) {
CsState &cs, CsValueRange args, CsValue &
) {
rule_add(cs, args[0].get_strr(), nullptr, args[1].get_code(), true); rule_add(cs, args[0].get_strr(), nullptr, args[1].get_code(), true);
}); });
new_command("depend", "ss", [this]( new_command("depend", "ss", [this](auto &cs, auto args, auto &) {
CsState &cs, CsValueRange args, CsValue &
) {
rule_add(cs, args[0].get_strr(), args[1].get_strr(), nullptr); rule_add(cs, args[0].get_strr(), args[1].get_strr(), nullptr);
}); });
new_command("duprule", "sssN", [this]( new_command("duprule", "sssN", [this](auto &cs, auto args, auto &) {
CsState &cs, CsValueRange args, CsValue &
) {
rule_dup( rule_dup(
cs, args[0].get_strr(), args[1].get_strr(), cs, args[0].get_strr(), args[1].get_strr(),
args[2].get_strr(), args[3].get_int() <= 2 args[2].get_strr(), args[3].get_int() <= 2
@ -652,13 +644,11 @@ int main(int argc, char **argv) {
os.register_rulecmds(); os.register_rulecmds();
os.new_command("echo", "C", [](CsState &, CsValueRange args, CsValue &) { os.new_command("echo", "C", [](auto &, auto args, auto &) {
writeln(args[0].get_strr()); writeln(args[0].get_strr());
}); });
os.new_command("shell", "C", [&os, &tpool]( os.new_command("shell", "C", [&os, &tpool](auto &, auto args, auto &res) {
CsState &, CsValueRange args, CsValue &res
) {
auto cnt = os.counters.back(); auto cnt = os.counters.back();
cnt->incr(); cnt->incr();
tpool.push([cnt, ds = String(args[0].get_strr())]() { tpool.push([cnt, ds = String(args[0].get_strr())]() {
@ -671,9 +661,7 @@ int main(int argc, char **argv) {
res.set_int(0); res.set_int(0);
}); });
os.new_command("getenv", "ss", [&os]( os.new_command("getenv", "ss", [&os](auto &, auto args, auto &res) {
CsState &, CsValueRange args, CsValue &res
) {
if (os.ignore_env) { if (os.ignore_env) {
res.set_cstr(""); res.set_cstr("");
return; return;
@ -683,9 +671,7 @@ int main(int argc, char **argv) {
)); ));
}); });
os.new_command("extreplace", "sss", []( os.new_command("extreplace", "sss", [](auto &cs, auto args, auto &res) {
CsState &cs, CsValueRange args, CsValue &res
) {
ConstCharRange lst = args[0].get_strr(); ConstCharRange lst = args[0].get_strr();
ConstCharRange oldext = args[1].get_strr(); ConstCharRange oldext = args[1].get_strr();
ConstCharRange newext = args[2].get_strr(); ConstCharRange newext = args[2].get_strr();
@ -713,15 +699,11 @@ int main(int argc, char **argv) {
res.set_str(ostd::move(ret)); res.set_str(ostd::move(ret));
}); });
os.new_command("invoke", "s", [&os]( os.new_command("invoke", "s", [&os](auto &, auto args, auto &res) {
CsState &, CsValueRange args, CsValue &res
) {
res.set_int(os.exec_main(args[0].get_strr())); res.set_int(os.exec_main(args[0].get_strr()));
}); });
os.new_command("glob", "C", [&os]( os.new_command("glob", "C", [&os](auto &cs, auto args, auto &res) {
CsState &cs, CsValueRange args, CsValue &res
) {
auto fnames = cscript::util::list_explode(cs, args[0].get_strr()); auto fnames = cscript::util::list_explode(cs, args[0].get_strr());
res.set_str(ostd::move(ob_expand_globs(fnames))); res.set_str(ostd::move(ob_expand_globs(fnames)));
}); });