use addnwstr
[nvi.git] / cl / cl_funcs.c
blob04ed6ed02649a61b861ae426d24916a52a129d6d
1 /*-
2 * Copyright (c) 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: cl_funcs.c,v 10.63 2001/04/21 06:36:24 skimo Exp $ (Berkeley) $Date: 2001/04/21 06:36:24 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
20 #include <bitstring.h>
21 #include <ctype.h>
22 #include <signal.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <termios.h>
27 #include <unistd.h>
29 #include "../common/common.h"
30 #include "../vi/vi.h"
31 #include "cl.h"
33 static void cl_rdiv __P((SCR *));
35 static int
36 addstr4(SCR *sp, void *str, size_t len, int wide)
38 CL_PRIVATE *clp;
39 WINDOW *win;
40 size_t y, x;
41 int iv;
43 clp = CLP(sp);
44 win = CLSP(sp) ? CLSP(sp) : stdscr;
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 getyx(win, y, x);
52 if (!F_ISSET(sp, SC_SCR_EXWROTE) &&
53 y == RLNO(sp, LASTLINE(sp)) && IS_SPLIT(sp)) {
54 iv = 1;
55 (void)wstandout(win);
58 #ifdef USE_WIDECHAR
59 if (wide) {
60 wchar_t *dstr;
61 size_t dlen;
62 INT2DISP(sp, str, len, dstr, dlen);
63 if (waddnwstr(win, (wchar_t*) str, len) == ERR)
64 return (1);
65 } else
66 #endif
67 if (waddnstr(win, str, len) == ERR)
68 return (1);
70 if (iv)
71 (void)wstandend(win);
72 return (0);
76 * cl_waddstr --
77 * Add len bytes from the string at the cursor, advancing the cursor.
79 * PUBLIC: int cl_waddstr __P((SCR *, const CHAR_T *, size_t));
81 int
82 cl_waddstr(sp, str, len)
83 SCR *sp;
84 const CHAR_T *str;
85 size_t len;
87 addstr4(sp, (void *)str, len, 1);
91 * cl_addstr --
92 * Add len bytes from the string at the cursor, advancing the cursor.
94 * PUBLIC: int cl_addstr __P((SCR *, const char *, size_t));
96 int
97 cl_addstr(sp, str, len)
98 SCR *sp;
99 const char *str;
100 size_t len;
102 addstr4(sp, (void *)str, len, 0);
106 * cl_attr --
107 * Toggle a screen attribute on/off.
109 * PUBLIC: int cl_attr __P((SCR *, scr_attr_t, int));
112 cl_attr(sp, attribute, on)
113 SCR *sp;
114 scr_attr_t attribute;
115 int on;
117 CL_PRIVATE *clp;
118 WINDOW *win;
120 clp = CLP(sp);
121 win = CLSP(sp) ? CLSP(sp) : stdscr;
123 switch (attribute) {
124 case SA_ALTERNATE:
126 * !!!
127 * There's a major layering violation here. The problem is that the
128 * X11 xterm screen has what's known as an "alternate" screen. Some
129 * xterm termcap/terminfo entries include sequences to switch to/from
130 * that alternate screen as part of the ti/te (smcup/rmcup) strings.
131 * Vi runs in the alternate screen, so that you are returned to the
132 * same screen contents on exit from vi that you had when you entered
133 * vi. Further, when you run :shell, or :!date or similar ex commands,
134 * you also see the original screen contents. This wasn't deliberate
135 * on vi's part, it's just that it historically sent terminal init/end
136 * sequences at those times, and the addition of the alternate screen
137 * sequences to the strings changed the behavior of vi. The problem
138 * caused by this is that we don't want to switch back to the alternate
139 * screen while getting a new command from the user, when the user is
140 * continuing to enter ex commands, e.g.:
142 * :!date <<< switch to original screen
143 * [Hit return to continue] <<< prompt user to continue
144 * :command <<< get command from user
146 * Note that the :command input is a true vi input mode, e.g., input
147 * maps and abbreviations are being done. So, we need to be able to
148 * switch back into the vi screen mode, without flashing the screen.
150 * To make matters worse, the curses initscr() and endwin() calls will
151 * do this automatically -- so, this attribute isn't as controlled by
152 * the higher level screen as closely as one might like.
154 if (on) {
155 if (clp->ti_te != TI_SENT) {
156 clp->ti_te = TI_SENT;
157 if (clp->smcup == NULL)
158 (void)cl_getcap(sp, "smcup", &clp->smcup);
159 if (clp->smcup != NULL)
160 (void)tputs(clp->smcup, 1, cl_putchar);
162 } else
163 if (clp->ti_te != TE_SENT) {
164 clp->ti_te = TE_SENT;
165 if (clp->rmcup == NULL)
166 (void)cl_getcap(sp, "rmcup", &clp->rmcup);
167 if (clp->rmcup != NULL)
168 (void)tputs(clp->rmcup, 1, cl_putchar);
169 (void)fflush(stdout);
171 (void)fflush(stdout);
172 break;
173 case SA_INVERSE:
174 if (F_ISSET(sp, SC_EX | SC_SCR_EXWROTE)) {
175 if (clp->smso == NULL)
176 return (1);
177 if (on)
178 (void)tputs(clp->smso, 1, cl_putchar);
179 else
180 (void)tputs(clp->rmso, 1, cl_putchar);
181 (void)fflush(stdout);
182 } else {
183 if (on)
184 (void)wstandout(win);
185 else
186 (void)wstandend(win);
188 break;
189 default:
190 abort();
192 return (0);
196 * cl_baud --
197 * Return the baud rate.
199 * PUBLIC: int cl_baud __P((SCR *, u_long *));
202 cl_baud(sp, ratep)
203 SCR *sp;
204 u_long *ratep;
206 CL_PRIVATE *clp;
209 * XXX
210 * There's no portable way to get a "baud rate" -- cfgetospeed(3)
211 * returns the value associated with some #define, which we may
212 * never have heard of, or which may be a purely local speed. Vi
213 * only cares if it's SLOW (w300), slow (w1200) or fast (w9600).
214 * Try and detect the slow ones, and default to fast.
216 clp = CLP(sp);
217 switch (cfgetospeed(&clp->orig)) {
218 case B50:
219 case B75:
220 case B110:
221 case B134:
222 case B150:
223 case B200:
224 case B300:
225 case B600:
226 *ratep = 600;
227 break;
228 case B1200:
229 *ratep = 1200;
230 break;
231 default:
232 *ratep = 9600;
233 break;
235 return (0);
239 * cl_bell --
240 * Ring the bell/flash the screen.
242 * PUBLIC: int cl_bell __P((SCR *));
245 cl_bell(sp)
246 SCR *sp;
248 if (F_ISSET(sp, SC_EX | SC_SCR_EXWROTE | SC_SCR_EX))
249 (void)write(STDOUT_FILENO, "\07", 1); /* \a */
250 else {
252 * Vi has an edit option which determines if the terminal
253 * should be beeped or the screen flashed.
255 if (O_ISSET(sp, O_FLASH))
256 (void)flash();
257 else
258 (void)beep();
260 return (0);
264 * cl_clrtoeol --
265 * Clear from the current cursor to the end of the line.
267 * PUBLIC: int cl_clrtoeol __P((SCR *));
270 cl_clrtoeol(sp)
271 SCR *sp;
273 WINDOW *win;
274 size_t spcnt, y, x;
276 win = CLSP(sp) ? CLSP(sp) : stdscr;
278 #if 0
279 if (IS_VSPLIT(sp)) {
280 /* The cursor must be returned to its original position. */
281 getyx(win, y, x);
282 for (spcnt = (sp->coff + sp->cols) - x; spcnt > 0; --spcnt)
283 (void)waddch(win, ' ');
284 (void)wmove(win, y, x);
285 return (0);
286 } else
287 #endif
288 return (wclrtoeol(win) == ERR);
292 * cl_cursor --
293 * Return the current cursor position.
295 * PUBLIC: int cl_cursor __P((SCR *, size_t *, size_t *));
298 cl_cursor(sp, yp, xp)
299 SCR *sp;
300 size_t *yp, *xp;
302 WINDOW *win;
303 win = CLSP(sp) ? CLSP(sp) : stdscr;
305 * The curses screen support splits a single underlying curses screen
306 * into multiple screens to support split screen semantics. For this
307 * reason the returned value must be adjusted to be relative to the
308 * current screen, and not absolute. Screens that implement the split
309 * using physically distinct screens won't need this hack.
311 getyx(win, *yp, *xp);
313 *yp -= sp->roff;
314 *xp -= sp->coff;
316 return (0);
320 * cl_deleteln --
321 * Delete the current line, scrolling all lines below it.
323 * PUBLIC: int cl_deleteln __P((SCR *));
326 cl_deleteln(sp)
327 SCR *sp;
329 CHAR_T ch;
330 CL_PRIVATE *clp;
331 WINDOW *win;
332 size_t col, lno, spcnt, y, x;
334 clp = CLP(sp);
335 win = CLSP(sp) ? CLSP(sp) : stdscr;
338 * This clause is required because the curses screen uses reverse
339 * video to delimit split screens. If the screen does not do this,
340 * this code won't be necessary.
342 * If the bottom line was in reverse video, rewrite it in normal
343 * video before it's scrolled.
345 * Check for the existence of a chgat function; XSI requires it, but
346 * historic implementations of System V curses don't. If it's not
347 * a #define, we'll fall back to doing it by hand, which is slow but
348 * acceptable.
350 * By hand means walking through the line, retrieving and rewriting
351 * each character. Curses has no EOL marker, so track strings of
352 * spaces, and copy the trailing spaces only if there's a non-space
353 * character following.
355 if (!F_ISSET(sp, SC_SCR_EXWROTE) && IS_SPLIT(sp)) {
356 getyx(win, y, x);
357 #ifdef mvchgat
358 mvwchgat(win, RLNO(sp, LASTLINE(sp)), 0, -1, A_NORMAL, 0, NULL);
359 #else
360 for (lno = RLNO(sp, LASTLINE(sp)), col = spcnt = 0;;) {
361 (void)wmove(win, lno, col);
362 ch = winch(win);
363 if (isblank(ch))
364 ++spcnt;
365 else {
366 (void)wmove(win, lno, col - spcnt);
367 for (; spcnt > 0; --spcnt)
368 (void)waddch(win, ' ');
369 (void)waddch(win, ch);
371 if (++col >= sp->cols)
372 break;
374 #endif
375 (void)wmove(win, y, x);
379 * The bottom line is expected to be blank after this operation,
380 * and other screens must support that semantic.
382 return (wdeleteln(win) == ERR);
386 * cl_discard --
387 * Discard a screen.
389 * PUBLIC: int cl_discard __P((SCR *, SCR **));
392 cl_discard(discardp, acquirep)
393 SCR *discardp, **acquirep;
395 CL_PRIVATE *clp;
396 SCR* tsp;
398 if (discardp) {
399 clp = CLP(discardp);
400 F_SET(clp, CL_LAYOUT);
402 if (CLSP(discardp)) {
403 delwin(CLSP(discardp));
404 CLSP(discardp) = NULL;
408 /* no screens got a piece; we're done */
409 if (!acquirep)
410 return 0;
412 for (; (tsp = *acquirep) != NULL; ++acquirep) {
413 clp = CLP(tsp);
414 F_SET(clp, CL_LAYOUT);
416 if (CLSP(tsp))
417 delwin(CLSP(tsp));
418 CLSP(tsp) = subwin(stdscr, tsp->rows, tsp->cols,
419 tsp->roff, tsp->coff);
422 /* discardp is going away, acquirep is taking up its space. */
423 return (0);
427 * cl_ex_adjust --
428 * Adjust the screen for ex. This routine is purely for standalone
429 * ex programs. All special purpose, all special case.
431 * PUBLIC: int cl_ex_adjust __P((SCR *, exadj_t));
434 cl_ex_adjust(sp, action)
435 SCR *sp;
436 exadj_t action;
438 CL_PRIVATE *clp;
439 int cnt;
441 clp = CLP(sp);
442 switch (action) {
443 case EX_TERM_SCROLL:
444 /* Move the cursor up one line if that's possible. */
445 if (clp->cuu1 != NULL)
446 (void)tputs(clp->cuu1, 1, cl_putchar);
447 else if (clp->cup != NULL)
448 (void)tputs(tgoto(clp->cup,
449 0, LINES - 2), 1, cl_putchar);
450 else
451 return (0);
452 /* FALLTHROUGH */
453 case EX_TERM_CE:
454 /* Clear the line. */
455 if (clp->el != NULL) {
456 (void)putchar('\r');
457 (void)tputs(clp->el, 1, cl_putchar);
458 } else {
460 * Historically, ex didn't erase the line, so, if the
461 * displayed line was only a single glyph, and <eof>
462 * was more than one glyph, the output would not fully
463 * overwrite the user's input. To fix this, output
464 * the maxiumum character number of spaces. Note,
465 * this won't help if the user entered extra prompt
466 * or <blank> characters before the command character.
467 * We'd have to do a lot of work to make that work, and
468 * it's almost certainly not worth the effort.
470 for (cnt = 0; cnt < MAX_CHARACTER_COLUMNS; ++cnt)
471 (void)putchar('\b');
472 for (cnt = 0; cnt < MAX_CHARACTER_COLUMNS; ++cnt)
473 (void)putchar(' ');
474 (void)putchar('\r');
475 (void)fflush(stdout);
477 break;
478 default:
479 abort();
481 return (0);
485 * cl_insertln --
486 * Push down the current line, discarding the bottom line.
488 * PUBLIC: int cl_insertln __P((SCR *));
491 cl_insertln(sp)
492 SCR *sp;
494 WINDOW *win;
495 win = CLSP(sp) ? CLSP(sp) : stdscr;
497 * The current line is expected to be blank after this operation,
498 * and the screen must support that semantic.
500 return (winsertln(win) == ERR);
504 * cl_keyval --
505 * Return the value for a special key.
507 * PUBLIC: int cl_keyval __P((SCR *, scr_keyval_t, CHAR_T *, int *));
510 cl_keyval(sp, val, chp, dnep)
511 SCR *sp;
512 scr_keyval_t val;
513 CHAR_T *chp;
514 int *dnep;
516 CL_PRIVATE *clp;
519 * VEOF, VERASE and VKILL are required by POSIX 1003.1-1990,
520 * VWERASE is a 4BSD extension.
522 clp = CLP(sp);
523 switch (val) {
524 case KEY_VEOF:
525 *dnep = (*chp = clp->orig.c_cc[VEOF]) == _POSIX_VDISABLE;
526 break;
527 case KEY_VERASE:
528 *dnep = (*chp = clp->orig.c_cc[VERASE]) == _POSIX_VDISABLE;
529 break;
530 case KEY_VKILL:
531 *dnep = (*chp = clp->orig.c_cc[VKILL]) == _POSIX_VDISABLE;
532 break;
533 #ifdef VWERASE
534 case KEY_VWERASE:
535 *dnep = (*chp = clp->orig.c_cc[VWERASE]) == _POSIX_VDISABLE;
536 break;
537 #endif
538 default:
539 *dnep = 1;
540 break;
542 return (0);
546 * cl_move --
547 * Move the cursor.
549 * PUBLIC: int cl_move __P((SCR *, size_t, size_t));
552 cl_move(sp, lno, cno)
553 SCR *sp;
554 size_t lno, cno;
556 WINDOW *win;
557 win = CLSP(sp) ? CLSP(sp) : stdscr;
558 /* See the comment in cl_cursor. */
559 if (wmove(win, RLNO(sp, lno), RCNO(sp, cno)) == ERR) {
560 msgq(sp, M_ERR, "Error: move: l(%u + %u) c(%u + %u)",
561 lno, sp->roff, cno, sp->coff);
562 return (1);
564 return (0);
568 * cl_refresh --
569 * Refresh the screen.
571 * PUBLIC: int cl_refresh __P((SCR *, int));
574 cl_refresh(sp, repaint)
575 SCR *sp;
576 int repaint;
578 GS *gp;
579 CL_PRIVATE *clp;
580 WINDOW *win;
581 SCR *psp, *tsp;
582 size_t y, x;
584 gp = sp->gp;
585 clp = CLP(sp);
586 win = CLSP(sp) ? CLSP(sp) : stdscr;
589 * If we received a killer signal, we're done, there's no point
590 * in refreshing the screen.
592 if (clp->killersig)
593 return (0);
596 * If repaint is set, the editor is telling us that we don't know
597 * what's on the screen, so we have to repaint from scratch.
599 * If repaint set or the screen layout changed, we need to redraw
600 * any lines separating vertically split screens. If the horizontal
601 * offsets are the same, then the split was vertical, and need to
602 * draw a dividing line.
604 if (repaint || F_ISSET(clp, CL_LAYOUT)) {
605 getyx(win, y, x);
606 for (psp = sp;
607 psp != (void *)&sp->wp->scrq; psp = psp->q.cqe_next)
608 for (tsp = psp->q.cqe_next;
609 tsp != (void *)&sp->wp->scrq;
610 tsp = tsp->q.cqe_next)
611 if (psp->roff == tsp->roff) {
612 if (psp->coff + psp->cols + 1 == tsp->coff)
613 cl_rdiv(psp);
614 else
615 if (tsp->coff + tsp->cols + 1 == psp->coff)
616 cl_rdiv(tsp);
618 (void)wmove(win, y, x);
619 F_CLR(clp, CL_LAYOUT);
623 * In the curses library, doing wrefresh(curscr) is okay, but the
624 * screen flashes when we then apply the refresh() to bring it up
625 * to date. So, use clearok().
627 if (repaint)
628 clearok(curscr, 1);
629 return (wrefresh(stdscr) == ERR || wrefresh(win) == ERR);
633 * cl_rdiv --
634 * Draw a dividing line between two vertically split screens.
636 static void
637 cl_rdiv(sp)
638 SCR *sp;
640 WINDOW *win;
641 size_t cnt;
643 win = CLSP(sp) ? CLSP(sp) : stdscr;
645 for (cnt = 0; cnt < sp->rows - 1; ++cnt) {
646 wmove(stdscr, sp->roff + cnt, sp->cols + sp->coff);
647 waddch(stdscr, '|');
652 * cl_rename --
653 * Rename the file.
655 * PUBLIC: int cl_rename __P((SCR *, char *, int));
658 cl_rename(sp, name, on)
659 SCR *sp;
660 char *name;
661 int on;
663 CL_PRIVATE *clp;
664 FILE *pfp;
665 GS *gp;
666 char buf[256], *p;
668 gp = sp->gp;
669 clp = CLP(sp);
671 if (on) {
672 if (!F_ISSET(clp, CL_RENAME_OK))
673 return (0);
676 * XXX
677 * We can only rename windows for xterm.
679 if (strncmp(OG_STR(gp, GO_TERM), "xterm", sizeof("xterm") - 1))
680 return (0);
683 * XXX
684 * Try and figure out the current name of this window. There
685 * are two forms of the xwininfo output I've seen:
687 * Window id: 0x400000d "name"
688 * Window id: 0x140000d (name)
690 #define COMMAND \
691 "expr \"`xwininfo -id $WINDOWID | grep id:`\" : '.* [\"(]\\(.*\\)[\")]'"
693 if (clp->oname == NULL &&
694 (pfp = popen(COMMAND, "r")) != NULL) {
695 if (fgets(buf, sizeof(buf), pfp) != NULL &&
696 (p = strchr(buf, '\n')) != NULL) {
697 *p = '\0';
698 clp->oname = strdup(buf);
700 (void)fclose(pfp);
703 cl_setname(gp, name);
705 F_SET(clp, CL_RENAME);
706 } else
707 if (F_ISSET(clp, CL_RENAME)) {
708 cl_setname(gp, clp->oname);
710 F_CLR(clp, CL_RENAME);
712 return (0);
716 * cl_setname --
717 * Set a X11 icon/window name.
719 * PUBLIC: void cl_setname __P((GS *, char *));
721 void
722 cl_setname(gp, name)
723 GS *gp;
724 char *name;
726 /* X11 xterm escape sequence to rename the icon/window. */
727 #define XTERM_RENAME "\033]0;%s\007"
729 (void)printf(XTERM_RENAME, name == NULL ? OG_STR(gp, GO_TERM) : name);
730 (void)fflush(stdout);
734 * cl_split --
735 * Split a screen.
737 * PUBLIC: int cl_split __P((SCR *, SCR *));
740 cl_split(origp, newp)
741 SCR *origp, *newp;
743 CL_PRIVATE *clp;
745 clp = CLP(origp);
746 F_SET(clp, CL_LAYOUT);
748 if (CLSP(origp))
749 delwin(CLSP(origp));
751 CLSP(origp) = subwin(stdscr, origp->rows, origp->cols,
752 origp->roff, origp->coff);
753 CLSP(newp) = subwin(stdscr, newp->rows, newp->cols,
754 newp->roff, newp->coff);
756 /* origp is the original screen, giving up space to newp. */
757 return (0);
761 * cl_suspend --
762 * Suspend a screen.
764 * PUBLIC: int cl_suspend __P((SCR *, int *));
767 cl_suspend(sp, allowedp)
768 SCR *sp;
769 int *allowedp;
771 struct termios t;
772 CL_PRIVATE *clp;
773 WINDOW *win;
774 GS *gp;
775 size_t y, x;
776 int changed;
778 gp = sp->gp;
779 clp = CLP(sp);
780 win = CLSP(sp) ? CLSP(sp) : stdscr;
781 *allowedp = 1;
784 * The ex implementation of this function isn't needed by screens not
785 * supporting ex commands that require full terminal canonical mode
786 * (e.g. :suspend).
788 * The vi implementation of this function isn't needed by screens not
789 * supporting vi process suspension, i.e. any screen that isn't backed
790 * by a UNIX shell.
792 * Setting allowedp to 0 will cause the editor to reject the command.
794 if (F_ISSET(sp, SC_EX)) {
795 /* Save the terminal settings, and restore the original ones. */
796 if (F_ISSET(clp, CL_STDIN_TTY)) {
797 (void)tcgetattr(STDIN_FILENO, &t);
798 (void)tcsetattr(STDIN_FILENO,
799 TCSASOFT | TCSADRAIN, &clp->orig);
802 /* Stop the process group. */
803 (void)kill(0, SIGTSTP);
805 /* Time passes ... */
807 /* Restore terminal settings. */
808 if (F_ISSET(clp, CL_STDIN_TTY))
809 (void)tcsetattr(STDIN_FILENO, TCSASOFT | TCSADRAIN, &t);
810 return (0);
814 * Move to the lower left-hand corner of the screen.
816 * XXX
817 * Not sure this is necessary in System V implementations, but it
818 * shouldn't hurt.
820 getyx(win, y, x);
821 (void)wmove(win, LINES - 1, 0);
822 (void)wrefresh(win);
825 * Temporarily end the screen. System V introduced a semantic where
826 * endwin() could be restarted. We use it because restarting curses
827 * from scratch often fails in System V. 4BSD curses didn't support
828 * restarting after endwin(), so we have to do what clean up we can
829 * without calling it.
831 /* Save the terminal settings. */
832 (void)tcgetattr(STDIN_FILENO, &t);
834 /* Restore the cursor keys to normal mode. */
835 (void)keypad(stdscr, FALSE);
837 /* Restore the window name. */
838 (void)cl_rename(sp, NULL, 0);
840 #ifdef HAVE_BSD_CURSES
841 (void)cl_attr(sp, SA_ALTERNATE, 0);
842 #else
843 (void)endwin();
844 #endif
846 * XXX
847 * Restore the original terminal settings. This is bad -- the
848 * reset can cause character loss from the tty queue. However,
849 * we can't call endwin() in BSD curses implementations, and too
850 * many System V curses implementations don't get it right.
852 (void)tcsetattr(STDIN_FILENO, TCSADRAIN | TCSASOFT, &clp->orig);
854 /* Stop the process group. */
855 (void)kill(0, SIGTSTP);
857 /* Time passes ... */
860 * If we received a killer signal, we're done. Leave everything
861 * unchanged. In addition, the terminal has already been reset
862 * correctly, so leave it alone.
864 if (clp->killersig) {
865 F_CLR(clp, CL_SCR_EX_INIT | CL_SCR_VI_INIT);
866 return (0);
869 /* Restore terminal settings. */
870 wrefresh(win); /* Needed on SunOs/Solaris ? */
871 if (F_ISSET(clp, CL_STDIN_TTY))
872 (void)tcsetattr(STDIN_FILENO, TCSASOFT | TCSADRAIN, &t);
874 #ifdef HAVE_BSD_CURSES
875 (void)cl_attr(sp, SA_ALTERNATE, 1);
876 #endif
878 /* Set the window name. */
879 (void)cl_rename(sp, sp->frp->name, 1);
881 /* Put the cursor keys into application mode. */
882 (void)keypad(stdscr, TRUE);
884 /* Refresh and repaint the screen. */
885 (void)wmove(win, y, x);
886 (void)cl_refresh(sp, 1);
888 /* If the screen changed size, set the SIGWINCH bit. */
889 if (cl_ssize(sp, 1, NULL, NULL, &changed))
890 return (1);
891 if (changed)
892 F_SET(CLP(sp), CL_SIGWINCH);
894 return (0);
898 * cl_usage --
899 * Print out the curses usage messages.
901 * PUBLIC: void cl_usage __P((void));
903 void
904 cl_usage()
906 #define USAGE "\
907 usage: ex [-eFRrSsv] [-c command] [-t tag] [-w size] [file ...]\n\
908 usage: vi [-eFlRrSv] [-c command] [-t tag] [-w size] [file ...]\n"
909 (void)fprintf(stderr, "%s", USAGE);
910 #undef USAGE
913 #ifdef DEBUG
915 * gdbrefresh --
916 * Stub routine so can flush out curses screen changes using gdb.
919 gdbrefresh()
921 refresh();
922 return (0); /* XXX Convince gdb to run it. */
924 #endif