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