xref: /plan9/sys/src/ape/cmd/sed/sed.h (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
1 #
2 /*
3  * sed -- stream  editor
4  *
5  *
6  */
7 
8 #define CBRA	1
9 #define	CCHR	2
10 #define	CDOT	4
11 #define	CCL	6
12 #define	CNL	8
13 #define	CDOL	10
14 #define	CEOF	11
15 #define CKET	12
16 #define CNULL	13
17 #define CLNUM	14
18 #define CEND	16
19 #define CDONT	17
20 #define	CBACK	18
21 
22 #define	STAR	01
23 
24 #define NLINES	256
25 #define	DEPTH	20
26 #define PTRSIZE	1024
27 #define RESIZE	20000
28 #define	ABUFSIZE	20
29 #define	LBSIZE	4000
30 #define	LABSIZE	50
31 #define NBRA	9
32 
33 typedef unsigned char uchar;
34 
35 FILE	*fin;
36 union reptr	*abuf[ABUFSIZE];
37 union reptr **aptr;
38 uchar	*lastre;
39 uchar	ibuf[512];
40 uchar	*cbp;
41 uchar	*ebp;
42 uchar	genbuf[LBSIZE];
43 uchar	*loc1;
44 uchar	*loc2;
45 uchar	*locs;
46 uchar	seof;
47 uchar	*reend;
48 uchar	*lbend;
49 uchar	*hend;
50 uchar	*lcomend;
51 union reptr	*ptrend;
52 int	eflag;
53 int	dolflag;
54 int	sflag;
55 int	jflag;
56 int	numbra;
57 int	delflag;
58 long	lnum;
59 uchar	linebuf[LBSIZE+1];
60 uchar	holdsp[LBSIZE+1];
61 uchar	*spend;
62 uchar	*hspend;
63 int	nflag;
64 int	gflag;
65 uchar	*braelist[NBRA];
66 uchar	*braslist[NBRA];
67 long	tlno[NLINES];
68 int	nlno;
69 #define MAXFILES	120
70 char	fname[MAXFILES][40];
71 FILE	*fcode[MAXFILES];
72 int	nfiles;
73 
74 #define ACOM	01
75 #define BCOM	020
76 #define CCOM	02
77 #define	CDCOM	025
78 #define	CNCOM	022
79 #define COCOM	017
80 #define	CPCOM	023
81 #define DCOM	03
82 #define ECOM	015
83 #define EQCOM	013
84 #define FCOM	016
85 #define GCOM	027
86 #define CGCOM	030
87 #define HCOM	031
88 #define CHCOM	032
89 #define ICOM	04
90 #define LCOM	05
91 #define NCOM	012
92 #define PCOM	010
93 #define QCOM	011
94 #define RCOM	06
95 #define SCOM	07
96 #define TCOM	021
97 #define WCOM	014
98 #define	CWCOM	024
99 #define	YCOM	026
100 #define XCOM	033
101 
102 uchar	*cp;
103 uchar	*reend;
104 uchar	*lbend;
105 
106 union	reptr {
107 	struct reptr1 {
108 		uchar	*ad1;
109 		uchar	*ad2;
110 		uchar	*re1;
111 		uchar	*rhs;
112 		FILE	*fcode;
113 		uchar	command;
114 		uchar	gfl;
115 		uchar	pfl;
116 		uchar	inar;
117 		uchar	negfl;
118 	} r1;
119 	struct reptr2 {
120 		uchar	*ad1;
121 		uchar	*ad2;
122 		union reptr	*lb1;
123 		uchar	*rhs;
124 		FILE	*fcode;
125 		uchar	command;
126 		uchar	gfl;
127 		uchar	pfl;
128 		uchar	inar;
129 		uchar	negfl;
130 	} r2;
131 } ptrspace[PTRSIZE], *rep;
132 
133 
134 uchar	respace[RESIZE];
135 
136 struct label {
137 	uchar	asc[9];
138 	union reptr	*chain;
139 	union reptr	*address;
140 } ltab[LABSIZE];
141 
142 struct label	*lab;
143 struct label	*labend;
144 
145 int	f;
146 int	depth;
147 
148 int	eargc;
149 uchar	**eargv;
150 
151 uchar	*address(uchar *);
152 int		advance(uchar *, uchar *);
153 void	arout(void);
154 extern	uchar	bittab[];
155 uchar	bad;
156 uchar	*badp;
157 int		cmp(uchar *, uchar *);
158 union reptr	**cmpend[DEPTH];
159 void	command(union reptr *);
160 uchar	compfl;
161 uchar	*compile(uchar *);
162 uchar	*compsub(uchar *);
163 void	dechain(void);
164 int	depth;
165 void	dosub(uchar *);
166 int		ecmp(uchar *, uchar *, int);
167 void	execute(uchar *);
168 void		fcomp(void);
169 uchar	*gline(uchar *);
170 uchar	*lformat(int, uchar *);
171 int		match(uchar *, int);
172 union reptr	*pending;
173 uchar	*place(uchar *, uchar *, uchar *);
174 int		rline(uchar *);
175 struct label	*search(struct label *);
176 int		substitute(union reptr *);
177 uchar	*text(uchar *);
178 uchar	*ycomp(uchar *);
179