Various fixes.
B - fixed usage, DISPLAY :0 vs :0.0 9term - fixed various terminal things rc - notice traps in Read _p9dir - only run disk code for disks dirread - getdirentries on FreeBSD and Linux are different w.r.t. meaning of off. notify - set up so signals interrupt system calls bprint - use bfmt.
This commit is contained in:
parent
5a82f26e50
commit
669250d159
11 changed files with 124 additions and 63 deletions
6
bin/B
6
bin/B
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
if [ $# -eq 0 ]
|
if [ $# -eq 0 ]
|
||||||
then
|
then
|
||||||
echo 'usage: B cmd...' 2>&1
|
echo 'usage: B file...' 2>&1
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -10,6 +10,10 @@ if [ "x$DISPLAY" = "x" ]
|
||||||
then
|
then
|
||||||
sam="/tmp/.sam.$USER"
|
sam="/tmp/.sam.$USER"
|
||||||
else
|
else
|
||||||
|
if [ "$DISPLAY" = ":0" ]
|
||||||
|
then
|
||||||
|
DISPLAY=:0.0
|
||||||
|
fi
|
||||||
sam="/tmp/.sam.$USER.$DISPLAY"
|
sam="/tmp/.sam.$USER.$DISPLAY"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,8 @@ struct Biobuf
|
||||||
|
|
||||||
int Bbuffered(Biobuf*);
|
int Bbuffered(Biobuf*);
|
||||||
Biobuf* Bfdopen(int, int);
|
Biobuf* Bfdopen(int, int);
|
||||||
|
int Bfmtinit(Fmt*, Biobuf*);
|
||||||
|
int Bfmtflush(Fmt*);
|
||||||
int Bfildes(Biobuf*);
|
int Bfildes(Biobuf*);
|
||||||
int Bflush(Biobuf*);
|
int Bflush(Biobuf*);
|
||||||
int Bgetc(Biobuf*);
|
int Bgetc(Biobuf*);
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,6 @@ threadmain(int argc, char *argv[])
|
||||||
|
|
||||||
draw(screen, screen->r, cols[BACK], nil, ZP);
|
draw(screen, screen->r, cols[BACK], nil, ZP);
|
||||||
geom();
|
geom();
|
||||||
|
|
||||||
loop();
|
loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,7 +117,7 @@ hangupnote(void *a, char *msg)
|
||||||
if(getpid() != mainpid)
|
if(getpid() != mainpid)
|
||||||
noted(NDFLT);
|
noted(NDFLT);
|
||||||
if(strcmp(msg, "hangup") == 0 && rcpid != 0){
|
if(strcmp(msg, "hangup") == 0 && rcpid != 0){
|
||||||
postnote(PNPROC, rcpid, "hangup");
|
postnote(PNGROUP, rcpid, "hangup");
|
||||||
noted(NDFLT);
|
noted(NDFLT);
|
||||||
}
|
}
|
||||||
noted(NDFLT);
|
noted(NDFLT);
|
||||||
|
|
@ -206,9 +205,13 @@ doreshape(void)
|
||||||
scrdraw();
|
scrdraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct winsize ows;
|
||||||
|
|
||||||
void
|
void
|
||||||
geom(void)
|
geom(void)
|
||||||
{
|
{
|
||||||
|
struct winsize ws;
|
||||||
|
Point p;
|
||||||
Rectangle r;
|
Rectangle r;
|
||||||
|
|
||||||
r = screen->r;
|
r = screen->r;
|
||||||
|
|
@ -223,6 +226,18 @@ geom(void)
|
||||||
t.f->maxtab = maxtab*stringwidth(font, "0");
|
t.f->maxtab = maxtab*stringwidth(font, "0");
|
||||||
fill();
|
fill();
|
||||||
updatesel();
|
updatesel();
|
||||||
|
|
||||||
|
p = stringsize(font, "0");
|
||||||
|
if(p.x == 0 || p.y == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ws.ws_row = Dy(r)/p.y;
|
||||||
|
ws.ws_col = Dx(r)/p.x;
|
||||||
|
ws.ws_xpixel = Dx(r);
|
||||||
|
ws.ws_ypixel = Dy(r);
|
||||||
|
if(ws.ws_row != ows.ws_row || ws.ws_col != ows.ws_col)
|
||||||
|
if(ioctl(rcfd[0], TIOCSWINSZ, &ws) < 0)
|
||||||
|
fprint(2, "ioctl: %r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -422,6 +437,7 @@ void
|
||||||
key(Rune r)
|
key(Rune r)
|
||||||
{
|
{
|
||||||
char buf[1];
|
char buf[1];
|
||||||
|
uint sig;
|
||||||
|
|
||||||
if(r == 0)
|
if(r == 0)
|
||||||
return;
|
return;
|
||||||
|
|
@ -472,12 +488,9 @@ key(Rune r)
|
||||||
case 0x7F: /* DEL: send interrupt */
|
case 0x7F: /* DEL: send interrupt */
|
||||||
t.qh = t.q0 = t.q1 = t.nr;
|
t.qh = t.q0 = t.q1 = t.nr;
|
||||||
show(t.q0);
|
show(t.q0);
|
||||||
buf[0] = 0x7f;
|
sig = 2; /* SIGINT */
|
||||||
if(write(rcfd[1], buf, 1) < 0)
|
if(ioctl(rcfd[0], TIOCSIG, &sig) < 0)
|
||||||
exits(0);
|
fprint(2, "sending interrupt: %r\n");
|
||||||
/* get rc to print prompt */
|
|
||||||
// r = '\n';
|
|
||||||
// paste(&r, 1, 1);
|
|
||||||
break;
|
break;
|
||||||
case 0x08: /* ^H: erase character */
|
case 0x08: /* ^H: erase character */
|
||||||
case 0x15: /* ^U: erase line */
|
case 0x15: /* ^U: erase line */
|
||||||
|
|
@ -543,7 +556,10 @@ consready(void)
|
||||||
for(i=t.qh; i<t.nr; i++){
|
for(i=t.qh; i<t.nr; i++){
|
||||||
c = t.r[i];
|
c = t.r[i];
|
||||||
if(c=='\n' || c=='\004')
|
if(c=='\n' || c=='\004')
|
||||||
|
{
|
||||||
|
fprint(2, "ready %d\n", c);
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -561,6 +577,7 @@ consread(void)
|
||||||
|
|
||||||
n = sizeof(buf);
|
n = sizeof(buf);
|
||||||
p = buf;
|
p = buf;
|
||||||
|
c = 0;
|
||||||
while(n >= UTFmax && (t.qh<t.nr || t.nraw > 0)) {
|
while(n >= UTFmax && (t.qh<t.nr || t.nraw > 0)) {
|
||||||
if(t.qh == t.nr){
|
if(t.qh == t.nr){
|
||||||
width = runetochar(p, &t.raw[0]);
|
width = runetochar(p, &t.raw[0]);
|
||||||
|
|
@ -571,18 +588,17 @@ consread(void)
|
||||||
c = *p;
|
c = *p;
|
||||||
p += width;
|
p += width;
|
||||||
n -= width;
|
n -= width;
|
||||||
if(!rawon && (c == '\n' || c == '\004')) {
|
if(!rawon && (c == '\n' || c == '\004'))
|
||||||
if(c == '\004')
|
|
||||||
p--;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
/* take out control-d when not doing a zero length write */
|
||||||
if(n < UTFmax && t.qh<t.nr && t.r[t.qh]=='\004')
|
n = p-buf;
|
||||||
t.qh++;
|
if(n > 1 && c == '\004')
|
||||||
/* put in control-d when doing a zero length write */
|
{
|
||||||
if(p == buf)
|
fprint(2, "remove 004\n");
|
||||||
*p++ = '\004';
|
n--;
|
||||||
if(write(rcfd[1], buf, p-buf) < 0)
|
}
|
||||||
|
if(write(rcfd[1], buf, n) < 0)
|
||||||
exits(0);
|
exits(0);
|
||||||
/* mallocstats(); */
|
/* mallocstats(); */
|
||||||
}
|
}
|
||||||
|
|
@ -1138,19 +1154,32 @@ rcstart(int fd[2])
|
||||||
argv[1] = "-i";
|
argv[1] = "-i";
|
||||||
argv[2] = 0;
|
argv[2] = 0;
|
||||||
|
|
||||||
getpts(fd, slave);
|
/*
|
||||||
|
* fd0 is slave (tty), fd1 is master (pty)
|
||||||
|
*/
|
||||||
|
fd[0] = fd[1] = -1;
|
||||||
|
if(getpts(fd, slave) < 0)
|
||||||
|
fprint(2, "getpts: %r\n");
|
||||||
|
|
||||||
switch(pid = fork()) {
|
switch(pid = fork()) {
|
||||||
case 0:
|
case 0:
|
||||||
putenv("TERM=9term");
|
putenv("TERM=9term");
|
||||||
close(fd[1]);
|
close(fd[1]);
|
||||||
setsid();
|
setsid();
|
||||||
|
// tcsetpgrp(0, pid);
|
||||||
sfd = open(slave, ORDWR);
|
sfd = open(slave, ORDWR);
|
||||||
|
fprint(2, "slave %s\n", slave);
|
||||||
|
if(sfd < 0)
|
||||||
|
fprint(2, "open %s: %r\n", slave);
|
||||||
|
if(ioctl(sfd, TIOCSCTTY, 0) < 0)
|
||||||
|
fprint(2, "ioctl TIOCSCTTY: %r\n");
|
||||||
// ioctl(sfd, I_PUSH, "ptem");
|
// ioctl(sfd, I_PUSH, "ptem");
|
||||||
// ioctl(sfd, I_PUSH, "ldterm");
|
// ioctl(sfd, I_PUSH, "ldterm");
|
||||||
dup(sfd, 0);
|
dup(sfd, 0);
|
||||||
dup(sfd, 1);
|
dup(sfd, 1);
|
||||||
dup(sfd, 2);
|
dup(sfd, 2);
|
||||||
execvp(argv[0], argv);
|
execvp(argv[0], argv);
|
||||||
|
_exits("oops");
|
||||||
break;
|
break;
|
||||||
case -1:
|
case -1:
|
||||||
fatal("proc failed: %r");
|
fatal("proc failed: %r");
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,5 @@ getchildwd(int pid, char *wdir, int bufn)
|
||||||
int
|
int
|
||||||
getpts(int fd[], char *slave)
|
getpts(int fd[], char *slave)
|
||||||
{
|
{
|
||||||
openpty(&fd[1], &fd[0], slave, 0, 0);
|
return openpty(&fd[1], &fd[0], slave, 0, 0);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -392,10 +392,12 @@ void
|
||||||
notifyf(void *unused0, char *s)
|
notifyf(void *unused0, char *s)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0;syssigname[i];i++) if(strncmp(s, syssigname[i], strlen(syssigname[i]))==0){
|
for(i=0;syssigname[i];i++)
|
||||||
|
if(strncmp(s, syssigname[i], strlen(syssigname[i]))==0){
|
||||||
if(strncmp(s, "sys: ", 5)!=0) interrupted=1;
|
if(strncmp(s, "sys: ", 5)!=0) interrupted=1;
|
||||||
goto Out;
|
goto Out;
|
||||||
}
|
}
|
||||||
|
|
||||||
pfmt(err, "rc: note: %s\n", s);
|
pfmt(err, "rc: note: %s\n", s);
|
||||||
noted(NDFLT);
|
noted(NDFLT);
|
||||||
return;
|
return;
|
||||||
|
|
@ -423,7 +425,11 @@ long Write(int fd, char *buf, long cnt)
|
||||||
}
|
}
|
||||||
long Read(int fd, char *buf, long cnt)
|
long Read(int fd, char *buf, long cnt)
|
||||||
{
|
{
|
||||||
return read(fd, buf, cnt);
|
int i;
|
||||||
|
|
||||||
|
i = read(fd, buf, cnt);
|
||||||
|
if(ntrap) dotrap();
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
long Seek(int fd, long cnt, long whence)
|
long Seek(int fd, long cnt, long whence)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,36 @@
|
||||||
|
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
#include <sys/disklabel.h>
|
#include <sys/disklabel.h>
|
||||||
|
static int diskdev[] = {
|
||||||
|
151, /* aacd */
|
||||||
|
116, /* ad */
|
||||||
|
157, /* ar */
|
||||||
|
118, /* afd */
|
||||||
|
133, /* amrd */
|
||||||
|
13, /* da */
|
||||||
|
102, /* fla */
|
||||||
|
109, /* idad */
|
||||||
|
95, /* md */
|
||||||
|
131, /* mlxd */
|
||||||
|
168, /* pst */
|
||||||
|
147, /* twed */
|
||||||
|
43, /* vn */
|
||||||
|
3, /* wd */
|
||||||
|
87, /* wfd */
|
||||||
|
};
|
||||||
|
static int
|
||||||
|
isdisk(struct stat *st)
|
||||||
|
{
|
||||||
|
int i, dev;
|
||||||
|
|
||||||
|
if(!S_ISCHR(st->st_mode))
|
||||||
|
return 0;
|
||||||
|
dev = major(st->st_rdev);
|
||||||
|
for(i=0; i<nelem(diskdev); i++)
|
||||||
|
if(diskdev[i] == dev)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#define _HAVEDISKLABEL
|
#define _HAVEDISKLABEL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -108,7 +138,7 @@ _p9dir(struct stat *st, char *name, Dir *d, char **str, char *estr)
|
||||||
|
|
||||||
/* fetch real size for disks */
|
/* fetch real size for disks */
|
||||||
#ifdef _HAVEDISKLABEL
|
#ifdef _HAVEDISKLABEL
|
||||||
if(S_ISCHR(st->st_mode)){
|
if(isdisk(st)){
|
||||||
int fd, n;
|
int fd, n;
|
||||||
struct disklabel lab;
|
struct disklabel lab;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ extern int _p9dir(struct stat*, char*, Dir*, char**, char*);
|
||||||
static int
|
static int
|
||||||
mygetdents(int fd, struct dirent *buf, int n)
|
mygetdents(int fd, struct dirent *buf, int n)
|
||||||
{
|
{
|
||||||
ssize_t nn;
|
|
||||||
off_t off;
|
off_t off;
|
||||||
|
|
||||||
off = p9seek(fd, 0, 1);
|
off = p9seek(fd, 0, 1);
|
||||||
|
|
@ -23,14 +22,8 @@ mygetdents(int fd, struct dirent *buf, int n)
|
||||||
static int
|
static int
|
||||||
mygetdents(int fd, struct dirent *buf, int n)
|
mygetdents(int fd, struct dirent *buf, int n)
|
||||||
{
|
{
|
||||||
ssize_t nn;
|
|
||||||
long off;
|
long off;
|
||||||
|
return getdirentries(fd, (void*)buf, n, &off);
|
||||||
off = p9seek(fd, 0, 1);
|
|
||||||
nn = getdirentries(fd, (void*)buf, n, &off);
|
|
||||||
if(nn > 0)
|
|
||||||
p9seek(fd, off, 0);
|
|
||||||
return nn;
|
|
||||||
}
|
}
|
||||||
#elif defined(__sun__)
|
#elif defined(__sun__)
|
||||||
static int
|
static int
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ static int sigs[] = {
|
||||||
SIGQUIT,
|
SIGQUIT,
|
||||||
SIGILL,
|
SIGILL,
|
||||||
SIGTRAP,
|
SIGTRAP,
|
||||||
SIGABRT,
|
/* SIGABRT, */
|
||||||
#ifdef SIGEMT
|
#ifdef SIGEMT
|
||||||
SIGEMT,
|
SIGEMT,
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -63,16 +63,17 @@ int
|
||||||
notify(void (*f)(void*, char*))
|
notify(void (*f)(void*, char*))
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
void (*sf)(int);
|
struct sigaction sa;
|
||||||
|
|
||||||
|
memset(&sa, 0, sizeof sa);
|
||||||
if(f == nil)
|
if(f == nil)
|
||||||
sf = SIG_DFL;
|
sa.sa_handler = SIG_DFL;
|
||||||
else{
|
else{
|
||||||
notifyf = f;
|
notifyf = f;
|
||||||
sf = notifysigf;
|
sa.sa_handler = notifysigf;
|
||||||
}
|
}
|
||||||
for(i=0; i<nelem(sigs); i++)
|
for(i=0; i<nelem(sigs); i++)
|
||||||
signal(sigs[i], sf);
|
sigaction(sigs[i], &sa, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,12 @@ main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
Biobuf b, *bp;
|
Biobuf b, *bp;
|
||||||
|
Fmt fmt;
|
||||||
|
|
||||||
Binit(&bout, 1, O_WRONLY);
|
Binit(&bout, 1, O_WRONLY);
|
||||||
|
Bfmtinit(&fmt, &bout);
|
||||||
|
fmtprint(&fmt, "hello, world\n");
|
||||||
|
Bfmtflush(&fmt);
|
||||||
|
|
||||||
if(argc == 1){
|
if(argc == 1){
|
||||||
Binit(&b, 0, O_RDONLY);
|
Binit(&b, 0, O_RDONLY);
|
||||||
|
|
|
||||||
|
|
@ -4,25 +4,17 @@
|
||||||
int
|
int
|
||||||
Bprint(Biobuf *bp, char *fmt, ...)
|
Bprint(Biobuf *bp, char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list args;
|
||||||
char *ip, *ep, *out;
|
Fmt f;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
ep = (char*)bp->ebuf;
|
if(Bfmtinit(&f, bp) < 0)
|
||||||
ip = ep + bp->ocount;
|
return -1;
|
||||||
va_start(ap, fmt);
|
va_start(args, fmt);
|
||||||
out = vseprint(ip, ep, fmt, ap);
|
f.args = args;
|
||||||
va_end(ap);
|
n = dofmt(&f, fmt);
|
||||||
if(out == 0 || out >= ep-5) {
|
va_end(args);
|
||||||
Bflush(bp);
|
if(n > 0 && Bfmtflush(&f) < 0)
|
||||||
ip = ep + bp->ocount;
|
return -1;
|
||||||
va_start(ap, fmt);
|
|
||||||
out = vseprint(ip, ep, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
if(out >= ep-5)
|
|
||||||
return Beof;
|
|
||||||
}
|
|
||||||
n = out-ip;
|
|
||||||
bp->ocount += n;
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ OFILES=\
|
||||||
bbuffered.$O\
|
bbuffered.$O\
|
||||||
bfildes.$O\
|
bfildes.$O\
|
||||||
bflush.$O\
|
bflush.$O\
|
||||||
|
bfmt.$O\
|
||||||
bgetc.$O\
|
bgetc.$O\
|
||||||
bgetd.$O\
|
bgetd.$O\
|
||||||
binit.$O\
|
binit.$O\
|
||||||
|
|
@ -26,6 +27,6 @@ HFILES=\
|
||||||
|
|
||||||
<$PLAN9/src/mksyslib
|
<$PLAN9/src/mksyslib
|
||||||
|
|
||||||
bcat: bcat.$O $LIB
|
bcat: bcat.$O $PLAN9/lib/$LIB
|
||||||
$CC -o bcat bcat.$O -L$PLAN9/lib -lbio -lfmt -lutf
|
$LD -o bcat bcat.$O -lbio -lfmt -lutf
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue