adjust indents

This commit is contained in:
Kelvin Sherlock 2016-02-10 21:58:00 -05:00
parent 6f53faeae7
commit 1339c0891f
2 changed files with 19 additions and 11 deletions

View File

@ -304,10 +304,9 @@ int begin_command::execute(Environment &env, const fdmask &fds, bool throwup) {
if (status) return env.status(status);
int rv;
{
indent_helper indent(env);
rv = vector_command::execute(env, newfds);
}
env.indent_and([&]{
rv = vector_command::execute(env, newfds);
});
env.echo("%s", type == BEGIN ? "end" : ")");
@ -388,13 +387,14 @@ int if_command::execute(Environment &env, const fdmask &fds, bool throwup) {
env.echo("%s", s.c_str());
if (ok) continue;
{
indent_helper indent(env);
int tmp = evaluate(c->type, s, env);
if (tmp < 0) { ok = true; rv = tmp; continue; }
if (tmp == 0) continue;
int tmp = evaluate(c->type, s, env);
if (tmp < 0) { ok = true; rv = tmp; continue; }
if (tmp == 0) continue;
env.indent_and([&](){
rv = c->execute(env, newfds);
}
});
}
env.echo("end");

View File

@ -91,6 +91,13 @@ public:
void echo(const char *format, ...);
template<class FX>
void indent_and(FX &&fx) {
int i = _indent++;
try { fx(); _indent = i; }
catch (...) { _indent = i; throw; }
}
private:
// magic variables.
@ -111,6 +118,7 @@ private:
std::unordered_map<std::string, EnvironmentEntry> _table;
};
/*
class indent_helper {
public:
indent_helper(Environment &e) : env(e) { env._indent++; }
@ -120,6 +128,6 @@ private:
Environment &env;
bool active = true;
};
*/
#endif