pci: don't do sanity check for missing pci bus, the check can misfire.
[minix.git] / commands / elle / eefed.c
blob00b7c28c9918d7acbd5a343b918b792c9e16fe4a
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"
11 * ED_INSERT -- Insert character given as argument.
14 ed_insert(c)
15 int c;
16 { register SBBUF *sb;
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? */
25 ed_insn(ch, cnt)
26 int ch, cnt;
27 { register int i;
28 if((i = cnt) > 0)
29 do { ed_insert(ch);
30 } while(--i);
33 ed_crins()
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 */
43 ed_sins (s) /* insert this string */
44 register char *s;
45 { register c;
46 while (c = *s++)
47 ed_insert (c);
50 ed_nsins (s, i) /* Insert string of N chars */
51 register char *s;
52 register int i;
53 { if(i > 0)
54 do { ed_insert(*s++); } while(--i);
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.
63 ed_indto(goal)
64 register int goal;
65 { register int ng;
67 ng = goal & ~07; /* Get distance to tab stop */
68 ed_insn(TAB, ((ng - (d_curind() & ~07)) >> 3));
69 ed_insn(SP, goal-ng);
72 /* Oddball routine - Set cur_dot to actual I/O location and
73 * tell display that cursor probably moved. This is not really a
74 * function of itself; it provides support for real functions.
76 ed_setcur()
77 { e_setcur(); /* Set cur_dot */
78 redp(RD_MOVE); /* Alert redisplay to check cursor loc */
81 /* Go to given dot */
82 ed_go (dot)
83 chroff dot;
84 { e_go(dot);
85 ed_setcur();
88 /* Go to given offset from current location */
89 ed_goff(off)
90 chroff off;
91 { e_goff(off);
92 ed_setcur();
95 /* Go to given INTEGER offset from current location */
96 ed_igoff(ioff)
97 int ioff;
98 { e_igoff(ioff);
99 ed_setcur();
102 /* Reset (delete all of) Buffer
103 * Should buffer be marked modified or not? Currently isn't.
105 ed_reset()
106 { if(e_blen() == 0)
107 return; /* Already empty */
108 e_reset();
109 cur_dot = 0;
110 cur_win->w_topldot = 0; /* Is this necessary? */
111 #if IMAGEN
112 redp(RD_WINRES|RD_REDO);
113 #else
114 redp(RD_WINRES); /* This window needs complete update */
115 #endif /*-IMAGEN*/
117 /* buf_mod(); */ /* Mark modified ?? */
118 /* mark_p = 0; */ /* Say no mark set ?? */
121 ed_deln(off)
122 chroff off;
123 { chroff dot;
124 dot = e_dot();
125 e_goff(off);
126 ed_delete(e_dot(), dot);
129 /* ED_DELETE(dot1,dot2) - Delete all characters between the two
130 * positions indicated by dot1 and dot2. Their order does not
131 * matter; cur_dot and mark_dot are updated as necessary.
133 ed_delete(dot1,dot2)
134 chroff dot1,dot2;
135 { chroff tmpdot, savdot;
137 if(dot1 > dot2)
138 { tmpdot = dot1;
139 dot1 = dot2;
140 dot2 = tmpdot;
142 e_go(dot1);
143 tmpdot = dot2-dot1;
144 sb_deln((SBBUF *)cur_buf,tmpdot);
146 savdot = cur_dot; /* Save cur_dot value */
147 cur_dot = dot1; /* so can set up for */
148 buf_tmod((chroff)0); /* call to update disp-change vars */
149 cur_dot = savdot;
151 if(cur_dot >= dot2)
152 cur_dot -= tmpdot;
153 else if(cur_dot > dot1)
154 cur_dot = dot1;
155 if(mark_dot >= dot2)
156 mark_dot -= tmpdot;
157 else if(mark_dot > dot1)
158 mark_dot = dot1;
159 e_gocur();
162 /* ED_KILL(dot1,dot2) - Kill (save and delete) text between two places in
163 * the buffer.
164 * We assume we are deleting from dot1 to dot2, thus if dot1 > dot2
165 * then backwards deletion is implied, and the saved text is prefixed
166 * (instead of appended) to any previously killed text.
168 ed_kill(dot1,dot2)
169 chroff dot1,dot2;
170 { register SBSTR *sd, *sdo;
171 SBSTR *e_copyn();
173 e_go(dot1);
174 sd = e_copyn(dot2-dot1);
175 if(sd == 0) return;
176 if(last_cmd == KILLCMD && (sdo = kill_ring[kill_ptr]))
177 { if(dot1 > dot2) /* Prefix new killed stuff onto old stuff */
178 { sbs_app(sd,sdo);
179 kill_ring[kill_ptr] = sd;
181 else /* Append new stuff to old stuff */
182 sbs_app(sdo,sd);
184 else kill_push(sd);
185 ed_delete(dot1,dot2);
188 kill_push(sdp)
189 SBSTR *sdp;
190 { register SBSTR *sd;
192 if(++kill_ptr >= KILL_LEN) kill_ptr = 0;
193 if(sd = kill_ring[kill_ptr])
194 sbs_del(sd);
195 kill_ring[kill_ptr] = sdp;
199 #define isupper(c) (('A' <= c) && (c <= 'Z'))
200 #define islower(c) (('a' <= c) && (c <= 'z'))
201 #define toupper(c) (c + ('A' - 'a'))
202 #define tolower(c) (c + ('a' - 'A'))
204 #if FX_UCWORD||FX_LCWORD||FX_UCIWORD||FX_UCREG||FX_LCREG
206 /* ED_CASE(dot1,dot2,downp) - Change the case within a region.
207 * downp = 0 for uppercase, 1 for lowercase, 2 for capitalize.
209 ed_case(dot1, dot2, downp)
210 chroff dot1, dot2;
211 int downp;
212 { chroff dcnt;
213 register int c, a, z;
214 int modflg;
216 modflg = 0;
217 if((dcnt = dot2 - dot1) < 0)
218 { dcnt = dot1;
219 dot1 = dot2;
220 dot2 = dcnt;
221 dcnt -= dot1;
223 e_go(dot1);
225 if(downp==2)
226 { a = 0; /* 0 looking for wd, 1 in word */
227 while(--dcnt >= 0)
228 { if(delimp(c = e_getc())) /* Char in wd? */
229 { a = 0; /* No */
230 continue;
232 if(a) /* If already inside word */
233 { if(isupper(c))
234 c = tolower(c);
235 else continue;
237 else /* If encountered start of word */
238 { a = 1;
239 if(islower(c))
240 c = toupper(c);
241 else continue;
243 e_backc();
244 e_ovwc(c);
245 modflg++;
247 goto casdon;
249 if(downp==0)
250 { a = 'a'; /* Convert to lower case */
251 z = 'z';
252 downp = -040;
254 else
255 { a = 'A'; /* Convert to upper case */
256 z = 'Z';
257 downp = 040;
259 while(--dcnt >= 0)
260 { if(a <= (c = e_getc()) && c <= z)
261 { e_backc();
262 e_ovwc(c+downp);
263 modflg++;
267 casdon: dot2 = cur_dot; /* Save dot */
268 e_setcur(); /* Set up for modification range chk*/
269 if(modflg)
270 buf_tmat(dot1); /* Stuff munged from there to here */
271 ed_go(dot2);
273 #endif /* any ed_case caller */
276 /* UPCASE(c) - Return upper-case version of character */
277 upcase(ch)
278 int ch;
279 { register int c;
280 c = ch&0177;
281 return(islower(c) ? toupper(c) : c);