2019-04-13 05:42:27 +00:00
|
|
|
// Functions for executing the eval builtin.
|
2019-04-12 11:53:08 +00:00
|
|
|
#include "config.h" // IWYU pragma: keep
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#ifdef HAVE__PROC_SELF_STAT
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "builtin.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "fallback.h" // IWYU pragma: keep
|
|
|
|
#include "io.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "proc.h"
|
|
|
|
#include "wgetopt.h"
|
|
|
|
#include "wutil.h" // IWYU pragma: keep
|
|
|
|
|
|
|
|
class parser_t;
|
|
|
|
|
2019-04-13 05:42:27 +00:00
|
|
|
/// Implementation of eval builtin.
|
2019-04-12 11:53:08 +00:00
|
|
|
int builtin_eval(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|
|
|
int argc = builtin_count_args(argv);
|
|
|
|
|
|
|
|
wcstring new_cmd;
|
|
|
|
for (size_t i = 1; i < argc; ++i) {
|
2019-04-13 05:42:27 +00:00
|
|
|
if (i > 1) new_cmd += L' ';
|
2019-04-12 11:53:08 +00:00
|
|
|
new_cmd += argv[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// debug(1, "new_cmd: %ls", new_cmd.c_str());
|
|
|
|
|
2019-04-13 05:42:27 +00:00
|
|
|
int status = STATUS_CMD_OK;
|
2019-04-12 11:53:08 +00:00
|
|
|
if (argc > 1) {
|
2019-04-13 06:02:45 +00:00
|
|
|
if (parser.eval(std::move(new_cmd), *streams.io_chain, block_type_t::TOP) != 0) {
|
2019-04-13 05:42:27 +00:00
|
|
|
// This indicates a parse error; nothing actually got executed.
|
|
|
|
status = STATUS_CMD_ERROR;
|
|
|
|
} else {
|
|
|
|
status = proc_get_last_status();
|
2019-04-12 11:53:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|