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, int);
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 int tagsafe; /* taglines is correct */
268 int tagexpand;
269 int taglines;
270 Rectangle tagtop;
271 };
273 void wininit(Window*, Window*, Rectangle);
274 void winlock(Window*, int);
275 void winlock1(Window*, int);
276 void winunlock(Window*);
277 void wintype(Window*, Text*, Rune);
278 void winundo(Window*, int);
279 void winsetname(Window*, Rune*, int);
280 void winsettag(Window*);
281 void winsettag1(Window*);
282 void wincommit(Window*, Text*);
283 int winresize(Window*, Rectangle, int, int);
284 void winclose(Window*);
285 void windelete(Window*);
286 int winclean(Window*, int);
287 void windirfree(Window*);
288 void winevent(Window*, char*, ...);
289 void winmousebut(Window*);
290 void winaddincl(Window*, Rune*, int);
291 void wincleartag(Window*);
292 char *winctlprint(Window*, char*, int);
294 struct Column
296 Rectangle r;
297 Text tag;
298 Row *row;
299 Window **w;
300 int nw;
301 int safe;
302 };
304 void colinit(Column*, Rectangle);
305 Window* coladd(Column*, Window*, Window*, int);
306 void colclose(Column*, Window*, int);
307 void colcloseall(Column*);
308 void colresize(Column*, Rectangle);
309 Text* colwhich(Column*, Point);
310 void coldragwin(Column*, Window*, int);
311 void colgrow(Column*, Window*, int);
312 int colclean(Column*);
313 void colsort(Column*);
314 void colmousebut(Column*);
316 struct Row
318 QLock lk;
319 Rectangle r;
320 Text tag;
321 Column **col;
322 int ncol;
324 };
326 void rowinit(Row*, Rectangle);
327 Column* rowadd(Row*, Column *c, int);
328 void rowclose(Row*, Column*, int);
329 Text* rowwhich(Row*, Point);
330 Column* rowwhichcol(Row*, Point);
331 void rowresize(Row*, Rectangle);
332 Text* rowtype(Row*, Rune, Point);
333 void rowdragcol(Row*, Column*, int but);
334 int rowclean(Row*);
335 void rowdump(Row*, char*);
336 int rowload(Row*, char*, int);
337 void rowloadfonts(char*);
339 struct Timer
341 int dt;
342 int cancel;
343 Channel *c; /* chan(int) */
344 Timer *next;
345 };
347 struct Command
349 int pid;
350 Rune *name;
351 int nname;
352 char *text;
353 char **av;
354 int iseditcmd;
355 Mntdir *md;
356 Command *next;
357 };
359 struct Dirtab
361 char *name;
362 uchar type;
363 uint qid;
364 uint perm;
365 };
367 struct Mntdir
369 int id;
370 int ref;
371 Rune *dir;
372 int ndir;
373 Mntdir *next;
374 int nincl;
375 Rune **incl;
376 };
378 struct Fid
380 int fid;
381 int busy;
382 int open;
383 Qid qid;
384 Window *w;
385 Dirtab *dir;
386 Fid *next;
387 Mntdir *mntdir;
388 int nrpart;
389 uchar rpart[UTFmax];
390 };
393 struct Xfid
395 void *arg; /* args to xfidinit */
396 Fcall fcall;
397 Xfid *next;
398 Channel *c; /* chan(void(*)(Xfid*)) */
399 Fid *f;
400 uchar *buf;
401 int flushed;
403 };
405 void xfidctl(void *);
406 void xfidflush(Xfid*);
407 void xfidopen(Xfid*);
408 void xfidclose(Xfid*);
409 void xfidread(Xfid*);
410 void xfidwrite(Xfid*);
411 void xfidctlwrite(Xfid*, Window*);
412 void xfideventread(Xfid*, Window*);
413 void xfideventwrite(Xfid*, Window*);
414 void xfidindexread(Xfid*);
415 void xfidutfread(Xfid*, Text*, uint, int);
416 int xfidruneread(Xfid*, Text*, uint, uint);
418 struct Reffont
420 Ref ref;
421 Font *f;
423 };
424 Reffont *rfget(int, int, int, char*);
425 void rfclose(Reffont*);
427 struct Rangeset
429 Range r[NRange];
430 };
432 struct Dirlist
434 Rune *r;
435 int nr;
436 int wid;
437 };
439 struct Expand
441 uint q0;
442 uint q1;
443 Rune *name;
444 int nname;
445 char *bname;
446 int jump;
447 union{
448 Text *at;
449 Rune *ar;
450 } u;
451 int (*agetc)(void*, uint);
452 int a0;
453 int a1;
454 };
456 enum
458 /* fbufalloc() guarantees room off end of BUFSIZE */
459 BUFSIZE = Maxblock+IOHDRSZ, /* size from fbufalloc() */
460 RBUFSIZE = BUFSIZE/sizeof(Rune),
461 EVENTSIZE = 256,
462 Scrollwid = 12, /* width of scroll bar */
463 Scrollgap = 4, /* gap right of scroll bar */
464 Margin = 4, /* margin around text */
465 Border = 2, /* line between rows, cols, windows */
466 };
468 #define QID(w,q) ((w<<8)|(q))
469 #define WIN(q) ((((ulong)(q).path)>>8) & 0xFFFFFF)
470 #define FILE(q) ((q).path & 0xFF)
472 #undef FALSE
473 #undef TRUE
475 enum
477 FALSE,
478 TRUE,
479 XXX,
480 };
482 enum
484 Empty = 0,
485 Null = '-',
486 Delete = 'd',
487 Insert = 'i',
488 Replace = 'r',
489 Filename = 'f',
490 };
492 enum /* editing */
494 Inactive = 0,
495 Inserting,
496 Collecting,
497 };
499 uint globalincref;
500 uint seq;
501 uint maxtab; /* size of a tab, in units of the '0' character */
503 Display *display;
504 Image *screen;
505 Font *font;
506 Mouse *mouse;
507 Mousectl *mousectl;
508 Keyboardctl *keyboardctl;
509 Reffont reffont;
510 Image *modbutton;
511 Image *colbutton;
512 Image *button;
513 Image *but2col;
514 Image *but3col;
515 Cursor boxcursor;
516 Row row;
517 int timerpid;
518 Disk *disk;
519 Text *seltext;
520 Text *argtext;
521 Text *mousetext; /* global because Text.close needs to clear it */
522 Text *typetext; /* global because Text.close needs to clear it */
523 Text *barttext; /* shared between mousetask and keyboardthread */
524 int bartflag;
525 int swapscrollbuttons;
526 Window *activewin;
527 Column *activecol;
528 Buffer snarfbuf;
529 Rectangle nullrect;
530 int fsyspid;
531 char *cputype;
532 char *objtype;
533 char *home;
534 char *fontnames[2];
535 Image *tagcols[NCOL];
536 Image *textcols[NCOL];
537 extern char wdir[]; /* must use extern because no dimension given */
538 int editing;
539 int erroutfd;
540 int messagesize; /* negotiated in 9P version setup */
541 int globalautoindent;
542 int dodollarsigns;
544 enum
546 Kscrolloneup = KF|0x20,
547 Kscrollonedown = KF|0x21,
548 };
550 Channel *cplumb; /* chan(Plumbmsg*) */
551 Channel *cwait; /* chan(Waitmsg) */
552 Channel *ccommand; /* chan(Command*) */
553 Channel *ckill; /* chan(Rune*) */
554 Channel *cxfidalloc; /* chan(Xfid*) */
555 Channel *cxfidfree; /* chan(Xfid*) */
556 Channel *cnewwindow; /* chan(Channel*) */
557 Channel *mouseexit0; /* chan(int) */
558 Channel *mouseexit1; /* chan(int) */
559 Channel *cexit; /* chan(int) */
560 Channel *cerr; /* chan(char*) */
561 Channel *cedit; /* chan(int) */
562 Channel *cwarn; /* chan(void*)[1] (really chan(unit)[1]) */
564 #define STACK 32768