Skip to content

Commit

Permalink
raw mode works! (for sigint)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNavaStar committed May 4, 2024
1 parent 485fb16 commit 4933bb5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
14 changes: 12 additions & 2 deletions src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ 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);
switch (type) {
case 0:
Signal signal;
signal.sig = get_sig(arg + 2);
signal.block = 0;
signal.mode = 0;
current[c] = signal;
c++;
break;
Expand Down Expand Up @@ -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;
}
}
9 changes: 4 additions & 5 deletions src/gdmp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#define _POSIX_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/include/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ typedef struct signal {
char *text;
} Signal;

int parse_args(int argc, char *argv[], Signal signals[31]);
int parse_args(int argc, char *argv[], Signal signals[31]);
int get_sig_from_code(char code);

0 comments on commit 4933bb5

Please sign in to comment.