1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1988 AT&T */ 28 /* All Rights Reserved */ 29 30 /* 31 * University Copyright- Copyright (c) 1982, 1986, 1988 32 * The Regents of the University of California 33 * All Rights Reserved 34 * 35 * University Acknowledgment- Portions of this document are derived from 36 * software developed by the University of California, Berkeley, and its 37 * contributors. 38 */ 39 40 #pragma ident "%Z%%M% %I% %E% SMI" 41 42 /*LINTLIBRARY*/ 43 44 #include <stdlib.h> 45 #include <sys/types.h> 46 #include "curses_inc.h" 47 48 /* 49 * Figure out (roughly) how much each of these capabilities costs. 50 * In the parameterized cases, we just take a typical case and 51 * use that value. This is done only once at startup, since it 52 * would be too expensive for intensive use. 53 */ 54 55 static int _cost_fn(char *, int); 56 57 static short offsets[] = { 58 52, /* insert_character, */ 59 21, /* delete_character, */ 60 12, /* cursor_home, */ 61 18, /* cursor_to_ll, */ 62 14, /* cursor_left, */ 63 17, /* cursor_right, */ 64 11, /* cursor_down, */ 65 19, /* cursor_up, */ 66 2, /* carriage_return, */ 67 134, /* tab, */ 68 0, /* back_tab, */ 69 6, /* clr_eol, */ 70 269, /* clr_bol, */ 71 #define FIRST_LOOP 13 72 108, /* parm_ich, */ 73 105, /* parm_dch, */ 74 111, /* parm_left_cursor, */ 75 114, /* parm_up_cursor, */ 76 107, /* parm_down_cursor, */ 77 112, /* parm_right_cursor, */ 78 #define SECOND_LOOP 19 79 }; 80 81 void 82 _init_costs(void) 83 { 84 short *costptr = &(SP->term_costs.icfixed); 85 char **str_array = (char **) cur_strs; 86 int i = 0; 87 char save_xflag = xon_xoff; 88 89 xon_xoff = 0; 90 /* 91 * This next block of code is actually correct in that it takes into 92 * account many things that wrefresh has to keep figuring in the function 93 * _useidch. Wrefresh MUST be changed (in the words of Tony Hansen) !!! 94 * 95 * Wrefresh has been changed (in my words -Phong Vo) !!!! 96 */ 97 *costptr++ = ((enter_insert_mode) && (exit_insert_mode)) ? 98 _cost_fn(enter_insert_mode, 0) + _cost_fn(exit_insert_mode, 0) : 0; 99 100 *costptr++ = ((enter_delete_mode) && (exit_delete_mode)) ? 101 _cost_fn(enter_delete_mode, 0) + _cost_fn(exit_delete_mode, 0) : 0; 102 103 while (i < FIRST_LOOP) 104 *costptr++ = _cost_fn(str_array[offsets[i++]], 1); 105 106 while (i < SECOND_LOOP) 107 *costptr++ = _cost_fn(tparm_p1(str_array[offsets[i++]], 10), 1); 108 109 *costptr++ = _cost_fn(tparm_p2(cursor_address, 8, 10), 1); 110 *costptr++ = _cost_fn(tparm_p1(row_address, 8), 1); 111 112 xon_xoff = save_xflag; 113 #ifdef DEBUG 114 if (outf) { 115 fprintf(outf, "icfixed %d=%d+%d\n", _COST(icfixed), 116 _cost_fn(enter_insert_mode, 0), 117 _cost_fn(exit_insert_mode, 0)); 118 fprintf(outf, "from ich1 %x '%s' %d\n", insert_character, 119 insert_character, _cost_fn(insert_character, 1)); 120 fprintf(outf, "ip %x '%s' %d\n", insert_padding, 121 insert_padding, _cost_fn(insert_padding, 1)); 122 fprintf(outf, "dcfixed %d\n", _COST(dcfixed)); 123 } 124 #endif /* DEBUG */ 125 /*FALLTHROUGH*/ 126 } 127 128 static int counter = 0; 129 int 130 /* ARGSUSED */ 131 _countchar(char dummy) 132 { 133 counter++; 134 return (0); 135 } 136 137 /* 138 * Figure out the _COST in characters to print this string. 139 * Due to padding, we can't just use strlen, so instead we 140 * feed it through tputs and trap the results. 141 * Even if the terminal uses xon/xoff handshaking, count the 142 * pad chars here since they estimate the real time to do the 143 * operation, useful in calculating costs. 144 */ 145 146 static int 147 _cost_fn(char *str, int affcnt) 148 { 149 if (str == NULL) 150 return (LARGECOST); 151 counter = 0; 152 (void) tputs(str, affcnt, _countchar); 153 return (counter); 154 } 155