source: trunk/minix/commands/elle/eef1.c@ 15

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

Minix 3.1.2a

File size: 6.0 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/*
7 * EEF1 Various functions
8 * Char move/ins/del
9 * Case change
10 * Char/word transpose
11 */
12
13#include "elle.h"
14
15/* EFUN: "Insert Self" */
16f_insself (c)
17int c;
18{
19#if IMAGEN
20 fim_insself(c);
21#else
22#if FX_FILLMODE
23 extern int fill_mode;
24
25 if(fill_mode) fx_insfill(c);
26 else
27#endif /*FX_FILLMODE*/
28 ed_insn(c, exp); /* Normal stuff */
29#endif /*-IMAGEN*/
30}
31
32/* EFUN: "Quoted Insert"
33** Inserts next char directly, <exp> number of times.
34** Does not check anything about the char and does not do anything
35** depending on the mode. In particular, CR is not turned into EOL.
36*/
37f_quotins()
38{
39 ed_insn(cmd_read(), exp); /* Insert next char directly */
40}
41
42#if FX_CRLF
43/* EFUN: "CRLF" */
44f_crlf()
45{
46#if IMAGEN
47 fim_crlf();
48#else
49 register int i;
50
51 if(e_goeol() == cur_dot /* If at end of current line */
52 && exp == 1 /* and inserting only 1 new line */
53 && e_lblankp() && e_lblankp()) /* and next 2 lines blank */
54 { e_gocur(); /* Then just re-use next line. */
55 e_gonl(); /* Go to its start */
56 e_setcur(); /* and establish cur_dot there. */
57 ed_delete(e_dot(), e_eoldot()); /* Ensure any blanks flushed */
58 }
59 else
60 { e_gocur(); /* Otherwise back to original place */
61 if((i = exp) > 0) /* and simply insert newlines */
62 do ed_crins();
63 while(--i);
64 }
65#endif /*-IMAGEN*/
66}
67#endif /*FX_CRLF*/
68
69
70/* EFUN: "Forward Character" */
71f_fchar()
72{ ed_igoff(exp);
73}
74
75/* EFUN: "Backward Character" */
76f_bchar()
77{ ed_igoff(-exp);
78}
79
80/* EFUN: "Delete Character" */
81f_dchar ()
82{
83#if IMAGEN
84 fim_dchar();
85#else
86 ef_deln(exp);
87#endif /*-IMAGEN*/
88}
89
90/* EFUN: "Backward Delete Character" */
91f_bdchar ()
92{
93#if IMAGEN
94 fim_bdchar();
95#else
96 ef_deln(-exp);
97#endif /*-IMAGEN*/
98}
99
100/* Delete forward or backward N characters.
101 * If arg, kills instead of deleting.
102 */
103ef_deln(x)
104int x;
105{
106 e_igoff(x);
107 if(exp_p) ed_kill(cur_dot, e_dot());
108 else ed_delete(cur_dot, e_dot());
109}
110
111
112#if FX_DELSPC
113/* EFUN: "Delete Horizontal Space" */
114/* Delete spaces/tabs around point.
115 */
116f_delspc()
117{ chroff dot1;
118
119 e_gobwsp(); /* Move backward over whitespace */
120 dot1 = e_dot(); /* Save point */
121 e_gofwsp(); /* Move forward over whitespace */
122 ed_delete(dot1,e_dot()); /* Delete twixt start and here */
123}
124#endif /*FX_DELSPC*/
125
126
127#if FX_TCHARS
128/* EFUN: "Transpose Characters"
129 * Transpose chars before and after cursor. Doesn't hack args yet.
130 * EMACS: With positive arg, exchs chars before & after cursor, moves right,
131 * and repeats the specified # of times, dragging the char to the
132 * left of the cursor right.
133 * With negative arg, transposes 2 chars to left of cursor, moves
134 * between them, and repeats the specified # of times, exactly undoing
135 * the positive arg form. With zero arg, transposes chars at point
136 * and mark.
137 * HOWEVER: at the end of a line, with no arg, the preceding 2 chars
138 * are transposed.
139 */
140f_tchars()
141{ register int c, c2;
142#if IMAGEN
143 c = e_rgetc(); /* Gosmacs style: twiddle prev 2 */
144 if (c == EOF)
145 return(e_gocur()); /* Do nothing at beginning of bfr */
146#else
147
148 if((c = e_getc()) == EOF /* If at EOF */
149 || e_rgetc() == LF) /* or at end of line, */
150 c = e_rgetc(); /* use preceding 2 chars */
151#endif /*-IMAGEN*/
152
153 if((c2 = e_rgetc()) == EOF) /* At beginning of buffer? */
154 return(e_gocur()); /* Yes, do nothing */
155 e_ovwc(c);
156 e_ovwc(c2);
157 e_setcur();
158 buf_tmod((chroff)-2); /* Munged these 2 chars */
159}
160#endif /*FX_TCHARS*/
161
162
163#if FX_FWORD
164/* EFUN: "Forward Word" */
165f_fword()
166{ chroff retdot;
167 if(e_wding(&retdot, exp))
168 ed_go(retdot);
169}
170#endif
171
172#if FX_BWORD
173/* EFUN: "Backward Word" */
174f_bword()
175{ exp = -exp;
176 f_fword();
177}
178#endif
179
180#if FX_KWORD
181/* EFUN: "Kill Word" */
182f_kword()
183{ chroff retdot;
184
185 if(e_wding(&retdot,exp))
186 { ed_kill(cur_dot,retdot);
187 this_cmd = KILLCMD;
188 }
189}
190#endif
191
192#if FX_BKWORD
193/* EFUN: "Backward Kill Word" */
194f_bkword()
195{ exp = -exp;
196 f_kword();
197}
198#endif
199
200
201#if FX_TWORDS
202/* EFUN: "Transpose Words" */
203/* Transpose word. Urk!
204 */
205f_twords()
206{ register SBSTR *sd1, *sd2;
207 register SBBUF *sb;
208 chroff begwd1, endwd1, begwd2, endwd2;
209
210 endwd2 = e_wdot(cur_dot, 1); /* Go to end of 2nd word */
211 begwd2 = e_wdot(endwd2, -1); /* Go to beg of 2nd word */
212 if(begwd2 >= endwd2) /* If no 2nd word, punt. */
213 return;
214 begwd1 = e_wdot(begwd2, -1); /* Go to beg of 1st word */
215 endwd1 = e_wdot(begwd1, 1); /* Go to end of 1st word */
216 if(begwd1 >= endwd1) /* If no 1st word, punt. */
217 return;
218 if(endwd1 > begwd2) /* Avoid possible overlap */
219 return;
220
221 e_go(begwd2);
222 sb = (SBBUF *)cur_buf;
223 sd2 = sb_killn(sb, endwd2 - begwd2); /* Excise wd 2 first */
224 e_go(begwd1);
225 sd1 = sb_killn(sb, endwd1 - begwd1); /* Excise wd 1 */
226 sb_sins(sb, sd2); /* Replace with wd 2 */
227 e_goff(begwd2 - endwd1); /* Move past between stuff */
228 sb_sins(sb, sd1); /* Insert wd 1 */
229 e_setcur();
230 buf_tmat(begwd1); /* Modified this range */
231}
232#endif /*FX_TWORDS*/
233
234
235/* Case hacking functions and support */
236
237#if FX_UCWORD
238/* EFUN: "Uppercase Word" */
239f_ucword()
240{ case_word(0);
241}
242#endif /*FX_UCWORD*/
243
244#if FX_LCWORD
245/* EFUN: "Lowercase Word" */
246f_lcword()
247{ case_word(1);
248}
249#endif /*FX_LCWORD*/
250
251#if FX_UCIWORD
252/* EFUN: "Uppercase Initial" */
253f_uciword()
254{ case_word(2);
255}
256#endif /*FX_UCIWORD*/
257
258#if FX_UCWORD||FX_LCWORD||FX_UCIWORD
259case_word (downp)
260{ chroff retdot;
261#if IMAGEN
262 chroff startdot;
263
264 /* Normalize our position to beginning of "current" word,
265 * where "current" is defined to be the current word we are in,
266 * or else the previous word if we are not in any word.
267 * All this silly nonsense just to perpetuate Gosmacs's
268 * wrong behaviour!
269 */
270 startdot = cur_dot; /* Save current position */
271 e_getc(); /* If at beg of word, ensure we get inside it */
272 e_gowd(-1); /* Go to start of this or prev word */
273 e_setcur(); /* Set cur_dot */
274#endif /*IMAGEN*/
275
276 if(e_wding(&retdot, exp))
277 { ed_case(cur_dot,retdot,downp);
278 e_gosetcur(retdot);
279 }
280#if IMAGEN
281 e_gosetcur(startdot);
282#endif /*IMAGEN*/
283}
284#endif /* any case_word caller */
Note: See TracBrowser for help on using the repository browser.