fix term.c

This commit is contained in:
~d6 2023-02-04 16:32:59 -05:00
parent 5f1e9f561e
commit 926d13ce55
1 changed files with 15 additions and 18 deletions

31
term.c
View File

@ -8,26 +8,23 @@ int main(int argc, char **argv) {
printf("usage: %s ROM\n", argv[0]); printf("usage: %s ROM\n", argv[0]);
return 1; return 1;
} }
char *rom = argv[1]; char *rom = argv[1]; // find term.rom
int fdm = -1; int fdm = -1; // allocate file descriptor
setenv("TERM", "ansi", 1);
// allocate a pty, fork, inititialize file descriptor
pid_t pid = forkpty(&fdm, NULL, NULL, NULL); pid_t pid = forkpty(&fdm, NULL, NULL, NULL);
if (pid < 0) { if (pid < 0) { // failure
// failure
printf("fork failed"); printf("fork failed");
return 1; return 1;
} else if (pid == 0) { } else if (pid == 0) { // child
// child setenv("TERM", "ansi", 1);
setsid(); execlp("bash", "bash", NULL); // exec bash
execlp("bash", "bash"); } else { // parent
} else { struct winsize ws = {23, 80, 8, 12}; // rows, cols, xps, ypx
// parent ioctl(fdm, TIOCSWINSZ, &ws); // set term window size
// rows, cols, xpixels, ypixels (little endian) dup2(fdm, 0); // use fdm for stdin
char argp[] = {23, 0, 80, 0, 8, 0, 12, 0}; dup2(fdm, 1); // use fdm for stdout
ioctl(fdm, TIOCSWINSZ, argp); execlp("uxnemu", "uxnemu", rom, NULL); // exec uxnemu
dup2(fdm, 0);
dup2(fdm, 1);
execlp("uxnemu", "uxnemu", rom);
} }
} }