Tweaks to make it work on Unix.
This commit is contained in:
parent
079d45c20e
commit
941c9f36a9
6 changed files with 86 additions and 66 deletions
|
|
@ -24,4 +24,6 @@ HFILES=\
|
||||||
CFLAGS+=-I../sam
|
CFLAGS+=-I../sam
|
||||||
LDFLAGS+=-lframe -ldraw -lthread -l9 -lregexp9 -lbio -lfmt -lutf -L$(X11)/lib -lX11 -lm
|
LDFLAGS+=-lframe -ldraw -lthread -l9 -lregexp9 -lbio -lfmt -lutf -L$(X11)/lib -lX11 -lm
|
||||||
|
|
||||||
|
samterm: $(9SRC)/lib/libdraw.a
|
||||||
|
|
||||||
include ../Makeone
|
include ../Makeone
|
||||||
|
|
|
||||||
|
|
@ -74,10 +74,10 @@ button(int but)
|
||||||
return mousep->buttons&(1<<(but-1));
|
return mousep->buttons&(1<<(but-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void
|
void
|
||||||
externload(int i)
|
externload(int i)
|
||||||
{
|
{
|
||||||
|
drawtopwindow();
|
||||||
plumbbase = malloc(plumbbuf[i].n);
|
plumbbase = malloc(plumbbuf[i].n);
|
||||||
if(plumbbase == 0)
|
if(plumbbase == 0)
|
||||||
return;
|
return;
|
||||||
|
|
@ -86,7 +86,6 @@ externload(int i)
|
||||||
plumbstop = plumbbase + plumbbuf[i].n;
|
plumbstop = plumbbase + plumbbuf[i].n;
|
||||||
got |= 1<<RPlumb;
|
got |= 1<<RPlumb;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
int
|
int
|
||||||
waitforio(void)
|
waitforio(void)
|
||||||
|
|
@ -140,11 +139,9 @@ again:
|
||||||
hoststop = hostbuf[i].data + hostbuf[i].n;
|
hoststop = hostbuf[i].data + hostbuf[i].n;
|
||||||
block = 0;
|
block = 0;
|
||||||
break;
|
break;
|
||||||
/*
|
|
||||||
case RPlumb:
|
case RPlumb:
|
||||||
externload(i);
|
externload(i);
|
||||||
break;
|
break;
|
||||||
*/
|
|
||||||
case RKeyboard:
|
case RKeyboard:
|
||||||
kbdc = r;
|
kbdc = r;
|
||||||
break;
|
break;
|
||||||
|
|
@ -250,7 +247,7 @@ ekbd(void)
|
||||||
int
|
int
|
||||||
kbdchar(void)
|
kbdchar(void)
|
||||||
{
|
{
|
||||||
int c, i;
|
int i, c;
|
||||||
|
|
||||||
c = externchar();
|
c = externchar();
|
||||||
if(c > 0)
|
if(c > 0)
|
||||||
|
|
@ -261,14 +258,12 @@ kbdchar(void)
|
||||||
got &= ~(1<<RKeyboard);
|
got &= ~(1<<RKeyboard);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
while(plumbc!=nil && nbrecv(plumbc, &i)>0){
|
while(plumbc!=nil && nbrecv(plumbc, &i)>0){
|
||||||
externload(i);
|
externload(i);
|
||||||
c = externchar();
|
c = externchar();
|
||||||
if(c > 0)
|
if(c > 0)
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if(!ecankbd())
|
if(!ecankbd())
|
||||||
return -1;
|
return -1;
|
||||||
return ekbd();
|
return ekbd();
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,20 @@ threadmain(int argc, char *argv[])
|
||||||
Rectangle r;
|
Rectangle r;
|
||||||
Flayer *nwhich;
|
Flayer *nwhich;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* sam is talking to us on fd 0 and 1.
|
||||||
|
* move these elsewhere so that if we accidentally
|
||||||
|
* use 0 and 1 in other code, nothing bad happens.
|
||||||
|
*/
|
||||||
|
dup(0, 3);
|
||||||
|
dup(1, 4);
|
||||||
|
hostfd[0] = 3;
|
||||||
|
hostfd[1] = 4;
|
||||||
|
close(0);
|
||||||
|
close(1);
|
||||||
|
open("/dev/null", OREAD);
|
||||||
|
dup(2, 1);
|
||||||
|
|
||||||
getscreen(argc, argv);
|
getscreen(argc, argv);
|
||||||
iconinit();
|
iconinit();
|
||||||
initio();
|
initio();
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ uchar indata[DATASIZE+1]; /* room for NUL */
|
||||||
uchar outdata[DATASIZE];
|
uchar outdata[DATASIZE];
|
||||||
short outcount;
|
short outcount;
|
||||||
int hversion;
|
int hversion;
|
||||||
|
int hostfd[2];
|
||||||
|
|
||||||
void inmesg(Hmesg, int);
|
void inmesg(Hmesg, int);
|
||||||
int inshort(int);
|
int inshort(int);
|
||||||
|
|
@ -510,7 +511,7 @@ outsend(void)
|
||||||
panic("outcount>sizeof outdata");
|
panic("outcount>sizeof outdata");
|
||||||
outdata[1]=outcount;
|
outdata[1]=outcount;
|
||||||
outdata[2]=outcount>>8;
|
outdata[2]=outcount>>8;
|
||||||
if(write(1, (char *)outdata, outcount+HSIZE)!=outcount+HSIZE)
|
if(write(hostfd[1], (char *)outdata, outcount+HSIZE)!=outcount+HSIZE)
|
||||||
panic("write error");
|
panic("write error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -651,7 +652,7 @@ hsetsnarf(int nc)
|
||||||
s1[n] = 0;
|
s1[n] = 0;
|
||||||
snarflen = n;
|
snarflen = n;
|
||||||
outTs(Tsetsnarf, n);
|
outTs(Tsetsnarf, n);
|
||||||
if(n>0 && write(1, s1, n)!=n)
|
if(n>0 && write(hostfd[1], s1, n)!=n)
|
||||||
panic("snarf write error");
|
panic("snarf write error");
|
||||||
free(s1);
|
free(s1);
|
||||||
}else
|
}else
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include <draw.h>
|
#include <draw.h>
|
||||||
|
|
@ -9,7 +13,7 @@
|
||||||
#include "flayer.h"
|
#include "flayer.h"
|
||||||
#include "samterm.h"
|
#include "samterm.h"
|
||||||
|
|
||||||
static char exname[64];
|
static char *exname;
|
||||||
|
|
||||||
void
|
void
|
||||||
getscreen(int argc, char **argv)
|
getscreen(int argc, char **argv)
|
||||||
|
|
@ -19,7 +23,7 @@ getscreen(int argc, char **argv)
|
||||||
USED(argc);
|
USED(argc);
|
||||||
USED(argv);
|
USED(argv);
|
||||||
if(initdraw(panic1, nil, "sam") < 0){
|
if(initdraw(panic1, nil, "sam") < 0){
|
||||||
fprint(2, "samterm: initimage: %r\n");
|
fprint(2, "samterm: initdraw: %r\n");
|
||||||
threadexitsall("init");
|
threadexitsall("init");
|
||||||
}
|
}
|
||||||
t = getenv("tabstop");
|
t = getenv("tabstop");
|
||||||
|
|
@ -58,33 +62,13 @@ screensize(int *w, int *h)
|
||||||
int
|
int
|
||||||
snarfswap(char *fromsam, int nc, char **tosam)
|
snarfswap(char *fromsam, int nc, char **tosam)
|
||||||
{
|
{
|
||||||
char *s1;
|
char *s;
|
||||||
int f, n, ss;
|
|
||||||
|
|
||||||
f = open("/dev/snarf", 0);
|
fprint(2, "snarfswap\n");
|
||||||
if(f < 0)
|
s = getsnarf();
|
||||||
return -1;
|
putsnarf(fromsam);
|
||||||
ss = SNARFSIZE;
|
*tosam = s;
|
||||||
if(hversion < 2)
|
return s ? strlen(s) : 0;
|
||||||
ss = 4096;
|
|
||||||
*tosam = s1 = alloc(ss);
|
|
||||||
n = read(f, s1, ss-1);
|
|
||||||
close(f);
|
|
||||||
if(n < 0)
|
|
||||||
n = 0;
|
|
||||||
if (n == 0) {
|
|
||||||
*tosam = 0;
|
|
||||||
free(s1);
|
|
||||||
} else
|
|
||||||
s1[n] = 0;
|
|
||||||
/*
|
|
||||||
f = create("/dev/snarf", 1, 0666);
|
|
||||||
if(f >= 0){
|
|
||||||
write(f, fromsam, nc);
|
|
||||||
close(f);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -101,68 +85,86 @@ removeextern(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
Readbuf hostbuf[2];
|
Readbuf hostbuf[2];
|
||||||
/*
|
|
||||||
Readbuf plumbbuf[2];
|
Readbuf plumbbuf[2];
|
||||||
|
|
||||||
void
|
void
|
||||||
extproc(void *argv)
|
extproc(void *argv)
|
||||||
{
|
{
|
||||||
Channel *c;
|
Channel *c;
|
||||||
int i, n, which, *fdp;
|
int i, n, which, fd;
|
||||||
void **arg;
|
void **arg;
|
||||||
|
|
||||||
arg = argv;
|
arg = argv;
|
||||||
c = arg[0];
|
c = arg[0];
|
||||||
fdp = arg[1];
|
fd = (int)arg[1];
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for(;;){
|
for(;;){
|
||||||
i = 1-i; / * toggle * /
|
i = 1-i; /* toggle */
|
||||||
n = read(*fdp, plumbbuf[i].data, sizeof plumbbuf[i].data);
|
n = read(fd, plumbbuf[i].data, sizeof plumbbuf[i].data);
|
||||||
if(n <= 0){
|
if(n <= 0){
|
||||||
fprint(2, "samterm: extern read error: %r\n");
|
fprint(2, "samterm: extern read error: %r\n");
|
||||||
threadexits("extern"); / * not a fatal error * /
|
threadexits("extern"); /* not a fatal error */
|
||||||
}
|
}
|
||||||
plumbbuf[i].n = n;
|
plumbbuf[i].n = n;
|
||||||
which = i;
|
which = i;
|
||||||
send(c, &which);
|
send(c, &which);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
void
|
void
|
||||||
extstart(void)
|
extstart(void)
|
||||||
{
|
{
|
||||||
char buf[32];
|
char *user, *disp;
|
||||||
int fd;
|
int fd, flags;
|
||||||
static int p[2];
|
|
||||||
static void *arg[2];
|
static void *arg[2];
|
||||||
|
|
||||||
return;
|
user = getenv("USER");
|
||||||
if(pipe(p) < 0)
|
if(user == nil)
|
||||||
return;
|
return;
|
||||||
sprint(exname, "/srv/sam.%s", "rsc"/*getuser()*/);
|
disp = getenv("DISPLAY");
|
||||||
fd = open(exname, 1, 0600);/* BUG was create */
|
if(disp)
|
||||||
if(fd < 0){ /* assume existing guy is more important */
|
exname = smprint("/tmp/.sam.%s.%s", user, disp);
|
||||||
Err:
|
else
|
||||||
close(p[0]);
|
exname = smprint("/tmp/.sam.%s", user);
|
||||||
close(p[1]);
|
if(exname == nil){
|
||||||
|
fprint(2, "not posting for B: out of memory\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sprint(buf, "%d", p[0]);
|
|
||||||
if(write(fd, buf, strlen(buf)) <= 0)
|
if(mkfifo(exname, 0600) < 0){
|
||||||
goto Err;
|
struct stat st;
|
||||||
close(fd);
|
if(errno != EEXIST || stat(exname, &st) < 0)
|
||||||
|
return;
|
||||||
|
if(!S_ISFIFO(st.st_mode)){
|
||||||
|
removeextern();
|
||||||
|
if(mkfifo(exname, 0600) < 0)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = open(exname, OREAD|O_NONBLOCK);
|
||||||
|
if(fd == -1){
|
||||||
|
removeextern();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* leave p[0] open so if the file is removed the event
|
* Turn off no-delay and provide ourselves as a lingering
|
||||||
* library won't get an error
|
* writer so as not to get end of file on read.
|
||||||
*/
|
*/
|
||||||
#if 0
|
flags = fcntl(fd, F_GETFL, 0);
|
||||||
|
if(flags<0 || fcntl(fd, F_SETFL, flags&~O_NONBLOCK)<0
|
||||||
|
||open(exname, OWRITE) < 0){
|
||||||
|
close(fd);
|
||||||
|
removeextern();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
plumbc = chancreate(sizeof(int), 0);
|
plumbc = chancreate(sizeof(int), 0);
|
||||||
arg[0] = plumbc;
|
arg[0] = plumbc;
|
||||||
arg[1] = &p[1];
|
arg[1] = (void*)fd;
|
||||||
proccreate(extproc, arg, 1024);
|
proccreate(extproc, arg, 8192);
|
||||||
#endif
|
|
||||||
atexit(removeextern);
|
atexit(removeextern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -277,7 +279,7 @@ hostproc(void *arg)
|
||||||
i = 0;
|
i = 0;
|
||||||
for(;;){
|
for(;;){
|
||||||
i = 1-i; /* toggle */
|
i = 1-i; /* toggle */
|
||||||
n = read(0, hostbuf[i].data, sizeof hostbuf[i].data);
|
n = read(hostfd[0], hostbuf[i].data, sizeof hostbuf[i].data);
|
||||||
if(n <= 0){
|
if(n <= 0){
|
||||||
fprint(2, "samterm: host read error: %r\n");
|
fprint(2, "samterm: host read error: %r\n");
|
||||||
threadexitsall("host");
|
threadexitsall("host");
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,7 @@ extern Channel *plumbc;
|
||||||
extern Channel *hostc;
|
extern Channel *hostc;
|
||||||
extern int hversion;
|
extern int hversion;
|
||||||
extern int plumbfd;
|
extern int plumbfd;
|
||||||
|
extern int hostfd[2];
|
||||||
|
|
||||||
Rune *gettext(Flayer*, long, ulong*);
|
Rune *gettext(Flayer*, long, ulong*);
|
||||||
void *alloc(ulong n);
|
void *alloc(ulong n);
|
||||||
|
|
@ -175,3 +176,8 @@ void outshort(int);
|
||||||
void outlong(long);
|
void outlong(long);
|
||||||
void outvlong(void*);
|
void outvlong(void*);
|
||||||
void outsend(void);
|
void outsend(void);
|
||||||
|
|
||||||
|
int perror(char*);
|
||||||
|
int remove(char*);
|
||||||
|
int create(char*, int, ulong);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue