Blob


1 /*#pragma varargck argpos editerror 1*/
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;
9 struct String
10 {
11 int n; /* excludes NUL */
12 Rune *r; /* includes NUL */
13 int nalloc;
14 };
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 } u;
23 ulong num;
24 Addr *next; /* or right side of , and ; */
25 };
27 struct Address
28 {
29 Range r;
30 File *f;
31 };
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 } u;
42 Cmd *next; /* pointer to next element in {} */
43 short num;
44 ushort flag; /* whatever */
45 ushort cmdc; /* command character; 'x' etc. */
46 };
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[];
60 #define INCR 25 /* delta when growing list */
62 struct 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 Block *blkptr;
69 long *longptr;
70 uchar* *ucharptr;
71 String* *stringptr;
72 File* *fileptr;
73 } u;
74 };
76 enum Defaddr{ /* default addresses */
77 aNo,
78 aDot,
79 aAll,
80 };
82 int nl_cmd(Text*, Cmd*), a_cmd(Text*, Cmd*), b_cmd(Text*, Cmd*);
83 int c_cmd(Text*, Cmd*), d_cmd(Text*, Cmd*);
84 int B_cmd(Text*, Cmd*), D_cmd(Text*, Cmd*), e_cmd(Text*, Cmd*);
85 int f_cmd(Text*, Cmd*), g_cmd(Text*, Cmd*), i_cmd(Text*, Cmd*);
86 int k_cmd(Text*, Cmd*), m_cmd(Text*, Cmd*), n_cmd(Text*, Cmd*);
87 int p_cmd(Text*, Cmd*);
88 int s_cmd(Text*, Cmd*), u_cmd(Text*, Cmd*), w_cmd(Text*, Cmd*);
89 int x_cmd(Text*, Cmd*), X_cmd(Text*, Cmd*), pipe_cmd(Text*, Cmd*);
90 int eq_cmd(Text*, Cmd*);
92 String *allocstring(int);
93 void freestring(String*);
94 String *getregexp(int);
95 Addr *newaddr(void);
96 Address cmdaddress(Addr*, Address, int);
97 int cmdexec(Text*, Cmd*);
98 void editerror(char*, ...);
99 int cmdlookup(int);
100 void resetxec(void);
101 void Straddc(String*, int);