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 int needundo;
196 };
198 uint textbacknl(Text*, uint, uint);
199 uint textbsinsert(Text*, uint, Rune*, uint, int, int*);
200 int textbswidth(Text*, Rune);
201 int textclickmatch(Text*, int, int, int, uint*);
202 void textclose(Text*);
203 void textcolumnate(Text*, Dirlist**, int);
204 void textcommit(Text*, int);
205 void textconstrain(Text*, uint, uint, uint*, uint*);
206 void textdelete(Text*, uint, uint, int);
207 void textdoubleclick(Text*, uint*, uint*);
208 void textfill(Text*);
209 void textframescroll(Text*, int);
210 void textinit(Text*, File*, Rectangle, Reffont*, Image**);
211 void textinsert(Text*, uint, Rune*, uint, int);
212 uint textload(Text*, uint, char*, int);
213 Rune textreadc(Text*, uint);
214 void textredraw(Text*, Rectangle, Font*, Image*, int);
215 void textreset(Text*);
216 int textresize(Text*, Rectangle, int);
217 void textscrdraw(Text*);
218 void textscroll(Text*, int);
219 void textselect(Text*);
220 int textselect2(Text*, uint*, uint*, Text**);
221 int textselect23(Text*, uint*, uint*, Image*, int);
222 int textselect3(Text*, uint*, uint*);
223 void textsetorigin(Text*, uint, int);
224 void textsetselect(Text*, uint, uint);
225 void textshow(Text*, uint, uint, int);
226 void texttype(Text*, Rune);
228 struct Window
230 QLock lk;
231 Ref ref;
232 Text tag;
233 Text body;
234 Rectangle r;
235 uchar isdir;
236 uchar isscratch;
237 uchar filemenu;
238 uchar dirty;
239 uchar autoindent;
240 int id;
241 Range addr;
242 Range limit;
243 uchar nopen[QMAX];
244 uchar nomark;
245 uchar noscroll;
246 Range wrselrange;
247 int rdselfd;
248 Column *col;
249 Xfid *eventx;
250 char *events;
251 int nevents;
252 int owner;
253 int maxlines;
254 Dirlist **dlp;
255 int ndl;
256 int putseq;
257 int nincl;
258 Rune **incl;
259 Reffont *reffont;
260 QLock ctllock;
261 uint ctlfid;
262 char *dumpstr;
263 char *dumpdir;
264 int dumpid;
265 int utflastqid;
266 int utflastboff;
267 int utflastq;
268 int tagsafe; /* taglines is correct */
269 int tagexpand;
270 int taglines;
271 Rectangle tagtop;
272 };
274 void wininit(Window*, Window*, Rectangle);
275 void winlock(Window*, int);
276 void winlock1(Window*, int);
277 void winunlock(Window*);
278 void wintype(Window*, Text*, Rune);
279 void winundo(Window*, int);
280 void winsetname(Window*, Rune*, int);
281 void winsettag(Window*);
282 void winsettag1(Window*);
283 void wincommit(Window*, Text*);
284 int winresize(Window*, Rectangle, int, int);
285 void winclose(Window*);
286 void windelete(Window*);
287 int winclean(Window*, int);
288 void windirfree(Window*);
289 void winevent(Window*, char*, ...);
290 void winmousebut(Window*);
291 void winaddincl(Window*, Rune*, int);
292 void wincleartag(Window*);
293 char *winctlprint(Window*, char*, int);
295 struct Column
297 Rectangle r;
298 Text tag;
299 Row *row;
300 Window **w;
301 int nw;
302 int safe;
303 };
305 void colinit(Column*, Rectangle);
306 Window* coladd(Column*, Window*, Window*, int);
307 void colclose(Column*, Window*, int);
308 void colcloseall(Column*);
309 void colresize(Column*, Rectangle);
310 Text* colwhich(Column*, Point);
311 void coldragwin(Column*, Window*, int);
312 void colgrow(Column*, Window*, int);
313 int colclean(Column*);
314 void colsort(Column*);
315 void colmousebut(Column*);
317 struct Row
319 QLock lk;
320 Rectangle r;
321 Text tag;
322 Column **col;
323 int ncol;
325 };
327 void rowinit(Row*, Rectangle);
328 Column* rowadd(Row*, Column *c, int);
329 void rowclose(Row*, Column*, int);
330 Text* rowwhich(Row*, Point);
331 Column* rowwhichcol(Row*, Point);
332 void rowresize(Row*, Rectangle);
333 Text* rowtype(Row*, Rune, Point);
334 void rowdragcol(Row*, Column*, int but);
335 int rowclean(Row*);
336 void rowdump(Row*, char*);
337 int rowload(Row*, char*, int);
338 void rowloadfonts(char*);
340 struct Timer
342 int dt;
343 int cancel;
344 Channel *c; /* chan(int) */
345 Timer *next;
346 };
348 struct Command
350 int pid;
351 Rune *name;
352 int nname;
353 char *text;
354 char **av;
355 int iseditcmd;
356 Mntdir *md;
357 Command *next;
358 };
360 struct Dirtab
362 char *name;
363 uchar type;
364 uint qid;
365 uint perm;
366 };
368 struct Mntdir
370 int id;
371 int ref;
372 Rune *dir;
373 int ndir;
374 Mntdir *next;
375 int nincl;
376 Rune **incl;
377 };
379 struct Fid
381 int fid;
382 int busy;
383 int open;
384 Qid qid;
385 Window *w;
386 Dirtab *dir;
387 Fid *next;
388 Mntdir *mntdir;
389 int nrpart;
390 uchar rpart[UTFmax];
391 };
394 struct Xfid
396 void *arg; /* args to xfidinit */
397 Fcall fcall;
398 Xfid *next;
399 Channel *c; /* chan(void(*)(Xfid*)) */
400 Fid *f;
401 uchar *buf;
402 int flushed;
404 };
406 void xfidctl(void *);
407 void xfidflush(Xfid*);
408 void xfidopen(Xfid*);
409 void xfidclose(Xfid*);
410 void xfidread(Xfid*);
411 void xfidwrite(Xfid*);
412 void xfidctlwrite(Xfid*, Window*);
413 void xfideventread(Xfid*, Window*);
414 void xfideventwrite(Xfid*, Window*);
415 void xfidindexread(Xfid*);
416 void xfidutfread(Xfid*, Text*, uint, int);
417 int xfidruneread(Xfid*, Text*, uint, uint);
419 struct Reffont
421 Ref ref;
422 Font *f;
424 };
425 Reffont *rfget(int, int, int, char*);
426 void rfclose(Reffont*);
428 struct Rangeset
430 Range r[NRange];
431 };
433 struct Dirlist
435 Rune *r;
436 int nr;
437 int wid;
438 };
440 struct Expand
442 uint q0;
443 uint q1;
444 Rune *name;
445 int nname;
446 char *bname;
447 int jump;
448 union{
449 Text *at;
450 Rune *ar;
451 } u;
452 int (*agetc)(void*, uint);
453 int a0;
454 int a1;
455 };
457 enum
459 /* fbufalloc() guarantees room off end of BUFSIZE */
460 BUFSIZE = Maxblock+IOHDRSZ, /* size from fbufalloc() */
461 RBUFSIZE = BUFSIZE/sizeof(Rune),
462 EVENTSIZE = 256,
463 Scrollwid = 12, /* width of scroll bar */
464 Scrollgap = 4, /* gap right of scroll bar */
465 Margin = 4, /* margin around text */
466 Border = 2, /* line between rows, cols, windows */
467 };
469 #define QID(w,q) ((w<<8)|(q))
470 #define WIN(q) ((((ulong)(q).path)>>8) & 0xFFFFFF)
471 #define FILE(q) ((q).path & 0xFF)
473 #undef FALSE
474 #undef TRUE
476 enum
478 FALSE,
479 TRUE,
480 XXX,
481 };
483 enum
485 Empty = 0,
486 Null = '-',
487 Delete = 'd',
488 Insert = 'i',
489 Replace = 'r',
490 Filename = 'f',
491 };
493 enum /* editing */
495 Inactive = 0,
496 Inserting,
497 Collecting,
498 };
500 uint globalincref;
501 uint seq;
502 uint maxtab; /* size of a tab, in units of the '0' character */
504 Display *display;
505 Image *screen;
506 Font *font;
507 Mouse *mouse;
508 Mousectl *mousectl;
509 Keyboardctl *keyboardctl;
510 Reffont reffont;
511 Image *modbutton;
512 Image *colbutton;
513 Image *button;
514 Image *but2col;
515 Image *but3col;
516 Cursor boxcursor;
517 Row row;
518 int timerpid;
519 Disk *disk;
520 Text *seltext;
521 Text *argtext;
522 Text *mousetext; /* global because Text.close needs to clear it */
523 Text *typetext; /* global because Text.close needs to clear it */
524 Text *barttext; /* shared between mousetask and keyboardthread */
525 int bartflag;
526 int swapscrollbuttons;
527 Window *activewin;
528 Column *activecol;
529 Buffer snarfbuf;
530 Rectangle nullrect;
531 int fsyspid;
532 char *cputype;
533 char *objtype;
534 char *home;
535 char *fontnames[2];
536 Image *tagcols[NCOL];
537 Image *textcols[NCOL];
538 extern char wdir[]; /* must use extern because no dimension given */
539 int editing;
540 int erroutfd;
541 int messagesize; /* negotiated in 9P version setup */
542 int globalautoindent;
543 int dodollarsigns;
545 enum
547 Kscrolloneup = KF|0x20,
548 Kscrollonedown = KF|0x21,
549 };
551 Channel *cplumb; /* chan(Plumbmsg*) */
552 Channel *cwait; /* chan(Waitmsg) */
553 Channel *ccommand; /* chan(Command*) */
554 Channel *ckill; /* chan(Rune*) */
555 Channel *cxfidalloc; /* chan(Xfid*) */
556 Channel *cxfidfree; /* chan(Xfid*) */
557 Channel *cnewwindow; /* chan(Channel*) */
558 Channel *mouseexit0; /* chan(int) */
559 Channel *mouseexit1; /* chan(int) */
560 Channel *cexit; /* chan(int) */
561 Channel *cerr; /* chan(char*) */
562 Channel *cedit; /* chan(int) */
563 Channel *cwarn; /* chan(void*)[1] (really chan(unit)[1]) */
565 #define STACK 32768