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); if (status) return env.status(status);
int rv; int rv;
{ env.indent_and([&]{
indent_helper indent(env); rv = vector_command::execute(env, newfds);
rv = vector_command::execute(env, newfds); });
}
env.echo("%s", type == BEGIN ? "end" : ")"); 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()); env.echo("%s", s.c_str());
if (ok) continue; if (ok) continue;
{
indent_helper indent(env); int tmp = evaluate(c->type, s, env);
int tmp = evaluate(c->type, s, env); if (tmp < 0) { ok = true; rv = tmp; continue; }
if (tmp < 0) { ok = true; rv = tmp; continue; } if (tmp == 0) continue;
if (tmp == 0) continue;
env.indent_and([&](){
rv = c->execute(env, newfds); rv = c->execute(env, newfds);
} });
} }
env.echo("end"); env.echo("end");

View File

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