ed.h revision 1.1 1 1.1 cgd /* ed.h: type and constant definitions for the ed editor. */
2 1.1 cgd /*
3 1.1 cgd * Copyright (c) 1993 The Regents of the University of California.
4 1.1 cgd * All rights reserved.
5 1.1 cgd *
6 1.1 cgd * This code is derived from software contributed to Berkeley by
7 1.1 cgd * Andrew Moore, Talke Studio.
8 1.1 cgd *
9 1.1 cgd * Redistribution and use in source and binary forms, with or without
10 1.1 cgd * modification, are permitted provided that the following conditions
11 1.1 cgd * are met:
12 1.1 cgd * 1. Redistributions of source code must retain the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer.
14 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 cgd * notice, this list of conditions and the following disclaimer in the
16 1.1 cgd * documentation and/or other materials provided with the distribution.
17 1.1 cgd * 3. All advertising materials mentioning features or use of this software
18 1.1 cgd * must display the following acknowledgement:
19 1.1 cgd * This product includes software developed by the University of
20 1.1 cgd * California, Berkeley and its contributors.
21 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
22 1.1 cgd * may be used to endorse or promote products derived from this software
23 1.1 cgd * without specific prior written permission.
24 1.1 cgd *
25 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.1 cgd * SUCH DAMAGE.
36 1.1 cgd *
37 1.1 cgd * @(#)ed.h 5.5 (Berkeley) 3/28/93
38 1.1 cgd */
39 1.1 cgd
40 1.1 cgd #include <unistd.h>
41 1.1 cgd # include <regex.h>
42 1.1 cgd #if defined(BSD) && BSD >= 199103 || defined(__386BSD__)
43 1.1 cgd # include <sys/param.h> /* for MAXPATHLEN */
44 1.1 cgd #endif
45 1.1 cgd
46 1.1 cgd #define BITSPERBYTE 8
47 1.1 cgd #define BITS(type) (BITSPERBYTE * (int)sizeof(type))
48 1.1 cgd #define CHARBITS BITS(char)
49 1.1 cgd #define INTBITS BITS(int)
50 1.1 cgd
51 1.1 cgd #define ESCHAR '\\'
52 1.1 cgd #define CCL '[' /* Character class: [...] */
53 1.1 cgd #define CCLEND ']'
54 1.1 cgd #define DITTO '&'
55 1.1 cgd
56 1.1 cgd /* sigflags values */
57 1.1 cgd #define SIG_INT 1
58 1.1 cgd #define SIG_HUP 2
59 1.1 cgd
60 1.1 cgd #define TRUE 1
61 1.1 cgd #define FALSE 0
62 1.1 cgd #define ERR (-2)
63 1.1 cgd #define EMOD (ERR - 1)
64 1.1 cgd
65 1.1 cgd #ifndef MAXPATHLEN
66 1.1 cgd # define MAXPATHLEN 255 /* _POSIX_PATH_MAX */
67 1.1 cgd #endif
68 1.1 cgd
69 1.1 cgd #define MAXFNAME MAXPATHLEN /* max file name size */
70 1.1 cgd #define MAXLINE (4 << 10) /* max number of chars per line */
71 1.1 cgd #define SE_MAX 30 /* max subexpressions in a regular expression */
72 1.1 cgd
73 1.1 cgd typedef regex_t pattern_t;
74 1.1 cgd
75 1.1 cgd #ifdef GNU_REGEX
76 1.1 cgd # define FASTMAP_SIZE 256 /* size of fastmap for 8 bit character set */
77 1.1 cgd #endif
78 1.1 cgd
79 1.1 cgd /* Line node */
80 1.1 cgd typedef struct line {
81 1.1 cgd struct line *next;
82 1.1 cgd struct line *prev;
83 1.1 cgd off_t seek; /* address of line in scratch buffer */
84 1.1 cgd
85 1.1 cgd #define ACTV (1 << (INTBITS - 1)) /* active status: high bit of len */
86 1.1 cgd
87 1.1 cgd int len; /* length of line */
88 1.1 cgd } line_t;
89 1.1 cgd
90 1.1 cgd
91 1.1 cgd typedef struct undo {
92 1.1 cgd
93 1.1 cgd /* type of undo nodes */
94 1.1 cgd #define UADD 0
95 1.1 cgd #define UDEL 1
96 1.1 cgd
97 1.1 cgd int type; /* command type */
98 1.1 cgd line_t *h; /* head of list */
99 1.1 cgd line_t *t; /* tail of list */
100 1.1 cgd } undo_t;
101 1.1 cgd
102 1.1 cgd #ifndef max
103 1.1 cgd # define max(a,b) ((a) > (b) ? (a) : (b))
104 1.1 cgd #endif
105 1.1 cgd
106 1.1 cgd #ifndef min
107 1.1 cgd # define min(a,b) ((a) < (b) ? (a) : (b))
108 1.1 cgd #endif
109 1.1 cgd
110 1.1 cgd /* nextln: return line after l wrt k */
111 1.1 cgd #define nextln(l,k) ((l)+1 > (k) ? 0 : (l)+1)
112 1.1 cgd
113 1.1 cgd /* nextln: return line before l wrt k */
114 1.1 cgd #define prevln(l,k) ((l)-1 < 0 ? (k) : (l)-1)
115 1.1 cgd
116 1.1 cgd #define skipblanks() while (isspace(*ibufp) && *ibufp != '\n') ibufp++
117 1.1 cgd
118 1.1 cgd /* spl1: disable some interrupts (requires reliable signals) */
119 1.1 cgd #define spl1() mutex++
120 1.1 cgd
121 1.1 cgd /* spl0: enable all interrupts; check sigflags (requires reliable signals) */
122 1.1 cgd #define spl0() \
123 1.1 cgd if (--mutex == 0) { \
124 1.1 cgd if (sigflags & SIG_HUP) dohup(); \
125 1.1 cgd if (sigflags & SIG_INT) dointr(); \
126 1.1 cgd }
127 1.1 cgd
128 1.1 cgd /* requeue: link pred before succ */
129 1.1 cgd #define requeue(pred, succ) (pred)->next = (succ), (succ)->prev = (pred)
130 1.1 cgd
131 1.1 cgd /* insqueue: insert elem in circular queue after pred */
132 1.1 cgd #define insqueue(elem, pred) \
133 1.1 cgd { \
134 1.1 cgd requeue((elem), (pred)->next); \
135 1.1 cgd requeue((pred), elem); \
136 1.1 cgd }
137 1.1 cgd
138 1.1 cgd /* remqueue: remove elem from circular queue */
139 1.1 cgd #define remqueue(elem) requeue((elem)->prev, (elem)->next);
140 1.1 cgd
141 1.1 cgd #ifndef __P
142 1.1 cgd # ifndef __STDC__
143 1.1 cgd # define __P(proto) ()
144 1.1 cgd # else
145 1.1 cgd # define __P(proto) proto
146 1.1 cgd # endif
147 1.1 cgd #endif
148 1.1 cgd
149 1.1 cgd /* local function declarations */
150 1.1 cgd int append __P((long, int));
151 1.1 cgd int cbcdec __P((char *, FILE *));
152 1.1 cgd int cbcenc __P((char *, int, FILE *));
153 1.1 cgd void cbcinit __P((void));
154 1.1 cgd int ckglob __P((void));
155 1.1 cgd int deflt __P((long, long));
156 1.1 cgd int del __P((long, long));
157 1.1 cgd int desgetc __P((FILE *));
158 1.1 cgd FILE *desopen __P((char *, char *));
159 1.1 cgd int desputc __P((int, FILE *));
160 1.1 cgd int docmd __P((int));
161 1.1 cgd char *ccl __P((int, char *));
162 1.1 cgd long doglob __P((void));
163 1.1 cgd void dohup __P((void));
164 1.1 cgd void dointr __P((void));
165 1.1 cgd int doprnt __P((long, long, int));
166 1.1 cgd long doread __P((long, char *));
167 1.1 cgd long dowrite __P((long, long, char *, char *));
168 1.1 cgd char *esctos __P((char *));
169 1.1 cgd long find __P((pattern_t *, int));
170 1.1 cgd void freecmdv __P((void));
171 1.1 cgd char *getcmdv __P((void));
172 1.1 cgd char *getfn __P((void));
173 1.1 cgd int getkey __P((void));
174 1.1 cgd char *getlhs __P((int));
175 1.1 cgd int getline __P((char *, int));
176 1.1 cgd int getlist __P((void));
177 1.1 cgd long getnum __P((int));
178 1.1 cgd long getone __P((void));
179 1.1 cgd line_t *getptr __P((long));
180 1.1 cgd long getrange __P((line_t *, line_t *));
181 1.1 cgd int getrhs __P((char *, int));
182 1.1 cgd char *gettxt __P((line_t *));
183 1.1 cgd undo_t *getuptr __P((int, long, long));
184 1.1 cgd int join __P((long, long));
185 1.1 cgd line_t *lpdup __P((line_t *));
186 1.1 cgd void lpqueue __P((line_t *));
187 1.1 cgd char *makesub __P((char *, int, int));
188 1.1 cgd int move __P((long, int));
189 1.1 cgd int oddesc __P((char *, char *));
190 1.1 cgd void onhup __P((int));
191 1.1 cgd void onintr __P((int));
192 1.1 cgd pattern_t *optpat __P((void));
193 1.1 cgd void prntln __P((char *, long, int));
194 1.1 cgd char *puttxt __P((char *));
195 1.1 cgd void quit __P((int));
196 1.1 cgd char *regsub __P((pattern_t *, char *, char *, int));
197 1.1 cgd int sbclose __P((void));
198 1.1 cgd int sbopen __P((void));
199 1.1 cgd int sgetline __P((char *, int, FILE *));
200 1.1 cgd char *subcat __P((char *, regmatch_t *, char *, char *, char *));
201 1.1 cgd int subst __P((pattern_t *, char *, int));
202 1.1 cgd int transfer __P((long));
203 1.1 cgd int undo __P((void));
204 1.1 cgd void ureset __P((void));
205