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");
220 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)
277 t = rowwhich(row, p);
278 if(t!=nil && !(t->what==Tag && ptinrect(p, t->scrollr))){
286 * TAG If we typed in the tag, might need to make it
287 * bigger to show text. \n causes tag to expand.
290 t->w->tagsafe = FALSE;
292 t->w->tagexpand = TRUE;
293 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 for(i=0; i<row->ncol; i++){
364 for(j=0; j<c->nw; j++){
366 wincommit(w, &w->tag);
368 /* windows owned by others get special treatment */
369 if(w->nopen[QWevent] > 0)
370 if(w->dumpstr == nil)
372 /* zeroxes of external windows are tossed */
373 if(t->file->ntext > 1)
374 for(n=0; n<t->file->ntext; n++){
375 w1 = t->file->text[n]->w;
378 if(w1->nopen[QWevent])
382 if(t->reffont->f != font)
383 fontname = t->reffont->f->name;
385 a = runetobyte(t->file->name, t->file->nname);
390 Bprint(b, "x%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid,
391 w->body.q0, w->body.q1,
392 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
394 }else if(w->dumpstr){
396 Bprint(b, "e%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid,
398 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
400 }else if((w->dirty==FALSE && access(a, 0)==0) || w->isdir){
402 t->file->dumpid = w->id;
403 Bprint(b, "f%11d %11d %11d %11d %11.7f %s\n", i, w->id,
404 w->body.q0, w->body.q1,
405 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
409 t->file->dumpid = w->id;
410 Bprint(b, "F%11d %11d %11d %11d %11.7f %11d %s\n", i, j,
411 w->body.q0, w->body.q1,
412 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
413 w->body.file->b.nc, fontname);
416 winctlprint(w, buf, 0);
417 Bwrite(b, buf, strlen(buf));
418 m = min(RBUFSIZE, w->tag.file->b.nc);
419 bufread(&w->tag.file->b, 0, r, m);
420 if(dodollarsigns && r[0] == '$'){
422 expandenv(&rp, (uint*)&m);
426 while(n<m && rp[n]!='\n')
428 Bprint(b, "%.*S\n", n, rp);
436 if(n > BUFSIZE/UTFmax)
438 bufread(&t->file->b, q0, r, n);
439 Bprint(b, "%.*S", n, r);
445 Bprint(b, "%s\n%s\n", w->dumpdir, w->dumpstr);
447 Bprint(b, "\n%s\n", w->dumpstr);
463 rdline(Biobuf *b, int *linep)
467 l = Brdline(b, '\n');
474 * Get font names from load file so we don't load fonts we won't use
477 rowloadfonts(char *file)
483 b = Bopen(file, OREAD);
486 /* current directory */
487 l = Brdline(b, '\n');
492 l = Brdline(b, '\n');
495 l[Blinelen(b)-1] = 0;
496 if(*l && strcmp(l, fontnames[i])!=0){
498 fontnames[i] = estrdup(l);
506 rowload(Row *row, char *file, int initing)
508 int i, j, line, y, nr, nfontr, n, ns, ndumped, dumpid, x, fd;
511 char *buf, *l, *t, *fontname;
512 Rune *r, rune, *fontr;
521 warning(nil, "can't find file for load: $home not defined\n");
524 sprint(buf, "%s/acme.dump", home);
527 b = Bopen(file, OREAD);
529 warning(nil, "can't open load file %s: %r\n", file);
532 /* current directory */
534 l = rdline(b, &line);
537 l[Blinelen(b)-1] = 0;
539 warning(nil, "can't chdir %s\n", l);
544 l = rdline(b, &line);
547 l[Blinelen(b)-1] = 0;
548 if(*l && strcmp(l, fontnames[i])!=0)
549 rfget(i, TRUE, i==0 && initing, l);
551 if(initing && row->ncol==0)
552 rowinit(row, screen->clipr);
553 l = rdline(b, &line);
560 percent = atof(l+i*12);
561 if(percent<0 || percent>=100)
563 x = row->r.min.x+percent*Dx(row->r)/100+0.5;
575 if(Dx(r1) < 50 || Dx(r2) < 50)
577 draw(screen, Rpt(r1.min, r2.max), display->white, nil, ZP);
582 draw(screen, r2, display->black, nil, ZP);
588 l = rdline(b, &line);
594 if(Blinelen(b) < 1+5*12+1)
596 l = rdline(b, &line); /* ctl line; ignored */
599 l = rdline(b, &line); /* directory */
602 l[Blinelen(b)-1] = 0;
605 r = bytetorune("./", &nr);
607 t = emalloc(strlen(home)+1+1);
608 sprint(t, "%s/", home);
609 r = bytetorune(t, &nr);
613 r = bytetorune(l, &nr);
614 l = rdline(b, &line); /* command */
617 t = emalloc(Blinelen(b)+1);
618 memmove(t, l, Blinelen(b));
619 run(nil, t, r, nr, TRUE, nil, nil, FALSE);
620 /* r is freed in run() */
623 if(Blinelen(b) < 1+5*12+1)
629 if(Blinelen(b) < 1+6*12+1)
632 ndumped = atoi(l+1+5*12+1);
635 if(Blinelen(b) < 1+5*12+1)
639 dumpid = atoi(l+1+1*12);
644 l[Blinelen(b)-1] = 0;
648 fontr = bytetorune(fontname, &nfontr);
653 percent = atof(l+1+4*12);
659 y = c->r.min.y+(percent*Dy(c->r))/100+0.5;
660 if(y<c->r.min.y || y>=c->r.max.y)
663 w = coladd(c, nil, nil, y);
665 w = coladd(c, nil, lookid(dumpid, TRUE), y);
669 l = rdline(b, &line);
672 l[Blinelen(b)-1] = 0;
673 r = bytetorune(l+5*12, &nr);
687 textinsert(&w->tag, w->tag.file->b.nc, r+n+1, nr-(n+1), TRUE);
689 /* simplest thing is to put it in a file and load that */
690 sprint(buf, "/tmp/d%d.%.4sacme", getpid(), getuser());
691 fd = create(buf, OWRITE, 0600);
694 warning(nil, "can't create temp file: %r\n");
697 bout = emalloc(sizeof(Biobuf));
698 Binit(bout, fd, OWRITE);
699 for(n=0; n<ndumped; n++){
703 if(rune == (Rune)Beof){
710 Bputrune(bout, rune);
714 textload(&w->body, 0, buf, 1);
717 w->body.file->mod = TRUE;
718 for(n=0; n<w->body.file->ntext; n++)
719 w->body.file->text[n]->w->dirty = TRUE;
721 }else if(dumpid==0 && r[ns+1]!='+' && r[ns+1]!='-')
722 get(&w->body, nil, nil, FALSE, XXX, nil, 0);
724 fontx(&w->body, nil, nil, 0, 0, fontr, nfontr);
728 if(q0>w->body.file->b.nc || q1>w->body.file->b.nc || q0>q1)
730 textshow(&w->body, q0, q1, 1);
731 w->maxlines = min(w->body.fr.nlines, max(w->maxlines, w->body.fr.maxlines));
739 warning(nil, "bad load file %s:%d\n", file, line);
747 allwindows(void (*f)(Window*, void*), void *arg)
752 for(i=0; i<row.ncol; i++){
754 for(j=0; j<c->nw; j++)