From 4933bb5623ba2e94f373d7537a2bb5e54f71d72e Mon Sep 17 00:00:00 2001 From: MrNavaStar Date: Fri, 3 May 2024 21:47:46 -0600 Subject: [PATCH] raw mode works! (for sigint) --- src/args.c | 14 ++++++++++++-- src/gdmp.c | 9 ++++----- src/include/args.h | 3 ++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/args.c b/src/args.c index c0bb2bd..fd89279 100644 --- a/src/args.c +++ b/src/args.c @@ -59,6 +59,9 @@ int parse_args(int argc, char *argv[], Signal signals[31]) { int c = 0; int cmd_offset = 0; + // SIGWINCH needs to be registered by default for resizing to work + signals[27].sig = SIGWINCH; + for (int i = 1; i < argc && cmd_offset == 0; i++) { char *arg = argv[i]; int type = get_type(arg); @@ -66,8 +69,6 @@ int parse_args(int argc, char *argv[], Signal signals[31]) { case 0: Signal signal; signal.sig = get_sig(arg + 2); - signal.block = 0; - signal.mode = 0; current[c] = signal; c++; break; @@ -99,4 +100,13 @@ int parse_args(int argc, char *argv[], Signal signals[31]) { for (int i = 0; i < c; i++) signals[current[i].sig - 1] = current[i]; return cmd_offset; +} + +int get_sig_from_code(char code) { + switch (code) { + case '\3': + return SIGINT; + default: + return 0; + } } \ No newline at end of file diff --git a/src/gdmp.c b/src/gdmp.c index e753b9c..cf20723 100644 --- a/src/gdmp.c +++ b/src/gdmp.c @@ -1,5 +1,4 @@ #define _POSIX_SOURCE -#include #include #include #include @@ -54,13 +53,13 @@ void io_handler(int pty) { sigprocmask(SIG_BLOCK, &mask, NULL); for (;;) { - n = read(STDIN_FILENO, buf, sizeof(buf)); - if (write(pty, buf, n) != n) err("Writen error to master pty."); + n = read(STDIN_FILENO, buf, 1); + int sig = get_sig_from_code(buf[0]); + if (sig != 0) sig_handler(sig); + else if (write(pty, buf, n) != n) err("Writen error to master pty."); } } - // SIGWINCH needs to be registered by default for resizing to work - trap(SIGWINCH, sig_handler); for (int i = 0; i < 31; i++) if (signals[i].sig) trap(signals[i].sig, sig_handler); diff --git a/src/include/args.h b/src/include/args.h index 89b0784..10769be 100644 --- a/src/include/args.h +++ b/src/include/args.h @@ -5,4 +5,5 @@ typedef struct signal { char *text; } Signal; -int parse_args(int argc, char *argv[], Signal signals[31]); \ No newline at end of file +int parse_args(int argc, char *argv[], Signal signals[31]); +int get_sig_from_code(char code); \ No newline at end of file