source: trunk/minix/commands/elle/eefed.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

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