add -W to specify window size.

various other little fixes.
This commit is contained in:
rsc 2004-04-29 17:13:24 +00:00
parent 3d72637f9b
commit be36ff6885
36 changed files with 332 additions and 304 deletions

3
bin/9c
View file

@ -12,7 +12,10 @@ usegcc()
-Wno-switch \
-Wno-comment \
-Wno-sign-compare \
-fno-omit-frame-pointer \
"
# want to put -fno-optimize-sibling-calls here but
# that option only works with gcc3+ it seems
cflags="$ngflags -ggdb"
}

View file

@ -20,7 +20,7 @@ if(! ~ $tag(1) */){
echo -n , | wr addr
ls -pF $tag(1) | sed 's/\*$//' |
9grep -v '^\.|\.o$|^o\.' |
9grep -v '^''?\.|\.o$|^''?o\.' |
mc | wr data
echo -n '#0' | wr addr
echo -n 'dot=addr' | wr ctl

View file

@ -526,6 +526,8 @@ char *getsnarf(void);
void putsnarf(char*);
void drawtopwindow(void);
void drawresizewindow(Rectangle);
extern char *winsize;
/*
* Port magic.

View file

@ -379,7 +379,7 @@ extern int netcrypt(void*, void*);
extern void p9notejmp(void*, p9jmp_buf, int);
extern void perror(const char*);
extern int postnote(int, int, char *);
extern double pow10(int);
extern double p9pow10(int);
/* extern int putenv(char*, char*); <stdlib.h. */
/* extern void qsort(void*, long, long, int (*)(void*, void*)); <stdlib.h> */
/* extern int p9setjmp(p9jmp_buf); */
@ -417,6 +417,7 @@ extern void needstack(int);
#define jmp_buf p9jmp_buf
#define syslog p9syslog
#define time p9time
#define pow10 p9pow10
#endif
/*
@ -556,6 +557,7 @@ extern void freenetconninfo(NetConnInfo*);
#define OTRUNC 16 /* or'ed in (except for exec), truncate file first */
#define OCEXEC 32 /* or'ed in, close on exec */
#define ORCLOSE 64 /* or'ed in, remove on close */
#define ODIRECT 128 /* or'ed in, bypass the cache */
#define OEXCL 0x1000 /* or'ed in, exclusive use (create only) */
#define AEXIST 0 /* accessible: exists */

View file

@ -115,7 +115,7 @@ int threadrecvfd(int);
long threadwrite(int, const void*, long);
int threadsendfd(int, int);
int threadsetgrp(int); /* set thread group, return old */
void threadsetname(char *name);
void threadsetname(char *fmt, ...);
void threadsleep(int);
Channel* threadwaitchan(void);
int tprivalloc(void);

View file

@ -186,7 +186,7 @@ Cursor whitearrow = {
void
usage(void)
{
fprint(2, "usage: 9term [-ars] [cmd ...]\n");
fprint(2, "usage: 9term [-ars] [-W winsize] [cmd ...]\n");
threadexitsall("usage");
}
@ -215,6 +215,9 @@ threadmain(int argc, char *argv[])
case 'w': /* started from "rio" window manager */
use9wm = 1;
break;
case 'W':
winsize = EARGF(usage());
break;
}ARGEND
if(font)

View file

@ -463,7 +463,7 @@ ttt=ttt->sub;
name, nameof(tt, 0));
Bprint(b, "\tindent_%s(addr+%lud, indent+\" \");\n",
nameof(tt, 1), t->val[j]);
Bprint(b, "\tprint(indent, \"\t}\\n\");\n");
Bprint(b, "\tprint(indent, \"}\\n\");\n");
break;
}
}

View file

@ -96,9 +96,14 @@ threadmain(int argc, char *argv[])
if(loadfile == nil)
goto Usage;
break;
case 'W':
winsize = ARGF();
if(winsize == nil)
goto Usage;
break;
default:
Usage:
fprint(2, "usage: acme -a -c ncol -f fontname -F fixedwidthfontname -l loadfile\n");
fprint(2, "usage: acme -a -c ncol -f fontname -F fixedwidthfontname -l loadfile -W winsize\n");
exits("usage");
}ARGEND

