mirror of
https://github.com/zoriya/ash.git
synced 2026-06-01 10:15:10 +00:00
Handling the SIGINT
This commit is contained in:
@@ -54,7 +54,8 @@ SRC = src/shell.c \
|
||||
src/key_bindings/autocompletion.c \
|
||||
src/builtin/builtin_bindkey.c \
|
||||
src/key_bindings/other_bindings.c \
|
||||
src/builtin/builtin_vars.c
|
||||
src/builtin/builtin_vars.c \
|
||||
src/key_bindings/signals.c
|
||||
|
||||
OBJ = $(SRC:%.c=%.o)
|
||||
OBJ += src/main.o
|
||||
|
||||
@@ -46,4 +46,6 @@ int down_history_command(int key, buffer_t *buffer, env_t *env);
|
||||
|
||||
int quoted_insert_command(int key, buffer_t *buffer, env_t *env);
|
||||
int clear_screen_command(int key, buffer_t *buffer, env_t *env);
|
||||
int complete_command(int key, buffer_t *buffer, env_t *env);
|
||||
int complete_command(int key, buffer_t *buffer, env_t *env);
|
||||
|
||||
int tty_sigintr_command(int key, buffer_t *buffer, env_t *env);
|
||||
@@ -71,4 +71,6 @@ my_addstr(window, str))
|
||||
#define my_clrtobot() (printf("\x1B[J"))
|
||||
|
||||
void my_npause(my_window *window);
|
||||
void my_nresume(my_window *window);
|
||||
void my_nresume(my_window *window);
|
||||
|
||||
extern my_window *stdwin;
|
||||
@@ -85,5 +85,6 @@ char *get_alias(char *cmd, alias_t *alias);
|
||||
char *add_separator(char *cmd, int *return_values, int index);
|
||||
char *get_alias_command(char *cmd, alias_t *alias);
|
||||
|
||||
void setup_sigint(void);
|
||||
|
||||
#define ERROR 84
|
||||
+1
-1
@@ -101,7 +101,7 @@ bool handle_parent_inout(redirection *inout[2], env_t *env, bool builtin)
|
||||
void run_cmd(char **argv, redirection *inout[2], env_t *env)
|
||||
{
|
||||
pid_t pid;
|
||||
int status;
|
||||
int status = 0;
|
||||
char *path;
|
||||
|
||||
if (strlen(argv[0]) == 0)
|
||||
|
||||
@@ -25,6 +25,7 @@ const key_function_t key_functions[] = {
|
||||
{"complete-command", &complete_command},
|
||||
{"clear-screen", &clear_screen_command},
|
||||
{"quoted-insert", "ed_insert_command},
|
||||
{"tty-sigintr", &tty_sigintr_command},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -43,6 +44,7 @@ const binding_t emacs_bindings[] = {
|
||||
{'\t', &complete_command},
|
||||
{CTRL('l'), &clear_screen_command},
|
||||
{CTRL('v'), "ed_insert_command},
|
||||
{CTRL('c'), &tty_sigintr_command},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** ash
|
||||
** File description:
|
||||
** signals
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
#include "shell.h"
|
||||
#include "key_functions.h"
|
||||
#include "my_ncurses.h"
|
||||
|
||||
void on_sigint(int sig, siginfo_t *info, void *context)
|
||||
{
|
||||
my_addstr(stdwin, "\n");
|
||||
}
|
||||
|
||||
void setup_sigint(void)
|
||||
{
|
||||
struct sigaction sa;
|
||||
|
||||
sa.sa_sigaction = &on_sigint;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sigaction(SIGINT, &sa, NULL);
|
||||
}
|
||||
|
||||
int tty_sigintr_command(int key, buffer_t *buffer, env_t *env)
|
||||
{
|
||||
if (buffer->buffer) {
|
||||
buffer->buffer[0] = '\0';
|
||||
buffer->pos = 0;
|
||||
env->vars = my_setenv(env->vars, "?", "130");
|
||||
}
|
||||
if (env->window) {
|
||||
my_addstr(env->window, "\n");
|
||||
prompt_prepare(buffer, env);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -74,6 +74,7 @@ void start_shell(env_t *env)
|
||||
buffer_t buffer = {NULL, 0, 0, 0, 0, NULL, false};
|
||||
int key;
|
||||
|
||||
setup_sigint();
|
||||
if (isatty(0)) {
|
||||
env->window = my_initwin();
|
||||
prompt_prepare(&buffer, env);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
int main()
|
||||
{
|
||||
while (1);
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user