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)
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++){
127 r1.max.x = r1.min.x+Dx(c->r)*dx/odx;
130 r2.max.x = r2.min.x+Border;
131 draw(screen, r2, display->black, nil, ZP);
139 rowdragcol(Row *row, Column *c, int _0)
149 setcursor(mousectl, &boxcursor);
152 while(mouse->buttons == b)
154 setcursor(mousectl, nil);
156 while(mouse->buttons)
161 for(i=0; i<row->ncol; i++)
164 error("can't find column");
168 if((abs(p.x-op.x)<5 && abs(p.y-op.y)<5))
170 if((i>0 && p.x<row->col[i-1]->r.min.x) || (i<row->ncol-1 && p.x>c->r.max.x)){
173 rowclose(row, c, FALSE);
174 if(rowadd(row, c, p.x) == nil) /* whoops! */
175 if(rowadd(row, c, x) == nil) /* WHOOPS! */
176 if(rowadd(row, c, -1)==nil){ /* shit! */
177 rowclose(row, c, TRUE);
186 if(p.x < d->r.min.x+80+Scrollwid)
187 p.x = d->r.min.x+80+Scrollwid;
188 if(p.x > c->r.max.x-80-Scrollwid)
189 p.x = c->r.max.x-80-Scrollwid;
191 r.max.x = c->r.max.x;
192 draw(screen, r, display->white, nil, ZP);
199 draw(screen, r, display->black, nil, ZP);
201 r.max.x = c->r.max.x;
207 rowclose(Row *row, Column *c, int dofree)
212 for(i=0; i<row->ncol; i++)
215 error("can't find column");
221 memmove(row->col+i, row->col+i+1, (row->ncol-i)*sizeof(Column*));
222 row->col = realloc(row->col, row->ncol*sizeof(Column*));
224 draw(screen, r, display->white, nil, ZP);
227 if(i == row->ncol){ /* extend last column right */
229 r.min.x = c->r.min.x;
230 r.max.x = row->r.max.x;
231 }else{ /* extend next window left */
233 r.max.x = c->r.max.x;
235 draw(screen, r, display->white, nil, ZP);
240 rowwhichcol(Row *row, Point p)
245 for(i=0; i<row->ncol; i++){
247 if(ptinrect(p, c->r))
254 rowwhich(Row *row, Point p)
258 if(ptinrect(p, row->tag.all))
260 c = rowwhichcol(row, p);
262 return colwhich(c, p);
267 rowtype(Row *row, Rune r, Point p)
280 t = rowwhich(row, p);
281 if(t!=nil && !(t->what==Tag && ptinrect(p, t->scrollr))){
288 /* Expand tag if necessary */
290 t->w->tagsafe = FALSE;
292 t->w->tagexpand = TRUE;
293 winresize(w, w->r, TRUE, TRUE);
309 for(i=0; i<row->ncol; i++)
310 clean &= colclean(row->col[i]);
315 rowdump(Row *row, char *file)
317 int i, j, fd, m, n, dumped;
320 char *buf, *a, *fontname;
331 warning(nil, "can't find file for dump: $home not defined\n");
334 sprint(buf, "%s/acme.dump", home);
337 fd = create(file, OWRITE, 0600);
339 warning(nil, "can't open %s: %r\n", file);
342 b = emalloc(sizeof(Biobuf));
343 Binit(b, fd, OWRITE);
345 Bprint(b, "%s\n", wdir);
346 Bprint(b, "%s\n", fontnames[0]);
347 Bprint(b, "%s\n", fontnames[1]);
348 for(i=0; i<row->ncol; i++){
350 Bprint(b, "%11.7f", 100.0*(c->r.min.x-row->r.min.x)/Dx(row->r));
356 for(i=0; i<row->ncol; i++){
358 for(j=0; j<c->nw; j++)
359 c->w[j]->body.file->dumpid = 0;
361 m = min(RBUFSIZE, row->tag.file->b.nc);
362 bufread(&row->tag.file->b, 0, r, m);
364 while(n<m && r[n]!='\n')
366 Bprint(b, "w %.*S\n", n, r);
367 for(i=0; i<row->ncol; i++){
369 m = min(RBUFSIZE, c->tag.file->b.nc);
370 bufread(&c->tag.file->b, 0, r, m);
372 while(n<m && r[n]!='\n')
374 Bprint(b, "c%11d %.*S\n", i, n, r);
376 for(i=0; i<row->ncol; i++){
378 for(j=0; j<c->nw; j++){
380 wincommit(w, &w->tag);
382 /* windows owned by others get special treatment */
383 if(w->nopen[QWevent] > 0)
384 if(w->dumpstr == nil)
386 /* zeroxes of external windows are tossed */
387 if(t->file->ntext > 1)
388 for(n=0; n<t->file->ntext; n++){
389 w1 = t->file->text[n]->w;
392 if(w1->nopen[QWevent])
396 if(t->reffont->f != font)
397 fontname = t->reffont->f->name;
399 a = runetobyte(t->file->name, t->file->nname);
404 Bprint(b, "x%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid,
405 w->body.q0, w->body.q1,
406 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
408 }else if(w->dumpstr){
410 Bprint(b, "e%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid,
412 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
414 }else if((w->dirty==FALSE && access(a, 0)==0) || w->isdir){
416 t->file->dumpid = w->id;
417 Bprint(b, "f%11d %11d %11d %11d %11.7f %s\n", i, w->id,
418 w->body.q0, w->body.q1,
419 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
423 t->file->dumpid = w->id;
424 Bprint(b, "F%11d %11d %11d %11d %11.7f %11d %s\n", i, j,
425 w->body.q0, w->body.q1,
426 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
427 w->body.file->b.nc, fontname);
430 winctlprint(w, buf, 0);
431 Bwrite(b, buf, strlen(buf));
432 m = min(RBUFSIZE, w->tag.file->b.nc);
433 bufread(&w->tag.file->b, 0, r, m);
435 while(n<m && r[n]!='\n')
437 Bprint(b, "%.*S\n", n, r);
443 if(n > BUFSIZE/UTFmax)
445 bufread(&t->file->b, q0, r, n);
446 Bprint(b, "%.*S", n, r);
452 Bprint(b, "%s\n%s\n", w->dumpdir, w->dumpstr);
454 Bprint(b, "\n%s\n", w->dumpstr);
470 rdline(Biobuf *b, int *linep)
474 l = Brdline(b, '\n');
481 * Get font names from load file so we don't load fonts we won't use
484 rowloadfonts(char *file)
490 b = Bopen(file, OREAD);
493 /* current directory */
494 l = Brdline(b, '\n');
499 l = Brdline(b, '\n');
502 l[Blinelen(b)-1] = 0;
503 if(*l && strcmp(l, fontnames[i])!=0){
505 fontnames[i] = estrdup(l);
513 rowload(Row *row, char *file, int initing)
515 int i, j, line, y, nr, nfontr, n, ns, ndumped, dumpid, x, fd, done;
518 char *buf, *l, *t, *fontname;
529 warning(nil, "can't find file for load: $home not defined\n");
532 sprint(buf, "%s/acme.dump", home);
535 b = Bopen(file, OREAD);
537 warning(nil, "can't open load file %s: %r\n", file);
540 /* current directory */
542 l = rdline(b, &line);
545 l[Blinelen(b)-1] = 0;
547 warning(nil, "can't chdir %s\n", l);
552 l = rdline(b, &line);
555 l[Blinelen(b)-1] = 0;
556 if(*l && strcmp(l, fontnames[i])!=0)
557 rfget(i, TRUE, i==0 && initing, l);
559 if(initing && row->ncol==0)
560 rowinit(row, screen->clipr);
561 l = rdline(b, &line);
568 percent = atof(l+i*12);
569 if(percent<0 || percent>=100)
571 x = row->r.min.x+percent*Dx(row->r)/100+0.5;
583 if(Dx(r1) < 50 || Dx(r2) < 50)
585 draw(screen, Rpt(r1.min, r2.max), display->white, nil, ZP);
590 draw(screen, r2, display->black, nil, ZP);
597 l = rdline(b, &line);
602 l[Blinelen(b)-1] = 0;
604 r = bytetorune(l+1*12, &nr);
612 textdelete(&row->col[i]->tag, 0, row->col[i]->tag.file->b.nc, TRUE);
613 textinsert(&row->col[i]->tag, 0, r+n+1, nr-(n+1), TRUE);
616 l[Blinelen(b)-1] = 0;
617 r = bytetorune(l+2, &nr);
625 textdelete(&row->tag, 0, row->tag.file->b.nc, TRUE);
626 textinsert(&row->tag, 0, r, nr, TRUE);
637 if(Blinelen(b) < 1+5*12+1)
639 l = rdline(b, &line); /* ctl line; ignored */
642 l = rdline(b, &line); /* directory */
645 l[Blinelen(b)-1] = 0;
648 r = bytetorune("./", &nr);
650 t = emalloc(strlen(home)+1+1);
651 sprint(t, "%s/", home);
652 r = bytetorune(t, &nr);
656 r = bytetorune(l, &nr);
657 l = rdline(b, &line); /* command */
660 t = emalloc(Blinelen(b)+1);
661 memmove(t, l, Blinelen(b));
662 run(nil, t, r, nr, TRUE, nil, nil, FALSE);
663 /* r is freed in run() */
666 if(Blinelen(b) < 1+5*12+1)
672 if(Blinelen(b) < 1+6*12+1)
675 ndumped = atoi(l+1+5*12+1);
678 if(Blinelen(b) < 1+5*12+1)
682 dumpid = atoi(l+1+1*12);
687 l[Blinelen(b)-1] = 0;
691 fontr = bytetorune(fontname, &nfontr);
696 percent = atof(l+1+4*12);
702 y = c->r.min.y+(percent*Dy(c->r))/100+0.5;
703 if(y<c->r.min.y || y>=c->r.max.y)
706 w = coladd(c, nil, nil, y);
708 w = coladd(c, nil, lookid(dumpid, TRUE), y);
712 l = rdline(b, &line);
715 l[Blinelen(b)-1] = 0;
716 r = bytetorune(l+5*12, &nr);
730 textinsert(&w->tag, w->tag.file->b.nc, r+n+1, nr-(n+1), TRUE);
732 /* simplest thing is to put it in a file and load that */
733 sprint(buf, "/tmp/d%d.%.4sacme", getpid(), getuser());
734 fd = create(buf, OWRITE, 0600);
737 warning(nil, "can't create temp file: %r\n");
740 bout = emalloc(sizeof(Biobuf));
741 Binit(bout, fd, OWRITE);
742 for(n=0; n<ndumped; n++){
754 Bputrune(bout, rune);
758 textload(&w->body, 0, buf, 1);
761 w->body.file->mod = TRUE;
762 for(n=0; n<w->body.file->ntext; n++)
763 w->body.file->text[n]->w->dirty = TRUE;
765 }else if(dumpid==0 && r[ns+1]!='+' && r[ns+1]!='-')
766 get(&w->body, nil, nil, FALSE, XXX, nil, 0);
768 fontx(&w->body, nil, nil, 0, 0, fontr, nfontr);
772 if(q0>w->body.file->b.nc || q1>w->body.file->b.nc || q0>q1)
774 textshow(&w->body, q0, q1, 1);
775 w->maxlines = min(w->body.fr.nlines, max(w->maxlines, w->body.fr.maxlines));
777 l = rdline(b, &line);
786 warning(nil, "bad load file %s:%d\n", file, line);
794 allwindows(void (*f)(Window*, void*), void *arg)
799 for(i=0; i<row.ncol; i++){
801 for(j=0; j<c->nw; j++)