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