17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
23*f6db9f27Scf46844 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate /* Copyright (c) 1981 Regents of the University of California */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #include "ex.h"
367c478bd9Sstevel@tonic-gate #include "ex_tty.h"
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate static unsigned char allocspace[256];
397c478bd9Sstevel@tonic-gate static unsigned char *freespace;
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate * Terminal type initialization routines,
437c478bd9Sstevel@tonic-gate * and calculation of flags at entry or after
447c478bd9Sstevel@tonic-gate * a shell escape which may change them.
457c478bd9Sstevel@tonic-gate */
467c478bd9Sstevel@tonic-gate static short GT;
477c478bd9Sstevel@tonic-gate
48*f6db9f27Scf46844 void
gettmode(void)49*f6db9f27Scf46844 gettmode(void)
507c478bd9Sstevel@tonic-gate {
517c478bd9Sstevel@tonic-gate short speed;
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate GT = 1;
547c478bd9Sstevel@tonic-gate if(gTTY(2) == -1)
557c478bd9Sstevel@tonic-gate return;
567c478bd9Sstevel@tonic-gate if (termiosflag)
577c478bd9Sstevel@tonic-gate speed = (short)cfgetospeed(&tty);
587c478bd9Sstevel@tonic-gate else
597c478bd9Sstevel@tonic-gate speed = tty.c_cflag & CBAUD;
607c478bd9Sstevel@tonic-gate if (ospeed != speed)
617c478bd9Sstevel@tonic-gate value(vi_SLOWOPEN) = (int)(speed) < B1200;
627c478bd9Sstevel@tonic-gate ospeed = speed;
637c478bd9Sstevel@tonic-gate normf = tty;
647c478bd9Sstevel@tonic-gate UPPERCASE = (tty.c_iflag & IUCLC) != 0;
657c478bd9Sstevel@tonic-gate if ((tty.c_oflag & TABDLY) == TAB3 || teleray_glitch)
667c478bd9Sstevel@tonic-gate GT = 0;
677c478bd9Sstevel@tonic-gate NONL = (tty.c_oflag & ONLCR) == 0;
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate
70*f6db9f27Scf46844 void
setterm(unsigned char * type)71*f6db9f27Scf46844 setterm(unsigned char *type)
727c478bd9Sstevel@tonic-gate {
737c478bd9Sstevel@tonic-gate char *tparm();
747c478bd9Sstevel@tonic-gate unsigned char *chrptr;
75*f6db9f27Scf46844 int unknown, i;
76*f6db9f27Scf46844 int l;
777c478bd9Sstevel@tonic-gate int errret;
787c478bd9Sstevel@tonic-gate extern unsigned char termtype[];
797c478bd9Sstevel@tonic-gate extern void setsize();
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate unknown = 0;
827c478bd9Sstevel@tonic-gate if (cur_term && exit_ca_mode)
83*f6db9f27Scf46844 putpad((unsigned char *)exit_ca_mode);
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate * The code in this if statement is from 4.1.2 and fixes a bug where
867c478bd9Sstevel@tonic-gate * you couldn't change the term type using the ":set term" command.
877c478bd9Sstevel@tonic-gate */
887c478bd9Sstevel@tonic-gate if (*termtype) {
897c478bd9Sstevel@tonic-gate #ifdef TRACE
907c478bd9Sstevel@tonic-gate if (trace) fprintf(trace, "CALLED del_curterm with %s\n", termtype);
917c478bd9Sstevel@tonic-gate #endif
927c478bd9Sstevel@tonic-gate del_curterm(cur_term); /* Zap the old data space which was allocated
937c478bd9Sstevel@tonic-gate * previously (this is a set command)
947c478bd9Sstevel@tonic-gate */
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate cur_term = 0;
977c478bd9Sstevel@tonic-gate strcpy(termtype, type);
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate #ifdef XPG4
1007c478bd9Sstevel@tonic-gate use_env(1); /* $LINES and $COLUMNS override terminfo */
1017c478bd9Sstevel@tonic-gate #endif /* XPG4 */
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate setupterm(type, 2, &errret);
1047c478bd9Sstevel@tonic-gate if (errret != 1) {
1057c478bd9Sstevel@tonic-gate unknown++;
1067c478bd9Sstevel@tonic-gate cur_term = 0;
1077c478bd9Sstevel@tonic-gate if (errret == 0) {
1087c478bd9Sstevel@tonic-gate setupterm("unknown", 1, &errret);
1097c478bd9Sstevel@tonic-gate if (errret == 0) {
1107c478bd9Sstevel@tonic-gate perror(gettext("Unable to setup term:'unknown' missing in the terminfo database"));
1117c478bd9Sstevel@tonic-gate exit(++errcnt);
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate }
1147c478bd9Sstevel@tonic-gate else if (errret == -1) {
1157c478bd9Sstevel@tonic-gate perror(gettext("Unable to find the terminfo database"));
1167c478bd9Sstevel@tonic-gate exit(++errcnt);
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate if (errret == 1)
1207c478bd9Sstevel@tonic-gate resetterm();
1217c478bd9Sstevel@tonic-gate #ifdef TRACE
1227c478bd9Sstevel@tonic-gate if (trace) fprintf(trace, "after setupterm, lines %d, columns %d, clear_screen '%s', cursor_address '%s'\n", lines, columns, clear_screen, cursor_address);
1237c478bd9Sstevel@tonic-gate #endif
1247c478bd9Sstevel@tonic-gate setsize();
1257c478bd9Sstevel@tonic-gate #ifdef OLD
1267c478bd9Sstevel@tonic-gate if(exit_attribute_mode)
1277c478bd9Sstevel@tonic-gate putpad(exit_attribute_mode);
1287c478bd9Sstevel@tonic-gate #endif
1297c478bd9Sstevel@tonic-gate exit_bold = (exit_standout_mode ? exit_standout_mode : (exit_attribute_mode ? exit_attribute_mode : 0));
1307c478bd9Sstevel@tonic-gate i = lines;
1317c478bd9Sstevel@tonic-gate if (lines <= 1)
1327c478bd9Sstevel@tonic-gate lines = 24;
1337c478bd9Sstevel@tonic-gate if (lines > TUBELINES)
1347c478bd9Sstevel@tonic-gate lines = TUBELINES;
1357c478bd9Sstevel@tonic-gate l = lines;
1367c478bd9Sstevel@tonic-gate if (ospeed < B1200)
1377c478bd9Sstevel@tonic-gate l = 9; /* including the message line at the bottom */
1387c478bd9Sstevel@tonic-gate else if (ospeed < B2400)
1397c478bd9Sstevel@tonic-gate l = 17;
1407c478bd9Sstevel@tonic-gate if (l > lines)
1417c478bd9Sstevel@tonic-gate l = lines;
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate * Initialize keypad arrow keys.
1447c478bd9Sstevel@tonic-gate */
1457c478bd9Sstevel@tonic-gate freespace = allocspace;
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate #ifdef sun
148*f6db9f27Scf46844 kpadd(arrows, (unsigned char *)key_ic, (unsigned char *)"i",
149*f6db9f27Scf46844 (unsigned char *)"inschar");
150*f6db9f27Scf46844 kpadd(arrows, (unsigned char *)key_eic, (unsigned char *)"i",
151*f6db9f27Scf46844 (unsigned char *)"inschar");
152*f6db9f27Scf46844 kpadd(arrows, (unsigned char *)key_up, (unsigned char *)"k",
153*f6db9f27Scf46844 (unsigned char *)"up");
154*f6db9f27Scf46844 kpadd(arrows, (unsigned char *)key_down, (unsigned char *)"j",
155*f6db9f27Scf46844 (unsigned char *)"down");
156*f6db9f27Scf46844 kpadd(arrows, (unsigned char *)key_left, (unsigned char *)"h",
157*f6db9f27Scf46844 (unsigned char *)"left");
158*f6db9f27Scf46844 kpadd(arrows, (unsigned char *)key_right, (unsigned char *)"l",
159*f6db9f27Scf46844 (unsigned char *)"right");
160*f6db9f27Scf46844 kpadd(arrows, (unsigned char *)key_home, (unsigned char *)"H",
161*f6db9f27Scf46844 (unsigned char *)"home");
1627c478bd9Sstevel@tonic-gate #else
1637c478bd9Sstevel@tonic-gate kpadd(arrows, key_ic, "i", "inschar");
1647c478bd9Sstevel@tonic-gate kpadd(immacs, key_ic, "\033", "inschar");
1657c478bd9Sstevel@tonic-gate kpadd(arrows, key_eic, "i", "inschar");
1667c478bd9Sstevel@tonic-gate kpadd(immacs, key_eic, "\033", "inschar");
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_up, "k", "up");
1697c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_down, "j", "down");
1707c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_left, "h", "left");
1717c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_right, "l", "right");
1727c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_home, "H", "home");
1737c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_il, "o\033", "insline");
1747c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_dl, "dd", "delline");
1757c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_clear, "\014", "clear");
1767c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_eol, "d$", "clreol");
1777c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_sf, "\005", "scrollf");
1787c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_dc, "x", "delchar");
1797c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_npage, "\006", "npage");
1807c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_ppage, "\002", "ppage");
1817c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_sr, "\031", "sr");
1827c478bd9Sstevel@tonic-gate kpboth(arrows, immacs, key_eos, "dG", "clreos");
183*f6db9f27Scf46844 #endif /* sun */
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate /*
1867c478bd9Sstevel@tonic-gate * Handle funny termcap capabilities
1877c478bd9Sstevel@tonic-gate */
1887c478bd9Sstevel@tonic-gate /* don't understand insert mode with multibyte characters */
1897c478bd9Sstevel@tonic-gate if(MB_CUR_MAX > 1) {
1907c478bd9Sstevel@tonic-gate enter_insert_mode = NULL;
1917c478bd9Sstevel@tonic-gate exit_insert_mode = NULL;
1927c478bd9Sstevel@tonic-gate #ifndef PRESUNEUC
1937c478bd9Sstevel@tonic-gate insert_character = NULL;
1947c478bd9Sstevel@tonic-gate #endif /* PRESUNEUC */
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate if (change_scroll_region && save_cursor && restore_cursor) insert_line=delete_line="";
1987c478bd9Sstevel@tonic-gate if (parm_insert_line && insert_line==NULL) insert_line="";
1997c478bd9Sstevel@tonic-gate if (parm_delete_line && delete_line==NULL) delete_line="";
2007c478bd9Sstevel@tonic-gate if (insert_character && enter_insert_mode==NULL) enter_insert_mode="";
2017c478bd9Sstevel@tonic-gate if (insert_character && exit_insert_mode==NULL) exit_insert_mode="";
2027c478bd9Sstevel@tonic-gate if (GT == 0)
2037c478bd9Sstevel@tonic-gate tab = back_tab = NOSTR;
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate #ifdef SIGTSTP
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate * Now map users susp char to ^Z, being careful that the susp
2087c478bd9Sstevel@tonic-gate * overrides any arrow key, but only for hackers (=new tty driver).
2097c478bd9Sstevel@tonic-gate */
2107c478bd9Sstevel@tonic-gate {
2117c478bd9Sstevel@tonic-gate static unsigned char sc[2];
212*f6db9f27Scf46844 int i;
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate if (!value(vi_NOVICE)) {
2157c478bd9Sstevel@tonic-gate sc[0] = tty.c_cc[VSUSP];
2167c478bd9Sstevel@tonic-gate sc[1] = 0;
2177c478bd9Sstevel@tonic-gate if (sc[0] == CTRL('z')) {
2187c478bd9Sstevel@tonic-gate for (i=0; i<=4; i++)
2197c478bd9Sstevel@tonic-gate if (arrows[i].cap && arrows[i].cap[0] == CTRL('z'))
2207c478bd9Sstevel@tonic-gate addmac(sc, NULL, NULL, arrows);
2217c478bd9Sstevel@tonic-gate } else if(sc[0])
2227c478bd9Sstevel@tonic-gate addmac(sc, "\32", "susp", arrows);
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate #endif
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate value(vi_WINDOW) = options[vi_WINDOW].odefault = l - 1;
2287c478bd9Sstevel@tonic-gate if (defwind)
2297c478bd9Sstevel@tonic-gate value(vi_WINDOW) = defwind;
2307c478bd9Sstevel@tonic-gate value(vi_SCROLL) = options[vi_SCROLL].odefault =
2317c478bd9Sstevel@tonic-gate hard_copy ? 11 : (value(vi_WINDOW) / 2);
2327c478bd9Sstevel@tonic-gate if (columns <= 4)
2337c478bd9Sstevel@tonic-gate columns = 1000;
2347c478bd9Sstevel@tonic-gate chrptr=(unsigned char *)tparm(cursor_address, 2, 2);
2357c478bd9Sstevel@tonic-gate if (chrptr==(unsigned char *)0 || chrptr[0] == 'O') /* OOPS */
2367c478bd9Sstevel@tonic-gate cursor_address = 0;
2377c478bd9Sstevel@tonic-gate else
2387c478bd9Sstevel@tonic-gate costCM = cost(tparm(cursor_address, 10, 8));
2397c478bd9Sstevel@tonic-gate costSR = cost(scroll_reverse);
2407c478bd9Sstevel@tonic-gate costAL = cost(insert_line);
2417c478bd9Sstevel@tonic-gate costDP = cost(tparm(parm_down_cursor, 10));
2427c478bd9Sstevel@tonic-gate costLP = cost(tparm(parm_left_cursor, 10));
2437c478bd9Sstevel@tonic-gate costRP = cost(tparm(parm_right_cursor, 10));
2447c478bd9Sstevel@tonic-gate costCE = cost(clr_eol);
2457c478bd9Sstevel@tonic-gate costCD = cost(clr_eos);
2467c478bd9Sstevel@tonic-gate if (i <= 0)
2477c478bd9Sstevel@tonic-gate lines = 2;
2487c478bd9Sstevel@tonic-gate /* proper strings to change tty type */
2497c478bd9Sstevel@tonic-gate termreset();
2507c478bd9Sstevel@tonic-gate gettmode();
2517c478bd9Sstevel@tonic-gate value(vi_REDRAW) = insert_line && delete_line;
2527c478bd9Sstevel@tonic-gate value(vi_OPTIMIZE) = !cursor_address && !tab;
2537c478bd9Sstevel@tonic-gate if (ospeed == B1200 && !value(vi_REDRAW))
2547c478bd9Sstevel@tonic-gate value(vi_SLOWOPEN) = 1; /* see also gettmode above */
2557c478bd9Sstevel@tonic-gate if (unknown)
256*f6db9f27Scf46844 serror((unsigned char *)gettext("%s: Unknown terminal type"),
257*f6db9f27Scf46844 type);
2587c478bd9Sstevel@tonic-gate }
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate #ifndef sun
2617c478bd9Sstevel@tonic-gate /*
2627c478bd9Sstevel@tonic-gate * Map both map1 and map2 as below. map2 surrounded by esc and
2637c478bd9Sstevel@tonic-gate * the 'i', 'R', or 'a' mode. However, because we don't know
2647c478bd9Sstevel@tonic-gate * the mode here we put in the escape and when the map() routine
2657c478bd9Sstevel@tonic-gate * is called for immacs mapping the mode is appended to the
2667c478bd9Sstevel@tonic-gate * macro. Therefore when you leave insert mode, to perform a
2677c478bd9Sstevel@tonic-gate * function key, it will (once the cursor movement is done)
2687c478bd9Sstevel@tonic-gate * restore you to the proper mode.
2697c478bd9Sstevel@tonic-gate */
2707c478bd9Sstevel@tonic-gate kpboth(map1, map2, key, mapto, desc)
2717c478bd9Sstevel@tonic-gate struct maps *map1, *map2;
2727c478bd9Sstevel@tonic-gate unsigned char *key, *mapto, *desc;
2737c478bd9Sstevel@tonic-gate {
2747c478bd9Sstevel@tonic-gate unsigned char surmapto[30];
2757c478bd9Sstevel@tonic-gate unsigned char *p;
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate if (key == 0)
2787c478bd9Sstevel@tonic-gate return;
2797c478bd9Sstevel@tonic-gate kpadd(map1, key, mapto, desc);
2807c478bd9Sstevel@tonic-gate if (any(*key, "\b\n "))
2817c478bd9Sstevel@tonic-gate return;
2827c478bd9Sstevel@tonic-gate strcpy(surmapto, "\33");
2837c478bd9Sstevel@tonic-gate strcat(surmapto, mapto);
2847c478bd9Sstevel@tonic-gate p = freespace;
2857c478bd9Sstevel@tonic-gate strcpy(p, surmapto);
2867c478bd9Sstevel@tonic-gate freespace += strlen(surmapto) + 1;
2877c478bd9Sstevel@tonic-gate kpadd(map2, key, p, desc);
2887c478bd9Sstevel@tonic-gate }
289*f6db9f27Scf46844 #endif /* !sun */
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate /*
2927c478bd9Sstevel@tonic-gate * Define a macro. mapstr is the structure (mode) in which it applies.
2937c478bd9Sstevel@tonic-gate * key is the input sequence, mapto what it turns into, and desc is a
2947c478bd9Sstevel@tonic-gate * human-readable description of what's going on.
2957c478bd9Sstevel@tonic-gate */
296*f6db9f27Scf46844 void
kpadd(struct maps * mapstr,unsigned char * key,unsigned char * mapto,unsigned char * desc)297*f6db9f27Scf46844 kpadd(struct maps *mapstr, unsigned char *key, unsigned char *mapto,
298*f6db9f27Scf46844 unsigned char *desc)
2997c478bd9Sstevel@tonic-gate {
3007c478bd9Sstevel@tonic-gate int i;
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate for (i=0; i<MAXNOMACS; i++)
3037c478bd9Sstevel@tonic-gate if (mapstr[i].cap == 0)
3047c478bd9Sstevel@tonic-gate break;
3057c478bd9Sstevel@tonic-gate if (key == 0 || i >= MAXNOMACS)
3067c478bd9Sstevel@tonic-gate return;
3077c478bd9Sstevel@tonic-gate mapstr[i].cap = key;
3087c478bd9Sstevel@tonic-gate mapstr[i].mapto = mapto;
3097c478bd9Sstevel@tonic-gate mapstr[i].descr = desc;
3107c478bd9Sstevel@tonic-gate }
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate unsigned char *
fkey(i)3137c478bd9Sstevel@tonic-gate fkey(i)
3147c478bd9Sstevel@tonic-gate int i;
3157c478bd9Sstevel@tonic-gate {
3167c478bd9Sstevel@tonic-gate if (i < 0 || i > 9)
317*f6db9f27Scf46844 return ((unsigned char *)NOSTR);
3187c478bd9Sstevel@tonic-gate switch (i) {
319*f6db9f27Scf46844 case 0: return ((unsigned char *)key_f0);
320*f6db9f27Scf46844 case 1: return ((unsigned char *)key_f1);
321*f6db9f27Scf46844 case 2: return ((unsigned char *)key_f2);
322*f6db9f27Scf46844 case 3: return ((unsigned char *)key_f3);
323*f6db9f27Scf46844 case 4: return ((unsigned char *)key_f4);
324*f6db9f27Scf46844 case 5: return ((unsigned char *)key_f5);
325*f6db9f27Scf46844 case 6: return ((unsigned char *)key_f6);
326*f6db9f27Scf46844 case 7: return ((unsigned char *)key_f7);
327*f6db9f27Scf46844 case 8: return ((unsigned char *)key_f8);
328*f6db9f27Scf46844 case 9: return ((unsigned char *)key_f9);
329*f6db9f27Scf46844 case 10: return ((unsigned char *)key_f0);
3307c478bd9Sstevel@tonic-gate }
331*f6db9f27Scf46844 return ((unsigned char *)NOSTR);
3327c478bd9Sstevel@tonic-gate }
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate /*
3357c478bd9Sstevel@tonic-gate * cost figures out how much (in characters) it costs to send the string
3367c478bd9Sstevel@tonic-gate * str to the terminal. It takes into account padding information, as
3377c478bd9Sstevel@tonic-gate * much as it can, for a typical case. (Right now the typical case assumes
3387c478bd9Sstevel@tonic-gate * the number of lines affected is the size of the screen, since this is
3397c478bd9Sstevel@tonic-gate * mainly used to decide if insert_line or scroll_reverse is better, and this always happens
3407c478bd9Sstevel@tonic-gate * at the top of the screen. We assume cursor motion (cursor_address) has little
3417c478bd9Sstevel@tonic-gate * padding, if any, required, so that case, which is really more important
3427c478bd9Sstevel@tonic-gate * than insert_line vs scroll_reverse, won't be really affected.)
3437c478bd9Sstevel@tonic-gate */
3447c478bd9Sstevel@tonic-gate
3457c478bd9Sstevel@tonic-gate static int costnum;
3467c478bd9Sstevel@tonic-gate
3477c478bd9Sstevel@tonic-gate /* ARGSUSED */
3487c478bd9Sstevel@tonic-gate int
countnum(char ch)3497c478bd9Sstevel@tonic-gate countnum(char ch)
3507c478bd9Sstevel@tonic-gate {
3517c478bd9Sstevel@tonic-gate costnum++;
352*f6db9f27Scf46844 return (0);
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate
355*f6db9f27Scf46844 int
cost(unsigned char * str)356*f6db9f27Scf46844 cost(unsigned char *str)
3577c478bd9Sstevel@tonic-gate {
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate if (str == NULL || *str=='O') /* OOPS */
3607c478bd9Sstevel@tonic-gate return 10000; /* infinity */
3617c478bd9Sstevel@tonic-gate costnum = 0;
3627c478bd9Sstevel@tonic-gate tputs((char *)str, lines, countnum);
3637c478bd9Sstevel@tonic-gate return costnum;
3647c478bd9Sstevel@tonic-gate }
365