master edit.h
ohmu  ·  2026-09-13
 1/*#pragma	varargck	argpos	editerror	1*/
 2
 3typedef struct Addr	Addr;
 4typedef struct Address	Address;
 5typedef struct Cmd	Cmd;
 6typedef struct List	List;
 7typedef struct String	String;
 8
 9struct String
10{
11	int	n;		/* excludes NUL */
12	Rune	*r;		/* includes NUL */
13	int	nalloc;
14};
15
16struct Addr
17{
18	char	type;	/* # (char addr), l (line addr), / ? . $ + - , ; */
19	union{
20		String	*re;
21		Addr	*left;		/* left side of , and ; */
22	} u;
23	ulong	num;
24	Addr	*next;			/* or right side of , and ; */
25};
26
27struct Address
28{
29	Range	r;
30	File	*f;
31};
32
33struct Cmd
34{
35	Addr	*addr;			/* address (range of text) */
36	String	*re;			/* regular expression for e.g. 'x' */
37	union{
38		Cmd	*cmd;		/* target of x, g, {, etc. */
39		String	*text;		/* text of a, c, i; rhs of s */
40		Addr	*mtaddr;		/* address for m, t */
41	} u;
42	Cmd	*next;			/* pointer to next element in {} */
43	short	num;
44	ushort	flag;			/* whatever */
45	ushort	cmdc;			/* command character; 'x' etc. */
46};
47
48extern struct cmdtab{
49	ushort	cmdc;		/* command character */
50	uchar	text;		/* takes a textual argument? */
51	uchar	regexp;		/* takes a regular expression? */
52	uchar	addr;		/* takes an address (m or t)? */
53	uchar	defcmd;		/* default command; 0==>none */
54	uchar	defaddr;	/* default address */
55	uchar	count;		/* takes a count e.g. s2/// */
56	char	*token;		/* takes text terminated by one of these */
57	int	(*fn)(Text*, Cmd*);	/* function to call with parse tree */
58}cmdtab[];
59
60#define	INCR	25	/* delta when growing list */
61
62struct List	/* code depends on a long being able to hold a pointer */
63{
64	int	nalloc;
65	int	nused;
66	union{
67		void	*listptr;
68		void*	*ptr;
69		uchar*	*ucharptr;
70		String*	*stringptr;
71	} u;
72};
73
74enum Defaddr{	/* default addresses */
75	aNo,
76	aDot,
77	aAll
78};
79
80int	nl_cmd(Text*, Cmd*), a_cmd(Text*, Cmd*), b_cmd(Text*, Cmd*);
81int	c_cmd(Text*, Cmd*), d_cmd(Text*, Cmd*);
82int	B_cmd(Text*, Cmd*), D_cmd(Text*, Cmd*), e_cmd(Text*, Cmd*);
83int	f_cmd(Text*, Cmd*), g_cmd(Text*, Cmd*), i_cmd(Text*, Cmd*);
84int	k_cmd(Text*, Cmd*), m_cmd(Text*, Cmd*), n_cmd(Text*, Cmd*);
85int	p_cmd(Text*, Cmd*);
86int	s_cmd(Text*, Cmd*), u_cmd(Text*, Cmd*), w_cmd(Text*, Cmd*);
87int	x_cmd(Text*, Cmd*), X_cmd(Text*, Cmd*), pipe_cmd(Text*, Cmd*);
88int	eq_cmd(Text*, Cmd*);
89
90String	*allocstring(int);
91void		freestring(String*);
92String	*getregexp(int);
93Addr	*newaddr(void);
94Address	cmdaddress(Addr*, Address, int);
95int	cmdexec(Text*, Cmd*);
96void	editerror(char*, ...);
97int	cmdlookup(int);
98void	resetxec(void);
99void	Straddc(String*, int);