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)
106 Rectangle or, r1, r2;
110 deltax = r.min.x - or.min.x;
113 r1.max.y = r1.min.y + font->height;
114 textresize(&row->tag, r1, TRUE);
117 draw(screen, r1, display->black, nil, ZP);
121 for(i=0; i<row->ncol; i++){
124 /* the test should not be necessary, but guarantee we don't lose a pixel */
128 r1.max.x = (c->r.max.x-or.min.x)*Dx(r)/Dx(or) + deltax;
131 r2.max.x = r2.min.x+Border;
132 draw(screen, r2, display->black, nil, ZP);
140 rowdragcol(Row *row, Column *c, int _0)
150 setcursor(mousectl, &boxcursor);
153 while(mouse->buttons == b)
155 setcursor(mousectl, nil);
157 while(mouse->buttons)
162 for(i=0; i<row->ncol; i++)
165 error("can't find column");
169 if((abs(p.x-op.x)<5 && abs(p.y-op.y)<5))
171 if((i>0 && p.x<row->col[i-1]->r.min.x) || (i<row->ncol-1 && p.x>c->r.max.x)){
174 rowclose(row, c, FALSE);
175 if(rowadd(row, c, p.x) == nil) /* whoops! */
176 if(rowadd(row, c, x) == nil) /* WHOOPS! */
177 if(rowadd(row, c, -1)==nil){ /* shit! */
178 rowclose(row, c, TRUE);
187 if(p.x < d->r.min.x+80+Scrollwid)
188 p.x = d->r.min.x+80+Scrollwid;
189 if(p.x > c->r.max.x-80-Scrollwid)
190 p.x = c->r.max.x-80-Scrollwid;
192 r.max.x = c->r.max.x;
193 draw(screen, r, display->white, nil, ZP);
200 draw(screen, r, display->black, nil, ZP);
202 r.max.x = c->r.max.x;
208 rowclose(Row *row, Column *c, int dofree)
213 for(i=0; i<row->ncol; i++)
216 error("can't find column");
222 memmove(row->col+i, row->col+i+1, (row->ncol-i)*sizeof(Column*));
223 row->col = realloc(row->col, row->ncol*sizeof(Column*));
225 draw(screen, r, display->white, nil, ZP);
228 if(i == row->ncol){ /* extend last column right */
230 r.min.x = c->r.min.x;
231 r.max.x = row->r.max.x;
232 }else{ /* extend next window left */
234 r.max.x = c->r.max.x;
236 draw(screen, r, display->white, nil, ZP);
241 rowwhichcol(Row *row, Point p)
246 for(i=0; i<row->ncol; i++){
248 if(ptinrect(p, c->r))
255 rowwhich(Row *row, Point p)
259 if(ptinrect(p, row->tag.all))
261 c = rowwhichcol(row, p);
263 return colwhich(c, p);
268 rowtype(Row *row, Rune r, Point p)
281 t = rowwhich(row, p);
282 if(t!=nil && !(t->what==Tag && ptinrect(p, t->scrollr))){
289 /* Expand tag if necessary */
291 t->w->tagsafe = FALSE;
293 t->w->tagexpand = TRUE;
294 winresize(w, w->r, TRUE, TRUE);
310 for(i=0; i<row->ncol; i++)
311 clean &= colclean(row->col[i]);
316 rowdump(Row *row, char *file)
318 int i, j, fd, m, n, dumped;
321 char *buf, *a, *fontname;
332 warning(nil, "can't find file for dump: $home not defined\n");
335 sprint(buf, "%s/acme.dump", home);
338 fd = create(file, OWRITE, 0600);
340 warning(nil, "can't open %s: %r\n", file);
343 b = emalloc(sizeof(Biobuf));
344 Binit(b, fd, OWRITE);
346 Bprint(b, "%s\n", wdir);
347 Bprint(b, "%s\n", fontnames[0]);
348 Bprint(b, "%s\n", fontnames[1]);
349 for(i=0; i<row->ncol; i++){
351 Bprint(b, "%11.7f", 100.0*(c->r.min.x-row->r.min.x)/Dx(row->r));
357 for(i=0; i<row->ncol; i++){
359 for(j=0; j<c->nw; j++)
360 c->w[j]->body.file->dumpid = 0;
362 m = min(RBUFSIZE, row->tag.file->b.nc);
363 bufread(&row->tag.file->b, 0, r, m);
365 while(n<m && r[n]!='\n')
367 Bprint(b, "w %.*S\n", n, r);
368 for(i=0; i<row->ncol; i++){
370 m = min(RBUFSIZE, c->tag.file->b.nc);
371 bufread(&c->tag.file->b, 0, r, m);
373 while(n<m && r[n]!='\n')
375 Bprint(b, "c%11d %.*S\n", i, n, r);
377 for(i=0; i<row->ncol; i++){
379 for(j=0; j<c->nw; j++){
381 wincommit(w, &w->tag);
383 /* windows owned by others get special treatment */
384 if(w->nopen[QWevent] > 0)
385 if(w->dumpstr == nil)
387 /* zeroxes of external windows are tossed */
388 if(t->file->ntext > 1)
389 for(n=0; n<t->file->ntext; n++){
390 w1 = t->file->text[n]->w;
393 if(w1->nopen[QWevent])
397 if(t->reffont->f != font)
398 fontname = t->reffont->f->name;
400 a = runetobyte(t->file->name, t->file->nname);
405 Bprint(b, "x%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid,
406 w->body.q0, w->body.q1,
407 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
409 }else if(w->dumpstr){
411 Bprint(b, "e%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid,
413 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
415 }else if((w->dirty==FALSE && access(a, 0)==0) || w->isdir){
417 t->file->dumpid = w->id;
418 Bprint(b, "f%11d %11d %11d %11d %11.7f %s\n", i, w->id,
419 w->body.q0, w->body.q1,
420 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
424 t->file->dumpid = w->id;
425 Bprint(b, "F%11d %11d %11d %11d %11.7f %11d %s\n", i, j,
426 w->body.q0, w->body.q1,
427 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
428 w->body.file->b.nc, fontname);
431 winctlprint(w, buf, 0);
432 Bwrite(b, buf, strlen(buf));
433 m = min(RBUFSIZE, w->tag.file->b.nc);
434 bufread(&w->tag.file->b, 0, r, m);
436 while(n<m && r[n]!='\n')
438 Bprint(b, "%.*S\n", n, r);
444 if(n > BUFSIZE/UTFmax)
446 bufread(&t->file->b, q0, r, n);
447 Bprint(b, "%.*S", n, r);
453 Bprint(b, "%s\n%s\n", w->dumpdir, w->dumpstr);
455 Bprint(b, "\n%s\n", w->dumpstr);
471 rdline(Biobuf *b, int *linep)
475 l = Brdline(b, '\n');
482 * Get font names from load file so we don't load fonts we won't use
485 rowloadfonts(char *file)
491 b = Bopen(file, OREAD);
494 /* current directory */
495 l = Brdline(b, '\n');
500 l = Brdline(b, '\n');
503 l[Blinelen(b)-1] = 0;
504 if(*l && strcmp(l, fontnames[i])!=0){
506 fontnames[i] = estrdup(l);
514 rowload(Row *row, char *file, int initing)
516 int i, j, line, y, nr, nfontr, n, ns, ndumped, dumpid, x, fd, done;
519 char *buf, *l, *t, *fontname;
530 warning(nil, "can't find file for load: $home not defined\n");
533 sprint(buf, "%s/acme.dump", home);
536 b = Bopen(file, OREAD);
538 warning(nil, "can't open load file %s: %r\n", file);
541 /* current directory */
543 l = rdline(b, &line);
546 l[Blinelen(b)-1] = 0;
548 warning(nil, "can't chdir %s\n", l);
553 l = rdline(b, &line);
556 l[Blinelen(b)-1] = 0;
557 if(*l && strcmp(l, fontnames[i])!=0)
558 rfget(i, TRUE, i==0 && initing, l);
560 if(initing && row->ncol==0)
561 rowinit(row, screen->clipr);
562 l = rdline(b, &line);
569 percent = atof(l+i*12);
570 if(percent<0 || percent>=100)
572 x = row->r.min.x+percent*Dx(row->r)/100+0.5;
584 if(Dx(r1) < 50 || Dx(r2) < 50)
586 draw(screen, Rpt(r1.min, r2.max), display->white, nil, ZP);
591 draw(screen, r2, display->black, nil, ZP);
598 l = rdline(b, &line);
603 l[Blinelen(b)-1] = 0;
605 r = bytetorune(l+1*12, &nr);
613 textdelete(&row->col[i]->tag, 0, row->col[i]->tag.file->b.nc, TRUE);
614 textinsert(&row->col[i]->tag, 0, r+n+1, nr-(n+1), TRUE);
617 l[Blinelen(b)-1] = 0;
618 r = bytetorune(l+2, &nr);
626 textdelete(&row->tag, 0, row->tag.file->b.nc, TRUE);
627 textinsert(&row->tag, 0, r, nr, TRUE);
640 if(Blinelen(b) < 1+5*12+1)
642 l = rdline(b, &line); /* ctl line; ignored */
645 l = rdline(b, &line); /* directory */
648 l[Blinelen(b)-1] = 0;
651 r = bytetorune("./", &nr);
653 t = emalloc(strlen(home)+1+1);
654 sprint(t, "%s/", home);
655 r = bytetorune(t, &nr);
659 r = bytetorune(l, &nr);
660 l = rdline(b, &line); /* command */
663 t = emalloc(Blinelen(b)+1);
664 memmove(t, l, Blinelen(b));
665 run(nil, t, r, nr, TRUE, nil, nil, FALSE);
666 /* r is freed in run() */
669 if(Blinelen(b) < 1+5*12+1)
675 if(Blinelen(b) < 1+6*12+1)
678 ndumped = atoi(l+1+5*12+1);
681 if(Blinelen(b) < 1+5*12+1)
685 dumpid = atoi(l+1+1*12);
690 l[Blinelen(b)-1] = 0;
694 fontr = bytetorune(fontname, &nfontr);
699 percent = atof(l+1+4*12);
705 y = c->r.min.y+(percent*Dy(c->r))/100+0.5;
706 if(y<c->r.min.y || y>=c->r.max.y)
709 w = coladd(c, nil, nil, y);
711 w = coladd(c, nil, lookid(dumpid, TRUE), y);
715 l = rdline(b, &line);
718 l[Blinelen(b)-1] = 0;
719 r = bytetorune(l+5*12, &nr);
733 textinsert(&w->tag, w->tag.file->b.nc, r+n+1, nr-(n+1), TRUE);
735 /* simplest thing is to put it in a file and load that */
736 sprint(buf, "/tmp/d%d.%.4sacme", getpid(), getuser());
737 fd = create(buf, OWRITE, 0600);
740 warning(nil, "can't create temp file: %r\n");
743 bout = emalloc(sizeof(Biobuf));
744 Binit(bout, fd, OWRITE);
745 for(n=0; n<ndumped; n++){
757 Bputrune(bout, rune);
761 textload(&w->body, 0, buf, 1);
764 w->body.file->mod = TRUE;
765 for(n=0; n<w->body.file->ntext; n++)
766 w->body.file->text[n]->w->dirty = TRUE;
768 }else if(dumpid==0 && r[ns+1]!='+' && r[ns+1]!='-')
769 get(&w->body, nil, nil, FALSE, XXX, nil, 0);
771 fontx(&w->body, nil, nil, 0, 0, fontr, nfontr);
775 if(q0>w->body.file->b.nc || q1>w->body.file->b.nc || q0>q1)
777 textshow(&w->body, q0, q1, 1);
778 w->maxlines = min(w->body.fr.nlines, max(w->maxlines, w->body.fr.maxlines));
780 l = rdline(b, &line);
787 warning(nil, "bad load file %s:%d\n", file, line);
795 allwindows(void (*f)(Window*, void*), void *arg)
800 for(i=0; i<row.ncol; i++){
802 for(j=0; j<c->nw; j++)