15 static Rune Lcolhdr[] = {
16 'N', 'e', 'w', 'c', 'o', 'l', ' ',
17 'K', 'i', 'l', 'l', ' ',
18 'P', 'u', 't', 'a', 'l', 'l', ' ',
19 'D', 'u', 'm', 'p', ' ',
20 'E', 'x', 'i', 't', ' ',
25 rowinit(Row *row, Rectangle r)
30 draw(screen, r, display->white, nil, ZP);
35 r1.max.y = r1.min.y + font->height;
37 textinit(t, fileaddtext(nil, t), r1, rfget(FALSE, FALSE, FALSE, nil), tagcols);
44 draw(screen, r1, display->black, nil, ZP);
45 textinsert(t, 0, Lcolhdr, 29, TRUE);
46 textsetselect(t, t->file->b.nc, t->file->b.nc);
50 rowadd(Row *row, Column *c, int x)
58 r.min.y = row->tag.fr.r.max.y+Border;
59 if(x<r.min.x && row->ncol>0){ /*steal 40% of last column by default */
60 d = row->col[row->ncol-1];
61 x = d->r.min.x + 3*Dx(d->r)/5;
63 /* look for column we'll land on */
64 for(i=0; i<row->ncol; i++){
71 i++; /* new column will go after d */
75 draw(screen, r, display->white, nil, ZP);
77 r1.max.x = min(x-Border, r.max.x-50);
79 r1.max.x = r1.min.x+50;
82 r1.max.x = r1.min.x+Border;
83 draw(screen, r1, display->black, nil, ZP);
87 c = emalloc(sizeof(Column));
94 row->col = realloc(row->col, (row->ncol+1)*sizeof(Column*));
95 memmove(row->col+i+1, row->col+i, (row->ncol-i)*sizeof(Column*));
103 rowresize(Row *row, Rectangle r)
105 int i, dx, odx, deltax;
106 Rectangle or, r1, r2;
112 deltax = r.min.x - or.min.x;
115 r1.max.y = r1.min.y + font->height;
116 textresize(&row->tag, r1, TRUE);
119 draw(screen, r1, display->black, nil, ZP);
123 for(i=0; i<row->ncol; i++){
126 /* the test should not be necessary, but guarantee we don't lose a pixel */
130 r1.max.x = (c->r.max.x-or.min.x)*Dx(r)/Dx(or) + deltax;
133 r2.max.x = r2.min.x+Border;
134 draw(screen, r2, display->black, nil, ZP);
142 rowdragcol(Row *row, Column *c, int _0)
152 setcursor(mousectl, &boxcursor);
155 while(mouse->buttons == b)
157 setcursor(mousectl, nil);
159 while(mouse->buttons)
164 for(i=0; i<row->ncol; i++)
167 error("can't find column");
171 if((abs(p.x-op.x)<5 && abs(p.y-op.y)<5))
173 if((i>0 && p.x<row->col[i-1]->r.min.x) || (i<row->ncol-1 && p.x>c->r.max.x)){
176 rowclose(row, c, FALSE);
177 if(rowadd(row, c, p.x) == nil) /* whoops! */
178 if(rowadd(row, c, x) == nil) /* WHOOPS! */
179 if(rowadd(row, c, -1)==nil){ /* shit! */
180 rowclose(row, c, TRUE);
189 if(p.x < d->r.min.x+80+Scrollwid)
190 p.x = d->r.min.x+80+Scrollwid;
191 if(p.x > c->r.max.x-80-Scrollwid)
192 p.x = c->r.max.x-80-Scrollwid;
194 r.max.x = c->r.max.x;
195 draw(screen, r, display->white, nil, ZP);
202 draw(screen, r, display->black, nil, ZP);
204 r.max.x = c->r.max.x;
210 rowclose(Row *row, Column *c, int dofree)
215 for(i=0; i<row->ncol; i++)
218 error("can't find column");
224 memmove(row->col+i, row->col+i+1, (row->ncol-i)*sizeof(Column*));
225 row->col = realloc(row->col, row->ncol*sizeof(Column*));
227 draw(screen, r, display->white, nil, ZP);
230 if(i == row->ncol){ /* extend last column right */
232 r.min.x = c->r.min.x;
233 r.max.x = row->r.max.x;
234 }else{ /* extend next window left */
236 r.max.x = c->r.max.x;
238 draw(screen, r, display->white, nil, ZP);
243 rowwhichcol(Row *row, Point p)
248 for(i=0; i<row->ncol; i++){
250 if(ptinrect(p, c->r))
257 rowwhich(Row *row, Point p)
261 if(ptinrect(p, row->tag.all))
263 c = rowwhichcol(row, p);
265 return colwhich(c, p);
270 rowtype(Row *row, Rune r, Point p)
283 t = rowwhich(row, p);
284 if(t!=nil && !(t->what==Tag && ptinrect(p, t->scrollr))){
291 /* Expand tag if necessary */
293 t->w->tagsafe = FALSE;
295 t->w->tagexpand = TRUE;
296 winresize(w, w->r, TRUE, TRUE);
312 for(i=0; i<row->ncol; i++)
313 clean &= colclean(row->col[i]);
318 rowdump(Row *row, char *file)
320 int i, j, fd, m, n, dumped;
323 char *buf, *a, *fontname;
334 warning(nil, "can't find file for dump: $home not defined\n");
337 sprint(buf, "%s/acme.dump", home);
340 fd = create(file, OWRITE, 0600);
342 warning(nil, "can't open %s: %r\n", file);
345 b = emalloc(sizeof(Biobuf));
346 Binit(b, fd, OWRITE);
348 Bprint(b, "%s\n", wdir);
349 Bprint(b, "%s\n", fontnames[0]);
350 Bprint(b, "%s\n", fontnames[1]);
351 for(i=0; i<row->ncol; i++){
353 Bprint(b, "%11.7f", 100.0*(c->r.min.x-row->r.min.x)/Dx(row->r));
359 for(i=0; i<row->ncol; i++){
361 for(j=0; j<c->nw; j++)
362 c->w[j]->body.file->dumpid = 0;
364 m = min(RBUFSIZE, row->tag.file->b.nc);
365 bufread(&row->tag.file->b, 0, r, m);
367 while(n<m && r[n]!='\n')
369 Bprint(b, "w %.*S\n", n, r);
370 for(i=0; i<row->ncol; i++){
372 m = min(RBUFSIZE, c->tag.file->b.nc);
373 bufread(&c->tag.file->b, 0, r, m);
375 while(n<m && r[n]!='\n')
377 Bprint(b, "c%11d %.*S\n", i, n, r);
379 for(i=0; i<row->ncol; i++){
381 for(j=0; j<c->nw; j++){
383 wincommit(w, &w->tag);
385 /* windows owned by others get special treatment */
386 if(w->nopen[QWevent] > 0)
387 if(w->dumpstr == nil)
389 /* zeroxes of external windows are tossed */
390 if(t->file->ntext > 1)
391 for(n=0; n<t->file->ntext; n++){
392 w1 = t->file->text[n]->w;
395 if(w1->nopen[QWevent])
399 if(t->reffont->f != font)
400 fontname = t->reffont->f->name;
402 a = runetobyte(t->file->name, t->file->nname);
407 Bprint(b, "x%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid,
408 w->body.q0, w->body.q1,
409 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
411 }else if(w->dumpstr){
413 Bprint(b, "e%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid,
415 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
417 }else if((w->dirty==FALSE && access(a, 0)==0) || w->isdir){
419 t->file->dumpid = w->id;
420 Bprint(b, "f%11d %11d %11d %11d %11.7f %s\n", i, w->id,
421 w->body.q0, w->body.q1,
422 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
426 t->file->dumpid = w->id;
427 Bprint(b, "F%11d %11d %11d %11d %11.7f %11d %s\n", i, j,
428 w->body.q0, w->body.q1,
429 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
430 w->body.file->b.nc, fontname);
433 winctlprint(w, buf, 0);
434 Bwrite(b, buf, strlen(buf));
435 m = min(RBUFSIZE, w->tag.file->b.nc);
436 bufread(&w->tag.file->b, 0, r, m);
438 while(n<m && r[n]!='\n')
440 Bprint(b, "%.*S\n", n, r);
446 if(n > BUFSIZE/UTFmax)
448 bufread(&t->file->b, q0, r, n);
449 Bprint(b, "%.*S", n, r);
455 Bprint(b, "%s\n%s\n", w->dumpdir, w->dumpstr);
457 Bprint(b, "\n%s\n", w->dumpstr);
473 rdline(Biobuf *b, int *linep)
477 l = Brdline(b, '\n');
484 * Get font names from load file so we don't load fonts we won't use
487 rowloadfonts(char *file)
493 b = Bopen(file, OREAD);
496 /* current directory */
497 l = Brdline(b, '\n');
502 l = Brdline(b, '\n');
505 l[Blinelen(b)-1] = 0;
506 if(*l && strcmp(l, fontnames[i])!=0){
508 fontnames[i] = estrdup(l);
516 rowload(Row *row, char *file, int initing)
518 int i, j, line, y, nr, nfontr, n, ns, ndumped, dumpid, x, fd, done;
521 char *buf, *l, *t, *fontname;
532 warning(nil, "can't find file for load: $home not defined\n");
535 sprint(buf, "%s/acme.dump", home);
538 b = Bopen(file, OREAD);
540 warning(nil, "can't open load file %s: %r\n", file);
543 /* current directory */
545 l = rdline(b, &line);
548 l[Blinelen(b)-1] = 0;
550 warning(nil, "can't chdir %s\n", l);
555 l = rdline(b, &line);
558 l[Blinelen(b)-1] = 0;
559 if(*l && strcmp(l, fontnames[i])!=0)
560 rfget(i, TRUE, i==0 && initing, l);
562 if(initing && row->ncol==0)
563 rowinit(row, screen->clipr);
564 l = rdline(b, &line);
571 percent = atof(l+i*12);
572 if(percent<0 || percent>=100)
574 x = row->r.min.x+percent*Dx(row->r)/100+0.5;
586 if(Dx(r1) < 50 || Dx(r2) < 50)
588 draw(screen, Rpt(r1.min, r2.max), display->white, nil, ZP);
593 draw(screen, r2, display->black, nil, ZP);
600 l = rdline(b, &line);
605 l[Blinelen(b)-1] = 0;
607 r = bytetorune(l+1*12, &nr);
615 textdelete(&row->col[i]->tag, 0, row->col[i]->tag.file->b.nc, TRUE);
616 textinsert(&row->col[i]->tag, 0, r+n+1, nr-(n+1), TRUE);
619 l[Blinelen(b)-1] = 0;
620 r = bytetorune(l+2, &nr);
628 textdelete(&row->tag, 0, row->tag.file->b.nc, TRUE);
629 textinsert(&row->tag, 0, r, nr, TRUE);
642 if(Blinelen(b) < 1+5*12+1)
644 l = rdline(b, &line); /* ctl line; ignored */
647 l = rdline(b, &line); /* directory */
650 l[Blinelen(b)-1] = 0;
653 r = bytetorune("./", &nr);
655 t = emalloc(strlen(home)+1+1);
656 sprint(t, "%s/", home);
657 r = bytetorune(t, &nr);
661 r = bytetorune(l, &nr);
662 l = rdline(b, &line); /* command */
665 t = emalloc(Blinelen(b)+1);
666 memmove(t, l, Blinelen(b));
667 run(nil, t, r, nr, TRUE, nil, nil, FALSE);
668 /* r is freed in run() */
671 if(Blinelen(b) < 1+5*12+1)
677 if(Blinelen(b) < 1+6*12+1)
680 ndumped = atoi(l+1+5*12+1);
683 if(Blinelen(b) < 1+5*12+1)
687 dumpid = atoi(l+1+1*12);
692 l[Blinelen(b)-1] = 0;
696 fontr = bytetorune(fontname, &nfontr);
701 percent = atof(l+1+4*12);
707 y = c->r.min.y+(percent*Dy(c->r))/100+0.5;
708 if(y<c->r.min.y || y>=c->r.max.y)
711 w = coladd(c, nil, nil, y);
713 w = coladd(c, nil, lookid(dumpid, TRUE), y);
717 l = rdline(b, &line);
720 l[Blinelen(b)-1] = 0;
721 r = bytetorune(l+5*12, &nr);
735 textinsert(&w->tag, w->tag.file->b.nc, r+n+1, nr-(n+1), TRUE);
737 /* simplest thing is to put it in a file and load that */
738 sprint(buf, "/tmp/d%d.%.4sacme", getpid(), getuser());
739 fd = create(buf, OWRITE, 0600);
742 warning(nil, "can't create temp file: %r\n");
745 bout = emalloc(sizeof(Biobuf));
746 Binit(bout, fd, OWRITE);
747 for(n=0; n<ndumped; n++){
759 Bputrune(bout, rune);
763 textload(&w->body, 0, buf, 1);
766 w->body.file->mod = TRUE;
767 for(n=0; n<w->body.file->ntext; n++)
768 w->body.file->text[n]->w->dirty = TRUE;
770 }else if(dumpid==0 && r[ns+1]!='+' && r[ns+1]!='-')
771 get(&w->body, nil, nil, FALSE, XXX, nil, 0);
773 fontx(&w->body, nil, nil, 0, 0, fontr, nfontr);
777 if(q0>w->body.file->b.nc || q1>w->body.file->b.nc || q0>q1)
779 textshow(&w->body, q0, q1, 1);
780 w->maxlines = min(w->body.fr.nlines, max(w->maxlines, w->body.fr.maxlines));
782 l = rdline(b, &line);
789 warning(nil, "bad load file %s:%d\n", file, line);
797 allwindows(void (*f)(Window*, void*), void *arg)
802 for(i=0; i<row.ncol; i++){
804 for(j=0; j<c->nw; j++)