xref: /plan9-contrib/sys/src/cmd/acme/dat.h (revision 9bcb93539438d7e15f51959b802af26285e4993f)
1 enum
2 {
3 	Qdir,
4 	Qacme,
5 	Qcons,
6 	Qconsctl,
7 	Qdraw,
8 	Qeditout,
9 	Qindex,
10 	Qlabel,
11 	Qnew,
12 
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 };
26 
27 enum
28 {
29 	Blockincr =	256,
30 	Maxblock = 	16*1024,
31 	NRange =		10,
32 	Infinity = 		0x7FFFFFFF,	/* huge value for regexp address */
33 };
34 
35 typedef	struct	Block Block;
36 typedef	struct	Buffer Buffer;
37 typedef	struct	Command Command;
38 typedef	struct	Column Column;
39 typedef	struct	Dirlist Dirlist;
40 typedef	struct	Dirtab Dirtab;
41 typedef	struct	Disk Disk;
42 typedef	struct	Expand Expand;
43 typedef	struct	Fid Fid;
44 typedef	struct	File File;
45 typedef	struct	Elog Elog;
46 typedef	struct	Mntdir Mntdir;
47 typedef	struct	Range Range;
48 typedef	struct	Rangeset Rangeset;
49 typedef	struct	Reffont Reffont;
50 typedef	struct	Row Row;
51 typedef	struct	Runestr Runestr;
52 typedef	struct	Text Text;
53 typedef	struct	Timer Timer;
54 typedef	struct	Window Window;
55 typedef	struct	Xfid Xfid;
56 
57 struct Runestr
58 {
59 	Rune	*r;
60 	int	nr;
61 };
62 
63 struct Range
64 {
65 	int	q0;
66 	int	q1;
67 };
68 
69 struct Block
70 {
71 	uint		addr;	/* disk address in bytes */
72 	union
73 	{
74 		uint	n;		/* number of used runes in block */
75 		Block	*next;	/* pointer to next in free list */
76 	};
77 };
78 
79 struct Disk
80 {
81 	int		fd;
82 	uint		addr;	/* length of temp file */
83 	Block	*free[Maxblock/Blockincr+1];
84 };
85 
86 Disk*	diskinit(void);
87 Block*	disknewblock(Disk*, uint);
88 void		diskrelease(Disk*, Block*);
89 void		diskread(Disk*, Block*, Rune*, uint);
90 void		diskwrite(Disk*, Block**, Rune*, uint);
91 
92 struct Buffer
93 {
94 	uint	nc;
95 	Rune	*c;			/* cache */
96 	uint	cnc;			/* bytes in cache */
97 	uint	cmax;		/* size of allocated cache */
98 	uint	cq;			/* position of cache */
99 	int		cdirty;	/* cache needs to be written */
100 	uint	cbi;			/* index of cache Block */
101 	Block	**bl;		/* array of blocks */
102 	uint	nbl;			/* number of blocks */
103 };
104 void		bufinsert(Buffer*, uint, Rune*, uint);
105 void		bufdelete(Buffer*, uint, uint);
106 uint		bufload(Buffer*, uint, int, int*);
107 void		bufread(Buffer*, uint, Rune*, uint);
108 void		bufclose(Buffer*);
109 void		bufreset(Buffer*);
110 
111 struct Elog
112 {
113 	short	type;		/* Delete, Insert, Filename */
114 	uint		q0;		/* location of change (unused in f) */
115 	uint		nd;		/* number of deleted characters */
116 	uint		nr;		/* # runes in string or file name */
117 	Rune		*r;
118 };
119 void	elogterm(File*);
120 void	elogclose(File*);
121 void	eloginsert(File*, int, Rune*, int);
122 void	elogdelete(File*, int, int);
123 void	elogreplace(File*, int, int, Rune*, int);
124 void	elogapply(File*);
125 
126 struct File
127 {
128 	Buffer;			/* the data */
129 	Buffer	delta;	/* transcript of changes */
130 	Buffer	epsilon;	/* inversion of delta for redo */
131 	Buffer	*elogbuf;	/* log of pending editor changes */
132 	Elog		elog;		/* current pending change */
133 	Rune		*name;	/* name of associated file */
134 	int		nname;	/* size of name */
135 	uvlong	qidpath;	/* of file when read */
136 	uint		mtime;	/* of file when read */
137 	int		dev;		/* of file when read */
138 	int		unread;	/* file has not been read from disk */
139 	int		editclean;	/* mark clean after edit command */
140 
141 	int		seq;		/* if seq==0, File acts like Buffer */
142 	int		mod;
143 	Text		*curtext;	/* most recently used associated text */
144 	Text		**text;	/* list of associated texts */
145 	int		ntext;
146 	int		dumpid;	/* used in dumping zeroxed windows */
147 };
148 File*		fileaddtext(File*, Text*);
149 void		fileclose(File*);
150 void		filedelete(File*, uint, uint);
151 void		filedeltext(File*, Text*);
152 void		fileinsert(File*, uint, Rune*, uint);
153 uint		fileload(File*, uint, int, int*);
154 void		filemark(File*);
155 void		filereset(File*);
156 void		filesetname(File*, Rune*, int);
157 void		fileundelete(File*, Buffer*, uint, uint);
158 void		fileuninsert(File*, Buffer*, uint, uint);
159 void		fileunsetname(File*, Buffer*);
160 void		fileundo(File*, int, uint*, uint*);
161 uint		fileredoseq(File*);
162 
163 enum	/* Text.what */
164 {
165 	Columntag,
166 	Rowtag,
167 	Tag,
168 	Body,
169 };
170 
171 struct Text
172 {
173 	File		*file;
174 	Frame;
175 	Reffont	*reffont;
176 	uint	org;
177 	uint	q0;
178 	uint	q1;
179 	int	what;
180 	int	tabstop;
181 	Window	*w;
182 	Rectangle scrollr;
183 	Rectangle lastsr;
184 	Rectangle all;
185 	Row		*row;
186 	Column	*col;
187 
188 	uint	eq0;	/* start of typing for ESC */
189 	uint	cq0;	/* cache position */
190 	int		ncache;	/* storage for insert */
191 	int		ncachealloc;
192 	Rune	*cache;
193 	int	nofill;
194 };
195 
196 uint		textbacknl(Text*, uint, uint);
197 uint		textbsinsert(Text*, uint, Rune*, uint, int, int*);
198 int		textbswidth(Text*, Rune);
199 int		textclickmatch(Text*, int, int, int, uint*);
200 void		textclose(Text*);
201 void		textcolumnate(Text*, Dirlist**, int);
202 void		textcommit(Text*, int);
203 void		textconstrain(Text*, uint, uint, uint*, uint*);
204 void		textdelete(Text*, uint, uint, int);
205 void		textdoubleclick(Text*, uint*, uint*);
206 void		textfill(Text*);
207 void		textframescroll(Text*, int);
208 void		textinit(Text*, File*, Rectangle, Reffont*, Image**);
209 void		textinsert(Text*, uint, Rune*, uint, int);
210 uint		textload(Text*, uint, char*, int);
211 Rune		textreadc(Text*, uint);
212 void		textredraw(Text*, Rectangle, Font*, Image*, int);
213 void		textreset(Text*);
214 int		textresize(Text*, Rectangle, int);
215 void		textscrdraw(Text*);
216 void		textscroll(Text*, int);
217 void		textselect(Text*);
218 int		textselect2(Text*, uint*, uint*, Text**);
219 int		textselect23(Text*, uint*, uint*, Image*, int);
220 int		textselect3(Text*, uint*, uint*);
221 void		textsetorigin(Text*, uint, int);
222 void		textsetselect(Text*, uint, uint);
223 void		textshow(Text*, uint, uint, int);
224 void		texttype(Text*, Rune);
225 
226 struct Window
227 {
228 		QLock;
229 		Ref;
230 	Text		tag;
231 	Text		body;
232 	Rectangle	r;
233 	uchar	isdir;
234 	uchar	isscratch;
235 	uchar	filemenu;
236 	uchar	dirty;
237 	uchar	autoindent;
238 	uchar	showdel;
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 	QLock	editoutlk;
272 };
273 
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);
294 
295 struct Column
296 {
297 	Rectangle r;
298 	Text	tag;
299 	Row		*row;
300 	Window	**w;
301 	int		nw;
302 	int		safe;
303 };
304 
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*);
316 
317 struct Row
318 {
319 	QLock;
320 	Rectangle r;
321 	Text	tag;
322 	Column	**col;
323 	int		ncol;
324 
325 };
326 
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*);
339 
340 struct Timer
341 {
342 	int		dt;
343 	int		cancel;
344 	Channel	*c;	/* chan(int) */
345 	Timer	*next;
346 };
347 
348 struct Command
349 {
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 };
359 
360 struct Dirtab
361 {
362 	char	*name;
363 	uchar	type;
364 	uint	qid;
365 	uint	perm;
366 };
367 
368 struct Mntdir
369 {
370 	int		id;
371 	int		ref;
372 	Rune		*dir;
373 	int		ndir;
374 	Mntdir	*next;
375 	int		nincl;
376 	Rune		**incl;
377 };
378 
379 struct Fid
380 {
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 };
392 
393 
394 struct Xfid
395 {
396 	void		*arg;	/* args to xfidinit */
397 	Fcall;
398 	Xfid	*next;
399 	Channel	*c;		/* chan(void(*)(Xfid*)) */
400 	Fid	*f;
401 	uchar	*buf;
402 	int	flushed;
403 
404 };
405 
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);
418 
419 struct Reffont
420 {
421 	Ref;
422 	Font		*f;
423 
424 };
425 Reffont	*rfget(int, int, int, char*);
426 void		rfclose(Reffont*);
427 
428 struct Rangeset
429 {
430 	Range	r[NRange];
431 };
432 
433 struct Dirlist
434 {
435 	Rune	*r;
436 	int		nr;
437 	int		wid;
438 };
439 
440 struct Expand
441 {
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 	};
452 	int	(*agetc)(void*, uint);
453 	int	a0;
454 	int	a1;
455 };
456 
457 enum
458 {
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 };
468 
469 #define	QID(w,q)	((w<<8)|(q))
470 #define	WIN(q)	((((ulong)(q).path)>>8) & 0xFFFFFF)
471 #define	FILE(q)	((q).path & 0xFF)
472 
473 enum
474 {
475 	FALSE,
476 	TRUE,
477 	XXX,
478 };
479 
480 enum
481 {
482 	Empty	= 0,
483 	Null		= '-',
484 	Delete	= 'd',
485 	Insert	= 'i',
486 	Replace	= 'r',
487 	Filename	= 'f',
488 };
489 
490 enum	/* editing */
491 {
492 	Inactive	= 0,
493 	Inserting,
494 	Collecting,
495 };
496 
497 uint		globalincref;
498 uint		seq;
499 uint		maxtab;	/* size of a tab, in units of the '0' character */
500 
501 Display		*display;
502 Image		*screen;
503 Font			*font;
504 Mouse		*mouse;
505 Mousectl		*mousectl;
506 Keyboardctl	*keyboardctl;
507 Reffont		reffont;
508 Image		*modbutton;
509 Image		*colbutton;
510 Image		*button;
511 Image		*but2col;
512 Image		*but3col;
513 Cursor		boxcursor;
514 Row			row;
515 int			timerpid;
516 Disk			*disk;
517 Text			*seltext;
518 Text			*argtext;
519 Text			*mousetext;	/* global because Text.close needs to clear it */
520 Text			*typetext;		/* global because Text.close needs to clear it */
521 Text			*barttext;		/* shared between mousetask and keyboardthread */
522 int			bartflag;
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 char			acmeerrorfile[128];
533 Image		*tagcols[NCOL];
534 Image		*textcols[NCOL];
535 int			plumbsendfd;
536 int			plumbeditfd;
537 char			wdir[];
538 int			editing;
539 int			messagesize;		/* negotiated in 9P version setup */
540 int			globalautoindent;
541 
542 enum
543 {
544 	Kscrolloneup		= KF|0x20,
545 	Kscrollonedown	= KF|0x21,
546 };
547 
548 Channel	*cplumb;		/* chan(Plumbmsg*) */
549 Channel	*cwait;		/* chan(Waitmsg) */
550 Channel	*ccommand;	/* chan(Command*) */
551 Channel	*ckill;		/* chan(Rune*) */
552 Channel	*cxfidalloc;	/* chan(Xfid*) */
553 Channel	*cxfidfree;	/* chan(Xfid*) */
554 Channel	*cnewwindow;	/* chan(Channel*) */
555 Channel	*mouseexit0;	/* chan(int) */
556 Channel	*mouseexit1;	/* chan(int) */
557 Channel	*cexit;		/* chan(int) */
558 Channel	*cerr;		/* chan(char*) */
559 Channel	*cedit;		/* chan(int) */
560 Channel	*cwarn;		/* chan(void*)[1] (really chan(unit)[1]) */
561 
562 #define	STACK	8192
563