fix line endings.

This commit is contained in:
Kelvin Sherlock 2018-05-10 21:07:31 -04:00
parent 12032fe800
commit 3f0a195014
1 changed files with 280 additions and 280 deletions

560
darlene.c
View File

@ -1,281 +1,281 @@
/* /*
* The original concept. Not the original code :) * The original concept. Not the original code :)
* *
*/ */
#include <Event.h> #include <Event.h>
#include <gsos.h> #include <gsos.h>
#include <Locator.h> #include <Locator.h>
#include <Memory.h> #include <Memory.h>
#include <texttool.h> #include <texttool.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <gno/gno.h> #include <gno/gno.h>
#include <gno/kerntool.h> #include <gno/kerntool.h>
#include <libutil.h> #include <libutil.h>
#include <sgtty.h> #include <sgtty.h>
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
#include <sys/ioctl.compat.h> #include <sys/ioctl.compat.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
extern void screen_init(void); extern void screen_init(void);
extern void screen_on(void); extern void screen_on(void);
extern void screen_off(void); extern void screen_off(void);
static char out_buffer[1024]; static char out_buffer[1024];
static char out_buffer_size = 0; static char out_buffer_size = 0;
static int master = -1; static int master = -1;
static void flush(void) { static void flush(void) {
if (out_buffer_size) { if (out_buffer_size) {
write(master, out_buffer, out_buffer_size); write(master, out_buffer, out_buffer_size);
out_buffer_size = 0; out_buffer_size = 0;
} }
} }
void send(char *data, unsigned size) { void send(char *data, unsigned size) {
if (out_buffer_size + size > sizeof(out_buffer)) { if (out_buffer_size + size > sizeof(out_buffer)) {
flush(); flush();
} }
if (size > sizeof(out_buffer) / 2) { if (size > sizeof(out_buffer) / 2) {
write(master, data, size); write(master, data, size);
return; return;
} }
memcpy(out_buffer + out_buffer_size, data, size); memcpy(out_buffer + out_buffer_size, data, size);
out_buffer_size += size; out_buffer_size += size;
} }
int int
openpty2(int *amaster, int *aslave, char *name, struct sgttyb *sg, struct winsize *winp) { openpty2(int *amaster, int *aslave, char *name, struct sgttyb *sg, struct winsize *winp) {
char ptyname[] = ".ptyq0"; char ptyname[] = ".ptyq0";
char ttyname[] = ".ttyq0"; char ttyname[] = ".ttyq0";
int master; int master;
int slave; int slave;
unsigned i; unsigned i;
for (i = 0; i < 16; ++i) { for (i = 0; i < 16; ++i) {
ptyname[5] = ttyname[5] = "0123456789abcdef"[i]; ptyname[5] = ttyname[5] = "0123456789abcdef"[i];
master = open(ptyname, O_RDWR); master = open(ptyname, O_RDWR);
if (master < 0) continue; if (master < 0) continue;
slave = open(ttyname, O_RDRW); slave = open(ttyname, O_RDRW);
if (slave < 0) { if (slave < 0) {
close(master); close(master);
continue; continue;
} }
*amaster = master; *amaster = master;
*aslave = slave; *aslave = slave;
if (name) strcpy(name, ttyname); if (name) strcpy(name, ttyname);
if (sg) stty(slave, sg); if (sg) stty(slave, sg);
if (winp) ioctl(slave, TIOCSWINSZ, (char *)winp); if (winp) ioctl(slave, TIOCSWINSZ, (char *)winp);
return 0; return 0;
} }
errno = ENOENT; errno = ENOENT;
return -1; return -1;
} }
#pragma databank 1 #pragma databank 1
static int _child(int master, int slave) { static int _child(int master, int slave) {
close(master); close(master);
logintty(slave); logintty(slave);
execve(":bin:gsh", "gsh -f"); execve(":bin:gsh", "gsh -f");
write(slave, "Unable to exec.\r\n", 27); write(slave, "Unable to exec.\r\n", 27);
close(slave); close(slave);
return 1; return 1;
} }
#pragma databank 0 #pragma databank 0
int int
forkpty2(int *amaster, char *name, struct sgttyb *sg, struct winsize *winp) { forkpty2(int *amaster, char *name, struct sgttyb *sg, struct winsize *winp) {
int ok; int ok;
int master, slave, pid; int master, slave, pid;
ok = openpty2(&master, &slave, name, sg, winp); ok = openpty2(&master, &slave, name, sg, winp);
if (ok < 0) return -1; if (ok < 0) return -1;
pid = fork2(_child, 256, 0, NULL, 4, master, slave); pid = fork2(_child, 256, 0, NULL, 4, master, slave);
if (pid < 0) { if (pid < 0) {
close(master); close(master);
close(slave); close(slave);
return -1; return -1;
} }
close(slave); close(slave);
return pid; return pid;
} }
#pragma databank 1 #pragma databank 1
static void sigchild(int sig, int x) { static void sigchild(int sig, int x) {
PostEvent(app4Mask,0); PostEvent(app4Mask,0);
} }
#pragma databank 0 #pragma databank 0
int main(int argc, char **argv) { int main(int argc, char **argv) {
int pid; int pid;
unsigned i; unsigned i;
Handle dpHandle = NULL; Handle dpHandle = NULL;
Handle shrHandle = NULL; Handle shrHandle = NULL;
Handle shdHandle = NULL; Handle shdHandle = NULL;
master = -1; master = -1;
kernStatus(); kernStatus();
if (_toolErr) { if (_toolErr) {
ErrWriteCString("GNO/ME required.\r\n"); ErrWriteCString("GNO/ME required.\r\n");
return 1; return 1;
} }
for (i = 1; i < argc; ++i) { for (i = 1; i < argc; ++i) {
char *cp = argv[i]; char *cp = argv[i];
if (cp[0] != '-') break; if (cp[0] != '-') break;
if (strcmp(cp, "--vt52") == 0) { if (strcmp(cp, "--vt52") == 0) {
} else if (strcmp(cp, "--vt100") == 0) { } else if (strcmp(cp, "--vt100") == 0) {
} else { } else {
ErrWriteCString("Unknown option: "); ErrWriteCString("Unknown option: ");
ErrWriteCString(cp); ErrWriteCString(cp);
ErrWriteCString("\r\n"); ErrWriteCString("\r\n");
return 1; return 1;
} }
} }
argc -= i; argc -= i;
argv += i; argv += i;
signal(SIGCHLD,sigchild); signal(SIGCHLD,sigchild);
pid = forkpty2(&master, NULL, NULL, NULL); pid = forkpty2(&master, NULL, NULL, NULL);
if ( pid < 0) { if ( pid < 0) {
ErrWriteCString("Unable to forkpty.\r\n"); ErrWriteCString("Unable to forkpty.\r\n");
return 1; return 1;
} }
dpHandle = NewHandle(0x0100, MyID, dpHandle = NewHandle(0x0100, MyID,
attrBank | attrPage |attrNoCross | attrFixed | attrLocked, attrBank | attrPage |attrNoCross | attrFixed | attrLocked,
0x000000); 0x000000);
shdHandle = NewHandle(0x8000, MyID, shdHandle = NewHandle(0x8000, MyID,
attrAddr | attrFixed | attrLocked, attrAddr | attrFixed | attrLocked,
(void *)0x012000); (void *)0x012000);
shrHandle = NewHandle(0x8000, MyID, shrHandle = NewHandle(0x8000, MyID,
attrAddr | attrFixed | attrLocked, attrAddr | attrFixed | attrLocked,
(void *)0xe12000); (void *)0xe12000);
if (!dpHandle || !shdHandle || !shrHandle) { if (!dpHandle || !shdHandle || !shrHandle) {
ErrWriteCString("Unable to allocate memory.\r\n"); ErrWriteCString("Unable to allocate memory.\r\n");
if (dpHandle) DisposeHandle(dpHandle); if (dpHandle) DisposeHandle(dpHandle);
if (shdHandle) DisposeHandle(shdHandle); if (shdHandle) DisposeHandle(shdHandle);
if (shrHandle) DisposeHandle(shrHandle); if (shrHandle) DisposeHandle(shrHandle);
return 1; return 1;
} }
EMStartUp((Word)*dpHandle, 0x14, 0, 0, 0, 0, MyID); EMStartUp((Word)*dpHandle, 0x14, 0, 0, 0, 0, MyID);
screen_init(); screen_init();
vt100_init(); vt100_init();
screen_init(); screen_init();
vt100_init(); vt100_init();
for(;;) { for(;;) {
static char buffer[1024]; static char buffer[1024];
int fio = 0; int fio = 0;
ioctl(master, FIONREAD, &fio); ioctl(master, FIONREAD, &fio);
if (fio > sizeof(buffer)) fio = sizeof(buffer); if (fio > sizeof(buffer)) fio = sizeof(buffer);
if (fio > 0) { if (fio > 0) {
fio = read(master, buffer, fio); fio = read(master, buffer, fio);
if (fio > 0) vt100_process(buffer, fio); if (fio > 0) vt100_process(buffer, fio);
} }
if (GetNextEvent(everyEvent, &event)) { if (GetNextEvent(everyEvent, &event)) {
fio = 1; fio = 1;
if (event.what == keyDownEvt) { if (event.what == keyDownEvt) {
unsigned char key = event.message; unsigned char key = event.message;
if (event.modifiers & appleKey) { if (event.modifiers & appleKey) {
switch (key) { switch (key) {
case 'Q': // quit case 'Q': // quit
case 'q': case 'q':
goto _exit1; goto _exit1;
break; break;
case 'V': // paste... case 'V': // paste...
case 'v': case 'v':
break; break;
case 'Z': // suspend (gnome) case 'Z': // suspend (gnome)
case 'z': { case 'z': {
/* EMStartUp puts the tty in RAW mode. */ /* EMStartUp puts the tty in RAW mode. */
static struct sgttyb sb; static struct sgttyb sb;
gtty(1,&sb); gtty(1,&sb);
sb.sg_flags &= ~RAW; sb.sg_flags &= ~RAW;
stty(1,&sb); stty(1,&sb);
screen_off(); screen_off();
Kkill(Kgetpid(), SIGSTOP, &errno); Kkill(Kgetpid(), SIGSTOP, &errno);
sb.sg_flags |= RAW; sb.sg_flags |= RAW;
stty(1,&sb); stty(1,&sb);
screen_on(); screen_on();
} }
break; break;
} }
} else { } else {
vt100_event(&event); vt100_event(&event);
} }
} }
if (event.what == app4Mask) { if (event.what == app4Mask) {
/* child signal received! */ /* child signal received! */
union wait wt; union wait wt;
ok = waitpid(pid, &wt, WNOHANG); ok = waitpid(pid, &wt, WNOHANG);
if (ok <= 0) continue; if (ok <= 0) continue;
display_str("\r\nChild exited.\r\n"); display_str("\r\nChild exited.\r\n");
break; break;
} }
} }
flush(); flush();
if (fio <= 0) asm { cop 0x7f } if (fio <= 0) asm { cop 0x7f }
} }
_exit1: _exit1:
flush(); flush();
if (master >= 0) close(master); if (master >= 0) close(master);
_exit: _exit:
// flush q // flush q
FlushEvents(everyEvent, 0); FlushEvents(everyEvent, 0);
display_cstr("\n\rPress any key to exit.\n\r"); display_cstr("\n\rPress any key to exit.\n\r");
while (!GetNextEvent(keyDownMask | autoKeyMask, &event)) ; while (!GetNextEvent(keyDownMask | autoKeyMask, &event)) ;
EMShutDown(); EMShutDown();
DisposeHandle(dpHandle); DisposeHandle(dpHandle);
DisposeHandle(shdHandle); DisposeHandle(shdHandle);
DisposeHandle(shrHandle); DisposeHandle(shrHandle);
screen_off(); screen_off();
return 0; return 0;
} }