test commandn

master
Daniel Kolesa 2015-10-13 21:23:41 +01:00
parent 3c9e6ea404
commit 49812b6b40
1 changed files with 11 additions and 9 deletions

20
main.cc
View File

@ -19,6 +19,10 @@ using ostd::String;
using ostd::Uint32; using ostd::Uint32;
using ostd::slice_until; using ostd::slice_until;
using cscript::CsState;
using cscript::TvalRange;
using cscript::StackedValue;
/* represents a rule definition, possibly with a function */ /* represents a rule definition, possibly with a function */
struct Rule { struct Rule {
String target; String target;
@ -148,7 +152,7 @@ static ConstCharRange ob_compare_subst(ConstCharRange expanded,
} }
struct ObState { struct ObState {
cscript::CsState cs; CsState cs;
ConstCharRange progname; ConstCharRange progname;
int jobs = 1; int jobs = 1;
@ -205,7 +209,7 @@ struct ObState {
} }
} }
if (func) { if (func) {
cscript::StackedValue targetv, sourcev, sourcesv; StackedValue targetv, sourcev, sourcesv;
targetv.id = cs.new_ident("target"); targetv.id = cs.new_ident("target");
if (!cscript::check_alias(targetv.id)) if (!cscript::check_alias(targetv.id))
@ -378,8 +382,7 @@ int main(int argc, char **argv) {
tpool.init(os.jobs); tpool.init(os.jobs);
os.cs.add_command("shell", "C", [](cscript::CsState &cs, os.cs.add_command("shell", "C", [](CsState &cs, ConstCharRange s) {
ConstCharRange s) {
RuleCounter *cnt = counters.back(); RuleCounter *cnt = counters.back();
cnt->incr(); cnt->incr();
char *ds = String(s).disown(); char *ds = String(s).disown();
@ -393,24 +396,23 @@ int main(int argc, char **argv) {
cs.result->set_int(0); cs.result->set_int(0);
}); });
os.cs.add_command("rule", "sseN", [](cscript::CsState &, const char *tgt, os.cs.add_command("rule", "sseN", [](CsState &, const char *tgt,
const char *dep, ostd::Uint32 *body, const char *dep, ostd::Uint32 *body,
int *numargs) { int *numargs) {
rule_add(tgt, dep, (*numargs > 2) ? body : nullptr); rule_add(tgt, dep, (*numargs > 2) ? body : nullptr);
}); });
os.cs.add_command("rule-", "seN", [](cscript::CsState &, const char *tgt, os.cs.add_command("rule-", "seN", [](CsState &, const char *tgt,
ostd::Uint32 *body, int *numargs) { ostd::Uint32 *body, int *numargs) {
rule_add(tgt, nullptr, (*numargs > 1) ? body : nullptr); rule_add(tgt, nullptr, (*numargs > 1) ? body : nullptr);
}); });
os.cs.add_command("getenv", "s", [](cscript::CsState &cs, os.cs.add_commandn("getenv", "s", [](CsState &cs, TvalRange args) {
const char *en) {
if (ignore_env) { if (ignore_env) {
cs.result->set_cstr(""); cs.result->set_cstr("");
return; return;
} }
const char *ret = getenv(en); const char *ret = getenv(args[0].get_str().data());
if (!ret || !ret[0]) { if (!ret || !ret[0]) {
cs.result->set_cstr(""); cs.result->set_cstr("");
return; return;