2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A/*
2N/A * University Copyright- Copyright (c) 1982, 1986, 1988
2N/A * The Regents of the University of California
2N/A * All Rights Reserved
2N/A *
2N/A * University Acknowledgment- Portions of this document are derived from
2N/A * software developed by the University of California, Berkeley, and its
2N/A * contributors.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <stdlib.h>
2N/A#include <sys/types.h>
2N/A#include "curses_inc.h"
2N/A
2N/A/*
2N/A * Figure out (roughly) how much each of these capabilities costs.
2N/A * In the parameterized cases, we just take a typical case and
2N/A * use that value. This is done only once at startup, since it
2N/A * would be too expensive for intensive use.
2N/A */
2N/A
2N/Astatic int _cost_fn(char *, int);
2N/A
2N/Astatic short offsets[] = {
2N/A 52, /* insert_character, */
2N/A 21, /* delete_character, */
2N/A 12, /* cursor_home, */
2N/A 18, /* cursor_to_ll, */
2N/A 14, /* cursor_left, */
2N/A 17, /* cursor_right, */
2N/A 11, /* cursor_down, */
2N/A 19, /* cursor_up, */
2N/A 2, /* carriage_return, */
2N/A 134, /* tab, */
2N/A 0, /* back_tab, */
2N/A 6, /* clr_eol, */
2N/A 269, /* clr_bol, */
2N/A#define FIRST_LOOP 13
2N/A 108, /* parm_ich, */
2N/A 105, /* parm_dch, */
2N/A 111, /* parm_left_cursor, */
2N/A 114, /* parm_up_cursor, */
2N/A 107, /* parm_down_cursor, */
2N/A 112, /* parm_right_cursor, */
2N/A#define SECOND_LOOP 19
2N/A };
2N/A
2N/Avoid
2N/A_init_costs(void)
2N/A{
2N/A short *costptr = &(SP->term_costs.icfixed);
2N/A char **str_array = (char **) cur_strs;
2N/A int i = 0;
2N/A char save_xflag = xon_xoff;
2N/A
2N/A xon_xoff = 0;
2N/A/*
2N/A * This next block of code is actually correct in that it takes into
2N/A * account many things that wrefresh has to keep figuring in the function
2N/A * _useidch. Wrefresh MUST be changed (in the words of Tony Hansen) !!!
2N/A *
2N/A * Wrefresh has been changed (in my words -Phong Vo) !!!!
2N/A */
2N/A *costptr++ = ((enter_insert_mode) && (exit_insert_mode)) ?
2N/A _cost_fn(enter_insert_mode, 0) + _cost_fn(exit_insert_mode, 0) : 0;
2N/A
2N/A *costptr++ = ((enter_delete_mode) && (exit_delete_mode)) ?
2N/A _cost_fn(enter_delete_mode, 0) + _cost_fn(exit_delete_mode, 0) : 0;
2N/A
2N/A while (i < FIRST_LOOP)
2N/A *costptr++ = _cost_fn(str_array[offsets[i++]], 1);
2N/A
2N/A while (i < SECOND_LOOP)
2N/A *costptr++ = _cost_fn(tparm_p1(str_array[offsets[i++]], 10), 1);
2N/A
2N/A *costptr++ = _cost_fn(tparm_p2(cursor_address, 8, 10), 1);
2N/A *costptr++ = _cost_fn(tparm_p1(row_address, 8), 1);
2N/A
2N/A xon_xoff = save_xflag;
2N/A#ifdef DEBUG
2N/A if (outf) {
2N/A fprintf(outf, "icfixed %d=%d+%d\n", _COST(icfixed),
2N/A _cost_fn(enter_insert_mode, 0),
2N/A _cost_fn(exit_insert_mode, 0));
2N/A fprintf(outf, "from ich1 %x '%s' %d\n", insert_character,
2N/A insert_character, _cost_fn(insert_character, 1));
2N/A fprintf(outf, "ip %x '%s' %d\n", insert_padding,
2N/A insert_padding, _cost_fn(insert_padding, 1));
2N/A fprintf(outf, "dcfixed %d\n", _COST(dcfixed));
2N/A }
2N/A#endif /* DEBUG */
2N/A/*FALLTHROUGH*/
2N/A}
2N/A
2N/Astatic int counter = 0;
2N/Aint
2N/A/* ARGSUSED */
2N/A_countchar(char dummy)
2N/A{
2N/A counter++;
2N/A return (0);
2N/A}
2N/A
2N/A/*
2N/A * Figure out the _COST in characters to print this string.
2N/A * Due to padding, we can't just use strlen, so instead we
2N/A * feed it through tputs and trap the results.
2N/A * Even if the terminal uses xon/xoff handshaking, count the
2N/A * pad chars here since they estimate the real time to do the
2N/A * operation, useful in calculating costs.
2N/A */
2N/A
2N/Astatic int
2N/A_cost_fn(char *str, int affcnt)
2N/A{
2N/A if (str == NULL)
2N/A return (LARGECOST);
2N/A counter = 0;
2N/A (void) tputs(str, affcnt, _countchar);
2N/A return (counter);
2N/A}