mirror of
https://github.com/ksherlock/mpw-shell.git
synced 2024-12-27 18:30:39 +00:00
adjust indents
This commit is contained in:
parent
6f53faeae7
commit
1339c0891f
20
command.cpp
20
command.cpp
@ -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");
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user