clean up env set via number.

This commit is contained in:
Kelvin Sherlock 2016-06-16 22:00:03 -04:00
parent ef99bb40de
commit a15c6fbd65

View File

@ -129,30 +129,6 @@ int builtin_shift(Environment &env, const std::vector<std::string> &tokens, cons
} while (--n); } while (--n);
env.set_argv(argv); env.set_argv(argv);
/*
for (unsigned i = 0; i < argv.size(); ++i) {
env.set(std::to_string(i+1), argv[i]);
}
env.set("#", argv.size());
// fix Parameters and "Parameters"
std::string p;
for (const auto &s : argv) {
p += quote(s);
p += " ";
}
p.pop_back();
env.set("\"Parameters\"", p);
p.clear();
for (const auto &s : argv) {
p += s;
p += " ";
}
p.pop_back();
env.set("Parameters", p);
*/
return 0; return 0;
} }
@ -625,7 +601,7 @@ int builtin_evaluate(Environment &env, std::vector<token> &&tokens, const fdmask
switch(type) { switch(type) {
case '=': case '=':
env.set(name, std::to_string(i)); env.set(name, i);
break; break;
case '+=': case '+=':
case '-=': case '-=':
@ -643,8 +619,7 @@ int builtin_evaluate(Environment &env, std::vector<token> &&tokens, const fdmask
break; break;
} }
std::string s = std::to_string(i); env.set(name, i);
env.set(name, s);
} }
break; break;
} }
@ -654,11 +629,11 @@ int builtin_evaluate(Environment &env, std::vector<token> &&tokens, const fdmask
int32_t i = evaluate_expression("Evaluate", std::move(tokens)); int32_t i = evaluate_expression("Evaluate", std::move(tokens));
// todo -- format based on -h, -o, or -b flag.
if (output == 'h') { if (output == 'h') {
fprintf(stdout, "0x%08x\n", i); fprintf(stdout, "0x%08x\n", i);
return 0; return 0;
} }
if (output == 'b') { if (output == 'b') {
std::string tmp("0b"); std::string tmp("0b");
@ -670,11 +645,13 @@ int builtin_evaluate(Environment &env, std::vector<token> &&tokens, const fdmask
fputs(tmp.c_str(), stdout); fputs(tmp.c_str(), stdout);
return 0; return 0;
} }
if (output == 'o') { if (output == 'o') {
// octal. // octal.
fprintf(stdout, "0%o\n", i); fprintf(stdout, "0%o\n", i);
return 0; return 0;
} }
fprintf(stdout, "%d\n", i); fprintf(stdout, "%d\n", i);
return 0; return 0;
} }