tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / nvi / dist / vi / v_event.c
blob59f3314f806b2d086fa163c6b6622e45af626df2
1 /* $NetBSD: v_event.c,v 1.2 2013/11/22 15:52:06 christos Exp $ */
2 /*-
3 * Copyright (c) 1996
4 * Keith Bostic. All rights reserved.
6 * See the LICENSE file for redistribution information.
7 */
9 #include "config.h"
11 #ifndef lint
12 static const char sccsid[] = "Id: v_event.c,v 8.21 2001/06/25 15:19:31 skimo Exp (Berkeley) Date: 2001/06/25 15:19:31 ";
13 #endif /* not lint */
15 #include <sys/types.h>
16 #include <sys/queue.h>
17 #include <sys/time.h>
19 #include <bitstring.h>
20 #include <ctype.h>
21 #include <errno.h>
22 #include <limits.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
28 #include "../common/common.h"
29 #include "../ipc/ip.h"
30 #include "vi.h"
33 * v_c_settop --
34 * Scrollbar position.
36 static int
37 v_c_settop(SCR *sp, VICMD *vp)
39 SMAP *smp;
40 size_t x = 0, y = LASTLINE(sp); /* Future: change to -1 to not
41 * display the cursor
43 size_t tx, ty = -1;
46 * We want to scroll the screen, without changing the cursor position.
47 * So, we fill the screen map and then flush it to the screen. Then,
48 * set the VIP_S_REFRESH flag so the main vi loop doesn't update the
49 * screen. When the next real command happens, the refresh code will
50 * notice that the screen map is way wrong and fix it.
52 * XXX
53 * There may be a serious performance problem here -- we're doing no
54 * optimization whatsoever, which means that we're copying the entire
55 * screen out to the X11 screen code on each change.
57 if (vs_sm_fill(sp, vp->ev.e_lno, P_TOP))
58 return (1);
59 for (smp = HMAP; smp <= TMAP; ++smp) {
60 SMAP_FLUSH(smp);
61 if (vs_line(sp, smp, &ty, &tx))
62 return (1);
63 if (ty != (size_t)-1) {
64 y = ty;
65 x = tx;
68 (void)sp->gp->scr_move(sp, y, x);
70 F_SET(VIP(sp), VIP_S_REFRESH);
72 return (sp->gp->scr_refresh(sp, 0));
76 * v_edit --
77 * Edit command.
79 static int
80 v_edit(SCR *sp, VICMD *vp)
82 EXCMD cmd;
84 ex_cinit(sp, &cmd, C_EDIT, 0, OOBLNO, OOBLNO, 0);
85 argv_exp0(sp, &cmd, vp->ev.e_csp, vp->ev.e_len);
86 return (v_exec_ex(sp, vp, &cmd));
90 * v_editopt --
91 * Set an option value.
93 static int
94 v_editopt(SCR *sp, VICMD *vp)
96 int rval;
97 const char *np;
98 size_t nlen;
99 char *p2;
101 INT2CHAR(sp, vp->ev.e_str2, STRLEN(vp->ev.e_str2)+1, np, nlen);
102 p2 = strdup(np);
103 rval = api_opts_set(sp, vp->ev.e_str1, p2,
104 vp->ev.e_val1, vp->ev.e_val1);
105 if (sp->gp->scr_reply != NULL)
106 (void)sp->gp->scr_reply(sp, rval, NULL);
107 free(p2);
108 return (rval);
112 * v_editsplit --
113 * Edit in a split screen.
115 static int
116 v_editsplit(SCR *sp, VICMD *vp)
118 EXCMD cmd;
120 ex_cinit(sp, &cmd, C_EDIT, 0, OOBLNO, OOBLNO, 0);
121 F_SET(&cmd, E_NEWSCREEN);
122 argv_exp0(sp, &cmd, vp->ev.e_csp, vp->ev.e_len);
123 return (v_exec_ex(sp, vp, &cmd));
127 * v_tag --
128 * Tag command.
130 static int
131 v_tag(SCR *sp, VICMD *vp)
133 EXCMD cmd;
135 if (v_curword(sp))
136 return (1);
138 ex_cinit(sp, &cmd, C_TAG, 0, OOBLNO, OOBLNO, 0);
139 argv_exp0(sp, &cmd, VIP(sp)->keyw, STRLEN(VIP(sp)->keyw));
140 return (v_exec_ex(sp, vp, &cmd));
144 * v_tagas --
145 * Tag on the supplied string.
147 static int
148 v_tagas(SCR *sp, VICMD *vp)
150 EXCMD cmd;
152 ex_cinit(sp, &cmd, C_TAG, 0, OOBLNO, OOBLNO, 0);
153 argv_exp0(sp, &cmd, vp->ev.e_csp, vp->ev.e_len);
154 return (v_exec_ex(sp, vp, &cmd));
158 * v_tagsplit --
159 * Tag in a split screen.
161 static int
162 v_tagsplit(SCR *sp, VICMD *vp)
164 EXCMD cmd;
166 if (v_curword(sp))
167 return (1);
169 ex_cinit(sp, &cmd, C_TAG, 0, OOBLNO, OOBLNO, 0);
170 F_SET(&cmd, E_NEWSCREEN);
171 argv_exp0(sp, &cmd, VIP(sp)->keyw, STRLEN(VIP(sp)->keyw));
172 return (v_exec_ex(sp, vp, &cmd));
176 * v_quit --
177 * Quit command.
179 static int
180 v_quit(SCR *sp, VICMD *vp)
182 EXCMD cmd;
184 ex_cinit(sp, &cmd, C_QUIT, 0, OOBLNO, OOBLNO, 0);
185 return (v_exec_ex(sp, vp, &cmd));
189 * v_erepaint --
190 * Repaint selected lines from the screen.
192 * PUBLIC: int v_erepaint __P((SCR *, EVENT *));
195 v_erepaint(SCR *sp, EVENT *evp)
197 SMAP *smp;
199 for (; evp->e_flno <= evp->e_tlno; ++evp->e_flno) {
200 smp = HMAP + evp->e_flno - 1;
201 SMAP_FLUSH(smp);
202 if (vs_line(sp, smp, NULL, NULL))
203 return (1);
205 return (0);
209 * v_sel_end --
210 * End selection.
212 static int
213 v_sel_end(SCR *sp, 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.
235 static int
236 v_sel_start(SCR *sp, EVENT *evp)
238 SMAP *smp;
239 VI_PRIVATE *vip;
241 smp = HMAP + evp->e_lno;
242 if (smp > TMAP) {
243 /* XXX */
244 return (1);
247 vip = VIP(sp);
248 vip->sel.lno = smp->lno;
249 vip->sel.cno =
250 vs_colpos(sp, smp->lno, evp->e_cno + (smp->soff - 1) * sp->cols);
251 return (0);
255 * v_wq --
256 * Write and quit command.
258 static int
259 v_wq(SCR *sp, VICMD *vp)
261 EXCMD cmd;
263 ex_cinit(sp, &cmd, C_WQ, 0, OOBLNO, OOBLNO, 0);
265 cmd.addr1.lno = 1;
266 if (db_last(sp, &cmd.addr2.lno))
267 return (1);
268 return (v_exec_ex(sp, vp, &cmd));
272 * v_write --
273 * Write command.
275 static int
276 v_write(SCR *sp, VICMD *vp)
278 EXCMD cmd;
280 ex_cinit(sp, &cmd, C_WRITE, 0, OOBLNO, OOBLNO, 0);
282 cmd.addr1.lno = 1;
283 if (db_last(sp, &cmd.addr2.lno))
284 return (1);
285 return (v_exec_ex(sp, vp, &cmd));
289 * v_writeas --
290 * Write command.
292 static int
293 v_writeas(SCR *sp, VICMD *vp)
295 EXCMD cmd;
297 ex_cinit(sp, &cmd, C_WRITE, 0, OOBLNO, OOBLNO, 0);
298 argv_exp0(sp, &cmd, vp->ev.e_csp, vp->ev.e_len);
300 cmd.addr1.lno = 1;
301 if (db_last(sp, &cmd.addr2.lno))
302 return (1);
303 return (v_exec_ex(sp, vp, &cmd));
307 * v_event --
308 * Find the event associated with a function.
310 * PUBLIC: int v_event __P((SCR *, VICMD *));
313 v_event(SCR *sp, VICMD *vp)
315 /* This array maps events to vi command functions. */
316 #define VIKEYDEF(a, b) { a, b, NULL, NULL }
317 static VIKEYS const vievents[] = {
318 #define V_C_SETTOP 0 /* VI_C_SETTOP */
319 VIKEYDEF(v_c_settop, 0),
320 #define V_EDIT 1 /* VI_EDIT */
321 VIKEYDEF(v_edit, 0),
322 #define V_EDITOPT 2 /* VI_EDITOPT */
323 VIKEYDEF(v_editopt, 0),
324 #define V_EDITSPLIT 3 /* VI_EDITSPLIT */
325 VIKEYDEF(v_editsplit, 0),
326 #define V_EMARK 4 /* VI_MOUSE_MOVE */
327 VIKEYDEF(v_emark, V_ABS_L|V_MOVE),
328 #define V_QUIT 5 /* VI_QUIT */
329 VIKEYDEF(v_quit, 0),
330 #define V_SEARCH 6 /* VI_SEARCH */
331 VIKEYDEF(v_esearch, V_ABS_L|V_MOVE),
332 #define V_TAG 7 /* VI_TAG */
333 VIKEYDEF(v_tag, 0),
334 #define V_TAGAS 8 /* VI_TAGAS */
335 VIKEYDEF(v_tagas, 0),
336 #define V_TAGSPLIT 9 /* VI_TAGSPLIT */
337 VIKEYDEF(v_tagsplit, 0),
338 #define V_WQ 10 /* VI_WQ */
339 VIKEYDEF(v_wq, 0),
340 #define V_WRITE 11 /* VI_WRITE */
341 VIKEYDEF(v_write, 0),
342 #define V_WRITEAS 12 /* VI_WRITEAS */
343 VIKEYDEF(v_writeas, 0),
346 switch (vp->ev.e_ipcom) {
347 case VI_C_BOL:
348 vp->kp = &vikeys['0'];
349 break;
350 case VI_C_BOTTOM:
351 vp->kp = &vikeys['G'];
352 break;
353 case VI_C_DEL:
354 vp->kp = &vikeys['x'];
355 break;
356 case VI_C_DOWN:
357 F_SET(vp, VC_C1SET);
358 vp->count = vp->ev.e_lno;
359 vp->kp = &vikeys['\012'];
360 break;
361 case VI_C_EOL:
362 vp->kp = &vikeys['$'];
363 break;
364 case VI_C_INSERT:
365 vp->kp = &vikeys['i'];
366 break;
367 case VI_C_LEFT:
368 vp->kp = &vikeys['\010'];
369 break;
370 case VI_C_PGDOWN:
371 F_SET(vp, VC_C1SET);
372 vp->count = vp->ev.e_lno;
373 vp->kp = &vikeys['\006'];
374 break;
375 case VI_C_PGUP:
376 F_SET(vp, VC_C1SET);
377 vp->count = vp->ev.e_lno;
378 vp->kp = &vikeys['\002'];
379 break;
380 case VI_C_RIGHT:
381 vp->kp = &vikeys['\040'];
382 break;
383 case VI_C_SEARCH:
384 vp->kp = &vievents[V_SEARCH];
385 break;
386 case VI_C_SETTOP:
387 vp->kp = &vievents[V_C_SETTOP];
388 break;
389 case VI_C_TOP:
390 F_SET(vp, VC_C1SET);
391 vp->count = 1;
392 vp->kp = &vikeys['G'];
393 break;
394 case VI_C_UP:
395 F_SET(vp, VC_C1SET);
396 vp->count = vp->ev.e_lno;
397 vp->kp = &vikeys['\020'];
398 break;
399 case VI_EDIT:
400 vp->kp = &vievents[V_EDIT];
401 break;
402 case VI_EDITOPT:
403 vp->kp = &vievents[V_EDITOPT];
404 break;
405 case VI_EDITSPLIT:
406 vp->kp = &vievents[V_EDITSPLIT];
407 break;
408 case VI_MOUSE_MOVE:
409 vp->kp = &vievents[V_EMARK];
410 break;
411 case VI_SEL_END:
412 v_sel_end(sp, &vp->ev);
413 /* XXX RETURN IGNORE */
414 break;
415 case VI_SEL_START:
416 v_sel_start(sp, &vp->ev);
417 /* XXX RETURN IGNORE */
418 break;
419 case VI_QUIT:
420 vp->kp = &vievents[V_QUIT];
421 break;
422 case VI_TAG:
423 vp->kp = &vievents[V_TAG];
424 break;
425 case VI_TAGAS:
426 vp->kp = &vievents[V_TAGAS];
427 break;
428 case VI_TAGSPLIT:
429 vp->kp = &vievents[V_TAGSPLIT];
430 break;
431 case VI_UNDO:
432 vp->kp = &vikeys['u'];
433 break;
434 case VI_WQ:
435 vp->kp = &vievents[V_WQ];
436 break;
437 case VI_WRITE:
438 vp->kp = &vievents[V_WRITE];
439 break;
440 case VI_WRITEAS:
441 vp->kp = &vievents[V_WRITEAS];
442 break;
443 default:
444 return (1);
446 return (0);