mirror of
https://github.com/Savapitech/42sh.git
synced 2026-03-18 21:50:35 +01:00
Add ignoreof
This commit is contained in:
@@ -50,6 +50,12 @@ int special_case(ef_t *ef, char **args)
|
||||
static
|
||||
bool handle_special_variables(ef_t *ef, char **args, char *var, int i)
|
||||
{
|
||||
if (strcmp(var, "ignoreof") == 0) {
|
||||
ef->exec_ctx->ignoreof = true;
|
||||
return true;
|
||||
}
|
||||
if (args[i] == nullptr)
|
||||
return false;
|
||||
if (strcmp(var, "precmd") == 0) {
|
||||
ef->exec_ctx->precmd = strdup(args[i]);
|
||||
return true;
|
||||
@@ -87,6 +93,8 @@ int builtins_set(ef_t *ef, char **args)
|
||||
{
|
||||
char *var = nullptr;
|
||||
|
||||
if (args[1] != nullptr && handle_special_variables(ef, args, args[1], 2))
|
||||
return RETURN_SUCCESS;
|
||||
if (my_array_len(args) < 3)
|
||||
return special_case(ef, args);
|
||||
return handle_set(ef, args, var);
|
||||
|
||||
@@ -30,6 +30,7 @@ typedef struct {
|
||||
size_t prompt_len;
|
||||
char *precmd;
|
||||
char *cwdcmd;
|
||||
bool ignoreof;
|
||||
} exec_ctx_t;
|
||||
|
||||
size_t update_command(char **buffer,
|
||||
|
||||
@@ -19,8 +19,10 @@ bool handle_key_ctrl_c(readline_helper_t *rh, exec_ctx_t *ec, buff_t *buff)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool handle_key_ctrl_d(readline_helper_t *, exec_ctx_t *, buff_t *buff)
|
||||
bool handle_key_ctrl_d(readline_helper_t *, exec_ctx_t *ec, buff_t *buff)
|
||||
{
|
||||
if (ec->ignoreof)
|
||||
return false;
|
||||
buff->sz = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ int shell_loop(int is_a_tty, exec_ctx_t *exec_ctx)
|
||||
buff_t buff = { .str = nullptr, 0, .cap = 0 };
|
||||
struct termios repl_settings;
|
||||
|
||||
U_DEBUG_CALL(debug_env_entries, exec_ctx->env);
|
||||
exec_ctx->isatty = is_a_tty;
|
||||
tcgetattr(STDIN_FILENO, &repl_settings);
|
||||
exec_ctx->saved_term_settings = repl_settings;
|
||||
@@ -152,12 +153,12 @@ int shell(opt_t *opt, char **env_ptr)
|
||||
local_t local = create_local();
|
||||
exec_ctx_t exec_ctx = {.env = &env, .local = &local, .opt = opt,
|
||||
.read_fd = get_read_fd(opt), .history = &history, .precmd = nullptr,
|
||||
.history_command = cmd_history, .alias = &alias, 0, .cwdcmd = nullptr};
|
||||
.history_command = cmd_history, .alias = &alias, 0, .cwdcmd = nullptr,
|
||||
.ignoreof = false };
|
||||
int shell_result;
|
||||
|
||||
if (exec_ctx.read_fd == -1 || (int)error_in_init(&exec_ctx))
|
||||
return RETURN_FAILURE;
|
||||
U_DEBUG_CALL(debug_env_entries, &env);
|
||||
shell_result = shell_loop(isatty(exec_ctx.read_fd), &exec_ctx);
|
||||
if (opt->cmd == NULL && isatty(exec_ctx.read_fd)) {
|
||||
WRITE_CONST(STDOUT_FILENO, "exit\n");
|
||||
|
||||
Reference in New Issue
Block a user