16 static Rune Lcolhdr[] = {
17 'N', 'e', 'w', 'c', 'o', 'l', ' ',
18 'K', 'i', 'l', 'l', ' ',
19 'P', 'u', 't', 'a', 'l', 'l', ' ',
20 'D', 'u', 'm', 'p', ' ',
21 'E', 'x', 'i', 't', ' ',
26 rowinit(Row *row, Rectangle r)
31 draw(screen, r, display->white, nil, ZP);
36 r1.max.y = r1.min.y + font->height;
38 textinit(t, fileaddtext(nil, t), r1, rfget(FALSE, FALSE, FALSE, nil), tagcols);
45 draw(screen, r1, display->black, nil, ZP);
46 textinsert(t, 0, Lcolhdr, 29, TRUE);
47 textsetselect(t, t->file->b.nc, t->file->b.nc);
51 rowadd(Row *row, Column *c, int x)
59 r.min.y = row->tag.fr.r.max.y+Border;
60 if(x<r.min.x && row->ncol>0){ /*steal 40% of last column by default */
61 d = row->col[row->ncol-1];
62 x = d->r.min.x + 3*Dx(d->r)/5;
64 /* look for column we'll land on */
65 for(i=0; i<row->ncol; i++){
72 i++; /* new column will go after d */
76 draw(screen, r, display->white, nil, ZP);
78 r1.max.x = min(x-Border, r.max.x-50);
80 r1.max.x = r1.min.x+50;
83 r1.max.x = r1.min.x+Border;
84 draw(screen, r1, display->black, nil, ZP);
88 c = emalloc(sizeof(Column));
95 row->col = realloc(row->col, (row->ncol+1)*sizeof(Column*));
96 memmove(row->col+i+1, row->col+i, (row->ncol-i)*sizeof(Column*));
104 rowresize(Row *row, Rectangle r)
107 Rectangle or, r1, r2;
111 deltax = r.min.x - or.min.x;
114 r1.max.y = r1.min.y + font->height;
115 textresize(&row->tag, r1, TRUE);
118 draw(screen, r1, display->black, nil, ZP);
122 for(i=0; i<row->ncol; i++){
125 /* the test should not be necessary, but guarantee we don't lose a pixel */
129 r1.max.x = (c->r.max.x-or.min.x)*Dx(r)/Dx(or) + deltax;
132 r2.max.x = r2.min.x+Border;
133 draw(screen, r2, display->black, nil, ZP);
141 rowdragcol(Row *row, Column *c, int _0)
151 setcursor(mousectl, &boxcursor);
154 while(mouse->buttons == b)
156 setcursor(mousectl, nil);
158 while(mouse->buttons)
163 for(i=0; i<row->ncol; i++)
166 error("can't find column");
170 if((abs(p.x-op.x)<5 && abs(p.y-op.y)<5))
172 if((i>0 && p.x<row->col[i-1]->r.min.x) || (i<row->ncol-1 && p.x>c->r.max.x)){
175 rowclose(row, c, FALSE);
176 if(rowadd(row, c, p.x) == nil) /* whoops! */
177 if(rowadd(row, c, x) == nil) /* WHOOPS! */
178 if(rowadd(row, c, -1)==nil){ /* shit! */
179 rowclose(row, c, TRUE);
188 if(p.x < d->r.min.x+80+Scrollwid)
189 p.x = d->r.min.x+80+Scrollwid;
190 if(p.x > c->r.max.x-80-Scrollwid)
191 p.x = c->r.max.x-80-Scrollwid;
193 r.max.x = c->r.max.x;
194 draw(screen, r, display->white, nil, ZP);
201 draw(screen, r, display->black, nil, ZP);
203 r.max.x = c->r.max.x;
209 rowclose(Row *row, Column *c, int dofree)
214 for(i=0; i<row->ncol; i++)
217 error("can't find column");
223 memmove(row->col+i, row->col+i+1, (row->ncol-i)*sizeof(Column*));
224 row->col = realloc(row->col, row->ncol*sizeof(Column*));
226 draw(screen, r, display->white, nil, ZP);
229 if(i == row->ncol){ /* extend last column right */
231 r.min.x = c->r.min.x;
232 r.max.x = row->r.max.x;
233 }else{ /* extend next window left */
235 r.max.x = c->r.max.x;
237 draw(screen, r, display->white, nil, ZP);
242 rowwhichcol(Row *row, Point p)
247 for(i=0; i<row->ncol; i++){
249 if(ptinrect(p, c->r))
256 rowwhich(Row *row, Point p)
260 if(ptinrect(p, row->tag.all))
262 c = rowwhichcol(row, p);
264 return colwhich(c, p);
269 rowtype(Row *row, Rune r, Point p)
282 t = rowwhich(row, p);
283 if(t!=nil && !(t->what==Tag && ptinrect(p, t->scrollr))){
290 /* Expand tag if necessary */
292 t->w->tagsafe = FALSE;
294 t->w->tagexpand = TRUE;
295 winresize(w, w->r, TRUE, TRUE);
311 for(i=0; i<row->ncol; i++)
312 clean &= colclean(row->col[i]);
317 rowdump(Row *row, char *file)
319 int i, j, fd, m, n, dumped;
322 char *buf, *a, *fontname;
333 warning(nil, "can't find file for dump: $home not defined\n");
336 sprint(buf, "%s/acme.dump", home);
339 fd = create(file, OWRITE, 0600);
341 warning(nil, "can't open %s: %r\n", file);
344 b = emalloc(sizeof(Biobuf));
345 Binit(b, fd, OWRITE);
347 Bprint(b, "%s\n", wdir);
348 Bprint(b, "%s\n", fontnames[0]);
349 Bprint(b, "%s\n", fontnames[1]);
350 for(i=0; i<row->ncol; i++){
352 Bprint(b, "%11.7f", 100.0*(c->r.min.x-row->r.min.x)/Dx(row->r));
358 for(i=0; i<row->ncol; i++){
360 for(j=0; j<c->nw; j++)
361 c->w[j]->body.file->dumpid = 0;
363 m = min(RBUFSIZE, row->tag.file->b.nc);
364 bufread(&row->tag.file->b, 0, r, m);
366 while(n<m && r[n]!='\n')
368 Bprint(b, "w %.*S\n", n, r);
369 for(i=0; i<row->ncol; i++){
371 m = min(RBUFSIZE, c->tag.file->b.nc);
372 bufread(&c->tag.file->b, 0, r, m);
374 while(n<m && r[n]!='\n')
376 Bprint(b, "c%11d %.*S\n", i, n, r);
378 for(i=0; i<row->ncol; i++){
380 for(j=0; j<c->nw; j++){
382 wincommit(w, &w->tag);
384 /* windows owned by others get special treatment */
385 if(w->nopen[QWevent] > 0)
386 if(w->dumpstr == nil)
388 /* zeroxes of external windows are tossed */
389 if(t->file->ntext > 1)
390 for(n=0; n<t->file->ntext; n++){
391 w1 = t->file->text[n]->w;
394 if(w1->nopen[QWevent])
398 if(t->reffont->f != font)
399 fontname = t->reffont->f->name;
401 a = runetobyte(t->file->name, t->file->nname);
406 Bprint(b, "x%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid,
407 w->body.q0, w->body.q1,
408 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
410 }else if(w->dumpstr){
412 Bprint(b, "e%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid,
414 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
416 }else if((w->dirty==FALSE && access(a, 0)==0) || w->isdir){
418 t->file->dumpid = w->id;
419 Bprint(b, "f%11d %11d %11d %11d %11.7f %s\n", i, w->id,
420 w->body.q0, w->body.q1,
421 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
425 t->file->dumpid = w->id;
426 Bprint(b, "F%11d %11d %11d %11d %11.7f %11d %s\n", i, j,
427 w->body.q0, w->body.q1,
428 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
429 w->body.file->b.nc, fontname);
432 winctlprint(w, buf, 0);
433 Bwrite(b, buf, strlen(buf));
434 m = min(RBUFSIZE, w->tag.file->b.nc);
435 bufread(&w->tag.file->b, 0, r, m);
437 while(n<m && r[n]!='\n')
439 Bprint(b, "%.*S\n", n, r);
445 if(n > BUFSIZE/UTFmax)
447 bufread(&t->file->b, q0, r, n);
448 Bprint(b, "%.*S", n, r);
454 Bprint(b, "%s\n%s\n", w->dumpdir, w->dumpstr);
456 Bprint(b, "\n%s\n", w->dumpstr);
472 rdline(Biobuf *b, int *linep)
476 l = Brdline(b, '\n');
483 * Get font names from load file so we don't load fonts we won't use
486 rowloadfonts(char *file)
492 b = Bopen(file, OREAD);
495 /* current directory */
496 l = Brdline(b, '\n');
501 l = Brdline(b, '\n');
504 l[Blinelen(b)-1] = 0;
505 if(*l && strcmp(l, fontnames[i])!=0){
507 fontnames[i] = estrdup(l);
515 rowload(Row *row, char *file, int initing)
517 int i, j, line, y, nr, nfontr, n, ns, ndumped, dumpid, x, fd, done;
520 char *buf, *l, *t, *fontname;
531 warning(nil, "can't find file for load: $home not defined\n");
534 sprint(buf, "%s/acme.dump", home);
537 b = Bopen(file, OREAD);
539 warning(nil, "can't open load file %s: %r\n", file);
542 /* current directory */
544 l = rdline(b, &line);
547 l[Blinelen(b)-1] = 0;
549 warning(nil, "can't chdir %s\n", l);
554 l = rdline(b, &line);
557 l[Blinelen(b)-1] = 0;
558 if(*l && strcmp(l, fontnames[i])!=0)
559 rfget(i, TRUE, i==0 && initing, l);
561 if(initing && row->ncol==0)
562 rowinit(row, screen->clipr);
563 l = rdline(b, &line);
570 percent = atof(l+i*12);
571 if(percent<0 || percent>=100)
573 x = row->r.min.x+percent*Dx(row->r)/100+0.5;
585 if(Dx(r1) < 50 || Dx(r2) < 50)
587 draw(screen, Rpt(r1.min, r2.max), display->white, nil, ZP);
592 draw(screen, r2, display->black, nil, ZP);
599 l = rdline(b, &line);
604 l[Blinelen(b)-1] = 0;
606 r = bytetorune(l+1*12, &nr);
614 textdelete(&row->col[i]->tag, 0, row->col[i]->tag.file->b.nc, TRUE);
615 textinsert(&row->col[i]->tag, 0, r+n+1, nr-(n+1), TRUE);
618 l[Blinelen(b)-1] = 0;
619 r = bytetorune(l+2, &nr);
627 textdelete(&row->tag, 0, row->tag.file->b.nc, TRUE);
628 textinsert(&row->tag, 0, r, nr, TRUE);
641 if(Blinelen(b) < 1+5*12+1)
643 l = rdline(b, &line); /* ctl line; ignored */
646 l = rdline(b, &line); /* directory */
649 l[Blinelen(b)-1] = 0;
652 r = bytetorune("./", &nr);
654 t = emalloc(strlen(home)+1+1);
655 sprint(t, "%s/", home);
656 r = bytetorune(t, &nr);
660 r = bytetorune(l, &nr);
661 l = rdline(b, &line); /* command */
664 t = emalloc(Blinelen(b)+1);
665 memmove(t, l, Blinelen(b));
666 run(nil, t, r, nr, TRUE, nil, nil, FALSE);
667 /* r is freed in run() */
670 if(Blinelen(b) < 1+5*12+1)
676 if(Blinelen(b) < 1+6*12+1)
679 ndumped = atoi(l+1+5*12+1);
682 if(Blinelen(b) < 1+5*12+1)
686 dumpid = atoi(l+1+1*12);
691 l[Blinelen(b)-1] = 0;
695 fontr = bytetorune(fontname, &nfontr);
700 percent = atof(l+1+4*12);
706 y = c->r.min.y+(percent*Dy(c->r))/100+0.5;
707 if(y<c->r.min.y || y>=c->r.max.y)
710 w = coladd(c, nil, nil, y);
712 w = coladd(c, nil, lookid(dumpid, TRUE), y);
716 l = rdline(b, &line);
719 l[Blinelen(b)-1] = 0;
720 r = bytetorune(l+5*12, &nr);
734 textinsert(&w->tag, w->tag.file->b.nc, r+n+1, nr-(n+1), TRUE);
736 /* simplest thing is to put it in a file and load that */
737 sprint(buf, "/tmp/d%d.%.4sacme", getpid(), getuser());
738 fd = create(buf, OWRITE, 0600);
741 warning(nil, "can't create temp file: %r\n");
744 bout = emalloc(sizeof(Biobuf));
745 Binit(bout, fd, OWRITE);
746 for(n=0; n<ndumped; n++){
758 Bputrune(bout, rune);
762 textload(&w->body, 0, buf, 1);
765 w->body.file->mod = TRUE;
766 for(n=0; n<w->body.file->ntext; n++)
767 w->body.file->text[n]->w->dirty = TRUE;
769 }else if(dumpid==0 && r[ns+1]!='+' && r[ns+1]!='-')
770 get(&w->body, nil, nil, FALSE, XXX, nil, 0);
772 fontx(&w->body, nil, nil, 0, 0, fontr, nfontr);
776 if(q0>w->body.file->b.nc || q1>w->body.file->b.nc || q0>q1)
778 textshow(&w->body, q0, q1, 1);
779 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++)