xref: /plan9/sys/src/cmd/acme/edit.h (revision af2e6ba6a88ebbe37fe767755ab16d53fbb9977b)
1 #pragma	varargck	argpos	editerror	1
2 
3 typedef struct Addr	Addr;
4 typedef struct Address	Address;
5 typedef struct Cmd	Cmd;
6 typedef struct List	List;
7 typedef struct String	String;
8 
9 struct String
10 {
11 	int	n;		/* excludes NUL */
12 	Rune	*r;		/* includes NUL */
13 	int	nalloc;
14 };
15 
16 struct Addr
17 {
18 	char	type;	/* # (char addr), l (line addr), / ? . $ + - , ; */
19 	union{
20 		String	*re;
21 		Addr	*left;		/* left side of , and ; */
22 	};
23 	ulong	num;
24 	Addr	*next;			/* or right side of , and ; */
25 };
26 
27 struct Address
28 {
29 	Range	r;
30 	File	*f;
31 };
32 
33 struct 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 	};
42 	Cmd	*next;			/* pointer to next element in {} */
43 	short	num;
44 	ushort	flag;			/* whatever */
45 	ushort	cmdc;			/* command character; 'x' etc. */
46 };
47 
48 extern 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 
62 struct List
63 {
64 	int	nalloc;
65 	int	nused;
66 	union{
67 		void	*listptr;
68 		void*	*ptr;
69 		uchar*	*ucharptr;
70 		String*	*stringptr;
71 	};
72 };
73 
74 enum Defaddr{	/* default addresses */
75 	aNo,
76 	aDot,
77 	aAll,
78 };
79 
80 int	nl_cmd(Text*, Cmd*), a_cmd(Text*, Cmd*), b_cmd(Text*, Cmd*);
81 int	c_cmd(Text*, Cmd*), d_cmd(Text*, Cmd*);
82 int	B_cmd(Text*, Cmd*), D_cmd(Text*, Cmd*), e_cmd(Text*, Cmd*);
83 int	f_cmd(Text*, Cmd*), g_cmd(Text*, Cmd*), i_cmd(Text*, Cmd*);
84 int	k_cmd(Text*, Cmd*), m_cmd(Text*, Cmd*), n_cmd(Text*, Cmd*);
85 int	p_cmd(Text*, Cmd*);
86 int	s_cmd(Text*, Cmd*), u_cmd(Text*, Cmd*), w_cmd(Text*, Cmd*);
87 int	x_cmd(Text*, Cmd*), X_cmd(Text*, Cmd*), pipe_cmd(Text*, Cmd*);
88 int	eq_cmd(Text*, Cmd*);
89 
90 String	*allocstring(int);
91 void	freestring(String*);
92 String	*getregexp(int);
93 Addr	*newaddr(void);
94 Address	cmdaddress(Addr*, Address, int);
95 int	cmdexec(Text*, Cmd*);
96 void	editerror(char*, ...);
97 int	cmdlookup(int);
98 void	resetxec(void);
99 void	Straddc(String*, int);
100