1 b3994ec5 2003-12-11 devnull #include <u.h>
2 b3994ec5 2003-12-11 devnull #include <libc.h>
3 b3994ec5 2003-12-11 devnull #include <draw.h>
4 b3994ec5 2003-12-11 devnull #include <thread.h>
5 b3994ec5 2003-12-11 devnull #include <cursor.h>
6 b3994ec5 2003-12-11 devnull #include <mouse.h>
7 b3994ec5 2003-12-11 devnull #include <keyboard.h>
8 b3994ec5 2003-12-11 devnull #include <frame.h>
9 b3994ec5 2003-12-11 devnull #include <fcall.h>
10 b3994ec5 2003-12-11 devnull #include <bio.h>
11 b3994ec5 2003-12-11 devnull #include <plumb.h>
12 b3994ec5 2003-12-11 devnull #include "dat.h"
13 b3994ec5 2003-12-11 devnull #include "fns.h"
15 b3994ec5 2003-12-11 devnull static Rune Lcolhdr[] = {
16 b3994ec5 2003-12-11 devnull 'N', 'e', 'w', 'c', 'o', 'l', ' ',
17 b3994ec5 2003-12-11 devnull 'K', 'i', 'l', 'l', ' ',
18 b3994ec5 2003-12-11 devnull 'P', 'u', 't', 'a', 'l', 'l', ' ',
19 b3994ec5 2003-12-11 devnull 'D', 'u', 'm', 'p', ' ',
20 b3994ec5 2003-12-11 devnull 'E', 'x', 'i', 't', ' ',
25 b3994ec5 2003-12-11 devnull rowinit(Row *row, Rectangle r)
27 b3994ec5 2003-12-11 devnull Rectangle r1;
30 b3994ec5 2003-12-11 devnull draw(screen, r, display->white, nil, ZP);
31 b3994ec5 2003-12-11 devnull row->r = r;
32 b3994ec5 2003-12-11 devnull row->col = nil;
33 b3994ec5 2003-12-11 devnull row->ncol = 0;
35 b3994ec5 2003-12-11 devnull r1.max.y = r1.min.y + font->height;
36 b3994ec5 2003-12-11 devnull t = &row->tag;
37 b3994ec5 2003-12-11 devnull textinit(t, fileaddtext(nil, t), r1, rfget(FALSE, FALSE, FALSE, nil), tagcols);
38 b3994ec5 2003-12-11 devnull t->what = Rowtag;
39 b3994ec5 2003-12-11 devnull t->row = row;
40 b3994ec5 2003-12-11 devnull t->w = nil;
41 b3994ec5 2003-12-11 devnull t->col = nil;
42 b3994ec5 2003-12-11 devnull r1.min.y = r1.max.y;
43 b3994ec5 2003-12-11 devnull r1.max.y += Border;
44 b3994ec5 2003-12-11 devnull draw(screen, r1, display->black, nil, ZP);
45 b3994ec5 2003-12-11 devnull textinsert(t, 0, Lcolhdr, 29, TRUE);
46 b3994ec5 2003-12-11 devnull textsetselect(t, t->file->b.nc, t->file->b.nc);
50 b3994ec5 2003-12-11 devnull rowadd(Row *row, Column *c, int x)
52 b3994ec5 2003-12-11 devnull Rectangle r, r1;
53 b3994ec5 2003-12-11 devnull Column *d;
57 b3994ec5 2003-12-11 devnull r = row->r;
58 b3994ec5 2003-12-11 devnull r.min.y = row->tag.fr.r.max.y+Border;
59 b3994ec5 2003-12-11 devnull if(x<r.min.x && row->ncol>0){ /*steal 40% of last column by default */
60 b3994ec5 2003-12-11 devnull d = row->col[row->ncol-1];
61 b3994ec5 2003-12-11 devnull x = d->r.min.x + 3*Dx(d->r)/5;
63 b3994ec5 2003-12-11 devnull /* look for column we'll land on */
64 b3994ec5 2003-12-11 devnull for(i=0; i<row->ncol; i++){
65 b3994ec5 2003-12-11 devnull d = row->col[i];
66 b3994ec5 2003-12-11 devnull if(x < d->r.max.x)
69 b3994ec5 2003-12-11 devnull if(row->ncol > 0){
70 b3994ec5 2003-12-11 devnull if(i < row->ncol)
71 b3994ec5 2003-12-11 devnull i++; /* new column will go after d */
72 b3994ec5 2003-12-11 devnull r = d->r;
73 b3994ec5 2003-12-11 devnull if(Dx(r) < 100)
74 b3994ec5 2003-12-11 devnull return nil;
75 b3994ec5 2003-12-11 devnull draw(screen, r, display->white, nil, ZP);
77 b3994ec5 2003-12-11 devnull r1.max.x = min(x, r.max.x-50);
78 b3994ec5 2003-12-11 devnull if(Dx(r1) < 50)
79 b3994ec5 2003-12-11 devnull r1.max.x = r1.min.x+50;
80 b3994ec5 2003-12-11 devnull colresize(d, r1);
81 b3994ec5 2003-12-11 devnull r1.min.x = r1.max.x;
82 b3994ec5 2003-12-11 devnull r1.max.x = r1.min.x+Border;
83 b3994ec5 2003-12-11 devnull draw(screen, r1, display->black, nil, ZP);
84 b3994ec5 2003-12-11 devnull r.min.x = r1.max.x;
86 b3994ec5 2003-12-11 devnull if(c == nil){
87 b3994ec5 2003-12-11 devnull c = emalloc(sizeof(Column));
88 b3994ec5 2003-12-11 devnull colinit(c, r);
89 b3994ec5 2003-12-11 devnull incref(&reffont.ref);
91 b3994ec5 2003-12-11 devnull colresize(c, r);
92 b3994ec5 2003-12-11 devnull c->row = row;
93 b3994ec5 2003-12-11 devnull c->tag.row = row;
94 b3994ec5 2003-12-11 devnull row->col = realloc(row->col, (row->ncol+1)*sizeof(Column*));
95 b3994ec5 2003-12-11 devnull memmove(row->col+i+1, row->col+i, (row->ncol-i)*sizeof(Column*));
96 b3994ec5 2003-12-11 devnull row->col[i] = c;
97 b3994ec5 2003-12-11 devnull row->ncol++;
98 b3994ec5 2003-12-11 devnull clearmouse();
99 b3994ec5 2003-12-11 devnull return c;
103 b3994ec5 2003-12-11 devnull rowresize(Row *row, Rectangle r)
105 b3994ec5 2003-12-11 devnull int i, dx, odx;
106 b3994ec5 2003-12-11 devnull Rectangle r1, r2;
107 b3994ec5 2003-12-11 devnull Column *c;
109 b3994ec5 2003-12-11 devnull dx = Dx(r);
110 b3994ec5 2003-12-11 devnull odx = Dx(row->r);
111 b3994ec5 2003-12-11 devnull row->r = r;
113 b3994ec5 2003-12-11 devnull r1.max.y = r1.min.y + font->height;
114 b3994ec5 2003-12-11 devnull textresize(&row->tag, r1);
115 b3994ec5 2003-12-11 devnull r1.min.y = r1.max.y;
116 b3994ec5 2003-12-11 devnull r1.max.y += Border;
117 b3994ec5 2003-12-11 devnull draw(screen, r1, display->black, nil, ZP);
118 b3994ec5 2003-12-11 devnull r.min.y = r1.max.y;
120 b3994ec5 2003-12-11 devnull r1.max.x = r1.min.x;
121 b3994ec5 2003-12-11 devnull for(i=0; i<row->ncol; i++){
122 b3994ec5 2003-12-11 devnull c = row->col[i];
123 b3994ec5 2003-12-11 devnull r1.min.x = r1.max.x;
124 b3994ec5 2003-12-11 devnull if(i == row->ncol-1)
125 b3994ec5 2003-12-11 devnull r1.max.x = r.max.x;
127 b3994ec5 2003-12-11 devnull r1.max.x = r1.min.x+Dx(c->r)*dx/odx;
128 b3994ec5 2003-12-11 devnull if(i > 0){
129 b3994ec5 2003-12-11 devnull r2 = r1;
130 b3994ec5 2003-12-11 devnull r2.max.x = r2.min.x+Border;
131 b3994ec5 2003-12-11 devnull draw(screen, r2, display->black, nil, ZP);
132 b3994ec5 2003-12-11 devnull r1.min.x = r2.max.x;
134 b3994ec5 2003-12-11 devnull colresize(c, r1);
139 b3994ec5 2003-12-11 devnull rowdragcol(Row *row, Column *c, int _0)
141 b3994ec5 2003-12-11 devnull Rectangle r;
142 b3994ec5 2003-12-11 devnull int i, b, x;
143 b3994ec5 2003-12-11 devnull Point p, op;
144 b3994ec5 2003-12-11 devnull Column *d;
146 b3994ec5 2003-12-11 devnull USED(_0);
148 b3994ec5 2003-12-11 devnull clearmouse();
149 b3994ec5 2003-12-11 devnull setcursor(mousectl, &boxcursor);
150 b3994ec5 2003-12-11 devnull b = mouse->buttons;
151 b3994ec5 2003-12-11 devnull op = mouse->xy;
152 b3994ec5 2003-12-11 devnull while(mouse->buttons == b)
153 b3994ec5 2003-12-11 devnull readmouse(mousectl);
154 b3994ec5 2003-12-11 devnull setcursor(mousectl, nil);
155 b3994ec5 2003-12-11 devnull if(mouse->buttons){
156 b3994ec5 2003-12-11 devnull while(mouse->buttons)
157 b3994ec5 2003-12-11 devnull readmouse(mousectl);
161 b3994ec5 2003-12-11 devnull for(i=0; i<row->ncol; i++)
162 b3994ec5 2003-12-11 devnull if(row->col[i] == c)
163 b3994ec5 2003-12-11 devnull goto Found;
164 b3994ec5 2003-12-11 devnull error("can't find column");
167 b3994ec5 2003-12-11 devnull if(i == 0)
169 b3994ec5 2003-12-11 devnull p = mouse->xy;
170 b3994ec5 2003-12-11 devnull if((abs(p.x-op.x)<5 && abs(p.y-op.y)<5))
172 b3994ec5 2003-12-11 devnull if((i>0 && p.x<row->col[i-1]->r.min.x) || (i<row->ncol-1 && p.x>c->r.max.x)){
173 b3994ec5 2003-12-11 devnull /* shuffle */
174 b3994ec5 2003-12-11 devnull x = c->r.min.x;
175 b3994ec5 2003-12-11 devnull rowclose(row, c, FALSE);
176 b3994ec5 2003-12-11 devnull if(rowadd(row, c, p.x) == nil) /* whoops! */
177 b3994ec5 2003-12-11 devnull if(rowadd(row, c, x) == nil) /* WHOOPS! */
178 b3994ec5 2003-12-11 devnull if(rowadd(row, c, -1)==nil){ /* shit! */
179 b3994ec5 2003-12-11 devnull rowclose(row, c, TRUE);
182 b3994ec5 2003-12-11 devnull colmousebut(c);
185 b3994ec5 2003-12-11 devnull d = row->col[i-1];
186 b3994ec5 2003-12-11 devnull if(p.x < d->r.min.x+80+Scrollwid)
187 b3994ec5 2003-12-11 devnull p.x = d->r.min.x+80+Scrollwid;
188 b3994ec5 2003-12-11 devnull if(p.x > c->r.max.x-80-Scrollwid)
189 b3994ec5 2003-12-11 devnull p.x = c->r.max.x-80-Scrollwid;
190 b3994ec5 2003-12-11 devnull r = d->r;
191 b3994ec5 2003-12-11 devnull r.max.x = c->r.max.x;
192 b3994ec5 2003-12-11 devnull draw(screen, r, display->white, nil, ZP);
193 b3994ec5 2003-12-11 devnull r.max.x = p.x;
194 b3994ec5 2003-12-11 devnull colresize(d, r);
195 b3994ec5 2003-12-11 devnull r = c->r;
196 b3994ec5 2003-12-11 devnull r.min.x = p.x;
197 b3994ec5 2003-12-11 devnull r.max.x = r.min.x;
198 b3994ec5 2003-12-11 devnull r.max.x += Border;
199 b3994ec5 2003-12-11 devnull draw(screen, r, display->black, nil, ZP);
200 b3994ec5 2003-12-11 devnull r.min.x = r.max.x;
201 b3994ec5 2003-12-11 devnull r.max.x = c->r.max.x;
202 b3994ec5 2003-12-11 devnull colresize(c, r);
203 b3994ec5 2003-12-11 devnull colmousebut(c);
207 b3994ec5 2003-12-11 devnull rowclose(Row *row, Column *c, int dofree)
209 b3994ec5 2003-12-11 devnull Rectangle r;
212 b3994ec5 2003-12-11 devnull for(i=0; i<row->ncol; i++)
213 b3994ec5 2003-12-11 devnull if(row->col[i] == c)
214 b3994ec5 2003-12-11 devnull goto Found;
215 b3994ec5 2003-12-11 devnull error("can't find column");
217 b3994ec5 2003-12-11 devnull r = c->r;
218 b3994ec5 2003-12-11 devnull if(dofree)
219 b3994ec5 2003-12-11 devnull colcloseall(c);
220 b3994ec5 2003-12-11 devnull memmove(row->col+i, row->col+i+1, (row->ncol-i)*sizeof(Column*));
221 b3994ec5 2003-12-11 devnull row->ncol--;
222 b3994ec5 2003-12-11 devnull row->col = realloc(row->col, row->ncol*sizeof(Column*));
223 b3994ec5 2003-12-11 devnull if(row->ncol == 0){
224 b3994ec5 2003-12-11 devnull draw(screen, r, display->white, nil, ZP);
227 b3994ec5 2003-12-11 devnull if(i == row->ncol){ /* extend last column right */
228 b3994ec5 2003-12-11 devnull c = row->col[i-1];
229 b3994ec5 2003-12-11 devnull r.min.x = c->r.min.x;
230 b3994ec5 2003-12-11 devnull r.max.x = row->r.max.x;
231 b3994ec5 2003-12-11 devnull }else{ /* extend next window left */
232 b3994ec5 2003-12-11 devnull c = row->col[i];
233 b3994ec5 2003-12-11 devnull r.max.x = c->r.max.x;
235 b3994ec5 2003-12-11 devnull draw(screen, r, display->white, nil, ZP);
236 b3994ec5 2003-12-11 devnull colresize(c, r);
240 b3994ec5 2003-12-11 devnull rowwhichcol(Row *row, Point p)
243 b3994ec5 2003-12-11 devnull Column *c;
245 b3994ec5 2003-12-11 devnull for(i=0; i<row->ncol; i++){
246 b3994ec5 2003-12-11 devnull c = row->col[i];
247 b3994ec5 2003-12-11 devnull if(ptinrect(p, c->r))
248 b3994ec5 2003-12-11 devnull return c;
250 b3994ec5 2003-12-11 devnull return nil;
254 b3994ec5 2003-12-11 devnull rowwhich(Row *row, Point p)
256 b3994ec5 2003-12-11 devnull Column *c;
258 b3994ec5 2003-12-11 devnull if(ptinrect(p, row->tag.all))
259 b3994ec5 2003-12-11 devnull return &row->tag;
260 b3994ec5 2003-12-11 devnull c = rowwhichcol(row, p);
262 b3994ec5 2003-12-11 devnull return colwhich(c, p);
263 b3994ec5 2003-12-11 devnull return nil;
267 b3994ec5 2003-12-11 devnull rowtype(Row *row, Rune r, Point p)
269 b3994ec5 2003-12-11 devnull Window *w;
270 b3994ec5 2003-12-11 devnull Text *t;
272 b3994ec5 2003-12-11 devnull clearmouse();
273 b3994ec5 2003-12-11 devnull qlock(&row->lk);
274 b3994ec5 2003-12-11 devnull if(bartflag)
275 b3994ec5 2003-12-11 devnull t = barttext;
277 b3994ec5 2003-12-11 devnull t = rowwhich(row, p);
278 b3994ec5 2003-12-11 devnull if(t!=nil && !(t->what==Tag && ptinrect(p, t->scrollr))){
279 b3994ec5 2003-12-11 devnull w = t->w;
280 b3994ec5 2003-12-11 devnull if(w == nil)
281 b3994ec5 2003-12-11 devnull texttype(t, r);
283 b3994ec5 2003-12-11 devnull winlock(w, 'K');
284 b3994ec5 2003-12-11 devnull wintype(w, t, r);
285 b3994ec5 2003-12-11 devnull winunlock(w);
288 b3994ec5 2003-12-11 devnull qunlock(&row->lk);
289 b3994ec5 2003-12-11 devnull return t;
293 b3994ec5 2003-12-11 devnull rowclean(Row *row)
295 b3994ec5 2003-12-11 devnull int clean;
298 b3994ec5 2003-12-11 devnull clean = TRUE;
299 b3994ec5 2003-12-11 devnull for(i=0; i<row->ncol; i++)
300 b3994ec5 2003-12-11 devnull clean &= colclean(row->col[i]);
301 b3994ec5 2003-12-11 devnull return clean;
305 b3994ec5 2003-12-11 devnull rowdump(Row *row, char *file)
307 b3994ec5 2003-12-11 devnull int i, j, fd, m, n, dumped;
308 b3994ec5 2003-12-11 devnull uint q0, q1;
309 b3994ec5 2003-12-11 devnull Biobuf *b;
310 b3994ec5 2003-12-11 devnull char *buf, *a, *fontname;
311 b3994ec5 2003-12-11 devnull Rune *r;
312 b3994ec5 2003-12-11 devnull Column *c;
313 b3994ec5 2003-12-11 devnull Window *w, *w1;
314 b3994ec5 2003-12-11 devnull Text *t;
316 b3994ec5 2003-12-11 devnull if(row->ncol == 0)
318 b3994ec5 2003-12-11 devnull buf = fbufalloc();
319 b3994ec5 2003-12-11 devnull if(file == nil){
320 b3994ec5 2003-12-11 devnull if(home == nil){
321 b3994ec5 2003-12-11 devnull warning(nil, "can't find file for dump: $home not defined\n");
322 b3994ec5 2003-12-11 devnull goto Rescue;
324 b3994ec5 2003-12-11 devnull sprint(buf, "%s/acme.dump", home);
325 b3994ec5 2003-12-11 devnull file = buf;
327 b3994ec5 2003-12-11 devnull fd = create(file, OWRITE, 0600);
328 b3994ec5 2003-12-11 devnull if(fd < 0){
329 b3994ec5 2003-12-11 devnull warning(nil, "can't open %s: %r\n", file);
330 b3994ec5 2003-12-11 devnull goto Rescue;
332 b3994ec5 2003-12-11 devnull b = emalloc(sizeof(Biobuf));
333 b3994ec5 2003-12-11 devnull Binit(b, fd, OWRITE);
334 b3994ec5 2003-12-11 devnull r = fbufalloc();
335 b3994ec5 2003-12-11 devnull Bprint(b, "%s\n", wdir);
336 b3994ec5 2003-12-11 devnull Bprint(b, "%s\n", fontnames[0]);
337 b3994ec5 2003-12-11 devnull Bprint(b, "%s\n", fontnames[1]);
338 b3994ec5 2003-12-11 devnull for(i=0; i<row->ncol; i++){
339 b3994ec5 2003-12-11 devnull c = row->col[i];
340 0fdffa38 2005-01-14 devnull Bprint(b, "%11.7f", 100.0*(c->r.min.x-row->r.min.x)/Dx(row->r));
341 b3994ec5 2003-12-11 devnull if(i == row->ncol-1)
342 b3994ec5 2003-12-11 devnull Bputc(b, '\n');
344 b3994ec5 2003-12-11 devnull Bputc(b, ' ');
346 b3994ec5 2003-12-11 devnull for(i=0; i<row->ncol; i++){
347 b3994ec5 2003-12-11 devnull c = row->col[i];
348 b3994ec5 2003-12-11 devnull for(j=0; j<c->nw; j++)
349 b3994ec5 2003-12-11 devnull c->w[j]->body.file->dumpid = 0;
351 b3994ec5 2003-12-11 devnull for(i=0; i<row->ncol; i++){
352 b3994ec5 2003-12-11 devnull c = row->col[i];
353 b3994ec5 2003-12-11 devnull for(j=0; j<c->nw; j++){
354 b3994ec5 2003-12-11 devnull w = c->w[j];
355 b3994ec5 2003-12-11 devnull wincommit(w, &w->tag);
356 b3994ec5 2003-12-11 devnull t = &w->body;
357 b3994ec5 2003-12-11 devnull /* windows owned by others get special treatment */
358 b3994ec5 2003-12-11 devnull if(w->nopen[QWevent] > 0)
359 b3994ec5 2003-12-11 devnull if(w->dumpstr == nil)
360 b3994ec5 2003-12-11 devnull continue;
361 b3994ec5 2003-12-11 devnull /* zeroxes of external windows are tossed */
362 b3994ec5 2003-12-11 devnull if(t->file->ntext > 1)
363 b3994ec5 2003-12-11 devnull for(n=0; n<t->file->ntext; n++){
364 b3994ec5 2003-12-11 devnull w1 = t->file->text[n]->w;
365 b3994ec5 2003-12-11 devnull if(w == w1)
366 b3994ec5 2003-12-11 devnull continue;
367 b3994ec5 2003-12-11 devnull if(w1->nopen[QWevent])
368 b3994ec5 2003-12-11 devnull goto Continue2;
370 b3994ec5 2003-12-11 devnull fontname = "";
371 b3994ec5 2003-12-11 devnull if(t->reffont->f != font)
372 b3994ec5 2003-12-11 devnull fontname = t->reffont->f->name;
373 b3994ec5 2003-12-11 devnull if(t->file->nname)
374 b3994ec5 2003-12-11 devnull a = runetobyte(t->file->name, t->file->nname);
376 b3994ec5 2003-12-11 devnull a = emalloc(1);
377 b3994ec5 2003-12-11 devnull if(t->file->dumpid){
378 b3994ec5 2003-12-11 devnull dumped = FALSE;
379 0fdffa38 2005-01-14 devnull Bprint(b, "x%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid,
380 b3994ec5 2003-12-11 devnull w->body.q0, w->body.q1,
381 78e51a8c 2005-01-14 devnull 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
382 b3994ec5 2003-12-11 devnull fontname);
383 b3994ec5 2003-12-11 devnull }else if(w->dumpstr){
384 b3994ec5 2003-12-11 devnull dumped = FALSE;
385 0fdffa38 2005-01-14 devnull Bprint(b, "e%11d %11d %11d %11d %11.7f %s\n", i, t->file->dumpid,
387 78e51a8c 2005-01-14 devnull 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
388 b3994ec5 2003-12-11 devnull fontname);
389 b3994ec5 2003-12-11 devnull }else if((w->dirty==FALSE && access(a, 0)==0) || w->isdir){
390 b3994ec5 2003-12-11 devnull dumped = FALSE;
391 b3994ec5 2003-12-11 devnull t->file->dumpid = w->id;
392 0fdffa38 2005-01-14 devnull Bprint(b, "f%11d %11d %11d %11d %11.7f %s\n", i, w->id,
393 b3994ec5 2003-12-11 devnull w->body.q0, w->body.q1,
394 78e51a8c 2005-01-14 devnull 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
395 b3994ec5 2003-12-11 devnull fontname);
397 b3994ec5 2003-12-11 devnull dumped = TRUE;
398 b3994ec5 2003-12-11 devnull t->file->dumpid = w->id;
399 0fdffa38 2005-01-14 devnull Bprint(b, "F%11d %11d %11d %11d %11d %11.7f %s\n", i, j,
400 b3994ec5 2003-12-11 devnull w->body.q0, w->body.q1,
401 78e51a8c 2005-01-14 devnull 100.0*(w->r.min.y-c->r.min.y)/Dy(c->r),
402 b3994ec5 2003-12-11 devnull w->body.file->b.nc, fontname);
404 b3994ec5 2003-12-11 devnull free(a);
405 b3994ec5 2003-12-11 devnull winctlprint(w, buf, 0);
406 b3994ec5 2003-12-11 devnull Bwrite(b, buf, strlen(buf));
407 b3994ec5 2003-12-11 devnull m = min(RBUFSIZE, w->tag.file->b.nc);
408 b3994ec5 2003-12-11 devnull bufread(&w->tag.file->b, 0, r, m);
410 b3994ec5 2003-12-11 devnull while(n<m && r[n]!='\n')
412 b3994ec5 2003-12-11 devnull r[n++] = '\n';
413 b3994ec5 2003-12-11 devnull Bprint(b, "%.*S", n, r);
414 b3994ec5 2003-12-11 devnull if(dumped){
416 b3994ec5 2003-12-11 devnull q1 = t->file->b.nc;
417 b3994ec5 2003-12-11 devnull while(q0 < q1){
418 b3994ec5 2003-12-11 devnull n = q1 - q0;
419 b3994ec5 2003-12-11 devnull if(n > BUFSIZE/UTFmax)
420 b3994ec5 2003-12-11 devnull n = BUFSIZE/UTFmax;
421 b3994ec5 2003-12-11 devnull bufread(&t->file->b, q0, r, n);
422 b3994ec5 2003-12-11 devnull Bprint(b, "%.*S", n, r);
423 b3994ec5 2003-12-11 devnull q0 += n;
426 b3994ec5 2003-12-11 devnull if(w->dumpstr){
427 b3994ec5 2003-12-11 devnull if(w->dumpdir)
428 b3994ec5 2003-12-11 devnull Bprint(b, "%s\n%s\n", w->dumpdir, w->dumpstr);
430 b3994ec5 2003-12-11 devnull Bprint(b, "\n%s\n", w->dumpstr);
432 b3994ec5 2003-12-11 devnull Continue2:;
435 b3994ec5 2003-12-11 devnull Bterm(b);
436 b3994ec5 2003-12-11 devnull close(fd);
437 b3994ec5 2003-12-11 devnull free(b);
438 b3994ec5 2003-12-11 devnull fbuffree(r);
441 b3994ec5 2003-12-11 devnull fbuffree(buf);
446 b3994ec5 2003-12-11 devnull rdline(Biobuf *b, int *linep)
448 b3994ec5 2003-12-11 devnull char *l;
450 b3994ec5 2003-12-11 devnull l = Brdline(b, '\n');
452 b3994ec5 2003-12-11 devnull (*linep)++;
453 b3994ec5 2003-12-11 devnull return l;
457 b3994ec5 2003-12-11 devnull * Get font names from load file so we don't load fonts we won't use
460 b3994ec5 2003-12-11 devnull rowloadfonts(char *file)
463 b3994ec5 2003-12-11 devnull Biobuf *b;
464 b3994ec5 2003-12-11 devnull char *l;
466 b3994ec5 2003-12-11 devnull b = Bopen(file, OREAD);
467 b3994ec5 2003-12-11 devnull if(b == nil)
469 b3994ec5 2003-12-11 devnull /* current directory */
470 b3994ec5 2003-12-11 devnull l = Brdline(b, '\n');
471 b3994ec5 2003-12-11 devnull if(l == nil)
472 b3994ec5 2003-12-11 devnull goto Return;
473 b3994ec5 2003-12-11 devnull /* global fonts */
474 b3994ec5 2003-12-11 devnull for(i=0; i<2; i++){
475 b3994ec5 2003-12-11 devnull l = Brdline(b, '\n');
476 b3994ec5 2003-12-11 devnull if(l == nil)
477 b3994ec5 2003-12-11 devnull goto Return;
478 b3994ec5 2003-12-11 devnull l[Blinelen(b)-1] = 0;
479 6d7fdb24 2004-12-27 devnull if(*l && strcmp(l, fontnames[i])!=0){
480 6d7fdb24 2004-12-27 devnull free(fontnames[i]);
481 b3994ec5 2003-12-11 devnull fontnames[i] = estrdup(l);
485 b3994ec5 2003-12-11 devnull Bterm(b);
489 b3994ec5 2003-12-11 devnull rowload(Row *row, char *file, int initing)
491 23aada89 2005-01-14 devnull int i, j, line, y, nr, nfontr, n, ns, ndumped, dumpid, x, fd;
492 23aada89 2005-01-14 devnull double percent;
493 b3994ec5 2003-12-11 devnull Biobuf *b, *bout;
494 b3994ec5 2003-12-11 devnull char *buf, *l, *t, *fontname;
495 b3994ec5 2003-12-11 devnull Rune *r, rune, *fontr;
496 b3994ec5 2003-12-11 devnull Column *c, *c1, *c2;
497 b3994ec5 2003-12-11 devnull uint q0, q1;
498 b3994ec5 2003-12-11 devnull Rectangle r1, r2;
499 b3994ec5 2003-12-11 devnull Window *w;
501 b3994ec5 2003-12-11 devnull buf = fbufalloc();
502 b3994ec5 2003-12-11 devnull if(file == nil){
503 b3994ec5 2003-12-11 devnull if(home == nil){
504 b3994ec5 2003-12-11 devnull warning(nil, "can't find file for load: $home not defined\n");
505 b3994ec5 2003-12-11 devnull goto Rescue1;
507 b3994ec5 2003-12-11 devnull sprint(buf, "%s/acme.dump", home);
508 b3994ec5 2003-12-11 devnull file = buf;
510 b3994ec5 2003-12-11 devnull b = Bopen(file, OREAD);
511 b3994ec5 2003-12-11 devnull if(b == nil){
512 b3994ec5 2003-12-11 devnull warning(nil, "can't open load file %s: %r\n", file);
513 b3994ec5 2003-12-11 devnull goto Rescue1;
515 b3994ec5 2003-12-11 devnull /* current directory */
516 b3994ec5 2003-12-11 devnull line = 0;
517 b3994ec5 2003-12-11 devnull l = rdline(b, &line);
518 b3994ec5 2003-12-11 devnull if(l == nil)
519 b3994ec5 2003-12-11 devnull goto Rescue2;
520 b3994ec5 2003-12-11 devnull l[Blinelen(b)-1] = 0;
521 b3994ec5 2003-12-11 devnull if(chdir(l) < 0){
522 b3994ec5 2003-12-11 devnull warning(nil, "can't chdir %s\n", l);
523 b3994ec5 2003-12-11 devnull goto Rescue2;
525 b3994ec5 2003-12-11 devnull /* global fonts */
526 b3994ec5 2003-12-11 devnull for(i=0; i<2; i++){
527 b3994ec5 2003-12-11 devnull l = rdline(b, &line);
528 b3994ec5 2003-12-11 devnull if(l == nil)
529 b3994ec5 2003-12-11 devnull goto Rescue2;
530 b3994ec5 2003-12-11 devnull l[Blinelen(b)-1] = 0;
531 b3994ec5 2003-12-11 devnull if(*l && strcmp(l, fontnames[i])!=0)
532 6d7fdb24 2004-12-27 devnull rfget(i, TRUE, i==0 && initing, l);
534 b3994ec5 2003-12-11 devnull if(initing && row->ncol==0)
535 b3994ec5 2003-12-11 devnull rowinit(row, screen->clipr);
536 b3994ec5 2003-12-11 devnull l = rdline(b, &line);
537 b3994ec5 2003-12-11 devnull if(l == nil)
538 b3994ec5 2003-12-11 devnull goto Rescue2;
539 b3994ec5 2003-12-11 devnull j = Blinelen(b)/12;
540 b3994ec5 2003-12-11 devnull if(j<=0 || j>10)
541 b3994ec5 2003-12-11 devnull goto Rescue2;
542 b3994ec5 2003-12-11 devnull for(i=0; i<j; i++){
543 23aada89 2005-01-14 devnull percent = atof(l+i*12);
544 b3994ec5 2003-12-11 devnull if(percent<0 || percent>=100)
545 b3994ec5 2003-12-11 devnull goto Rescue2;
546 0fdffa38 2005-01-14 devnull x = row->r.min.x+percent*Dx(row->r)/100+0.5;
547 b3994ec5 2003-12-11 devnull if(i < row->ncol){
548 b3994ec5 2003-12-11 devnull if(i == 0)
549 b3994ec5 2003-12-11 devnull continue;
550 b3994ec5 2003-12-11 devnull c1 = row->col[i-1];
551 b3994ec5 2003-12-11 devnull c2 = row->col[i];
552 b3994ec5 2003-12-11 devnull r1 = c1->r;
553 b3994ec5 2003-12-11 devnull r2 = c2->r;
554 b3994ec5 2003-12-11 devnull r1.max.x = x;
555 b3994ec5 2003-12-11 devnull r2.min.x = x+Border;
556 b3994ec5 2003-12-11 devnull if(Dx(r1) < 50 || Dx(r2) < 50)
557 b3994ec5 2003-12-11 devnull continue;
558 b3994ec5 2003-12-11 devnull draw(screen, Rpt(r1.min, r2.max), display->white, nil, ZP);
559 b3994ec5 2003-12-11 devnull colresize(c1, r1);
560 b3994ec5 2003-12-11 devnull colresize(c2, r2);
561 b3994ec5 2003-12-11 devnull r2.min.x = x;
562 b3994ec5 2003-12-11 devnull r2.max.x = x+Border;
563 b3994ec5 2003-12-11 devnull draw(screen, r2, display->black, nil, ZP);
565 b3994ec5 2003-12-11 devnull if(i >= row->ncol)
566 b3994ec5 2003-12-11 devnull rowadd(row, nil, x);
568 b3994ec5 2003-12-11 devnull for(;;){
569 b3994ec5 2003-12-11 devnull l = rdline(b, &line);
570 b3994ec5 2003-12-11 devnull if(l == nil)
572 b3994ec5 2003-12-11 devnull dumpid = 0;
573 b3994ec5 2003-12-11 devnull switch(l[0]){
574 b3994ec5 2003-12-11 devnull case 'e':
575 b3994ec5 2003-12-11 devnull if(Blinelen(b) < 1+5*12+1)
576 b3994ec5 2003-12-11 devnull goto Rescue2;
577 b3994ec5 2003-12-11 devnull l = rdline(b, &line); /* ctl line; ignored */
578 b3994ec5 2003-12-11 devnull if(l == nil)
579 b3994ec5 2003-12-11 devnull goto Rescue2;
580 b3994ec5 2003-12-11 devnull l = rdline(b, &line); /* directory */
581 b3994ec5 2003-12-11 devnull if(l == nil)
582 b3994ec5 2003-12-11 devnull goto Rescue2;
583 b3994ec5 2003-12-11 devnull l[Blinelen(b)-1] = 0;
584 b3994ec5 2003-12-11 devnull if(*l == '\0'){
585 b3994ec5 2003-12-11 devnull if(home == nil)
586 b3994ec5 2003-12-11 devnull r = bytetorune("./", &nr);
588 b3994ec5 2003-12-11 devnull t = emalloc(strlen(home)+1+1);
589 b3994ec5 2003-12-11 devnull sprint(t, "%s/", home);
590 b3994ec5 2003-12-11 devnull r = bytetorune(t, &nr);
591 b3994ec5 2003-12-11 devnull free(t);
594 b3994ec5 2003-12-11 devnull r = bytetorune(l, &nr);
595 b3994ec5 2003-12-11 devnull l = rdline(b, &line); /* command */
596 b3994ec5 2003-12-11 devnull if(l == nil)
597 b3994ec5 2003-12-11 devnull goto Rescue2;
598 b3994ec5 2003-12-11 devnull t = emalloc(Blinelen(b)+1);
599 b3994ec5 2003-12-11 devnull memmove(t, l, Blinelen(b));
600 b3994ec5 2003-12-11 devnull run(nil, t, r, nr, TRUE, nil, nil, FALSE);
601 b3994ec5 2003-12-11 devnull /* r is freed in run() */
602 b3994ec5 2003-12-11 devnull continue;
603 b3994ec5 2003-12-11 devnull case 'f':
604 b3994ec5 2003-12-11 devnull if(Blinelen(b) < 1+5*12+1)
605 b3994ec5 2003-12-11 devnull goto Rescue2;
606 b3994ec5 2003-12-11 devnull fontname = l+1+5*12;
607 b3994ec5 2003-12-11 devnull ndumped = -1;
609 b3994ec5 2003-12-11 devnull case 'F':
610 b3994ec5 2003-12-11 devnull if(Blinelen(b) < 1+6*12+1)
611 b3994ec5 2003-12-11 devnull goto Rescue2;
612 b3994ec5 2003-12-11 devnull fontname = l+1+6*12;
613 b3994ec5 2003-12-11 devnull ndumped = atoi(l+1+5*12+1);
615 b3994ec5 2003-12-11 devnull case 'x':
616 b3994ec5 2003-12-11 devnull if(Blinelen(b) < 1+5*12+1)
617 b3994ec5 2003-12-11 devnull goto Rescue2;
618 b3994ec5 2003-12-11 devnull fontname = l+1+5*12;
619 b3994ec5 2003-12-11 devnull ndumped = -1;
620 b3994ec5 2003-12-11 devnull dumpid = atoi(l+1+1*12);
622 b3994ec5 2003-12-11 devnull default:
623 b3994ec5 2003-12-11 devnull goto Rescue2;
625 b3994ec5 2003-12-11 devnull l[Blinelen(b)-1] = 0;
626 b3994ec5 2003-12-11 devnull fontr = nil;
627 b3994ec5 2003-12-11 devnull nfontr = 0;
628 b3994ec5 2003-12-11 devnull if(*fontname)
629 b3994ec5 2003-12-11 devnull fontr = bytetorune(fontname, &nfontr);
630 b3994ec5 2003-12-11 devnull i = atoi(l+1+0*12);
631 b3994ec5 2003-12-11 devnull j = atoi(l+1+1*12);
632 b3994ec5 2003-12-11 devnull q0 = atoi(l+1+2*12);
633 b3994ec5 2003-12-11 devnull q1 = atoi(l+1+3*12);
634 23aada89 2005-01-14 devnull percent = atof(l+1+4*12);
635 b3994ec5 2003-12-11 devnull if(i<0 || i>10)
636 b3994ec5 2003-12-11 devnull goto Rescue2;
637 b3994ec5 2003-12-11 devnull if(i > row->ncol)
638 b3994ec5 2003-12-11 devnull i = row->ncol;
639 b3994ec5 2003-12-11 devnull c = row->col[i];
640 0fdffa38 2005-01-14 devnull y = c->r.min.y+(percent*Dy(c->r))/100+0.5;
641 b3994ec5 2003-12-11 devnull if(y<c->r.min.y || y>=c->r.max.y)
643 b3994ec5 2003-12-11 devnull if(dumpid == 0)
644 b3994ec5 2003-12-11 devnull w = coladd(c, nil, nil, y);
646 b3994ec5 2003-12-11 devnull w = coladd(c, nil, lookid(dumpid, TRUE), y);
647 b3994ec5 2003-12-11 devnull if(w == nil)
648 b3994ec5 2003-12-11 devnull continue;
649 b3994ec5 2003-12-11 devnull w->dumpid = j;
650 b3994ec5 2003-12-11 devnull l = rdline(b, &line);
651 b3994ec5 2003-12-11 devnull if(l == nil)
652 b3994ec5 2003-12-11 devnull goto Rescue2;
653 b3994ec5 2003-12-11 devnull l[Blinelen(b)-1] = 0;
654 b3994ec5 2003-12-11 devnull r = bytetorune(l+5*12, &nr);
655 b3994ec5 2003-12-11 devnull ns = -1;
656 b3994ec5 2003-12-11 devnull for(n=0; n<nr; n++){
657 b3994ec5 2003-12-11 devnull if(r[n] == '/')
659 b3994ec5 2003-12-11 devnull if(r[n] == ' ')
662 b3994ec5 2003-12-11 devnull if(dumpid == 0)
663 b3994ec5 2003-12-11 devnull winsetname(w, r, n);
664 b3994ec5 2003-12-11 devnull for(; n<nr; n++)
665 b3994ec5 2003-12-11 devnull if(r[n] == '|')
667 b3994ec5 2003-12-11 devnull wincleartag(w);
668 b3994ec5 2003-12-11 devnull textinsert(&w->tag, w->tag.file->b.nc, r+n+1, nr-(n+1), TRUE);
669 b3994ec5 2003-12-11 devnull if(ndumped >= 0){
670 b3994ec5 2003-12-11 devnull /* simplest thing is to put it in a file and load that */
671 b3994ec5 2003-12-11 devnull sprint(buf, "/tmp/d%d.%.4sacme", getpid(), getuser());
672 b3994ec5 2003-12-11 devnull fd = create(buf, OWRITE|ORCLOSE, 0600);
673 b3994ec5 2003-12-11 devnull if(fd < 0){
674 1a8f27c3 2004-05-14 devnull free(r);
675 b3994ec5 2003-12-11 devnull warning(nil, "can't create temp file: %r\n");
676 b3994ec5 2003-12-11 devnull goto Rescue2;
678 b3994ec5 2003-12-11 devnull bout = emalloc(sizeof(Biobuf));
679 b3994ec5 2003-12-11 devnull Binit(bout, fd, OWRITE);
680 b3994ec5 2003-12-11 devnull for(n=0; n<ndumped; n++){
681 b3994ec5 2003-12-11 devnull rune = Bgetrune(b);
682 b3994ec5 2003-12-11 devnull if(rune == '\n')
684 b3994ec5 2003-12-11 devnull if(rune == (Rune)Beof){
685 1a8f27c3 2004-05-14 devnull free(r);
686 b3994ec5 2003-12-11 devnull Bterm(bout);
687 b3994ec5 2003-12-11 devnull free(bout);
688 b3994ec5 2003-12-11 devnull close(fd);
689 b3994ec5 2003-12-11 devnull goto Rescue2;
691 b3994ec5 2003-12-11 devnull Bputrune(bout, rune);
693 b3994ec5 2003-12-11 devnull Bterm(bout);
694 b3994ec5 2003-12-11 devnull free(bout);
695 b3994ec5 2003-12-11 devnull textload(&w->body, 0, buf, 1);
696 b3994ec5 2003-12-11 devnull close(fd);
697 b3994ec5 2003-12-11 devnull w->body.file->mod = TRUE;
698 b3994ec5 2003-12-11 devnull for(n=0; n<w->body.file->ntext; n++)
699 b3994ec5 2003-12-11 devnull w->body.file->text[n]->w->dirty = TRUE;
700 b3994ec5 2003-12-11 devnull winsettag(w);
701 b3994ec5 2003-12-11 devnull }else if(dumpid==0 && r[ns+1]!='+' && r[ns+1]!='-')
702 b3994ec5 2003-12-11 devnull get(&w->body, nil, nil, FALSE, XXX, nil, 0);
703 b3994ec5 2003-12-11 devnull if(fontr){
704 b3994ec5 2003-12-11 devnull fontx(&w->body, nil, nil, 0, 0, fontr, nfontr);
705 b3994ec5 2003-12-11 devnull free(fontr);
707 6d7fdb24 2004-12-27 devnull free(r);
708 b3994ec5 2003-12-11 devnull if(q0>w->body.file->b.nc || q1>w->body.file->b.nc || q0>q1)
709 b3994ec5 2003-12-11 devnull q0 = q1 = 0;
710 b3994ec5 2003-12-11 devnull textshow(&w->body, q0, q1, 1);
711 b3994ec5 2003-12-11 devnull w->maxlines = min(w->body.fr.nlines, max(w->maxlines, w->body.fr.maxlines));
713 b3994ec5 2003-12-11 devnull Bterm(b);
715 b3994ec5 2003-12-11 devnull fbuffree(buf);
716 6d7fdb24 2004-12-27 devnull return TRUE;
718 b3994ec5 2003-12-11 devnull Rescue2:
719 b3994ec5 2003-12-11 devnull warning(nil, "bad load file %s:%d\n", file, line);
720 b3994ec5 2003-12-11 devnull Bterm(b);
721 6d7fdb24 2004-12-27 devnull Rescue1:
722 6d7fdb24 2004-12-27 devnull fbuffree(buf);
723 6d7fdb24 2004-12-27 devnull return FALSE;
727 b3994ec5 2003-12-11 devnull allwindows(void (*f)(Window*, void*), void *arg)
729 b3994ec5 2003-12-11 devnull int i, j;
730 b3994ec5 2003-12-11 devnull Column *c;
732 b3994ec5 2003-12-11 devnull for(i=0; i<row.ncol; i++){
733 b3994ec5 2003-12-11 devnull c = row.col[i];
734 b3994ec5 2003-12-11 devnull for(j=0; j<c->nw; j++)
735 b3994ec5 2003-12-11 devnull (*f)(c->w[j], arg);