View file

@ -109,21 +109,20 @@ xnet(int first)
totinb = 0;
totoub = 0;
for(i=0; i<nline; i++){
if((q = strchr(line[i], ':')) != nil)
*q = ' ';
tokens(i);
if(ntok < 8+8)
continue;
if(strncmp(tok[0], "eth", 3) != 0)
continue;
q = strchr(tok[0], ':');
*q++ = 0;
tok[0] = q;
inb = atoll(tok[0]);
oub = atoll(tok[8]);
in = atoll(tok[1]);
ou = atoll(tok[9]);
inb = atoll(tok[1]);
oub = atoll(tok[9]);
in = atoll(tok[2]);
ou = atoll(tok[10]);
b = inb+oub;
p = in+ou;
e = atoll(tok[2])+atoll(tok[10]);
e = atoll(tok[3])+atoll(tok[11]);
totb += b;
totp += p;
tote += e;

View file

@ -1956,7 +1956,7 @@ void usage(void)
int i;
fprintf(stderr,"Usage %s [options] [infile]\n", argv0);
fprintf(stderr,
"option ::= -l logfile | -m\n"
"option ::= -W winsize | -l logfile | -m\n"
"\n"
"Read a polygonal line graph in an ASCII format (one x y pair per line, delimited\n"
"by spaces with a label after each polyline), and view it interactively. Use\n"
@ -1981,6 +1981,9 @@ void main(int argc, char *argv[])
break;
case 'l': logfil = fopen(ARGF(),"w");
break;
case 'W':
winsize = EARGF(usage());
break;
default: usage();
} ARGEND

View file

@ -6,7 +6,7 @@
void
usage(void)
{
fprint(2, "usage: img [file]\n");
fprint(2, "usage: img [-W winsize] [file]\n");
exits("usage");
}
@ -29,6 +29,9 @@ main(int argc, char **argv)
Event e;
ARGBEGIN{
case 'W':
winsize = EARGF(usage());
break;
default:
usage();
}ARGEND
@ -48,6 +51,8 @@ main(int argc, char **argv)
if((image=readimage(display, fd, 0)) == nil)
sysfatal("readimage: %r");
drawresizewindow(Rect(0,0,Dx(image->r),Dy(image->r)));
einit(Emouse|Ekeyboard);
eresized(0);
for(;;){

View file

@ -332,7 +332,7 @@ update1(Graph *g, long v, ulong vmax)
void
usage(void)
{
fprint(2, "usage: stats [-O] [-S scale] [-LY] [-%s] [machine...]\n", argchars);
fprint(2, "usage: stats [-O] [-S scale] [-LY] [-W winsize] [-%s] [machine...]\n", argchars);
exits("usage");
}
@ -710,6 +710,9 @@ threadmain(int argc, char *argv[])
case 'O':
oldsystem = 1;
break;
case 'W':
winsize = EARGF(usage());
break;
default:
if(nargs>=sizeof args || strchr(argchars, ARGC())==nil)
usage();

View file

@ -171,6 +171,13 @@ void buttons(int);
void drawall(void);
void tclose1(Thing*);
void
usage(void)
{
fprint(2, "usage: tweak [-W winsize] file...\n");
exits("usage");
}
void
main(int argc, char *argv[])
{
@ -178,6 +185,13 @@ main(int argc, char *argv[])
Event e;
Thing *t;
ARGBEGIN{
case 'W':
winsize = EARGF(usage());
break;
default:
usage();
}ARGEND
mag = Mag;
if(initdraw(error, 0, "tweak") < 0){
fprint(2, "tweak: initdraw failed: %r\n");
@ -191,7 +205,7 @@ main(int argc, char *argv[])
}
einit(Emouse|Ekeyboard);
eresized(0);
i = 1;
i = 0;
setjmp(err);
for(; i<argc; i++){
file = argv[i];

View file

@ -43,6 +43,13 @@ eresized(int new)
flushimage(display, 1);
}
void
usage(void)
{
fprint(2, "usage: bmp -39cdektv -W winsize [file.bmp ...]\n");
exits("usage");
}
void
main(int argc, char *argv[])
{
@ -50,6 +57,9 @@ main(int argc, char *argv[])
char *err;
ARGBEGIN{
case 'W':
winsize = EARGF(usage());
break;
case '3': /* produce encoded, compressed, three-color bitmap file; no display by default */
threeflag++;
/* fall through */
@ -89,8 +99,7 @@ main(int argc, char *argv[])
outchan = CMAP8;
break;
default:
fprint(2, "usage: bmp -39cdektv [file.bmp ...]\n");
exits("usage");
usage();
}ARGEND;
err = nil;

View file

@ -56,6 +56,14 @@ eresized(int new)
flushimage(display, 1);
}
void
usage(void)
{
fprint(2, "usage: gif -39cdektv -W winsize [file.gif ...]\n");
exits("usage");
}
void
main(int argc, char *argv[])
{
@ -63,6 +71,9 @@ main(int argc, char *argv[])
char *err;
ARGBEGIN{
case 'W':
winsize = EARGF(usage());
break;
case '3': /* produce encoded, compressed, three-color bitmap file; no display by default */
threeflag++;
/* fall through */
@ -102,8 +113,7 @@ main(int argc, char *argv[])
outchan = CMAP8;
break;
default:
fprint(2, "usage: gif -39cdektv [file.gif ...]\n");
exits("usage");
usage();
}ARGEND;
err = nil;

View file

@ -258,7 +258,7 @@ Bgeticon(Biobuf *b, Icon *icon)
void
usage(void)
{
fprint(2, "usage: %s [file]\n", argv0);
fprint(2, "usage: %s -W winsize [file]\n", argv0);
exits("usage");
}
@ -444,6 +444,9 @@ main(int argc, char **argv)
Event e;
ARGBEGIN{
case 'W':
winsize = EARGF(usage());
break;
case 'd':
debug = 1;
break;

View file

@ -45,6 +45,13 @@ eresized(int new)
flushimage(display, 1);
}
void
usage(void)
{
fprint(2, "usage: jpg -39cdefFkJrtv -W winsize [file.jpg ...]\n");
exits("usage");
}
void
main(int argc, char *argv[])
{
@ -54,6 +61,9 @@ main(int argc, char *argv[])
yflag = 0;
ARGBEGIN{
case 'W':
winsize = EARGF(usage());
break;
case 'c': /* produce encoded, compressed, bitmap file; no display by default */
cflag++;
dflag++;
@ -110,8 +120,7 @@ main(int argc, char *argv[])
outchan = CMAP8;
break;
default:
fprint(2, "usage: jpg -39cdefFkJrtv [file.jpg ...]\n");
exits("usage");
usage();
}ARGEND;
if(yflag==0 && dflag==0 && colorspace==CYCbCr){ /* see if we should convert right to RGB */

View file

@ -43,6 +43,13 @@ eresized(int new)
flushimage(display, 1);
}
void
usage(void)
{
fprint(2, "usage: png -39cdekrtv -W winsize [file.png ...]\n");
exits("usage");
}
void
main(int argc, char *argv[])
{
@ -51,6 +58,9 @@ main(int argc, char *argv[])
char buf[12+1];
ARGBEGIN{
case 'W':
winsize = EARGF(usage());
break;
case 'c': /* produce encoded, compressed, bitmap file; no display by default */
cflag++;
dflag++;
@ -96,8 +106,7 @@ main(int argc, char *argv[])
outchan = CMAP8;
break;
default:
fprint(2, "usage: png -39cdekrtv [file.png ...]\n");
exits("usage");
usage();
}ARGEND;
if(dflag==0 && colorspace==CYCbCr){ /* see if we should convert right to RGB */

View file

@ -41,6 +41,13 @@ eresized(int new)
flushimage(display, 1);
}
void
usage(void)
{
fprint(2, "usage: ppm -39cdektv -W winsize [file.ppm ...]\n");
exits("usage");
}
void
main(int argc, char *argv[])
{
@ -48,6 +55,9 @@ main(int argc, char *argv[])
char *err;
ARGBEGIN{
case 'W':
winsize = EARGF(usage());
break;
case '3': /* produce encoded, compressed, three-color bitmap file; no display by default */
threeflag++;
/* fall through */
@ -87,8 +97,7 @@ main(int argc, char *argv[])
outchan = CMAP8;
break;
default:
fprint(2, "usage: ppm -39cdektv [file.ppm ...]\n");
exits("usage");
usage();
}ARGEND;
err = nil;

View file

@ -43,6 +43,13 @@ eresized(int new)
flushimage(display, 1);
}
void
usage(void)
{
fprint(2, "usage: yuv -39cdektv -W winsize [file.yuv ...]\n");
exits("usage");
}
void
main(int argc, char *argv[])
{
@ -50,6 +57,9 @@ main(int argc, char *argv[])
char *err;
ARGBEGIN{
case 'W':
winsize = EARGF(usage());
break;
case '3': /* produce encoded, compressed, three-color bitmap file; no display by default */
threeflag++;
/* fall through */
@ -89,8 +99,7 @@ main(int argc, char *argv[])
outchan = CMAP8;
break;
default:
fprint(2, "usage: yuv -39cdektv [file.yuv ...]\n");
exits("usage");
usage();
}ARGEND;
err = nil;

View file

@ -1,245 +0,0 @@
/*
* mc - columnate
*
* mc[-][-LINEWIDTH][-t][file...]
* - causes break on colon
* -LINEWIDTH sets width of line in which to columnate(default 80)
* -t suppresses expanding multiple blanks into tabs
*
*/
#include <u.h>
#include <sys/ioctl.h>
#include <sys/termios.h>
#include <libc.h>
#include <draw.h>
#include <bio.h>
#define WIDTH 80
#define TAB 4
#define WORD_ALLOC_QUANTA 1024
#define ALLOC_QUANTA 4096
int linewidth=WIDTH;
int colonflag=0;
int tabflag=0; /* -t flag turned off forever */
Rune *cbuf, *cbufp;
Rune **word;
int maxwidth=0;
int nalloc=ALLOC_QUANTA;
int nwalloc=WORD_ALLOC_QUANTA;
int nchars=0;
int nwords=0;
Biobuf bin;
Biobuf bout;
void getwidth(void), readbuf(int), error(char *);
void scanwords(void), columnate(void), morechars(void);
void
main(int argc, char *argv[])
{
int i;
int lineset;
int ifd;
lineset = 0;
Binit(&bout, 1, OWRITE);
while(argc > 1 && argv[1][0] == '-'){
--argc; argv++;
switch(argv[0][1]){
case '\0':
colonflag = 1;
break;
case 't':
tabflag = 0;
break;
default:
linewidth = atoi(&argv[0][1]);
if(linewidth <= 1)
linewidth = WIDTH;
lineset = 1;
break;
}
}
if(lineset == 0)
getwidth();
cbuf = cbufp = malloc(ALLOC_QUANTA*(sizeof *cbuf));
word = malloc(WORD_ALLOC_QUANTA*(sizeof *word));
if(word == 0 || cbuf == 0)
error("out of memory");
if(argc == 1)
readbuf(0);
else{
for(i = 1; i < argc; i++){
if((ifd = open(*++argv, OREAD)) == -1)
fprint(2, "mc: can't open %s (%r)\n", *argv);
else{
readbuf(ifd);
Bflush(&bin);
close(ifd);
}
}
}
columnate();
exits(0);
}
void
error(char *s)
{
fprint(2, "mc: %s\n", s);
exits(s);
}
void
readbuf(int fd)
{
int lastwascolon = 0;
long c;
int linesiz = 0;
Binit(&bin, fd, OREAD);
do{
if(nchars++ >= nalloc)
morechars();
*cbufp++ = c = Bgetrune(&bin);
linesiz++;
if(c == '\t') {
cbufp[-1] = L' ';
while(linesiz%TAB != 0) {
if(nchars++ >= nalloc)
morechars();
*cbufp++ = L' ';
linesiz++;
}
}
if(colonflag && c == ':')
lastwascolon++;
else if(lastwascolon){
if(c == '\n'){
--nchars; /* skip newline */
*cbufp = L'\0';
while(nchars > 0 && cbuf[--nchars] != '\n')
;
if(nchars)
nchars++;
columnate();
if (nchars)
Bputc(&bout, '\n');
Bprint(&bout, "%S", cbuf+nchars);
nchars = 0;
cbufp = cbuf;
}
lastwascolon = 0;
}
if(c == '\n')
linesiz = 0;
}while(c >= 0);
}
void
scanwords(void)
{
Rune *p, *q;
int i;
nwords=0;
maxwidth=0;
for(p = q = cbuf, i = 0; i < nchars; i++){
if(*p++ == L'\n'){
if(nwords >= nwalloc){
nwalloc += WORD_ALLOC_QUANTA;
if((word = realloc(word, nwalloc*sizeof(*word)))==0)
error("out of memory");
}
word[nwords++] = q;
p[-1] = L'\0';
if(p-q > maxwidth)
maxwidth = p-q;
q = p;
}
}
}
void
columnate(void)
{
int i, j;
int words_per_line;
int nlines;
int col;
int endcol;
scanwords();
if(nwords==0)
return;
words_per_line = linewidth/maxwidth;
if(words_per_line <= 0)
words_per_line = 1;
nlines=(nwords+words_per_line-1)/words_per_line;
for(i = 0; i < nlines; i++){
col = endcol = 0;
for(j = i; j < nwords; j += nlines){
endcol += maxwidth;
Bprint(&bout, "%S", word[j]);
col += word[j+1]-word[j]-1;
if(j+nlines < nwords){
if(tabflag) {
int tabcol = (col|(TAB-1))+1;
while(tabcol <= endcol){
Bputc(&bout, '\t');
col = tabcol;
tabcol += TAB;
}
}
while(col < endcol){
Bputc(&bout, ' ');
col++;
}
}
}
Bputc(&bout, '\n');
}
}
void
morechars(void)
{
nalloc += ALLOC_QUANTA;
if((cbuf = realloc(cbuf, nalloc*sizeof(*cbuf))) == 0)
error("out of memory");
cbufp = cbuf+nchars-1;
}
/*
* These routines discover the width of the display.
* It takes some work. If we do the easy calls to the
* draw library, the screen flashes due to repainting
* when mc exits.
*/
int
windowrect(struct winsize *ws)
{
int tty;
if((tty = open("/dev/tty", OWRITE)) < 0)
tty = 1;
if(ioctl(tty, TIOCGWINSZ, ws) < 0){
if(tty != 1)
close(tty);
return -1;
}
if(tty != 1)
close(tty);
return 0;
}
void
getwidth(void)
{
struct winsize ws;
if(windowrect(&ws) < 0)
return;
linewidth = ws.ws_col;
}

View file

@ -149,6 +149,7 @@ main(int arc, char *arv[]){
fd = dup(0, -1); /* because openpl will close 0! */
dflag=0;
oflag="";
winsize = "512x512";
for(i=1;i!=arc;i++) if(arv[i][0]=='-') switch(arv[i][1]){
case 'd': dflag=1; break;
case 'o': oflag=arv[i]+2; break;
@ -168,7 +169,6 @@ main(int arc, char *arv[]){
case 'D': break;
case 'd': break;
case 'o': break;
case 'W': break;
case 's': break;
case 'e': erase(); break;
case 'C': closepl(); break;
@ -177,6 +177,7 @@ main(int arc, char *arv[]){
case 'f': cfill(ap+1); break;
case 'p': pen(ap+1); break;
case 'g': grade(atof(ap+1)); break;
case 'W': winsize = ap+1; break;
}
}
else if ((bp = Bopen(arv[1], OREAD)) == 0) {

View file

@ -29,6 +29,8 @@ File *lastfile;
Disk *disk;
long seq;
char *winsize;
Rune baddir[] = { '<', 'b', 'a', 'd', 'd', 'i', 'r', '>', '\n'};
void usage(void);
@ -82,6 +84,10 @@ main(int argc, char *argv[])
argc--;
break;
case 'W':
--argc, argv++;
break;
default:
dprint("sam: unknown flag %c\n", argv[0][1]);
exits("usage");
@ -101,7 +107,7 @@ main(int argc, char *argv[])
if(home == 0)
home = "/";
if(!dflag)
startup(machine, Rflag, arg, ap);
startup(machine, Rflag, arg, argv);
notify(notifyf);
getcurwd();
if(argc>1){

View file

@ -28,10 +28,15 @@ static char *exname;
void
getscreen(int argc, char **argv)
{
int i;
char *t;
USED(argc);
USED(argv);
/* not exactly right */
for(i=0; i<argc-1; i++){
if(strcmp(argv[i], "-W") == 0)
winsize = argv[i+1];
}
if(initdraw(panic1, nil, "sam") < 0){
fprint(2, "samterm: initdraw: %r\n");
threadexitsall("init");

View file

@ -87,10 +87,12 @@ threadmain(int argc, char *argv[])
Bprint(bout, "prev: %V\n", root.prev);
}
fprint(2, "read...\n");
n = vtread(z, root.score, VtDirType, buf, bsize);
if(n < 0)
sysfatal("could not read root dir");
fprint(2, "...\n");
/* fake up top level source */
memset(&source, 0, sizeof(source));
memmove(source.score, root.score, VtScoreSize);

View file

@ -1,3 +1,4 @@
#define _GNU_SOURCE /* for Linux O_DIRECT */
#include <u.h>
#define NOPLAN9DEFINES
#include <libc.h>
@ -25,6 +26,10 @@ p9create(char *path, int mode, ulong perm)
}else{
umode = (mode&3)|O_CREAT|O_TRUNC;
mode &= ~(3|OTRUNC);
if(mode&ODIRECT){
umode |= O_DIRECT;
mode &= ~ODIRECT;
}
if(mode&OEXCL){
umode |= O_EXCL;
mode &= ~OEXCL;

View file

@ -167,3 +167,4 @@ HFILES=\
%.$O: utf/%.c
$CC $CFLAGS utf/$stem.c
rendez-Linux.$O: rendez-futex.c rendez-signal.c

View file

@ -1,3 +1,4 @@
#define _GNU_SOURCE /* for Linux O_DIRECT */
#include <u.h>
#define NOPLAN9DEFINES
#include <libc.h>
@ -16,6 +17,10 @@ p9open(char *name, int mode)
umode |= O_TRUNC;
mode ^= OTRUNC;
}
if(mode&ODIRECT){
umode |= O_DIRECT;
mode ^= ODIRECT;
}
if(mode){
werrstr("mode not supported");
return -1;

View file

@ -34,8 +34,10 @@ getqlp(void)
for(p = op+1; ; p++){
if(p == &ql.x[nelem(ql.x)])
p = ql.x;
if(p == op)
if(p == op){
fprint(2, "qlock: out of qlp\n");
abort();
}
if(_tas(&(p->inuse)) == 0){
ql.p = p;
p->next = nil;
@ -233,8 +235,10 @@ wunlock(RWLock *q)
QLp *p;
lock(&q->lock);
if(q->writer == 0)
if(q->writer == 0){
fprint(2, "wunlock: not holding lock\n");
abort();
}
p = q->head;
if(p == nil){
q->writer = 0;
@ -252,8 +256,10 @@ wunlock(RWLock *q)
return;
}
if(p->state != QueuingR)
if(p->state != QueuingR){
fprint(2, "wunlock: bad state\n");
abort();
}
/* wake waiting readers */
while(q->head != nil && q->head->state == QueuingR){
@ -274,12 +280,16 @@ rsleep(Rendez *r)
{
QLp *t, *me;
if(!r->l)
if(!r->l){
fprint(2, "rsleep: no lock\n");
abort();
}
lock(&r->l->lock);
/* we should hold the qlock */
if(!r->l->locked)
if(!r->l->locked){
fprint(2, "rsleep: not locked\n");
abort();
}
/* add ourselves to the wait list */
me = getqlp();
@ -309,8 +319,10 @@ rsleep(Rendez *r)
while((*_rendezvousp)((ulong)me, 0x23456) == ~0)
;
me->inuse = 0;
if(!r->l->locked)
if(!r->l->locked){
fprint(2, "rsleep: not locked after wakeup\n");
abort();
}
}
int
@ -323,11 +335,15 @@ rwakeup(Rendez *r)
* put on front so guys that have been waiting will not get starved
*/
if(!r->l)
if(!r->l){
fprint(2, "rwakeup: no lock\n");
abort();
}
lock(&r->l->lock);
if(!r->l->locked)
if(!r->l->locked){
fprint(2, "rwakeup: not locked\n");
abort();
}
t = r->head;
if(t == nil){

View file

@ -11,6 +11,9 @@
#include <cursor.h>
#include "x11-memdraw.h"
char *winsize;
static int parsewinsize(char*, Rectangle*, int*);
static Memimage *xattach(char*);
static void plan9cmap(void);
static int setupcmap(XWindow);
@ -180,7 +183,7 @@ static Memimage*
xattach(char *label)
{
char *argv[2], *disp;
int i, n, xrootid;
int i, n, xrootid, havemin;
Rectangle r;
XClassHint classhint;
XDrawable pmid;
@ -318,8 +321,14 @@ xattach(char *label)
* This is arbitrary. In theory we should read the
* command line and allow the traditional X options.
*/
if(winsize){
if(parsewinsize(winsize, &r, &havemin) < 0)
sysfatal("%r");
}else{
r = Rect(0, 0, WidthOfScreen(xscreen)*3/4,
HeightOfScreen(xscreen)*3/4);
havemin = 0;
}
memset(&attr, 0, sizeof attr);
attr.colormap = _x.cmap;
@ -353,7 +362,14 @@ xattach(char *label)
name.nitems = strlen((char*)name.value);
memset(&normalhint, 0, sizeof normalhint);
normalhint.flags = USSize|PMaxSize;
normalhint.flags = PSize|PMaxSize;
if(winsize){
normalhint.flags &= ~PSize;
normalhint.flags |= USSize;
normalhint.width = Dx(r);
normalhint.height = Dy(r);
}
normalhint.max_width = WidthOfScreen(xscreen);
normalhint.max_height = HeightOfScreen(xscreen);
@ -382,6 +398,15 @@ xattach(char *label)
);
XFlush(_x.display);
if(havemin){
XWindowChanges ch;
memset(&ch, 0, sizeof ch);
ch.x = r.min.x;
ch.y = r.min.y;
XConfigureWindow(_x.display, _x.drawable, CWX|CWY, &ch);
fprint(2, "havemin %d %d\n", r.min.x, r.min.y);
}
/*
* Look up clipboard atom.
*/
@ -783,3 +808,73 @@ xreplacescreenimage(void)
return 1;
}
static int
parsewinsize(char *s, Rectangle *r, int *havemin)
{
char c, *os;
int i, j, k, l;
os = s;
*havemin = 0;
*r = Rect(0,0,0,0);
if(!isdigit(*s))
goto oops;
i = strtol(s, &s, 0);
if(*s == 'x'){
s++;
if(!isdigit(*s))
goto oops;
j = strtol(s, &s, 0);
r->max.x = i;
r->max.y = j;
if(*s == 0)
return 0;
if(*s != '@')
goto oops;
s++;
if(!isdigit(*s))
goto oops;
i = strtol(s, &s, 0);
if(*s != ',' && *s != ' ')
goto oops;
s++;
if(!isdigit(*s))
goto oops;
j = strtol(s, &s, 0);
if(*s != 0)
goto oops;
*r = rectaddpt(*r, Pt(i,j));
*havemin = 1;
return 0;
}
c = *s;
if(c != ' ' && c != ',')
goto oops;
s++;
if(!isdigit(*s))
goto oops;
j = strtol(s, &s, 0);
if(*s != c)
goto oops;
s++;
if(!isdigit(*s))
goto oops;
k = strtol(s, &s, 0);
if(*s != c)
goto oops;
s++;
if(!isdigit(*s))
goto oops;
l = strtol(s, &s, 0);
if(*s != 0)
goto oops;
*r = Rect(i,j,k,l);
*havemin = 1;
return 0;
oops:
werrstr("bad syntax in window size '%s'", os);
return -1;
}

View file

@ -15,3 +15,18 @@ drawtopwindow(void)
XFlush(_x.display);
}
void
drawresizewindow(Rectangle r)
{
// XConfigureRequestEvent e;
XWindowChanges e;
int value_mask;
memset(&e, 0, sizeof e);
value_mask = CWWidth|CWHeight;
// e.x = r.min.x;
// e.y = r.min.y;
e.width = Dx(r);
e.height = Dy(r);
XConfigureWindow(_x.display, _x.drawable, value_mask, &e);
}

View file

@ -156,6 +156,7 @@ dwarfget128(DwarfBuf *b)
{n1++;
return c;
}
c &= ~0x80;
d = *b->p++;
c |= (d&0x7F)<<7;
if(!(d&0x80))

View file

@ -155,6 +155,7 @@ _newproc(void (*f)(void *arg), void *arg, uint stacksize, char *name, int grp, i
else
*_threadpq.tail = p;
_threadpq.tail = &p->next;
if(_threadprocs == 1)
_threadmultiproc();
_threadprocs++;

View file

@ -52,20 +52,20 @@ threadgetgrp(void)
}
void
threadsetname(char *name)
threadsetname(char *fmt, ...)
{
/*
int fd, n;
char buf[128], *s;
*/
Proc *p;
Thread *t;
va_list arg;
p = _threadgetproc();
t = p->thread;
if (t->cmdname)
free(t->cmdname);
t->cmdname = strdup(name);
va_start(arg, fmt);
t->cmdname = vsmprint(fmt, arg);
va_end(fmt);
/* Plan 9 only
if(p->nthreads == 1){
snprint(buf, sizeof buf, "#p/%d/args", getpid());

View file

@ -52,7 +52,7 @@ threadmain(int argc, char **argv)
buffer = atoi(ARGF());
break;
case 'p':
fn=proccreate;
fn = proccreate;
break;
}ARGEND

View file

@ -13,6 +13,8 @@ typedef struct VtSconn VtSconn;
struct VtSconn
{
int ctl;
int ref;
QLock lk;
char dir[NETPATHLEN];
VtSrv *srv;
VtConn *c;
@ -29,6 +31,27 @@ struct VtSrv
static void listenproc(void*);
static void connproc(void*);
static void
scincref(VtSconn *sc)
{
qlock(&sc->lk);
sc->ref++;
qunlock(&sc->lk);
}
static void
scdecref(VtSconn *sc)
{
qlock(&sc->lk);
if(--sc->ref > 0){
qunlock(&sc->lk);
return;
}
if(sc->c)
vtfreeconn(sc->c);
vtfree(sc);
}
VtSrv*
vtlisten(char *addr)
{
@ -55,14 +78,13 @@ listenproc(void *v)
srv = v;
for(;;){
fprint(2, "listen for venti\n");
ctl = listen(srv->adir, dir);
if(ctl < 0){
srv->dead = 1;
break;
}
fprint(2, "got one\n");
sc = vtmallocz(sizeof(VtSconn));
sc->ref = 1;
sc->ctl = ctl;
sc->srv = srv;
strcpy(sc->dir, dir);
@ -82,8 +104,8 @@ connproc(void *v)
int fd;
r = nil;
c = nil;
sc = v;
sc->c = nil;
fprint(2, "new call %s on %d\n", sc->dir, sc->ctl);
fd = accept(sc->ctl, sc->dir);
close(sc->ctl);
@ -122,7 +144,9 @@ connproc(void *v)
break;
r->rx.tag = r->tx.tag;
r->sc = sc;
scincref(sc);
if(_vtqsend(sc->srv->q, r) < 0){
scdecref(sc);
fprint(2, "hungup queue\n");
break;
}
@ -136,10 +160,8 @@ out:
vtfcallclear(&r->tx);
vtfree(r);
}
if(c)
vtfreeconn(c);
fprint(2, "freed %s\n", sc->dir);
vtfree(sc);
scdecref(sc);
return;
}
@ -167,6 +189,7 @@ vtrespond(VtReq *r)
return;
}
vtsend(sc->c, p);
scdecref(sc);
vtfcallclear(&r->tx);
vtfcallclear(&r->rx);
vtfree(r);