source: trunk/minix/commands/elle/eef2.c@ 9

Last change on this file since 9 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/*
7 * EEF2 Various functions
8 */
9
10#include "elle.h"
11
12/* Line Handling functions */
13
14/* EFUN: "Beginning of Line" */
15f_begline()
16{ e_gobol();
17 ed_setcur();
18}
19
20/* EFUN: "End of Line" */
21f_endline()
22{ e_goeol();
23 ed_setcur();
24}
25
26/* EFUN: "Next Line" */
27/* Goes to beginning of next line */
28f_nxtline()
29{ return(down_bline(exp));
30}
31
32/* EFUN: "Previous Line" */
33/* Goes to beginning of previous line */
34f_prvline()
35{ return(down_bline(-exp));
36}
37
38/* EFUN: "Down Real Line" */
39f_dnrline ()
40{ down_line(exp);
41}
42
43/* EFUN: "Up Real Line" */
44f_uprline ()
45{ down_line(-exp);
46}
47
48#if FX_OLINE
49/* EFUN: "Open Line" */
50f_oline()
51{ register int i;
52 chroff savdot;
53
54 savdot = cur_dot;
55 if((i = exp) > 0)
56 do { ed_crins(); }
57 while(--i);
58 e_gosetcur(savdot);
59}
60#endif /*FX_OLINE*/
61
62#if FX_DELBLINES
63/* EFUN: "Delete Blank Lines" */
64/* Delete blank lines around point.
65 */
66f_delblines()
67{ register int c;
68 chroff dot1, dot2, oldcur;
69
70 oldcur = cur_dot;
71 do { e_gobwsp(); }
72 while ((c = e_rgetc()) == LF);
73 if (c != EOF)
74 e_gonl();
75 dot1 = e_dot();
76 if(dot1 > oldcur) return;
77 do { e_gofwsp(); }
78 while ((c = e_getc()) == LF);
79 if(c != EOF)
80 e_gobol();
81 dot2 = e_dot();
82 if(dot2 < oldcur) return;
83 ed_delete(dot1,dot2);
84}
85#endif /*FX_DELBLINES*/
86
87#if FX_KLINE
88/* EFUN: "Kill Line" */
89f_kline()
90{
91 if(exp_p)
92 e_goline(exp); /* Move that many lines */
93 /* (if 0, goes to BOL) */
94 else /* No arg, handle specially */
95 { if(e_lblankp()) /* Is rest of line blank? */
96 ; /* Yes, now at next line! */
97 else e_goeol(); /* No, go to EOL rather than NL */
98 }
99 ed_kill(cur_dot,e_dot());
100 e_setcur();
101 this_cmd = KILLCMD;
102}
103#endif /*FX_KLINE*/
104
105#if FX_BKLINE
106/* EFUN: "Backward Kill Line" (not EMACS) */
107/* Originally an Iconographics function.
108*/
109f_bkline()
110{
111 if(exp_p) exp = -exp; /* If arg, invert it */
112 else
113 { exp = 0; /* No arg, furnish 0 */
114 exp_p = 1;
115 }
116 f_kline(); /* Invoke "Kill Line" */
117}
118#endif /*FX_BKLINE*/
119
120#if FX_GOLINE
121/* EFUN: "Goto Line" (not EMACS) (GNU goto-line) */
122f_goline()
123{
124 e_gobob();
125 down_bline(exp-1); /* already at line 1 */
126}
127#endif /*FX_GOLINE*/
128
129
130down_bline(arg)
131int arg;
132{
133 if(arg)
134 e_goline(arg);
135 ed_setcur();
136}
137
138#if FX_DNRLINE || FX_UPRLINE
139down_line (x)
140int x;
141{ register int i, res;
142
143 res = x ? e_goline(x) : 1; /* Move that many lines */
144 goal = 0;
145 if(res == 0) /* Hit buffer limits (EOF)? */
146 { if(x > 0) /* Moving downwards? */
147 {
148#if !(IMAGEN) /* If IMAGEN, do not extend!! */
149 if(x == 1) ed_crins(); /* Yeah, maybe extend */
150 else
151#endif
152 goal = indtion(cur_dot);
153 goto done;
154 }
155 }
156
157 if(last_cmd == LINECMD /* If previous cmd also a line move */
158 && pgoal != -1) /* and we have a previous goal col */
159 goal = pgoal; /* then make it the current goal */
160 else goal = indtion(cur_dot); /* Else invent goal from current pos */
161
162 i = inindex(e_dot(), goal); /* See # chars needed to reach goal */
163 if(i == -1) /* If off edge of line, */
164 e_goeol(); /* just move to end of this line */
165 else e_igoff(i); /* else move to goal. */
166
167done: pgoal = goal;
168 this_cmd = LINECMD;
169 ed_setcur();
170}
171#endif /*FX_DNRLINE || FX_UPRLINE*/
172
173
174
175
176/* Region Handling functions */
177
178/* EFUN: "Set/Pop Mark" */
179f_setmark()
180{
181 mark_dot = e_dot();
182 mark_p = 1;
183 if(ev_markshow) /* If have one, show indicator */
184 saytoo(ev_markshow); /* that mark was set. */
185}
186
187/* EFUN: "Exchange Point and Mark" */
188f_exchmark()
189{ chroff tmpdot;
190
191 if(chkmark())
192 { tmpdot = mark_dot;
193 mark_dot = cur_dot;
194 ed_go(tmpdot); /* Set cur_dot and go there */
195 }
196}
197
198/* EFUN: "Kill Region" */
199f_kregion()
200{
201 if(chkmark())
202 { ed_kill(cur_dot,mark_dot); /* Will adj cur_dot, mark_dot */
203 e_gocur();
204 this_cmd = KILLCMD;
205 }
206}
207
208/* EFUN: "Copy Region" */
209f_copreg()
210{
211 if(chkmark())
212 { e_gocur();
213 kill_push(e_copyn(mark_dot - cur_dot));
214 e_gocur();
215 }
216}
217
218
219/* EFUN: "Uppercase Region" */
220f_ucreg()
221{ ef_creg(0);
222}
223
224/* EFUN: "Lowercase Region" */
225f_lcreg()
226{ ef_creg(1);
227}
228
229ef_creg(downp)
230int downp;
231{
232 if(chkmark())
233 ed_case(cur_dot,mark_dot,downp);
234}
235
236#if FX_FILLREG
237/* EFUN: "Fill Region" */
238f_fillreg()
239{ if(chkmark())
240 ed_fill(mark_dot,cur_dot,0);
241}
242#endif /*FX_FILLREG*/
243
244/* CHKMARK() - minor utility for region-hacking functions.
245 * Returns TRUE if mark exists.
246 * Otherwise complains to user and returns 0.
247 */
248chkmark()
249{ if(mark_p == 0)
250 ding("No mark!");
251 return(mark_p);
252}
253
254
255/* Paragraph functions */
256
257#if FX_FPARA
258/* EFUN: "Forward Paragraph" */
259f_fpara()
260{ int e_gobpa(), e_goepa();
261
262 exp_do(e_goepa, e_gobpa);
263 ed_setcur();
264}
265#endif /*FX_FPARA*/
266
267#if FX_BPARA
268/* EFUN: "Backward Paragraph" */
269/* Go to beginning of paragraph.
270 * Skip all whitespace until text seen, then stop at beginning of
271 * 1st line starting with whitespace.
272 */
273f_bpara()
274{ int e_gobpa(), e_goepa();
275
276 exp_do(e_gobpa, e_goepa);
277 ed_setcur();
278}
279#endif /*FX_BPARA*/
280
281#if FX_MRKPARA
282/* EFUN: "Mark Paragraph" */
283f_mrkpara()
284{
285 f_fpara(); /* Go to end of paragraph */
286 f_setmark(); /* Put mark there */
287 f_bpara(); /* Then back to start of paragraph */
288}
289#endif /*FX_MRKPARA*/
290
291#if FX_FILLPARA
292/* EFUN: "Fill Paragraph" */
293f_fillpara()
294{
295 chroff savloc, endloc;
296
297 savloc = cur_dot;
298#if ICONOGRAPHICS
299 e_getc(); /* DON'T go to next para if at end */
300 e_gobpa(); /* of this one!! */
301#endif /*ICONOGRAPHICS*/
302 e_goepa(); /* Go to end of parag */
303 if(e_rgetc() != LF) /* If last char EOL, back over it. */
304 e_getc();
305 endloc = e_dot(); /* Remember where end is */
306 e_gobpa(); /* Go to beg of parag */
307#if ICONOGRAPHICS
308 kill_push(e_copyn(endloc - e_dot ()));
309 /* put old version on kill ring */
310#endif /*ICONOGRAPHICS*/
311 e_fwsp(); /* Move over initial whitespace */
312 ed_fill(e_dot(), endloc, 0); /* Fill this region, return to dot */
313}
314#endif /*FX_FILLPARA*/
Note: See TracBrowser for help on using the repository browser.