ctags fix
[nvi.git] / ip / ip_funcs.c
blobf4f11e8c13aadb6541c82db14b48441f76b204b1
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: ip_funcs.c,v 8.16 2000/06/28 20:20:37 skimo Exp $ (Berkeley) $Date: 2000/06/28 20:20:37 $";
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 <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
23 #include "../common/common.h"
24 #include "../vi/vi.h"
25 #include "../ipc/ip.h"
26 #include "extern.h"
29 * ip_addstr --
30 * Add len bytes from the string at the cursor, advancing the cursor.
32 * PUBLIC: int ip_addstr __P((SCR *, const char *, size_t));
34 int
35 ip_addstr(sp, str, len)
36 SCR *sp;
37 const char *str;
38 size_t len;
40 IP_BUF ipb;
41 IP_PRIVATE *ipp;
42 int iv, rval;
44 ipp = IPP(sp);
47 * If ex isn't in control, it's the last line of the screen and
48 * it's a split screen, use inverse video.
50 iv = 0;
51 if (!F_ISSET(sp, SC_SCR_EXWROTE) &&
52 ipp->row == LASTLINE(sp) && IS_SPLIT(sp)) {
53 iv = 1;
54 ip_attr(sp, SA_INVERSE, 1);
56 ipb.code = SI_ADDSTR;
57 ipb.len1 = len;
58 ipb.str1 = str;
59 rval = vi_send(ipp->o_fd, "a", &ipb);
60 /* XXXX */
61 ipp->col += len;
63 if (iv)
64 ip_attr(sp, SA_INVERSE, 0);
65 return (rval);
69 * ip_attr --
70 * Toggle a screen attribute on/off.
72 * PUBLIC: int ip_attr __P((SCR *, scr_attr_t, int));
74 int
75 ip_attr(sp, attribute, on)
76 SCR *sp;
77 scr_attr_t attribute;
78 int on;
80 IP_BUF ipb;
81 IP_PRIVATE *ipp = IPP(sp);
83 ipb.code = SI_ATTRIBUTE;
84 ipb.val1 = attribute;
85 ipb.val2 = on;
87 return (vi_send(ipp->o_fd, "12", &ipb));
91 * ip_baud --
92 * Return the baud rate.
94 * PUBLIC: int ip_baud __P((SCR *, u_long *));
96 int
97 ip_baud(sp, ratep)
98 SCR *sp;
99 u_long *ratep;
101 *ratep = 9600; /* XXX: Translation: fast. */
102 return (0);
106 * ip_bell --
107 * Ring the bell/flash the screen.
109 * PUBLIC: int ip_bell __P((SCR *));
112 ip_bell(sp)
113 SCR *sp;
115 IP_BUF ipb;
116 IP_PRIVATE *ipp = IPP(sp);
118 ipb.code = SI_BELL;
120 return (vi_send(ipp->o_fd, NULL, &ipb));
124 * ip_busy --
125 * Display a busy message.
127 * PUBLIC: void ip_busy __P((SCR *, const char *, busy_t));
129 void
130 ip_busy(sp, str, bval)
131 SCR *sp;
132 const char *str;
133 busy_t bval;
135 IP_BUF ipb;
136 IP_PRIVATE *ipp = IPP(sp);
138 switch (bval) {
139 case BUSY_ON:
140 ipb.code = SI_BUSY_ON;
141 ipb.str1 = str;
142 ipb.len1 = strlen(str);
143 (void)vi_send(ipp->o_fd, "a", &ipb);
144 break;
145 case BUSY_OFF:
146 ipb.code = SI_BUSY_OFF;
147 (void)vi_send(ipp->o_fd, NULL, &ipb);
148 break;
149 case BUSY_UPDATE:
150 break;
152 return;
156 * ip_clrtoeol --
157 * Clear from the current cursor to the end of the line.
159 * PUBLIC: int ip_clrtoeol __P((SCR *));
162 ip_clrtoeol(sp)
163 SCR *sp;
165 IP_BUF ipb;
166 IP_PRIVATE *ipp = IPP(sp);
168 /* Temporary hack until we can pass screen pointers
169 * or name screens
171 if (IS_VSPLIT(sp)) {
172 size_t x, y, spcnt;
173 IP_PRIVATE *ipp;
174 int error;
176 ipp = IPP(sp);
177 y = ipp->row;
178 x = ipp->col;
179 error = 0;
180 for (spcnt = sp->cols - x;
181 spcnt > 0 && ! error; --spcnt)
182 error = ip_addstr(sp, " ", 1);
183 if (sp->coff == 0)
184 error |= ip_addstr(sp, "|", 1);
185 error |= ip_move(sp, y, x);
186 return error;
189 ipb.code = SI_CLRTOEOL;
191 return (vi_send(ipp->o_fd, NULL, &ipb));
195 * ip_cursor --
196 * Return the current cursor position.
198 * PUBLIC: int ip_cursor __P((SCR *, size_t *, size_t *));
201 ip_cursor(sp, yp, xp)
202 SCR *sp;
203 size_t *yp, *xp;
205 IP_PRIVATE *ipp;
207 ipp = IPP(sp);
208 *yp = ipp->row;
209 *xp = ipp->col;
210 return (0);
214 * ip_deleteln --
215 * Delete the current line, scrolling all lines below it.
217 * PUBLIC: int ip_deleteln __P((SCR *));
220 ip_deleteln(sp)
221 SCR *sp;
223 IP_BUF ipb;
224 IP_PRIVATE *ipp = IPP(sp);
227 * This clause is required because the curses screen uses reverse
228 * video to delimit split screens. If the screen does not do this,
229 * this code won't be necessary.
231 * If the bottom line was in reverse video, rewrite it in normal
232 * video before it's scrolled.
234 if (!F_ISSET(sp, SC_SCR_EXWROTE) && IS_SPLIT(sp)) {
235 ipb.code = SI_REWRITE;
236 ipb.val1 = RLNO(sp, LASTLINE(sp));
237 if (vi_send(ipp->o_fd, "1", &ipb))
238 return (1);
242 * The bottom line is expected to be blank after this operation,
243 * and other screens must support that semantic.
245 ipb.code = SI_DELETELN;
246 return (vi_send(ipp->o_fd, NULL, &ipb));
250 * ip_discard --
251 * Discard a screen.
253 * PUBLIC: int ip_discard __P((SCR *, SCR **));
256 ip_discard(discardp, acquirep)
257 SCR *discardp, **acquirep;
259 return (0);
263 * ip_ex_adjust --
264 * Adjust the screen for ex.
266 * PUBLIC: int ip_ex_adjust __P((SCR *, exadj_t));
269 ip_ex_adjust(sp, action)
270 SCR *sp;
271 exadj_t action;
273 abort();
274 /* NOTREACHED */
278 * ip_insertln --
279 * Push down the current line, discarding the bottom line.
281 * PUBLIC: int ip_insertln __P((SCR *));
284 ip_insertln(sp)
285 SCR *sp;
287 IP_BUF ipb;
288 IP_PRIVATE *ipp = IPP(sp);
290 ipb.code = SI_INSERTLN;
292 return (vi_send(ipp->o_fd, NULL, &ipb));
296 * ip_keyval --
297 * Return the value for a special key.
299 * PUBLIC: int ip_keyval __P((SCR *, scr_keyval_t, CHAR_T *, int *));
302 ip_keyval(sp, val, chp, dnep)
303 SCR *sp;
304 scr_keyval_t val;
305 CHAR_T *chp;
306 int *dnep;
309 * VEOF, VERASE and VKILL are required by POSIX 1003.1-1990,
310 * VWERASE is a 4BSD extension.
312 switch (val) {
313 case KEY_VEOF:
314 *dnep = '\004'; /* ^D */
315 break;
316 case KEY_VERASE:
317 *dnep = '\b'; /* ^H */
318 break;
319 case KEY_VKILL:
320 *dnep = '\025'; /* ^U */
321 break;
322 #ifdef VWERASE
323 case KEY_VWERASE:
324 *dnep = '\027'; /* ^W */
325 break;
326 #endif
327 default:
328 *dnep = 1;
329 break;
331 return (0);
335 * ip_move --
336 * Move the cursor.
338 * PUBLIC: int ip_move __P((SCR *, size_t, size_t));
341 ip_move(sp, lno, cno)
342 SCR *sp;
343 size_t lno, cno;
345 IP_PRIVATE *ipp;
346 IP_BUF ipb;
348 ipp = IPP(sp);
349 ipp->row = lno;
350 ipp->col = cno;
352 ipb.code = SI_MOVE;
353 ipb.val1 = RLNO(sp, lno);
354 ipb.val2 = RCNO(sp, cno);
355 return (vi_send(ipp->o_fd, "12", &ipb));
359 * ip_refresh --
360 * Refresh the screen.
362 * PUBLIC: int ip_refresh __P((SCR *, int));
365 ip_refresh(sp, repaint)
366 SCR *sp;
367 int repaint;
369 IP_BUF ipb;
370 IP_PRIVATE *ipp;
371 db_recno_t total;
373 ipp = IPP(sp);
376 * If the scroll bar information has changed since we last sent
377 * it, resend it. Currently, we send three values:
379 * top The line number of the first line in the screen.
380 * num The number of lines visible on the screen.
381 * total The number of lines in the file.
383 * XXX
384 * This is a gross violation of layering... we're looking at data
385 * structures at which we have absolutely no business whatsoever
386 * looking...
388 ipb.val1 = HMAP->lno;
389 ipb.val2 = TMAP->lno - HMAP->lno;
390 (void)db_last(sp, &total);
391 ipb.val3 = total == 0 ? 1 : total;
392 if (ipb.val1 != ipp->sb_top ||
393 ipb.val2 != ipp->sb_num || ipb.val3 != ipp->sb_total) {
394 ipb.code = SI_SCROLLBAR;
395 (void)vi_send(ipp->o_fd, "123", &ipb);
396 ipp->sb_top = ipb.val1;
397 ipp->sb_num = ipb.val2;
398 ipp->sb_total = ipb.val3;
401 /* Refresh/repaint the screen. */
402 ipb.code = repaint ? SI_REDRAW : SI_REFRESH;
403 return (vi_send(ipp->o_fd, NULL, &ipb));
407 * ip_rename --
408 * Rename the file.
410 * PUBLIC: int ip_rename __P((SCR *, char *, int));
413 ip_rename(sp, name, on)
414 SCR *sp;
415 char *name;
416 int on;
418 IP_BUF ipb;
419 IP_PRIVATE *ipp = IPP(sp);
421 ipb.code = SI_RENAME;
422 ipb.str1 = name;
423 ipb.len1 = strlen(name);
424 return (vi_send(ipp->o_fd, "a", &ipb));
428 * ip_reply --
429 * Reply to a message.
431 * PUBLIC: int ip_reply __P((SCR *, int, char *));
434 ip_reply(sp, status, msg)
435 SCR *sp;
436 int status;
437 char *msg;
439 IP_BUF ipb;
440 IP_PRIVATE *ipp = IPP(sp);
442 ipb.code = SI_REPLY;
443 ipb.val1 = status;
444 ipb.str1 = msg == NULL ? "" : msg;
445 ipb.len1 = strlen(ipb.str1);
446 return (vi_send(ipp->o_fd, "1a", &ipb));
450 * ip_split --
451 * Split a screen.
453 * PUBLIC: int ip_split __P((SCR *, SCR *));
456 ip_split(origp, newp)
457 SCR *origp, *newp;
459 return (0);
463 * ip_suspend --
464 * Suspend a screen.
466 * PUBLIC: int ip_suspend __P((SCR *, int *));
469 ip_suspend(sp, allowedp)
470 SCR *sp;
471 int *allowedp;
473 *allowedp = 0;
474 return (0);
478 * ip_usage --
479 * Print out the ip usage messages.
481 * PUBLIC: void ip_usage __P((void));
483 void
484 ip_usage()
486 #define USAGE "\
487 usage: vi [-eFlRrSv] [-c command] [-I ifd.ofd] [-t tag] [-w size] [file ...]\n"
488 (void)fprintf(stderr, "%s", USAGE);
489 #undef USAGE