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