From 349e9b7851d38cc042defe5e2627afd6a01d59db Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 20 Aug 2015 12:59:15 -0700 Subject: [PATCH] start moving funcs into ObState --- main.cc | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/main.cc b/main.cc index f890823..acb6855 100644 --- a/main.cc +++ b/main.cc @@ -21,6 +21,13 @@ struct Rule { struct ObState { cscript::CsState cs; ostd::ConstCharRange progname; + + template + int error(int retcode, ostd::ConstCharRange fmt, A &&...args) { + ostd::err.write(progname, ": "); + ostd::err.writefln(fmt, ostd::forward(args)...); + return retcode; + } }; ostd::Vector rules; @@ -56,14 +63,6 @@ static bool ob_check_exec(ostd::ConstCharRange tname, return ob_check_ts(tname, deps); } -template -static int ob_error(ObState &os, int retcode, ostd::ConstCharRange fmt, - A &&...args) { - ostd::err.write(os.progname, ": "); - ostd::err.writefln(fmt, ostd::forward(args)...); - return retcode; -} - static int ob_exec_rule(ObState &os, ostd::ConstCharRange target, ostd::ConstCharRange from = ostd::ConstCharRange()); @@ -107,7 +106,7 @@ static int ob_exec_func(ObState &os, ostd::ConstCharRange tname, if (!r.func) continue; if (func) - return ob_error(os, 1, "redefinition of rule '%s'", tname); + return os.error(1, "redefinition of rule '%s'", tname); func = r.func; } if (func) { @@ -190,10 +189,9 @@ static int ob_exec_rule(ObState &os, ostd::ConstCharRange target, } if (rlist.empty() && !ob_check_file(target)) { if (from.empty()) - return ob_error(os, 1, "no rule to run target '%s'", target); + return os.error(1, "no rule to run target '%s'", target); else - return ob_error(os, 1, "no rule to run target '%s' " - "(needed by '%s')", + return os.error(1, "no rule to run target '%s' (needed by '%s')", target, from); return 1; } @@ -239,10 +237,10 @@ int main(int argc, char **argv) { os.cs.add_command("rule", "sseN", ob_rule_cmd); if (!os.cs.run_file("cubefile", true)) - return ob_error(os, 1, "failed creating rules"); + return os.error(1, "failed creating rules"); if (rules.empty()) - return ob_error(os, 1, "no targets"); + return os.error(1, "no targets"); return ob_exec_rule(os, (argc > 1) ? argv[1] : "all"); } \ No newline at end of file