extreplace is not part of globs system

master
Daniel Kolesa 2015-11-07 16:57:29 +00:00
parent 7b29404dbd
commit ccaae1e418
2 changed files with 23 additions and 23 deletions

View File

@ -159,27 +159,4 @@ void cs_register_globs(cscript::CsState &cs) {
auto fnames = cscript::util::list_explode(lst);
cs.result->set_str(ob_expand_globs(fnames).disown());
});
cs.add_command("extreplace", "sss", [](cscript::CsState &cs,
const char *lst,
const char *oldext,
const char *newext) {
String ret;
if (oldext[0] == '.') ++oldext;
if (newext[0] == '.') ++newext;
auto fnames = cscript::util::list_explode(lst);
for (ConstCharRange it: fnames.iter()) {
if (!ret.empty()) ret += ' ';
auto dot = ostd::find_last(it, '.');
if (!dot.empty() && ((dot + 1) == oldext)) {
ret += ostd::slice_until(it, dot);
ret += '.';
ret += newext;
} else {
ret += it;
}
}
cs.result->set_str(ret.iter());
ret.disown();
});
}

23
main.cc
View File

@ -454,6 +454,29 @@ int main(int argc, char **argv) {
}
});
os.cs.add_command("extreplace", "sss", [](cscript::CsState &cs,
const char *lst,
const char *oldext,
const char *newext) {
String ret;
if (oldext[0] == '.') ++oldext;
if (newext[0] == '.') ++newext;
auto fnames = cscript::util::list_explode(lst);
for (ConstCharRange it: fnames.iter()) {
if (!ret.empty()) ret += ' ';
auto dot = ostd::find_last(it, '.');
if (!dot.empty() && ((dot + 1) == oldext)) {
ret += ostd::slice_until(it, dot);
ret += '.';
ret += newext;
} else {
ret += it;
}
}
cs.result->set_str(ret.iter());
ret.disown();
});
os.cs.add_command("invoke", "s", [](CsState &cs, const char *name) {
cs.result->set_int(((ObState &)cs).exec_main(name));
});