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, 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);
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");
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);
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))){
299 for(i=0; i<row->ncol; i++)
300 clean &= colclean(row->col[i]);
305 rowdump(Row *row, char *file)
307 int i, j, fd, m, n, dumped;
310 char *buf, *a, *fontname;
321 warning(nil, "can't find file for dump: $home not defined\n");
324 sprint(buf, "%s/acme.dump", home);
327 fd = create(file, OWRITE, 0600);
329 warning(nil, "can't open %s: %r\n", file);
332 b = emalloc(sizeof(Biobuf));
333 Binit(b, fd, OWRITE);
335 Bprint(b, "%s\n", wdir);
336 Bprint(b, "%s\n", fontnames[0]);
337 Bprint(b, "%s\n", fontnames[1]);
338 for(i=0; i<row->ncol; i++){
340 Bprint(b, "%11d", 100*(c->r.min.x-row->r.min.x)/Dx(row->r));
346 for(i=0; i<row->ncol; i++){
348 for(j=0; j<c->nw; j++)
349 c->w[j]->body.file->dumpid = 0;
351 for(i=0; i<row->ncol; i++){
353 for(j=0; j<c->nw; j++){
355 wincommit(w, &w->tag);
357 /* windows owned by others get special treatment */
358 if(w->nopen[QWevent] > 0)
359 if(w->dumpstr == nil)
361 /* zeroxes of external windows are tossed */
362 if(t->file->ntext > 1)
363 for(n=0; n<t->file->ntext; n++){
364 w1 = t->file->text[n]->w;
367 if(w1->nopen[QWevent])
371 if(t->reffont->f != font)
372 fontname = t->reffont->f->name;
374 a = runetobyte(t->file->name, t->file->nname);
379 Bprint(b, "x%11d %11d %11d %11d %11d %s\n", i, t->file->dumpid,
380 w->body.q0, w->body.q1,
381 100*(w->r.min.y-c->r.min.y)/Dy(c->r),
383 }else if(w->dumpstr){
385 Bprint(b, "e%11d %11d %11d %11d %11d %s\n", i, t->file->dumpid,
387 100*(w->r.min.y-c->r.min.y)/Dy(c->r),
389 }else if((w->dirty==FALSE && access(a, 0)==0) || w->isdir){
391 t->file->dumpid = w->id;
392 Bprint(b, "f%11d %11d %11d %11d %11d %s\n", i, w->id,
393 w->body.q0, w->body.q1,
394 100*(w->r.min.y-c->r.min.y)/Dy(c->r),
398 t->file->dumpid = w->id;
399 Bprint(b, "F%11d %11d %11d %11d %11d %11d %s\n", i, j,
400 w->body.q0, w->body.q1,
401 100*(w->r.min.y-c->r.min.y)/Dy(c->r),
402 w->body.file->b.nc, fontname);
405 winctlprint(w, buf, 0);
406 Bwrite(b, buf, strlen(buf));
407 m = min(RBUFSIZE, w->tag.file->b.nc);
408 bufread(&w->tag.file->b, 0, r, m);
410 while(n<m && r[n]!='\n')
413 Bprint(b, "%.*S", n, r);
419 if(n > BUFSIZE/UTFmax)
421 bufread(&t->file->b, q0, r, n);
422 Bprint(b, "%.*S", n, r);
428 Bprint(b, "%s\n%s\n", w->dumpdir, w->dumpstr);
430 Bprint(b, "\n%s\n", w->dumpstr);
446 rdline(Biobuf *b, int *linep)
450 l = Brdline(b, '\n');
457 * Get font names from load file so we don't load fonts we won't use
460 rowloadfonts(char *file)
466 b = Bopen(file, OREAD);
469 /* current directory */
470 l = Brdline(b, '\n');
475 l = Brdline(b, '\n');
478 l[Blinelen(b)-1] = 0;
479 if(*l && strcmp(l, fontnames[i])!=0)
480 fontnames[i] = estrdup(l);
487 rowload(Row *row, char *file, int initing)
489 int i, j, line, percent, y, nr, nfontr, n, ns, ndumped, dumpid, x, fd;
491 char *buf, *l, *t, *fontname;
492 Rune *r, rune, *fontr;
501 warning(nil, "can't find file for load: $home not defined\n");
504 sprint(buf, "%s/acme.dump", home);
507 b = Bopen(file, OREAD);
509 warning(nil, "can't open load file %s: %r\n", file);
512 /* current directory */
514 l = rdline(b, &line);
517 l[Blinelen(b)-1] = 0;
519 warning(nil, "can't chdir %s\n", l);
524 l = rdline(b, &line);
527 l[Blinelen(b)-1] = 0;
528 if(*l && strcmp(l, fontnames[i])!=0)
529 rfget(i, TRUE, i==0 && initing, estrdup(l));
531 if(initing && row->ncol==0)
532 rowinit(row, screen->clipr);
533 l = rdline(b, &line);
540 percent = atoi(l+i*12);
541 if(percent<0 || percent>=100)
543 x = row->r.min.x+percent*Dx(row->r)/100;
553 if(Dx(r1) < 50 || Dx(r2) < 50)
555 draw(screen, Rpt(r1.min, r2.max), display->white, nil, ZP);
560 draw(screen, r2, display->black, nil, ZP);
566 l = rdline(b, &line);
572 if(Blinelen(b) < 1+5*12+1)
574 l = rdline(b, &line); /* ctl line; ignored */
577 l = rdline(b, &line); /* directory */
580 l[Blinelen(b)-1] = 0;
583 r = bytetorune("./", &nr);
585 t = emalloc(strlen(home)+1+1);
586 sprint(t, "%s/", home);
587 r = bytetorune(t, &nr);
591 r = bytetorune(l, &nr);
592 l = rdline(b, &line); /* command */
595 t = emalloc(Blinelen(b)+1);
596 memmove(t, l, Blinelen(b));
597 run(nil, t, r, nr, TRUE, nil, nil, FALSE);
598 /* r is freed in run() */
601 if(Blinelen(b) < 1+5*12+1)
607 if(Blinelen(b) < 1+6*12+1)
610 ndumped = atoi(l+1+5*12+1);
613 if(Blinelen(b) < 1+5*12+1)
617 dumpid = atoi(l+1+1*12);
622 l[Blinelen(b)-1] = 0;
626 fontr = bytetorune(fontname, &nfontr);
631 percent = atoi(l+1+4*12);
637 y = c->r.min.y+(percent*Dy(c->r))/100;
638 if(y<c->r.min.y || y>=c->r.max.y)
641 w = coladd(c, nil, nil, y);
643 w = coladd(c, nil, lookid(dumpid, TRUE), y);
647 l = rdline(b, &line);
650 l[Blinelen(b)-1] = 0;
651 r = bytetorune(l+5*12, &nr);
665 textinsert(&w->tag, w->tag.file->b.nc, r+n+1, nr-(n+1), TRUE);
667 /* simplest thing is to put it in a file and load that */
668 sprint(buf, "/tmp/d%d.%.4sacme", getpid(), getuser());
669 fd = create(buf, OWRITE|ORCLOSE, 0600);
672 warning(nil, "can't create temp file: %r\n");
675 bout = emalloc(sizeof(Biobuf));
676 Binit(bout, fd, OWRITE);
677 for(n=0; n<ndumped; n++){
681 if(rune == (Rune)Beof){
688 Bputrune(bout, rune);
692 textload(&w->body, 0, buf, 1);
694 w->body.file->mod = TRUE;
695 for(n=0; n<w->body.file->ntext; n++)
696 w->body.file->text[n]->w->dirty = TRUE;
698 }else if(dumpid==0 && r[ns+1]!='+' && r[ns+1]!='-')
699 get(&w->body, nil, nil, FALSE, XXX, nil, 0);
702 fontx(&w->body, nil, nil, 0, 0, fontr, nfontr);
705 if(q0>w->body.file->b.nc || q1>w->body.file->b.nc || q0>q1)
707 textshow(&w->body, q0, q1, 1);
708 w->maxlines = min(w->body.fr.nlines, max(w->maxlines, w->body.fr.maxlines));
717 warning(nil, "bad load file %s:%d\n", file, line);
723 allwindows(void (*f)(Window*, void*), void *arg)
728 for(i=0; i<row.ncol; i++){
730 for(j=0; j<c->nw; j++)