xref: /plan9/sys/src/cmd/sam/parse.h (revision 5e91980f0bca263e952809e3dc0cfc5dde74b999)
1 typedef struct Addr Addr;
2 typedef struct Cmd Cmd;
3 struct Addr
4 {
5 	char	type;	/* # (char addr), l (line addr), / ? . $ + - , ; */
6 	union{
7 		String	*re;
8 		Addr	*aleft;		/* left side of , and ; */
9 	} g;
10 	Posn	num;
11 	Addr	*next;			/* or right side of , and ; */
12 };
13 
14 #define	are	g.re
15 #define	left	g.aleft
16 
17 struct Cmd
18 {
19 	Addr	*addr;			/* address (range of text) */
20 	String	*re;			/* regular expression for e.g. 'x' */
21 	union{
22 		Cmd	*cmd;		/* target of x, g, {, etc. */
23 		String	*text;		/* text of a, c, i; rhs of s */
24 		Addr	*addr;		/* address for m, t */
25 	} g;
26 	Cmd	*next;			/* pointer to next element in {} */
27 	short	num;
28 	ushort	flag;			/* whatever */
29 	ushort	cmdc;			/* command character; 'x' etc. */
30 };
31 
32 #define	ccmd	g.cmd
33 #define	ctext	g.text
34 #define	caddr	g.addr
35 
36 typedef struct Cmdtab Cmdtab;
37 struct Cmdtab
38 {
39 	ushort	cmdc;		/* command character */
40 	uchar	text;		/* takes a textual argument? */
41 	uchar	regexp;		/* takes a regular expression? */
42 	uchar	addr;		/* takes an address (m or t)? */
43 	uchar	defcmd;		/* default command; 0==>none */
44 	uchar	defaddr;	/* default address */
45 	uchar	count;		/* takes a count e.g. s2/// */
46 	char	*token;		/* takes text terminated by one of these */
47 	int	(*fn)(File*, Cmd*);	/* function to call with parse tree */
48 }cmdtab[];
49 
50 enum Defaddr{	/* default addresses */
51 	aNo,
52 	aDot,
53 	aAll,
54 };
55 
56 int	nl_cmd(File*, Cmd*), a_cmd(File*, Cmd*), b_cmd(File*, Cmd*);
57 int	c_cmd(File*, Cmd*), cd_cmd(File*, Cmd*), d_cmd(File*, Cmd*);
58 int	D_cmd(File*, Cmd*), e_cmd(File*, Cmd*);
59 int	f_cmd(File*, Cmd*), g_cmd(File*, Cmd*), i_cmd(File*, Cmd*);
60 int	k_cmd(File*, Cmd*), m_cmd(File*, Cmd*), n_cmd(File*, Cmd*);
61 int	p_cmd(File*, Cmd*), q_cmd(File*, Cmd*);
62 int	s_cmd(File*, Cmd*), u_cmd(File*, Cmd*), w_cmd(File*, Cmd*);
63 int	x_cmd(File*, Cmd*), X_cmd(File*, Cmd*), plan9_cmd(File*, Cmd*);
64 int	eq_cmd(File*, Cmd*);
65 
66 
67 String	*getregexp(int);
68 Addr	*newaddr(void);
69 Address	address(Addr*, Address, int);
70 int	cmdexec(File*, Cmd*);
71