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

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);