get rid of USD.docs,
[nvi.git] / vi / v_event.c
blob66fd901039c774fdfb10f928ec2a41a1e060538c
1 /*-
2 * Copyright (c) 1996
3 * Keith Bostic. All rights reserved.
5 * See the LICENSE file for redistribution information.
6 */
8 #include "config.h"
10 #ifndef lint
11 static const char sccsid[] = "$Id: v_event.c,v 8.14 1997/04/12 17:19:22 bostic Exp $ (Berkeley) $Date: 1997/04/12 17:19:22 $";
12 #endif /* not lint */
14 #include <sys/types.h>
15 #include <sys/queue.h>
16 #include <sys/time.h>
18 #include <bitstring.h>
19 #include <ctype.h>
20 #include <errno.h>
21 #include <limits.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
27 #include "../common/common.h"
28 #include "../ipc/ip.h"
29 #include "vi.h"
32 * v_c_settop --
33 * Scrollbar position.
35 static int
36 v_c_settop(sp, vp)
37 SCR *sp;
38 VICMD *vp;
40 SMAP *smp;
43 * We want to scroll the screen, without changing the cursor position.
44 * So, we fill the screen map and then flush it to the screen. Then,
45 * set the VIP_S_REFRESH flag so the main vi loop doesn't update the
46 * screen. When the next real command happens, the refresh code will
47 * notice that the screen map is way wrong and fix it.
49 * XXX
50 * There may be a serious performance problem here -- we're doing no
51 * optimization whatsoever, which means that we're copying the entire
52 * screen out to the X11 screen code on each change.
54 if (vs_sm_fill(sp, vp->ev.e_lno, P_TOP))
55 return (1);
56 for (smp = HMAP; smp <= TMAP; ++smp) {
57 SMAP_FLUSH(smp);
58 if (vs_line(sp, smp, NULL, NULL))
59 return (1);
62 F_SET(VIP(sp), VIP_S_REFRESH);
64 return (sp->gp->scr_refresh(sp, 0));
68 * v_edit --
69 * Edit command.
71 static int
72 v_edit(sp, vp)
73 SCR *sp;
74 VICMD *vp;
76 EXCMD cmd;
78 ex_cinit(sp, &cmd, C_EDIT, 0, OOBLNO, OOBLNO, 0);
79 argv_exp0(sp, &cmd, vp->ev.e_csp, vp->ev.e_len);
80 return (v_exec_ex(sp, vp, &cmd));
84 * v_editopt --
85 * Set an option value.
87 static int
88 v_editopt(sp, vp)
89 SCR *sp;
90 VICMD *vp;
93 return (api_opts_set(sp,
94 vp->ev.e_str1, vp->ev.e_str2, vp->ev.e_val1, vp->ev.e_val1));
98 * v_editsplit --
99 * Edit in a split screen.
101 static int
102 v_editsplit(sp, vp)
103 SCR *sp;
104 VICMD *vp;
106 EXCMD cmd;
108 ex_cinit(sp, &cmd, C_EDIT, 0, OOBLNO, OOBLNO, 0);
109 F_SET(&cmd, E_NEWSCREEN);
110 argv_exp0(sp, &cmd, vp->ev.e_csp, vp->ev.e_len);
111 return (v_exec_ex(sp, vp, &cmd));
115 * v_tag --
116 * Tag command.
118 static int
119 v_tag(sp, vp)
120 SCR *sp;
121 VICMD *vp;
123 EXCMD cmd;
125 if (v_curword(sp))
126 return (1);
128 ex_cinit(sp, &cmd, C_TAG, 0, OOBLNO, OOBLNO, 0);
129 argv_exp0(sp, &cmd, VIP(sp)->keyw, strlen(VIP(sp)->keyw));
130 return (v_exec_ex(sp, vp, &cmd));
134 * v_tagas --
135 * Tag on the supplied string.
137 static int
138 v_tagas(sp, vp)
139 SCR *sp;
140 VICMD *vp;
142 EXCMD cmd;
144 ex_cinit(sp, &cmd, C_TAG, 0, OOBLNO, OOBLNO, 0);
145 argv_exp0(sp, &cmd, vp->ev.e_csp, vp->ev.e_len);
146 return (v_exec_ex(sp, vp, &cmd));
150 * v_tagsplit --
151 * Tag in a split screen.
153 static int
154 v_tagsplit(sp, vp)
155 SCR *sp;
156 VICMD *vp;
158 EXCMD cmd;
160 if (v_curword(sp))
161 return (1);
163 ex_cinit(sp, &cmd, C_TAG, 0, OOBLNO, OOBLNO, 0);
164 F_SET(&cmd, E_NEWSCREEN);
165 argv_exp0(sp, &cmd, VIP(sp)->keyw, strlen(VIP(sp)->keyw));
166 return (v_exec_ex(sp, vp, &cmd));
170 * v_quit --
171 * Quit command.
173 static int
174 v_quit(sp, vp)
175 SCR *sp;
176 VICMD *vp;
178 EXCMD cmd;
180 ex_cinit(sp, &cmd, C_QUIT, 0, OOBLNO, OOBLNO, 0);
181 return (v_exec_ex(sp, vp, &cmd));
185 * v_erepaint --
186 * Repaint selected lines from the screen.
188 * PUBLIC: int v_erepaint __P((SCR *, EVENT *));
191 v_erepaint(sp, evp)
192 SCR *sp;
193 EVENT *evp;
195 SMAP *smp;
197 for (; evp->e_flno <= evp->e_tlno; ++evp->e_flno) {
198 smp = HMAP + evp->e_flno - 1;
199 SMAP_FLUSH(smp);
200 if (vs_line(sp, smp, NULL, NULL))
201 return (1);
203 return (0);
207 * v_sel_end --
208 * End selection.
211 v_sel_end(sp, evp)
212 SCR *sp;
213 EVENT *evp;
215 SMAP *smp;
216 VI_PRIVATE *vip;
218 smp = HMAP + evp->e_lno;
219 if (smp > TMAP) {
220 /* XXX */
221 return (1);
224 vip = VIP(sp);
225 vip->sel.lno = smp->lno;
226 vip->sel.cno =
227 vs_colpos(sp, smp->lno, evp->e_cno + (smp->soff - 1) * sp->cols);
228 return (0);
232 * v_sel_start --
233 * Start selection.
236 v_sel_start(sp, evp)
237 SCR *sp;
238 EVENT *evp;
240 SMAP *smp;
241 VI_PRIVATE *vip;
243 smp = HMAP + evp->e_lno;
244 if (smp > TMAP) {
245 /* XXX */
246 return (1);
249 vip = VIP(sp);
250 vip->sel.lno = smp->lno;
251 vip->sel.cno =
252 vs_colpos(sp, smp->lno, evp->e_cno + (smp->soff - 1) * sp->cols);
253 return (0);
257 * v_wq --
258 * Write and quit command.
260 static int
261 v_wq(sp, vp)
262 SCR *sp;
263 VICMD *vp;
265 EXCMD cmd;
267 ex_cinit(sp, &cmd, C_WQ, 0, OOBLNO, OOBLNO, 0);
269 cmd.addr1.lno = 1;
270 if (db_last(sp, &cmd.addr2.lno))
271 return (1);
272 return (v_exec_ex(sp, vp, &cmd));
276 * v_write --
277 * Write command.
279 static int
280 v_write(sp, vp)
281 SCR *sp;
282 VICMD *vp;
284 EXCMD cmd;
286 ex_cinit(sp, &cmd, C_WRITE, 0, OOBLNO, OOBLNO, 0);
288 cmd.addr1.lno = 1;
289 if (db_last(sp, &cmd.addr2.lno))
290 return (1);
291 return (v_exec_ex(sp, vp, &cmd));
295 * v_writeas --
296 * Write command.
298 static int
299 v_writeas(sp, vp)
300 SCR *sp;
301 VICMD *vp;
303 EXCMD cmd;
305 ex_cinit(sp, &cmd, C_WRITE, 0, OOBLNO, OOBLNO, 0);
306 argv_exp0(sp, &cmd, vp->ev.e_csp, vp->ev.e_len);
308 cmd.addr1.lno = 1;
309 if (db_last(sp, &cmd.addr2.lno))
310 return (1);
311 return (v_exec_ex(sp, vp, &cmd));
315 * v_event --
316 * Find the event associated with a fucntion.
318 * PUBLIC: int v_event __P((SCR *, VICMD *));
321 v_event(sp, vp)
322 SCR *sp;
323 VICMD *vp;
325 /* This array maps events to vi command functions. */
326 static VIKEYS const vievents[] = {
327 #define V_C_SETTOP 0 /* VI_C_SETTOP */
328 {v_c_settop, 0},
329 #define V_EDIT 1 /* VI_EDIT */
330 {v_edit, 0},
331 #define V_EDITOPT 2 /* VI_EDITOPT */
332 {v_editopt, 0},
333 #define V_EDITSPLIT 3 /* VI_EDITSPLIT */
334 {v_editsplit, 0},
335 #define V_EMARK 4 /* VI_MOUSE_MOVE */
336 {v_emark, V_ABS_L|V_MOVE},
337 #define V_QUIT 5 /* VI_QUIT */
338 {v_quit, 0},
339 #define V_SEARCH 6 /* VI_SEARCH */
340 {v_esearch, V_ABS_L|V_MOVE},
341 #define V_TAG 7 /* VI_TAG */
342 {v_tag, 0},
343 #define V_TAGAS 8 /* VI_TAGAS */
344 {v_tagas, 0},
345 #define V_TAGSPLIT 9 /* VI_TAGSPLIT */
346 {v_tagsplit, 0},
347 #define V_WQ 10 /* VI_WQ */
348 {v_wq, 0},
349 #define V_WRITE 11 /* VI_WRITE */
350 {v_write, 0},
351 #define V_WRITEAS 12 /* VI_WRITEAS */
352 {v_writeas, 0},
355 switch (vp->ev.e_ipcom) {
356 case VI_C_BOL:
357 vp->kp = &vikeys['0'];
358 break;
359 case VI_C_BOTTOM:
360 vp->kp = &vikeys['G'];
361 break;
362 case VI_C_DEL:
363 vp->kp = &vikeys['x'];
364 break;
365 case VI_C_DOWN:
366 F_SET(vp, VC_C1SET);
367 vp->count = vp->ev.e_lno;
368 vp->kp = &vikeys['\012'];
369 break;
370 case VI_C_EOL:
371 vp->kp = &vikeys['$'];
372 break;
373 case VI_C_INSERT:
374 vp->kp = &vikeys['i'];
375 break;
376 case VI_C_LEFT:
377 vp->kp = &vikeys['\010'];
378 break;
379 case VI_C_PGDOWN:
380 F_SET(vp, VC_C1SET);
381 vp->count = vp->ev.e_lno;
382 vp->kp = &vikeys['\006'];
383 break;
384 case VI_C_PGUP:
385 F_SET(vp, VC_C1SET);
386 vp->count = vp->ev.e_lno;
387 vp->kp = &vikeys['\002'];
388 break;
389 case VI_C_RIGHT:
390 vp->kp = &vikeys['\040'];
391 break;
392 case VI_C_SEARCH:
393 vp->kp = &vievents[V_SEARCH];
394 break;
395 case VI_C_SETTOP:
396 vp->kp = &vievents[V_C_SETTOP];
397 break;
398 case VI_C_TOP:
399 F_SET(vp, VC_C1SET);
400 vp->count = 1;
401 vp->kp = &vikeys['G'];
402 break;
403 case VI_C_UP:
404 F_SET(vp, VC_C1SET);
405 vp->count = vp->ev.e_lno;
406 vp->kp = &vikeys['\020'];
407 break;
408 case VI_EDIT:
409 vp->kp = &vievents[V_EDIT];
410 break;
411 case VI_EDITOPT:
412 vp->kp = &vievents[V_EDITOPT];
413 break;
414 case VI_EDITSPLIT:
415 vp->kp = &vievents[V_EDITSPLIT];
416 break;
417 case VI_MOUSE_MOVE:
418 vp->kp = &vievents[V_EMARK];
419 break;
420 case VI_SEL_END:
421 v_sel_end(sp, &vp->ev);
422 /* XXX RETURN IGNORE */
423 break;
424 case VI_SEL_START:
425 v_sel_start(sp, &vp->ev);
426 /* XXX RETURN IGNORE */
427 break;
428 case VI_QUIT:
429 vp->kp = &vievents[V_QUIT];
430 break;
431 case VI_TAG:
432 vp->kp = &vievents[V_TAG];
433 break;
434 case VI_TAGAS:
435 vp->kp = &vievents[V_TAGAS];
436 break;
437 case VI_TAGSPLIT:
438 vp->kp = &vievents[V_TAGSPLIT];
439 break;
440 case VI_UNDO:
441 vp->kp = &vikeys['u'];
442 break;
443 case VI_WQ:
444 vp->kp = &vievents[V_WQ];
445 break;
446 case VI_WRITE:
447 vp->kp = &vievents[V_WRITE];
448 break;
449 case VI_WRITEAS:
450 vp->kp = &vievents[V_WRITEAS];
451 break;
452 default:
453 return (1);
455 return (0);