Blob


1 enum
2 {
3 Qdir,
4 Qacme,
5 Qcons,
6 Qconsctl,
7 Qdraw,
8 Qeditout,
9 Qindex,
10 Qlabel,
11 Qnew,
13 QWaddr,
14 QWbody,
15 QWctl,
16 QWdata,
17 QWeditout,
18 QWerrors,
19 QWevent,
20 QWrdsel,
21 QWwrsel,
22 QWtag,
23 QWxdata,
24 QMAX,
25 };
27 enum
28 {
29 Blockincr = 256,
30 Maxblock = 8*1024,
31 NRange = 10,
32 Infinity = 0x7FFFFFFF, /* huge value for regexp address */
33 };
35 #define Buffer AcmeBuffer
36 typedef struct Block Block;
37 typedef struct Buffer Buffer;
38 typedef struct Command Command;
39 typedef struct Column Column;
40 typedef struct Dirlist Dirlist;
41 typedef struct Dirtab Dirtab;
42 typedef struct Disk Disk;
43 typedef struct Expand Expand;
44 typedef struct Fid Fid;
45 typedef struct File File;
46 typedef struct Elog Elog;
47 typedef struct Mntdir Mntdir;
48 typedef struct Range Range;
49 typedef struct Rangeset Rangeset;
50 typedef struct Reffont Reffont;
51 typedef struct Row Row;
52 typedef struct Runestr Runestr;
53 typedef struct Text Text;
54 typedef struct Timer Timer;
55 typedef struct Window Window;
56 typedef struct Xfid Xfid;
58 struct Runestr
59 {
60 Rune *r;
61 int nr;
62 };
64 struct Range
65 {
66 int q0;
67 int q1;
68 };
70 struct Block
71 {
72 uint addr; /* disk address in bytes */
73 union
74 {
75 uint n; /* number of used runes in block */
76 Block *next; /* pointer to next in free list */
77 } u;
78 };
80 struct Disk
81 {
82 int fd;
83 uint addr; /* length of temp file */
84 Block *free[Maxblock/Blockincr+1];
85 };
87 Disk* diskinit(void);
88 Block* disknewblock(Disk*, uint);
89 void diskrelease(Disk*, Block*);
90 void diskread(Disk*, Block*, Rune*, uint);
91 void diskwrite(Disk*, Block**, Rune*, uint);
93 struct Buffer
94 {
95 uint nc;
96 Rune *c; /* cache */
97 uint cnc; /* bytes in cache */
98 uint cmax; /* size of allocated cache */
99 uint cq; /* position of cache */
100 int cdirty; /* cache needs to be written */
101 uint cbi; /* index of cache Block */
102 Block **bl; /* array of blocks */
103 uint nbl; /* number of blocks */
104 };
105 void bufinsert(Buffer*, uint, Rune*, uint);
106 void bufdelete(Buffer*, uint, uint);
107 uint bufload(Buffer*, uint, int, int*);
108 void bufread(Buffer*, uint, Rune*, uint);
109 void bufclose(Buffer*);
110 void bufreset(Buffer*);
112 struct Elog
114 short type; /* Delete, Insert, Filename */
115 uint q0; /* location of change (unused in f) */
116 uint nd; /* number of deleted characters */
117 uint nr; /* # runes in string or file name */
118 Rune *r;
119 };
120 void elogterm(File*);
121 void elogclose(File*);
122 void eloginsert(File*, int, Rune*, int);
123 void elogdelete(File*, int, int);
124 void elogreplace(File*, int, int, Rune*, int);
125 void elogapply(File*);
127 struct File
129 Buffer b; /* the data */
130 Buffer delta; /* transcript of changes */
131 Buffer epsilon; /* inversion of delta for redo */
132 Buffer *elogbuf; /* log of pending editor changes */
133 Elog elog; /* current pending change */
134 Rune *name; /* name of associated file */
135 int nname; /* size of name */
136 uvlong qidpath; /* of file when read */
137 uint mtime; /* of file when read */
138 int dev; /* of file when read */
139 int unread; /* file has not been read from disk */
140 int editclean; /* mark clean after edit command */
142 int seq; /* if seq==0, File acts like Buffer */
143 int mod;
144 Text *curtext; /* most recently used associated text */
145 Text **text; /* list of associated texts */
146 int ntext;
147 int dumpid; /* used in dumping zeroxed windows */
148 };
149 File* fileaddtext(File*, Text*);
150 void fileclose(File*);
151 void filedelete(File*, uint, uint);
152 void filedeltext(File*, Text*);
153 void fileinsert(File*, uint, Rune*, uint);
154 uint fileload(File*, uint, int, int*);
155 void filemark(File*);
156 void filereset(File*);
157 void filesetname(File*, Rune*, int);
158 void fileundelete(File*, Buffer*, uint, uint);
159 void fileuninsert(File*, Buffer*, uint, uint);
160 void fileunsetname(File*, Buffer*);
161 void fileundo(File*, int, uint*, uint*);
162 uint fileredoseq(File*);
164 enum /* Text.what */
166 Columntag,
167 Rowtag,
168 Tag,
169 Body,
170 };
172 struct Text
174 File *file;
175 Frame fr;
176 Reffont *reffont;
177 uint org;
178 uint q0;
179 uint q1;
180 int what;
181 int tabstop;
182 Window *w;
183 Rectangle scrollr;
184 Rectangle lastsr;
185 Rectangle all;
186 Row *row;
187 Column *col;
189 uint eq0; /* start of typing for ESC */
190 uint cq0; /* cache position */
191 int ncache; /* storage for insert */
192 int ncachealloc;
193 Rune *cache;
194 int nofill;
195 };
197 uint textbacknl(Text*, uint, uint);
198 uint textbsinsert(Text*, uint, Rune*, uint, int, int*);
199 int textbswidth(Text*, Rune);
200 int textclickmatch(Text*, int, int, int, uint*);
201 void textclose(Text*);
202 void textcolumnate(Text*, Dirlist**, int);
203 void textcommit(Text*, int);
204 void textconstrain(Text*, uint, uint, uint*, uint*);
205 void textdelete(Text*, uint, uint, int);
206 void textdoubleclick(Text*, uint*, uint*);
207 void textfill(Text*);
208 void textframescroll(Text*, int);
209 void textinit(Text*, File*, Rectangle, Reffont*, Image**);
210 void textinsert(Text*, uint, Rune*, uint, int);
211 uint textload(Text*, uint, char*, int);
212 Rune textreadc(Text*, uint);
213 void textredraw(Text*, Rectangle, Font*, Image*, int);
214 void textreset(Text*);
215 int textresize(Text*, Rectangle);
216 void textscrdraw(Text*);
217 void textscroll(Text*, int);
218 void textselect(Text*);
219 int textselect2(Text*, uint*, uint*, Text**);
220 int textselect23(Text*, uint*, uint*, Image*, int);
221 int textselect3(Text*, uint*, uint*);
222 void textsetorigin(Text*, uint, int);
223 void textsetselect(Text*, uint, uint);
224 void textshow(Text*, uint, uint, int);
225 void texttype(Text*, Rune);
227 struct Window
229 QLock lk;
230 Ref ref;
231 Text tag;
232 Text body;
233 Rectangle r;
234 uchar isdir;
235 uchar isscratch;
236 uchar filemenu;
237 uchar dirty;
238 uchar autoindent;
239 int id;
240 Range addr;
241 Range limit;
242 uchar nopen[QMAX];
243 uchar nomark;
244 uchar noscroll;
245 Range wrselrange;
246 int rdselfd;
247 Column *col;
248 Xfid *eventx;
249 char *events;
250 int nevents;
251 int owner;
252 int maxlines;
253 Dirlist **dlp;
254 int ndl;
255 int putseq;
256 int nincl;
257 Rune **incl;
258 Reffont *reffont;
259 QLock ctllock;
260 uint ctlfid;
261 char *dumpstr;
262 char *dumpdir;
263 int dumpid;
264 int utflastqid;
265 int utflastboff;
266 int utflastq;
267 };
269 void wininit(Window*, Window*, Rectangle);
270 void winlock(Window*, int);
271 void winlock1(Window*, int);
272 void winunlock(Window*);
273 void wintype(Window*, Text*, Rune);
274 void winundo(Window*, int);
275 void winsetname(Window*, Rune*, int);
276 void winsettag(Window*);
277 void winsettag1(Window*);
278 void wincommit(Window*, Text*);
279 int winresize(Window*, Rectangle, int);
280 void winclose(Window*);
281 void windelete(Window*);
282 int winclean(Window*, int);
283 void windirfree(Window*);
284 void winevent(Window*, char*, ...);
285 void winmousebut(Window*);
286 void winaddincl(Window*, Rune*, int);
287 void wincleartag(Window*);
288 char *winctlprint(Window*, char*, int);
290 struct Column
292 Rectangle r;
293 Text tag;
294 Row *row;
295 Window **w;
296 int nw;
297 int safe;
298 };
300 void colinit(Column*, Rectangle);
301 Window* coladd(Column*, Window*, Window*, int);
302 void colclose(Column*, Window*, int);
303 void colcloseall(Column*);
304 void colresize(Column*, Rectangle);
305 Text* colwhich(Column*, Point);
306 void coldragwin(Column*, Window*, int);
307 void colgrow(Column*, Window*, int);
308 int colclean(Column*);
309 void colsort(Column*);
310 void colmousebut(Column*);
312 struct Row
314 QLock lk;
315 Rectangle r;
316 Text tag;
317 Column **col;
318 int ncol;
320 };
322 void rowinit(Row*, Rectangle);
323 Column* rowadd(Row*, Column *c, int);
324 void rowclose(Row*, Column*, int);
325 Text* rowwhich(Row*, Point);
326 Column* rowwhichcol(Row*, Point);
327 void rowresize(Row*, Rectangle);
328 Text* rowtype(Row*, Rune, Point);
329 void rowdragcol(Row*, Column*, int but);
330 int rowclean(Row*);
331 void rowdump(Row*, char*);
332 int rowload(Row*, char*, int);
333 void rowloadfonts(char*);
335 struct Timer
337 int dt;
338 int cancel;
339 Channel *c; /* chan(int) */
340 Timer *next;
341 };
343 struct Command
345 int pid;
346 Rune *name;
347 int nname;
348 char *text;
349 char **av;
350 int iseditcmd;
351 Mntdir *md;
352 Command *next;
353 };
355 struct Dirtab
357 char *name;
358 uchar type;
359 uint qid;
360 uint perm;
361 };
363 struct Mntdir
365 int id;
366 int ref;
367 Rune *dir;
368 int ndir;
369 Mntdir *next;
370 int nincl;
371 Rune **incl;
372 };
374 struct Fid
376 int fid;
377 int busy;
378 int open;
379 Qid qid;
380 Window *w;
381 Dirtab *dir;
382 Fid *next;
383 Mntdir *mntdir;
384 int nrpart;
385 uchar rpart[UTFmax];
386 };
389 struct Xfid
391 void *arg; /* args to xfidinit */
392 Fcall fcall;
393 Xfid *next;
394 Channel *c; /* chan(void(*)(Xfid*)) */
395 Fid *f;
396 uchar *buf;
397 int flushed;
399 };
401 void xfidctl(void *);
402 void xfidflush(Xfid*);
403 void xfidopen(Xfid*);
404 void xfidclose(Xfid*);
405 void xfidread(Xfid*);
406 void xfidwrite(Xfid*);
407 void xfidctlwrite(Xfid*, Window*);
408 void xfideventread(Xfid*, Window*);
409 void xfideventwrite(Xfid*, Window*);
410 void xfidindexread(Xfid*);
411 void xfidutfread(Xfid*, Text*, uint, int);
412 int xfidruneread(Xfid*, Text*, uint, uint);
414 struct Reffont
416 Ref ref;
417 Font *f;
419 };
420 Reffont *rfget(int, int, int, char*);
421 void rfclose(Reffont*);
423 struct Rangeset
425 Range r[NRange];
426 };
428 struct Dirlist
430 Rune *r;
431 int nr;
432 int wid;
433 };
435 struct Expand
437 uint q0;
438 uint q1;
439 Rune *name;
440 int nname;
441 char *bname;
442 int jump;
443 union{
444 Text *at;
445 Rune *ar;
446 } u;
447 int (*agetc)(void*, uint);
448 int a0;
449 int a1;
450 };
452 enum
454 /* fbufalloc() guarantees room off end of BUFSIZE */
455 BUFSIZE = Maxblock+IOHDRSZ, /* size from fbufalloc() */
456 RBUFSIZE = BUFSIZE/sizeof(Rune),
457 EVENTSIZE = 256,
458 Scrollwid = 12, /* width of scroll bar */
459 Scrollgap = 4, /* gap right of scroll bar */
460 Margin = 4, /* margin around text */
461 Border = 2, /* line between rows, cols, windows */
462 };
464 #define QID(w,q) ((w<<8)|(q))
465 #define WIN(q) ((((ulong)(q).path)>>8) & 0xFFFFFF)
466 #define FILE(q) ((q).path & 0xFF)
468 #undef FALSE
469 #undef TRUE
471 enum
473 FALSE,
474 TRUE,
475 XXX,
476 };
478 enum
480 Empty = 0,
481 Null = '-',
482 Delete = 'd',
483 Insert = 'i',
484 Replace = 'r',
485 Filename = 'f',
486 };
488 enum /* editing */
490 Inactive = 0,
491 Inserting,
492 Collecting,
493 };
495 uint globalincref;
496 uint seq;
497 uint maxtab; /* size of a tab, in units of the '0' character */
499 Display *display;
500 Image *screen;
501 Font *font;
502 Mouse *mouse;
503 Mousectl *mousectl;
504 Keyboardctl *keyboardctl;
505 Reffont reffont;
506 Image *modbutton;
507 Image *colbutton;
508 Image *button;
509 Image *but2col;
510 Image *but3col;
511 Cursor boxcursor;
512 Row row;
513 int timerpid;
514 Disk *disk;
515 Text *seltext;
516 Text *argtext;
517 Text *mousetext; /* global because Text.close needs to clear it */
518 Text *typetext; /* global because Text.close needs to clear it */
519 Text *barttext; /* shared between mousetask and keyboardthread */
520 int bartflag;
521 int swapscrollbuttons;
522 Window *activewin;
523 Column *activecol;
524 Buffer snarfbuf;
525 Rectangle nullrect;
526 int fsyspid;
527 char *cputype;
528 char *objtype;
529 char *home;
530 char *fontnames[2];
531 Image *tagcols[NCOL];
532 Image *textcols[NCOL];
533 extern char wdir[]; /* must use extern because no dimension given */
534 int editing;
535 int erroutfd;
536 int messagesize; /* negotiated in 9P version setup */
537 int globalautoindent;
538 int dodollarsigns;
540 enum
542 Kscrolloneup = KF|0x20,
543 Kscrollonedown = KF|0x21,
544 };
546 Channel *cplumb; /* chan(Plumbmsg*) */
547 Channel *cwait; /* chan(Waitmsg) */
548 Channel *ccommand; /* chan(Command*) */
549 Channel *ckill; /* chan(Rune*) */
550 Channel *cxfidalloc; /* chan(Xfid*) */
551 Channel *cxfidfree; /* chan(Xfid*) */
552 Channel *cnewwindow; /* chan(Channel*) */
553 Channel *mouseexit0; /* chan(int) */
554 Channel *mouseexit1; /* chan(int) */
555 Channel *cexit; /* chan(int) */
556 Channel *cerr; /* chan(char*) */
557 Channel *cedit; /* chan(int) */
558 Channel *cwarn; /* chan(void*)[1] (really chan(unit)[1]) */
560 #define STACK 32768