tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / nvi / dist / ip / ip_funcs.c
blobfcdc60924b382e57c1b054ac3dc405980d94285d
1 /* $NetBSD: ip_funcs.c,v 1.3 2013/11/27 17:55:46 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: ip_funcs.c,v 8.23 2001/06/25 15:19:23 skimo Exp (Berkeley) Date: 2001/06/25 15:19:23 ";
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 <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <string.h>
25 #include "../common/common.h"
26 #include "../vi/vi.h"
27 #include "../ipc/ip.h"
30 * ip_addstr --
31 * Add len bytes from the string at the cursor, advancing the cursor.
33 * PUBLIC: int ip_waddstr __P((SCR *, const CHAR_T *, size_t));
35 int
36 ip_waddstr(SCR *sp, const CHAR_T *str, size_t len)
38 IP_BUF ipb;
39 IP_PRIVATE *ipp;
40 int rval;
42 ipp = IPP(sp);
44 memset(&ipb, 0, sizeof(ipb));
45 ipb.code = SI_WADDSTR;
46 ipb.len1 = len * sizeof(CHAR_T);
47 ipb.str1 = __UNCONST(str);
48 rval = vi_send(ipp->o_fd, "a", &ipb);
49 /* XXXX */
50 ipp->col += len;
52 return (rval);
56 * ip_addstr --
57 * Add len bytes from the string at the cursor, advancing the cursor.
59 * PUBLIC: int ip_addstr __P((SCR *, const char *, size_t));
61 int
62 ip_addstr(SCR *sp, const char *str, size_t len)
64 IP_BUF ipb;
65 IP_PRIVATE *ipp;
66 int iv, rval;
68 ipp = IPP(sp);
71 * If ex isn't in control, it's the last line of the screen and
72 * it's a split screen, use inverse video.
74 memset(&ipb, 0, sizeof(ipb));
75 iv = 0;
76 if (!F_ISSET(sp, SC_SCR_EXWROTE) &&
77 ipp->row == LASTLINE(sp) && IS_SPLIT(sp)) {
78 iv = 1;
79 ip_attr(sp, SA_INVERSE, 1);
81 ipb.code = SI_ADDSTR;
82 ipb.len1 = len;
83 ipb.str1 = str;
84 rval = vi_send(ipp->o_fd, "a", &ipb);
85 /* XXXX */
86 ipp->col += len;
88 if (iv)
89 ip_attr(sp, SA_INVERSE, 0);
90 return (rval);
94 * ip_attr --
95 * Toggle a screen attribute on/off.
97 * PUBLIC: int ip_attr __P((SCR *, scr_attr_t, int));
99 int
100 ip_attr(SCR *sp, scr_attr_t attribute, int on)
102 IP_BUF ipb;
103 IP_PRIVATE *ipp = IPP(sp);
105 memset(&ipb, 0, sizeof(ipb));
106 if (attribute == SA_ALTERNATE) {
107 if (on) F_SET(ipp, IP_ON_ALTERNATE);
108 else F_CLR(ipp, IP_ON_ALTERNATE);
111 ipb.code = SI_ATTRIBUTE;
112 ipb.val1 = attribute;
113 ipb.val2 = on;
115 return (vi_send(ipp->o_fd, "12", &ipb));
119 * ip_baud --
120 * Return the baud rate.
122 * PUBLIC: int ip_baud __P((SCR *, u_long *));
125 ip_baud(SCR *sp, u_long *ratep)
127 *ratep = 9600; /* XXX: Translation: fast. */
128 return (0);
132 * ip_bell --
133 * Ring the bell/flash the screen.
135 * PUBLIC: int ip_bell __P((SCR *));
138 ip_bell(SCR *sp)
140 IP_BUF ipb;
141 IP_PRIVATE *ipp = IPP(sp);
143 memset(&ipb, 0, sizeof(ipb));
144 ipb.code = SI_BELL;
146 return (vi_send(ipp->o_fd, NULL, &ipb));
150 * ip_busy --
151 * Display a busy message.
153 * PUBLIC: void ip_busy __P((SCR *, const char *, busy_t));
155 void
156 ip_busy(SCR *sp, const char *str, busy_t bval)
158 IP_BUF ipb;
159 IP_PRIVATE *ipp = IPP(sp);
161 memset(&ipb, 0, sizeof(ipb));
162 switch (bval) {
163 case BUSY_ON:
164 ipb.code = SI_BUSY_ON;
165 ipb.str1 = str;
166 ipb.len1 = strlen(str);
167 (void)vi_send(ipp->o_fd, "a", &ipb);
168 break;
169 case BUSY_OFF:
170 ipb.code = SI_BUSY_OFF;
171 (void)vi_send(ipp->o_fd, NULL, &ipb);
172 break;
173 case BUSY_UPDATE:
174 break;
176 return;
180 * ip_child --
181 * Prepare child.
183 * PUBLIC: int ip_child __P((SCR *));
186 ip_child(SCR *sp)
188 IP_PRIVATE *ipp = IPP(sp);
190 if (ipp->t_fd != -1) {
191 dup2(ipp->t_fd, 0);
192 dup2(ipp->t_fd, 1);
193 dup2(ipp->t_fd, 2);
194 close(ipp->t_fd);
196 return 0;
200 * ip_clrtoeol --
201 * Clear from the current cursor to the end of the line.
203 * PUBLIC: int ip_clrtoeol __P((SCR *));
206 ip_clrtoeol(SCR *sp)
208 IP_BUF ipb;
209 IP_PRIVATE *ipp = IPP(sp);
211 /* Temporary hack until we can pass screen pointers
212 * or name screens
214 memset(&ipb, 0, sizeof(ipb));
215 if (IS_VSPLIT(sp)) {
216 size_t x, y, spcnt;
217 int error;
219 y = ipp->row;
220 x = ipp->col;
221 error = 0;
222 for (spcnt = sp->cols - x;
223 spcnt > 0 && ! error; --spcnt)
224 error = ip_addstr(sp, " ", 1);
225 if (sp->coff == 0)
226 error |= ip_addstr(sp, "|", 1);
227 error |= ip_move(sp, y, x);
228 return error;
231 ipb.code = SI_CLRTOEOL;
233 return (vi_send(ipp->o_fd, NULL, &ipb));
237 * ip_cursor --
238 * Return the current cursor position.
240 * PUBLIC: int ip_cursor __P((SCR *, size_t *, size_t *));
243 ip_cursor(SCR *sp, size_t *yp, size_t *xp)
245 IP_PRIVATE *ipp;
247 ipp = IPP(sp);
248 *yp = ipp->row;
249 *xp = ipp->col;
250 return (0);
254 * ip_deleteln --
255 * Delete the current line, scrolling all lines below it.
257 * PUBLIC: int ip_deleteln __P((SCR *));
260 ip_deleteln(SCR *sp)
262 IP_BUF ipb;
263 IP_PRIVATE *ipp = IPP(sp);
266 * This clause is required because the curses screen uses reverse
267 * video to delimit split screens. If the screen does not do this,
268 * this code won't be necessary.
270 * If the bottom line was in reverse video, rewrite it in normal
271 * video before it's scrolled.
273 memset(&ipb, 0, sizeof(ipb));
274 if (!F_ISSET(sp, SC_SCR_EXWROTE) && IS_SPLIT(sp)) {
275 ipb.code = SI_REWRITE;
276 ipb.val1 = RLNO(sp, LASTLINE(sp));
277 if (vi_send(ipp->o_fd, "1", &ipb))
278 return (1);
282 * The bottom line is expected to be blank after this operation,
283 * and other screens must support that semantic.
285 ipb.code = SI_DELETELN;
286 return (vi_send(ipp->o_fd, NULL, &ipb));
290 * ip_discard --
291 * Discard a screen.
293 * PUBLIC: int ip_discard __P((SCR *, SCR **));
296 ip_discard(SCR *discardp, SCR **acquirep)
298 return (0);
302 * ip_ex_adjust --
303 * Adjust the screen for ex.
305 * PUBLIC: int ip_ex_adjust __P((SCR *, exadj_t));
308 ip_ex_adjust(SCR *sp, exadj_t action)
310 abort();
311 /* NOTREACHED */
315 * ip_insertln --
316 * Push down the current line, discarding the bottom line.
318 * PUBLIC: int ip_insertln __P((SCR *));
321 ip_insertln(SCR *sp)
323 IP_BUF ipb;
324 IP_PRIVATE *ipp = IPP(sp);
326 memset(&ipb, 0, sizeof(ipb));
327 ipb.code = SI_INSERTLN;
329 return (vi_send(ipp->o_fd, NULL, &ipb));
333 * ip_keyval --
334 * Return the value for a special key.
336 * PUBLIC: int ip_keyval __P((SCR *, scr_keyval_t, CHAR_T *, int *));
339 ip_keyval(SCR *sp, scr_keyval_t val, CHAR_T *chp, int *dnep)
342 * VEOF, VERASE and VKILL are required by POSIX 1003.1-1990,
343 * VWERASE is a 4BSD extension.
345 switch (val) {
346 case KEY_VEOF:
347 *dnep = '\004'; /* ^D */
348 break;
349 case KEY_VERASE:
350 *dnep = '\b'; /* ^H */
351 break;
352 case KEY_VKILL:
353 *dnep = '\025'; /* ^U */
354 break;
355 #ifdef VWERASE
356 case KEY_VWERASE:
357 *dnep = '\027'; /* ^W */
358 break;
359 #endif
360 default:
361 *dnep = 1;
362 break;
364 return (0);
368 * ip_move --
369 * Move the cursor.
371 * PUBLIC: int ip_move __P((SCR *, size_t, size_t));
374 ip_move(SCR *sp, size_t lno, size_t cno)
376 IP_PRIVATE *ipp;
377 IP_BUF ipb;
379 ipp = IPP(sp);
380 ipp->row = lno;
381 ipp->col = cno;
383 memset(&ipb, 0, sizeof(ipb));
384 ipb.code = SI_MOVE;
385 ipb.val1 = RLNO(sp, lno);
386 ipb.val2 = RCNO(sp, cno);
387 return (vi_send(ipp->o_fd, "12", &ipb));
391 * PUBLIC: void ip_msg __P((SCR *, mtype_t, char *, size_t));
393 void
394 ip_msg(SCR *sp, mtype_t mtype, char *line, size_t len)
396 IP_PRIVATE *ipp = IPP(sp);
398 if (F_ISSET(ipp, IP_ON_ALTERNATE))
399 vs_msg(sp, mtype, line, len);
400 else {
401 write(ipp->t_fd, line, len);
402 F_CLR(sp, SC_EX_WAIT_NO);
407 * ip_refresh --
408 * Refresh the screen.
410 * PUBLIC: int ip_refresh __P((SCR *, int));
413 ip_refresh(SCR *sp, int repaint)
415 IP_BUF ipb;
416 IP_PRIVATE *ipp;
417 db_recno_t total;
419 ipp = IPP(sp);
422 * If the scroll bar information has changed since we last sent
423 * it, resend it. Currently, we send three values:
425 * top The line number of the first line in the screen.
426 * num The number of lines visible on the screen.
427 * total The number of lines in the file.
429 * XXX
430 * This is a gross violation of layering... we're looking at data
431 * structures at which we have absolutely no business whatsoever
432 * looking...
434 memset(&ipb, 0, sizeof(ipb));
435 ipb.val1 = HMAP->lno;
436 ipb.val2 = TMAP->lno - HMAP->lno;
437 if (sp->ep != NULL && sp->ep->db != NULL)
438 (void)db_last(sp, &total);
439 ipb.val3 = total == 0 ? 1 : total;
440 if (ipb.val1 != ipp->sb_top ||
441 ipb.val2 != ipp->sb_num || ipb.val3 != ipp->sb_total) {
442 ipb.code = SI_SCROLLBAR;
443 (void)vi_send(ipp->o_fd, "123", &ipb);
444 ipp->sb_top = ipb.val1;
445 ipp->sb_num = ipb.val2;
446 ipp->sb_total = ipb.val3;
449 /* Refresh/repaint the screen. */
450 ipb.code = repaint ? SI_REDRAW : SI_REFRESH;
451 return (vi_send(ipp->o_fd, NULL, &ipb));
455 * ip_rename --
456 * Rename the file.
458 * PUBLIC: int ip_rename __P((SCR *, char *, int));
461 ip_rename(SCR *sp, char *name, int on)
463 IP_BUF ipb;
464 IP_PRIVATE *ipp = IPP(sp);
466 memset(&ipb, 0, sizeof(ipb));
467 ipb.code = SI_RENAME;
468 ipb.str1 = name;
469 ipb.len1 = name ? strlen(name) : 0;
470 return (vi_send(ipp->o_fd, "a", &ipb));
474 * ip_reply --
475 * Reply to a message.
477 * PUBLIC: int ip_reply __P((SCR *, int, char *));
480 ip_reply(SCR *sp, int status, char *msg)
482 IP_BUF ipb;
483 IP_PRIVATE *ipp = IPP(sp);
485 memset(&ipb, 0, sizeof(ipb));
486 ipb.code = SI_REPLY;
487 ipb.val1 = status;
488 ipb.str1 = msg == NULL ? "" : msg;
489 ipb.len1 = strlen(ipb.str1);
490 return (vi_send(ipp->o_fd, "1a", &ipb));
494 * ip_split --
495 * Split a screen.
497 * PUBLIC: int ip_split __P((SCR *, SCR *));
500 ip_split(SCR *origp, SCR *newp)
502 return (0);
506 * ip_suspend --
507 * Suspend a screen.
509 * PUBLIC: int ip_suspend __P((SCR *, int *));
512 ip_suspend(SCR *sp, int *allowedp)
514 *allowedp = 0;
515 return (0);
519 * ip_usage --
520 * Print out the ip usage messages.
522 * PUBLIC: void ip_usage __P((void));
524 void
525 ip_usage(void)
527 #define USAGE "\
528 usage: vi [-eFlRrSv] [-c command] [-I ifd.ofd] [-t tag] [-w size] [file ...]\n"
529 (void)fprintf(stderr, "%s", USAGE);
530 #undef USAGE