various little bug fixes
This commit is contained in:
parent
6b53e2a4d0
commit
892de79874
8 changed files with 2351 additions and 8 deletions
|
|
@ -174,6 +174,9 @@ struct Text
|
||||||
uint org;
|
uint org;
|
||||||
uint q0;
|
uint q0;
|
||||||
uint q1;
|
uint q1;
|
||||||
|
uint oldorg;
|
||||||
|
uint oldq0;
|
||||||
|
uint oldq1;
|
||||||
int what;
|
int what;
|
||||||
int tabstop;
|
int tabstop;
|
||||||
Window *w;
|
Window *w;
|
||||||
|
|
|
||||||
|
|
@ -580,6 +580,9 @@ get(Text *et, Text *t, Text *argt, int flag1, int _0, Rune *arg, int narg)
|
||||||
r = bytetorune(name, &n);
|
r = bytetorune(name, &n);
|
||||||
for(i=0; i<t->file->ntext; i++){
|
for(i=0; i<t->file->ntext; i++){
|
||||||
u = t->file->text[i];
|
u = t->file->text[i];
|
||||||
|
u->oldorg = u->org;
|
||||||
|
u->oldq0 = u->q0;
|
||||||
|
u->oldq1 = u->q1;
|
||||||
/* second and subsequent calls with zero an already empty buffer, but OK */
|
/* second and subsequent calls with zero an already empty buffer, but OK */
|
||||||
textreset(u);
|
textreset(u);
|
||||||
windirfree(u->w);
|
windirfree(u->w);
|
||||||
|
|
@ -601,6 +604,14 @@ get(Text *et, Text *t, Text *argt, int flag1, int _0, Rune *arg, int narg)
|
||||||
t->file->unread = FALSE;
|
t->file->unread = FALSE;
|
||||||
for(i=0; i<t->file->ntext; i++){
|
for(i=0; i<t->file->ntext; i++){
|
||||||
u = t->file->text[i];
|
u = t->file->text[i];
|
||||||
|
if(u->oldorg > u->file->b.nc)
|
||||||
|
u->oldorg = u->file->b.nc;
|
||||||
|
if(u->oldq0 > u->file->b.nc)
|
||||||
|
u->oldq0 = u->file->b.nc;
|
||||||
|
if(u->oldq1 > u->file->b.nc)
|
||||||
|
u->oldq1 = u->file->b.nc;
|
||||||
|
u->org = u->oldorg;
|
||||||
|
textshow(u, u->oldq0, u->oldq1, 1);
|
||||||
textsetselect(&u->w->tag, u->w->tag.file->b.nc, u->w->tag.file->b.nc);
|
textsetselect(&u->w->tag, u->w->tag.file->b.nc, u->w->tag.file->b.nc);
|
||||||
textscrdraw(u);
|
textscrdraw(u);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,9 @@ void
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i, ok, stdout;
|
int i, ok, stdout;
|
||||||
|
char **oargv;
|
||||||
|
|
||||||
|
oargv = argv;
|
||||||
level = 6;
|
level = 6;
|
||||||
stdout = 0;
|
stdout = 0;
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
|
|
@ -36,6 +38,20 @@ main(int argc, char **argv)
|
||||||
case 'c':
|
case 'c':
|
||||||
stdout++;
|
stdout++;
|
||||||
break;
|
break;
|
||||||
|
case 'd':
|
||||||
|
/*
|
||||||
|
* gnu tar expects bzip2 -d to decompress
|
||||||
|
* humor it. ugh.
|
||||||
|
*/
|
||||||
|
/* remove -d from command line - magic! */
|
||||||
|
if(strcmp(argv[0], "-d") == 0){
|
||||||
|
while(*argv++)
|
||||||
|
*(argv-1) = *argv;
|
||||||
|
}else
|
||||||
|
memmove(_args-1, _args, strlen(_args)+1);
|
||||||
|
exec("bunzip2", oargv);
|
||||||
|
sysfatal("exec bunzip2 failed");
|
||||||
|
break;
|
||||||
case '1': case '2': case '3': case '4':
|
case '1': case '2': case '3': case '4':
|
||||||
case '5': case '6': case '7': case '8': case '9':
|
case '5': case '6': case '7': case '8': case '9':
|
||||||
level = ARGC() - '0';
|
level = ARGC() - '0';
|
||||||
|
|
|
||||||
241
src/cmd/fmt.c
Normal file
241
src/cmd/fmt.c
Normal file
|
|
@ -0,0 +1,241 @@
|
||||||
|
#include <u.h>
|
||||||
|
#include <libc.h>
|
||||||
|
#include <bio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* block up paragraphs, possibly with indentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
int extraindent = 0; /* how many spaces to indent all lines */
|
||||||
|
int indent = 0; /* current value of indent, before extra indent */
|
||||||
|
int length = 70; /* how many columns per output line */
|
||||||
|
int join = 1; /* can lines be joined? */
|
||||||
|
int maxtab = 8;
|
||||||
|
Biobuf bin;
|
||||||
|
Biobuf bout;
|
||||||
|
|
||||||
|
typedef struct Word Word;
|
||||||
|
struct Word{
|
||||||
|
int bol;
|
||||||
|
int indent;
|
||||||
|
char text[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
void fmt(void);
|
||||||
|
|
||||||
|
void
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
fprint(2, "usage: %s [-j] [-i indent] [-l length] [file...]\n", argv0);
|
||||||
|
exits("usage");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int i, f;
|
||||||
|
char *s, *err;
|
||||||
|
|
||||||
|
ARGBEGIN{
|
||||||
|
case 'i':
|
||||||
|
extraindent = atoi(EARGF(usage()));
|
||||||
|
break;
|
||||||
|
case 'j':
|
||||||
|
join = 0;
|
||||||
|
break;
|
||||||
|
case 'w':
|
||||||
|
case 'l':
|
||||||
|
length = atoi(EARGF(usage()));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage();
|
||||||
|
}ARGEND
|
||||||
|
|
||||||
|
if(length <= indent){
|
||||||
|
fprint(2, "%s: line length<=indentation\n", argv0);
|
||||||
|
exits("length");
|
||||||
|
}
|
||||||
|
|
||||||
|
s=getenv("tabstop");
|
||||||
|
if(s!=nil && atoi(s)>0)
|
||||||
|
maxtab=atoi(s);
|
||||||
|
err = nil;
|
||||||
|
Binit(&bout, 1, OWRITE);
|
||||||
|
if(argc <= 0){
|
||||||
|
Binit(&bin, 0, OREAD);
|
||||||
|
fmt();
|
||||||
|
}else{
|
||||||
|
for(i=0; i<argc; i++){
|
||||||
|
f = open(argv[i], OREAD);
|
||||||
|
if(f < 0){
|
||||||
|
fprint(2, "%s: can't open %s: %r\n", argv0, argv[i]);
|
||||||
|
err = "open";
|
||||||
|
}else{
|
||||||
|
Binit(&bin, f, OREAD);
|
||||||
|
fmt();
|
||||||
|
Bterm(&bin);
|
||||||
|
if(i != argc-1)
|
||||||
|
Bputc(&bout, '\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exits(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
indentof(char **linep)
|
||||||
|
{
|
||||||
|
int i, ind;
|
||||||
|
char *line;
|
||||||
|
|
||||||
|
ind = 0;
|
||||||
|
line = *linep;
|
||||||
|
for(i=0; line[i]; i++)
|
||||||
|
switch(line[i]){
|
||||||
|
default:
|
||||||
|
*linep = line;
|
||||||
|
return ind;
|
||||||
|
case ' ':
|
||||||
|
ind++;
|
||||||
|
break;
|
||||||
|
case '\t':
|
||||||
|
ind += maxtab;
|
||||||
|
ind -= ind%maxtab;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* plain white space doesn't change the indent */
|
||||||
|
*linep = "";
|
||||||
|
return indent;
|
||||||
|
}
|
||||||
|
|
||||||
|
Word**
|
||||||
|
addword(Word **words, int *nwordp, char *s, int l, int indent, int bol)
|
||||||
|
{
|
||||||
|
Word *w;
|
||||||
|
|
||||||
|
w = malloc(sizeof(Word)+l+1);
|
||||||
|
memmove(w->text, s, l);
|
||||||
|
w->text[l] = '\0';
|
||||||
|
w->indent = indent;
|
||||||
|
w->bol = bol;
|
||||||
|
words = realloc(words, (*nwordp+1)*sizeof(Word*));
|
||||||
|
words[(*nwordp)++] = w;
|
||||||
|
return words;
|
||||||
|
}
|
||||||
|
|
||||||
|
Word**
|
||||||
|
parseline(char *line, Word **words, int *nwordp)
|
||||||
|
{
|
||||||
|
int ind, l, bol;
|
||||||
|
|
||||||
|
ind = indentof(&line);
|
||||||
|
indent = ind;
|
||||||
|
bol = 1;
|
||||||
|
for(;;){
|
||||||
|
/* find next word */
|
||||||
|
while(*line==' ' || *line=='\t')
|
||||||
|
line++;
|
||||||
|
if(*line == '\0'){
|
||||||
|
if(bol)
|
||||||
|
return addword(words, nwordp, "", 0, -1, bol);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* how long is this word? */
|
||||||
|
for(l=0; line[l]; l++)
|
||||||
|
if(line[l]==' ' || line[l]=='\t')
|
||||||
|
break;
|
||||||
|
words = addword(words, nwordp, line, l, indent, bol);
|
||||||
|
bol = 0;
|
||||||
|
line += l;
|
||||||
|
}
|
||||||
|
return words;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
printindent(int w)
|
||||||
|
{
|
||||||
|
while(w >= maxtab){
|
||||||
|
Bputc(&bout, '\t');
|
||||||
|
w -= maxtab;
|
||||||
|
}
|
||||||
|
while(w > 0){
|
||||||
|
Bputc(&bout, ' ');
|
||||||
|
w--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* give extra space if word ends with period, etc. */
|
||||||
|
int
|
||||||
|
nspaceafter(char *s)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = strlen(s);
|
||||||
|
if(n < 2)
|
||||||
|
return 1;
|
||||||
|
if(isupper(s[0]) && n < 4)
|
||||||
|
return 1;
|
||||||
|
if(strchr(".!?", s[n-1]) != nil)
|
||||||
|
return 2;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
printwords(Word **w, int nw)
|
||||||
|
{
|
||||||
|
int i, j, n, col, nsp;
|
||||||
|
|
||||||
|
/* one output line per loop */
|
||||||
|
for(i=0; i<nw; ){
|
||||||
|
/* if it's a blank line, print it */
|
||||||
|
if(w[i]->indent == -1){
|
||||||
|
Bputc(&bout, '\n');
|
||||||
|
if(++i == nw) /* out of words */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* emit leading indent */
|
||||||
|
col = extraindent+w[i]->indent;
|
||||||
|
printindent(col);
|
||||||
|
/* emit words until overflow; always emit at least one word */
|
||||||
|
for(n=0;; n++){
|
||||||
|
Bprint(&bout, "%s", w[i]->text);
|
||||||
|
col += utflen(w[i]->text);
|
||||||
|
if(++i == nw)
|
||||||
|
break; /* out of words */
|
||||||
|
if(w[i]->indent != w[i-1]->indent)
|
||||||
|
break; /* indent change */
|
||||||
|
nsp = nspaceafter(w[i-1]->text);
|
||||||
|
if(col+nsp+utflen(w[i]->text) > extraindent+length)
|
||||||
|
break; /* fold line */
|
||||||
|
if(!join && n != 0 && w[i]->bol)
|
||||||
|
break;
|
||||||
|
for(j=0; j<nsp; j++)
|
||||||
|
Bputc(&bout, ' '); /* emit space; another word will follow */
|
||||||
|
col += nsp;
|
||||||
|
}
|
||||||
|
/* emit newline */
|
||||||
|
Bputc(&bout, '\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
fmt(void)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
int i, nw;
|
||||||
|
Word **w;
|
||||||
|
|
||||||
|
nw = 0;
|
||||||
|
w = nil;
|
||||||
|
while((s = Brdstr(&bin, '\n', 1)) != nil){
|
||||||
|
w = parseline(s, w, &nw);
|
||||||
|
free(s);
|
||||||
|
}
|
||||||
|
printwords(w, nw);
|
||||||
|
for(i=0; i<nw; i++)
|
||||||
|
free(w[i]);
|
||||||
|
free(w);
|
||||||
|
}
|
||||||
|
|
@ -29,13 +29,29 @@ void
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, ok, stdout;
|
int i, ok, stdout;
|
||||||
|
char **oargv;
|
||||||
|
|
||||||
|
oargv = argv;
|
||||||
level = 6;
|
level = 6;
|
||||||
stdout = 0;
|
stdout = 0;
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
case 'D':
|
case 'D':
|
||||||
debug++;
|
debug++;
|
||||||
break;
|
break;
|
||||||
|
case 'd':
|
||||||
|
/*
|
||||||
|
* gnu tar expects gzip -d to decompress
|
||||||
|
* humor it. ugh.
|
||||||
|
*/
|
||||||
|
/* remove -d from command line - magic! */
|
||||||
|
if(strcmp(argv[0], "-d") == 0){
|
||||||
|
while(*argv++)
|
||||||
|
*(argv-1) = *argv;
|
||||||
|
}else
|
||||||
|
memmove(_args-1, _args, strlen(_args)+1);
|
||||||
|
exec("gunzip", oargv);
|
||||||
|
sysfatal("exec gunzip failed");
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose++;
|
verbose++;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ PLAN9=../..
|
||||||
<$PLAN9/src/mkhdr
|
<$PLAN9/src/mkhdr
|
||||||
|
|
||||||
TARG=`ls *.c | sed 's/\.c//'`
|
TARG=`ls *.c | sed 's/\.c//'`
|
||||||
LDFLAGS=$LDFLAGS
|
LDFLAGS=$LDFLAGS -L$X11/lib -lX11
|
||||||
SHORTLIB=sec fs mux regexp9 thread bio 9
|
SHORTLIB=sec fs mux regexp9 draw thread bio 9
|
||||||
|
|
||||||
<$PLAN9/src/mkmany
|
<$PLAN9/src/mkmany
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,7 @@ button(XButtonEvent *e)
|
||||||
if(c){
|
if(c){
|
||||||
if (debug) fprintf(stderr, "but: e x=%d y=%d c x=%d y=%d dx=%d dy=%d BORDR %d\n",
|
if (debug) fprintf(stderr, "but: e x=%d y=%d c x=%d y=%d dx=%d dy=%d BORDR %d\n",
|
||||||
e->x, e->y, c->x, c->y, c->dx, c->dy, BORDER);
|
e->x, e->y, c->x, c->y, c->dx, c->dy, BORDER);
|
||||||
if (e->x <= BORDER || e->x > (c->dx + BORDER) ||
|
if(borderorient(c, e->x, e->y) != BorderUnknown){
|
||||||
e->y <= BORDER || e->y > (c->dy + BORDER)) {
|
|
||||||
switch (e->button) {
|
switch (e->button) {
|
||||||
case Button1:
|
case Button1:
|
||||||
case Button2:
|
case Button2:
|
||||||
|
|
@ -66,8 +65,7 @@ button(XButtonEvent *e)
|
||||||
}
|
}
|
||||||
e->x += c->x - BORDER;
|
e->x += c->x - BORDER;
|
||||||
e->y += c->y - BORDER;
|
e->y += c->y - BORDER;
|
||||||
}
|
} else if (e->window != e->root) {
|
||||||
else if (e->window != e->root) {
|
|
||||||
if (debug) fprintf(stderr, "but no client: e x=%d y=%d\n",
|
if (debug) fprintf(stderr, "but no client: e x=%d y=%d\n",
|
||||||
e->x, e->y);
|
e->x, e->y);
|
||||||
XTranslateCoordinates(dpy, e->window, s->root, e->x, e->y,
|
XTranslateCoordinates(dpy, e->window, s->root, e->x, e->y,
|
||||||
|
|
|
||||||
2058
src/cmd/tweak.c
Normal file
2058
src/cmd/tweak.c
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue