This commit is contained in:
Kelvin Sherlock 2018-05-10 11:26:30 -04:00
parent 3cd69c8e8b
commit e82452f216
2 changed files with 156 additions and 11 deletions

131
darlene.c Normal file
View File

@ -0,0 +1,131 @@
/*
* The original concept. Not the original code :)
*
*/
#include <texttool.h>
#include <gsos.h>
#include <Event.h>
#include <fcntl.h>
#include <Locator.h>
#include <Memory.h>
#include <sgtty.h>
#include <libutil.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/ioctl.compat.h>
int
openpty2(int *amaster, int *aslave, char *name, struct sgttyb *sg, struct winsize *winp) {
char ptyname[] = ".ptyq0";
char ttyname[] = ".ttyq0";
int master;
int slave;
unsigned i;
for (i = 0; i < 16; ++i) {
ptyname[5] = ttyname[5] = "0123456789abcdef"[i];
master = open(ptyname, O_RDWR);
if (master < 0) continue;
slave = open(ttyname, O_RDRW);
if (slave < 0) {
close(master);
continue;
}
*amaster = master;
*aslave = slave;
if (name) strcpy(name, ttyname);
if (sg) stty(slave, sg);
if (winp) ioctl(slave, TIOCSWINSZ, (char *)winp);
return 0;
}
errno = ENOENT;
return -1;
}
#pragma databank 1
static int _child(int master, int slave) {
close(master);
logintty(slave);
execve(":bin:gsh", "gsh -f");
write(slave, "Unable to exec.\r\n", 27);
close(slave);
return 1;
}
#pragma databank 0
int
forkpty2(int *amaster, char *name, struct sgttyb *sg, struct winsize *winp) {
int ok;
int master, slave, pid;
ok = openpty2(&master, &slave, name, sg, winp);
if (ok < 0) return -1;
pid = fork2(_child, 256, 0, NULL, 4, master, slave);
if (pid < 0) {
close(master);
close(slave);
return -1;
}
close(slave);
return pid;
}
#pragma databank 1
static void sigchild(int sig, int x) {
PostEvent(0x8000,0);
}
#pragma databank 0
int main(int argc, char **argv) {
int fd;
int pid;
signal(SIGCHLD,sigchild);
pid = forkpty2(&fd, NULL, NULL, NULL);
if ( pid < 0) {
ErrWriteCString("Unable to forkpty.\r\n");
return 1;
}
for(;;) {
int fio = 0;
ioctl(fd, FIONREAD, &fio);
if (fio > 256) fio = 256;
if (fio > 0) {
fio = read(fd, buffer, fio);
if (fio > 0) vt100_process(buffer, fio);
}
GetNextEvent(...);
if (fio <= 0) {
union wait wt;
ok = waitpid(pid, &wt, WNOHANG);
if (ok <= 0)
}
asm { cop 0x7f }
}
if (fd >= 0) close(fd);
return 0;
}

36
main.c
View File

@ -194,6 +194,30 @@ int main(int argc, char **argv) {
kernStatus();
if (!_toolErr) __gno = true;
// todo:keypad flag of some sort?
for (i = 1; i < argv; ++i) {
char *cp = argv[i];
if (cp[0] != '-') break;
if (strcmp(cp, "--vt52") == 0) {
} else if (strcmp(cp, "--vt100") == 0) {
} else {
ErrWriteCString("Unknown option: ");
ErrWriteCString(cp);
ErrWriteCString("\r\n");
return 1;
}
}
argv += i;
argc -= i;
if (argc != 1) {
ErrWriteCString("Usage: marlene host[:port]\r\n");
return 1;
}
TextStartUp();
SetOutputDevice(1,3);
SetOutGlobals(0x7f, 0);
@ -219,14 +243,6 @@ int main(int argc, char **argv) {
EMStartUp((Word)*dpHandle, 0x14, 0, 0, 0, 0, MyID);
// todo: -vt52 -> start in vt52 mode (DECANM = 0)
// todo:keypad flag of some sort?
if (argc != 2) {
ErrWriteCString("Usage: marlene host[:port]\r\n");
goto _exit;
}
screen_init();
vt100_init();
@ -261,7 +277,7 @@ int main(int argc, char **argv) {
}
// marinetti is now connected
if (!ResolveHost(argv[1], &cvt)) {
if (!ResolveHost(argv[0], &cvt)) {
display_cstr("Unable to resolve address.\r\n");
goto _exit;
}
@ -287,8 +303,6 @@ int main(int argc, char **argv) {
telnet_init();
//fd = open ("tcp.log", O_TRUNC | O_WRONLY | O_CREAT, 0777);
for(;;) {
static rrBuff rr;