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.
6 /* EEFED - ED-type functions
11 * ED_INSERT -- Insert character given as argument.
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? */
36 if (eolcrlf(cur_buf
)) /* If EOL is made of CR-LF */
37 ed_insert(CR
); /* then first insert CR, then drop down to */
39 ed_insert(LF
); /* Insert LF */
43 ed_sins (s
) /* insert this string */
50 ed_nsins (s
, i
) /* Insert string of N chars */
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
67 ng
= goal
& ~07; /* Get distance to tab stop */
68 ed_insn(TAB
, ((ng
- (d_curind() & ~07)) >> 3));
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.
77 { e_setcur(); /* Set cur_dot */
78 redp(RD_MOVE
); /* Alert redisplay to check cursor loc */
88 /* Go to given offset from current location */
95 /* Go to given INTEGER offset from current location */
102 /* Reset (delete all of) Buffer
103 * Should buffer be marked modified or not? Currently isn't.
107 return; /* Already empty */
110 cur_win
->w_topldot
= 0; /* Is this necessary? */
112 redp(RD_WINRES
|RD_REDO
);
114 redp(RD_WINRES
); /* This window needs complete update */
117 /* buf_mod(); */ /* Mark modified ?? */
118 /* mark_p = 0; */ /* Say no mark set ?? */
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.
135 { chroff tmpdot
, savdot
;
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 */
153 else if(cur_dot
> dot1
)
157 else if(mark_dot
> dot1
)
162 /* ED_KILL(dot1,dot2) - Kill (save and delete) text between two places in
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.
170 { register SBSTR
*sd
, *sdo
;
174 sd
= e_copyn(dot2
-dot1
);
176 if(last_cmd
== KILLCMD
&& (sdo
= kill_ring
[kill_ptr
]))
177 { if(dot1
> dot2
) /* Prefix new killed stuff onto old stuff */
179 kill_ring
[kill_ptr
] = sd
;
181 else /* Append new stuff to old stuff */
185 ed_delete(dot1
,dot2
);
190 { register SBSTR
*sd
;
192 if(++kill_ptr
>= KILL_LEN
) kill_ptr
= 0;
193 if(sd
= kill_ring
[kill_ptr
])
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
)
213 register int c
, a
, z
;
217 if((dcnt
= dot2
- dot1
) < 0)
226 { a
= 0; /* 0 looking for wd, 1 in word */
228 { if(delimp(c
= e_getc())) /* Char in wd? */
232 if(a
) /* If already inside word */
237 else /* If encountered start of word */
250 { a
= 'a'; /* Convert to lower case */
255 { a
= 'A'; /* Convert to upper case */
260 { if(a
<= (c
= e_getc()) && c
<= z
)
267 casdon
: dot2
= cur_dot
; /* Save dot */
268 e_setcur(); /* Set up for modification range chk*/
270 buf_tmat(dot1
); /* Stuff munged from there to here */
273 #endif /* any ed_case caller */
276 /* UPCASE(c) - Return upper-case version of character */
281 return(islower(c
) ? toupper(c
) : c
);