Repository navigation
Expand file tree
/
Copy patheefed.c
More file actions
283 lines (247 loc) · 5.95 KB
/
Copy patheefed.c
File metadata and controls
283 lines (247 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
* This software is quasi-public; it may be used freely with
* like software, but may NOT be sold or made part of licensed
* products without permission of the author.
*/
/* EEFED - ED-type functions
*/
#include "elle.h"
/*
* ED_INSERT -- Insert character given as argument.
*/
ed_insert(c)
int c;
{ register SBBUF *sb;
sb = (SBBUF *) cur_buf; /* For a little speed */
sb_putc(sb,c); /* Insert the char */
cur_dot++; /* Advance dot */
buf_tmod((chroff)-1); /* Mark buffer modified, for redisplay etc. */
/* Perhaps later use specialized routine? */
}
ed_insn(ch, cnt)
int ch, cnt;
{ register int i;
if((i = cnt) > 0)
do { ed_insert(ch);
} while(--i);
}
ed_crins()
{
#if FX_EOLMODE
if (eolcrlf(cur_buf)) /* If EOL is made of CR-LF */
ed_insert(CR); /* then first insert CR, then drop down to */
#endif
ed_insert(LF); /* Insert LF */
}
ed_sins (s) /* insert this string */
register char *s;
{ register c;
while (c = *s++)
ed_insert (c);
}
ed_nsins (s, i) /* Insert string of N chars */
register char *s;
register int i;
{ if(i > 0)
do { ed_insert(*s++); } while(--i);
}
/* ED_INDTO(col) - Indent to specified column.
** Finds current cursor position, and inserts tabs and spaces
** so cursor ends up at column goal. Does nothing if already at or past
** specified column.
*/
ed_indto(goal)
register int goal;
{ register int ng;
ng = goal & ~07; /* Get distance to tab stop */
ed_insn(TAB, ((ng - (d_curind() & ~07)) >> 3));
ed_insn(SP, goal-ng);
}
/* Oddball routine - Set cur_dot to actual I/O location and
* tell display that cursor probably moved. This is not really a
* function of itself; it provides support for real functions.
*/
ed_setcur()
{ e_setcur(); /* Set cur_dot */
redp(RD_MOVE); /* Alert redisplay to check cursor loc */
}
/* Go to given dot */
ed_go (dot)
chroff dot;
{ e_go(dot);
ed_setcur();
}
/* Go to given offset from current location */
ed_goff(off)
chroff off;
{ e_goff(off);
ed_setcur();
}
/* Go to given INTEGER offset from current location */
ed_igoff(ioff)
int ioff;
{ e_igoff(ioff);
ed_setcur();
}
/* Reset (delete all of) Buffer
* Should buffer be marked modified or not? Currently isn't.
*/
ed_reset()
{ if(e_blen() == 0)
return; /* Already empty */
e_reset();
cur_dot = 0;
cur_win->w_topldot = 0; /* Is this necessary? */
#if IMAGEN
redp(RD_WINRES|RD_REDO);
#else
redp(RD_WINRES); /* This window needs complete update */
#endif /*-IMAGEN*/
/* buf_mod(); */ /* Mark modified ?? */
/* mark_p = 0; */ /* Say no mark set ?? */
}
ed_deln(off)
chroff off;
{ chroff dot;
dot = e_dot();
e_goff(off);
ed_delete(e_dot(), dot);
}
/* ED_DELETE(dot1,dot2) - Delete all characters between the two
* positions indicated by dot1 and dot2. Their order does not
* matter; cur_dot and mark_dot are updated as necessary.
*/
ed_delete(dot1,dot2)
chroff dot1,dot2;
{ chroff tmpdot, savdot;
if(dot1 > dot2)
{ tmpdot = dot1;
dot1 = dot2;
dot2 = tmpdot;
}
e_go(dot1);
tmpdot = dot2-dot1;
sb_deln((SBBUF *)cur_buf,tmpdot);
savdot = cur_dot; /* Save cur_dot value */
cur_dot = dot1; /* so can set up for */
buf_tmod((chroff)0); /* call to update disp-change vars */
cur_dot = savdot;
if(cur_dot >= dot2)
cur_dot -= tmpdot;
else if(cur_dot > dot1)
cur_dot = dot1;
if(mark_dot >= dot2)
mark_dot -= tmpdot;
else if(mark_dot > dot1)
mark_dot = dot1;
e_gocur();
}
/* ED_KILL(dot1,dot2) - Kill (save and delete) text between two places in
* the buffer.
* We assume we are deleting from dot1 to dot2, thus if dot1 > dot2
* then backwards deletion is implied, and the saved text is prefixed
* (instead of appended) to any previously killed text.
*/
ed_kill(dot1,dot2)
chroff dot1,dot2;
{ register SBSTR *sd, *sdo;
SBSTR *e_copyn();
e_go(dot1);
sd = e_copyn(dot2-dot1);
if(sd == 0) return;
if(last_cmd == KILLCMD && (sdo = kill_ring[kill_ptr]))
{ if(dot1 > dot2) /* Prefix new killed stuff onto old stuff */
{ sbs_app(sd,sdo);
kill_ring[kill_ptr] = sd;
}
else /* Append new stuff to old stuff */
sbs_app(sdo,sd);
}
else kill_push(sd);
ed_delete(dot1,dot2);
}
kill_push(sdp)
SBSTR *sdp;
{ register SBSTR *sd;
if(++kill_ptr >= KILL_LEN) kill_ptr = 0;
if(sd = kill_ring[kill_ptr])
sbs_del(sd);
kill_ring[kill_ptr] = sdp;
}
#define isupper(c) (('A' <= c) && (c <= 'Z'))
#define islower(c) (('a' <= c) && (c <= 'z'))
#define toupper(c) (c + ('A' - 'a'))
#define tolower(c) (c + ('a' - 'A'))
#if FX_UCWORD||FX_LCWORD||FX_UCIWORD||FX_UCREG||FX_LCREG
/* ED_CASE(dot1,dot2,downp) - Change the case within a region.
* downp = 0 for uppercase, 1 for lowercase, 2 for capitalize.
*/
ed_case(dot1, dot2, downp)
chroff dot1, dot2;
int downp;
{ chroff dcnt;
register int c, a, z;
int modflg;
modflg = 0;
if((dcnt = dot2 - dot1) < 0)
{ dcnt = dot1;
dot1 = dot2;
dot2 = dcnt;
dcnt -= dot1;
}
e_go(dot1);
if(downp==2)
{ a = 0; /* 0 looking for wd, 1 in word */
while(--dcnt >= 0)
{ if(delimp(c = e_getc())) /* Char in wd? */
{ a = 0; /* No */
continue;
}
if(a) /* If already inside word */
{ if(isupper(c))
c = tolower(c);
else continue;
}
else /* If encountered start of word */
{ a = 1;
if(islower(c))
c = toupper(c);
else continue;
}
e_backc();
e_ovwc(c);
modflg++;
}
goto casdon;
}
if(downp==0)
{ a = 'a'; /* Convert to lower case */
z = 'z';
downp = -040;
}
else
{ a = 'A'; /* Convert to upper case */
z = 'Z';
downp = 040;
}
while(--dcnt >= 0)
{ if(a <= (c = e_getc()) && c <= z)
{ e_backc();
e_ovwc(c+downp);
modflg++;
}
}
casdon: dot2 = cur_dot; /* Save dot */
e_setcur(); /* Set up for modification range chk*/
if(modflg)
buf_tmat(dot1); /* Stuff munged from there to here */
ed_go(dot2);
}
#endif /* any ed_case caller */
/* UPCASE(c) - Return upper-case version of character */
upcase(ch)
int ch;
{ register int c;
c = ch&0177;
return(islower(c) ? toupper(c) : c);
}