#define COMPUTE_OVERHEAD 1
#define LONG_DIST (8 - COMPUTE_OVERHEAD)
#define NOT_LOCAL(fy, fx, ty, tx) ((tx > LONG_DIST) \
&& (tx < screen_columns - 1 - LONG_DIST) \
&& (abs(ty-fy) + abs(tx-fx) > LONG_DIST))
#include <curses.priv.h>
#include <term.h>
#include <ctype.h>
MODULE_ID("$Id: lib_mvcur.c,v 1.113 2008/08/16 19:30:58 tom Exp $")
#define WANT_CHAR(y, x) SP->_newscr->_line[y].text[x]
#define BAUDRATE cur_term->_baudrate
#if defined(MAIN) || defined(NCURSES_TEST)
#include <sys/time.h>
static bool profiling = FALSE;
static float diff;
#endif
#define OPT_SIZE 512
static int normalized_cost(const char *const cap, int affcnt);
#ifdef TRACE
static int
trace_cost_of(const char *capname, const char *cap, int affcnt)
{
int result = _nc_msec_cost(cap, affcnt);
TR(TRACE_CHARPUT | TRACE_MOVE,
("CostOf %s %d %s", capname, result, _nc_visbuf(cap)));
return result;
}
#define CostOf(cap,affcnt) trace_cost_of(#cap,cap,affcnt);
static int
trace_normalized_cost(const char *capname, const char *cap, int affcnt)
{
int result = normalized_cost(cap, affcnt);
TR(TRACE_CHARPUT | TRACE_MOVE,
("NormalizedCost %s %d %s", capname, result, _nc_visbuf(cap)));
return result;
}
#define NormalizedCost(cap,affcnt) trace_normalized_cost(#cap,cap,affcnt);
#else
#define CostOf(cap,affcnt) _nc_msec_cost(cap,affcnt);
#define NormalizedCost(cap,affcnt) normalized_cost(cap,affcnt);
#endif
NCURSES_EXPORT(int)
_nc_msec_cost(const char *const cap, int affcnt)
{
if (cap == 0)
return (INFINITY);
else {
const char *cp;
float cum_cost = 0.0;
for (cp = cap; *cp; cp++) {
if (cp[0] == '$' && cp[1] == '<' && strchr(cp, '>')) {
float number = 0.0;
for (cp += 2; *cp != '>'; cp++) {
if (isdigit(UChar(*cp)))
number = number * 10 + (*cp - '0');
else if (*cp == '*')
number *= affcnt;
else if (*cp == '.' && (*++cp != '>') && isdigit(UChar(*cp)))
number += (*cp - '0') / 10.0;
}
#if NCURSES_NO_PADDING
if (!GetNoPadding(SP))
#endif
cum_cost += number * 10;
} else
cum_cost += SP->_char_padding;
}
return ((int) cum_cost);
}
}
static int
normalized_cost(const char *const cap, int affcnt)
{
int cost = _nc_msec_cost(cap, affcnt);
if (cost != INFINITY)
cost = (cost + SP->_char_padding - 1) / SP->_char_padding;
return cost;
}
static void
reset_scroll_region(void)
{
if (change_scroll_region) {
TPUTS_TRACE("change_scroll_region");
putp(TPARM_2(change_scroll_region, 0, screen_lines - 1));
}
}
NCURSES_EXPORT(void)
_nc_mvcur_resume(void)
{
if (enter_ca_mode) {
TPUTS_TRACE("enter_ca_mode");
putp(enter_ca_mode);
}
reset_scroll_region();
SP->_cursrow = SP->_curscol = -1;
if (SP->_cursor != -1) {
int cursor = SP->_cursor;
SP->_cursor = -1;
curs_set(cursor);
}
}
NCURSES_EXPORT(void)
_nc_mvcur_init(void)
{
if (isatty(fileno(SP->_ofp)))
SP->_char_padding = ((BAUDBYTE * 1000 * 10)
/ (BAUDRATE > 0 ? BAUDRATE : 9600));
else
SP->_char_padding = 1;
if (SP->_char_padding <= 0)
SP->_char_padding = 1;
TR(TRACE_CHARPUT | TRACE_MOVE, ("char_padding %d msecs", SP->_char_padding));
SP->_cr_cost = CostOf(carriage_return, 0);
SP->_home_cost = CostOf(cursor_home, 0);
SP->_ll_cost = CostOf(cursor_to_ll, 0);
#if USE_HARD_TABS
if (getenv("NCURSES_NO_HARD_TABS") == 0) {
SP->_ht_cost = CostOf(tab, 0);
SP->_cbt_cost = CostOf(back_tab, 0);
} else {
SP->_ht_cost = INFINITY;
SP->_cbt_cost = INFINITY;
}
#endif
SP->_cub1_cost = CostOf(cursor_left, 0);
SP->_cuf1_cost = CostOf(cursor_right, 0);
SP->_cud1_cost = CostOf(cursor_down, 0);
SP->_cuu1_cost = CostOf(cursor_up, 0);
SP->_smir_cost = CostOf(enter_insert_mode, 0);
SP->_rmir_cost = CostOf(exit_insert_mode, 0);
SP->_ip_cost = 0;
if (insert_padding) {
SP->_ip_cost = CostOf(insert_padding, 0);
}
SP->_address_cursor = cursor_address ? cursor_address : cursor_mem_address;
SP->_cup_cost = CostOf(TPARM_2(SP->_address_cursor, 23, 23), 1);
SP->_cub_cost = CostOf(TPARM_1(parm_left_cursor, 23), 1);
SP->_cuf_cost = CostOf(TPARM_1(parm_right_cursor, 23), 1);
SP->_cud_cost = CostOf(TPARM_1(parm_down_cursor, 23), 1);
SP->_cuu_cost = CostOf(TPARM_1(parm_up_cursor, 23), 1);
SP->_hpa_cost = CostOf(TPARM_1(column_address, 23), 1);
SP->_vpa_cost = CostOf(TPARM_1(row_address, 23), 1);
SP->_ed_cost = NormalizedCost(clr_eos, 1);
SP->_el_cost = NormalizedCost(clr_eol, 1);
SP->_el1_cost = NormalizedCost(clr_bol, 1);
SP->_dch1_cost = NormalizedCost(delete_character, 1);
SP->_ich1_cost = NormalizedCost(insert_character, 1);
if (back_color_erase)
SP->_el_cost = 0;
SP->_dch_cost = NormalizedCost(TPARM_1(parm_dch, 23), 1);
SP->_ich_cost = NormalizedCost(TPARM_1(parm_ich, 23), 1);
SP->_ech_cost = NormalizedCost(TPARM_1(erase_chars, 23), 1);
SP->_rep_cost = NormalizedCost(TPARM_2(repeat_char, ' ', 23), 1);
SP->_cup_ch_cost = NormalizedCost(TPARM_2(SP->_address_cursor, 23, 23), 1);
SP->_hpa_ch_cost = NormalizedCost(TPARM_1(column_address, 23), 1);
SP->_cuf_ch_cost = NormalizedCost(TPARM_1(parm_right_cursor, 23), 1);
SP->_inline_cost = min(SP->_cup_ch_cost,
min(SP->_hpa_ch_cost,
SP->_cuf_ch_cost));
if (save_cursor != 0
&& enter_ca_mode != 0
&& strstr(enter_ca_mode, save_cursor) != 0) {
T(("...suppressed sc/rc capability due to conflict with smcup/rmcup"));
save_cursor = 0;
restore_cursor = 0;
}
_nc_mvcur_resume();
}
NCURSES_EXPORT(void)
_nc_mvcur_wrap(void)
{
mvcur(-1, -1, screen_lines - 1, 0);
if (SP->_cursor != -1) {
int cursor = SP->_cursor;
curs_set(1);
SP->_cursor = cursor;
}
if (exit_ca_mode) {
TPUTS_TRACE("exit_ca_mode");
putp(exit_ca_mode);
}
_nc_outch('\r');
}
static NCURSES_INLINE int
repeated_append(string_desc * target, int total, int num, int repeat, const char *src)
{
size_t need = repeat * strlen(src);
if (need < target->s_size) {
while (repeat-- > 0) {
if (_nc_safe_strcat(target, src)) {
total += num;
} else {
total = INFINITY;
break;
}
}
} else {
total = INFINITY;
}
return total;
}
#ifndef NO_OPTIMIZE
#define NEXTTAB(fr) (fr + init_tabs - (fr % init_tabs))
#define LASTTAB(fr) ((fr > 0) ? ((fr - 1) / init_tabs) * init_tabs : -1)
static int
relative_move(string_desc * target, int from_y, int from_x, int to_y, int
to_x, bool ovw)
{
string_desc save;
int n, vcost = 0, hcost = 0;
(void) _nc_str_copy(&save, target);
if (to_y != from_y) {
vcost = INFINITY;
if (row_address != 0
&& _nc_safe_strcat(target, TPARM_1(row_address, to_y))) {
vcost = SP->_vpa_cost;
}
if (to_y > from_y) {
n = (to_y - from_y);
if (parm_down_cursor
&& SP->_cud_cost < vcost
&& _nc_safe_strcat(_nc_str_copy(target, &save),
TPARM_1(parm_down_cursor, n))) {
vcost = SP->_cud_cost;
}
if (cursor_down
&& (*cursor_down != '\n' || SP->_nl)
&& (n * SP->_cud1_cost < vcost)) {
vcost = repeated_append(_nc_str_copy(target, &save), 0,
SP->_cud1_cost, n, cursor_down);
}
} else {
n = (from_y - to_y);
if (parm_up_cursor
&& SP->_cuu_cost < vcost
&& _nc_safe_strcat(_nc_str_copy(target, &save),
TPARM_1(parm_up_cursor, n))) {
vcost = SP->_cuu_cost;
}
if (cursor_up && (n * SP->_cuu1_cost < vcost)) {
vcost = repeated_append(_nc_str_copy(target, &save), 0,
SP->_cuu1_cost, n, cursor_up);
}
}
if (vcost == INFINITY)
return (INFINITY);
}
save = *target;
if (to_x != from_x) {
char str[OPT_SIZE];
string_desc check;
hcost = INFINITY;
if (column_address
&& _nc_safe_strcat(_nc_str_copy(target, &save),
TPARM_1(column_address, to_x))) {
hcost = SP->_hpa_cost;
}
if (to_x > from_x) {
n = to_x - from_x;
if (parm_right_cursor
&& SP->_cuf_cost < hcost
&& _nc_safe_strcat(_nc_str_copy(target, &save),
TPARM_1(parm_right_cursor, n))) {
hcost = SP->_cuf_cost;
}
if (cursor_right) {
int lhcost = 0;
(void) _nc_str_init(&check, str, sizeof(str));
#if USE_HARD_TABS
if (init_tabs > 0 && tab) {
int nxt, fr;
for (fr = from_x; (nxt = NEXTTAB(fr)) <= to_x; fr = nxt) {
lhcost = repeated_append(&check, lhcost,
SP->_ht_cost, 1, tab);
if (lhcost == INFINITY)
break;
}
n = to_x - fr;
from_x = fr;
}
#endif
if (n <= 0 || n >= (int) check.s_size)
ovw = FALSE;
#if BSD_TPUTS
if (ovw
&& n > 0
&& n < (int) check.s_size
&& vcost == 0
&& str[0] == '\0') {
int wanted = CharOf(WANT_CHAR(to_y, from_x));
if (is8bits(wanted) && isdigit(wanted))
ovw = FALSE;
}
#endif
if (ovw) {
int i;
for (i = 0; i < n; i++) {
NCURSES_CH_T ch = WANT_CHAR(to_y, from_x + i);
if (!SameAttrOf(ch, SCREEN_ATTRS(SP))
#if USE_WIDEC_SUPPORT
|| !Charable(ch)
#endif
) {
ovw = FALSE;
break;
}
}
}
if (ovw) {
int i;
for (i = 0; i < n; i++)
*check.s_tail++ = (char) CharOf(WANT_CHAR(to_y,
from_x + i));
*check.s_tail = '\0';
check.s_size -= n;
lhcost += n * SP->_char_padding;
} else {
lhcost = repeated_append(&check, lhcost, SP->_cuf1_cost,
n, cursor_right);
}
if (lhcost < hcost
&& _nc_safe_strcat(_nc_str_copy(target, &save), str)) {
hcost = lhcost;
}
}
} else {
n = from_x - to_x;
if (parm_left_cursor
&& SP->_cub_cost < hcost
&& _nc_safe_strcat(_nc_str_copy(target, &save),
TPARM_1(parm_left_cursor, n))) {
hcost = SP->_cub_cost;
}
if (cursor_left) {
int lhcost = 0;
(void) _nc_str_init(&check, str, sizeof(str));
#if USE_HARD_TABS
if (init_tabs > 0 && back_tab) {
int nxt, fr;
for (fr = from_x; (nxt = LASTTAB(fr)) >= to_x; fr = nxt) {
lhcost = repeated_append(&check, lhcost,
SP->_cbt_cost, 1, back_tab);
if (lhcost == INFINITY)
break;
}
n = fr - to_x;
}
#endif
lhcost = repeated_append(&check, lhcost, SP->_cub1_cost, n, cursor_left);
if (lhcost < hcost
&& _nc_safe_strcat(_nc_str_copy(target, &save), str)) {
hcost = lhcost;
}
}
}
if (hcost == INFINITY)
return (INFINITY);
}
return (vcost + hcost);
}
#endif
static NCURSES_INLINE int
onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
{
string_desc result;
char buffer[OPT_SIZE];
int tactic = 0, newcost, usecost = INFINITY;
int t5_cr_cost;
#if defined(MAIN) || defined(NCURSES_TEST)
struct timeval before, after;
gettimeofday(&before, NULL);
#endif
#define NullResult _nc_str_null(&result, sizeof(buffer))
#define InitResult _nc_str_init(&result, buffer, sizeof(buffer))
if (_nc_safe_strcpy(InitResult, TPARM_2(SP->_address_cursor, ynew, xnew))) {
tactic = 0;
usecost = SP->_cup_cost;
#if defined(TRACE) || defined(NCURSES_TEST)
if (!(_nc_optimize_enable & OPTIMIZE_MVCUR))
goto nonlocal;
#endif
if (yold == -1 || xold == -1 || NOT_LOCAL(yold, xold, ynew, xnew)) {
#if defined(MAIN) || defined(NCURSES_TEST)
if (!profiling) {
(void) fputs("nonlocal\n", stderr);
goto nonlocal;
}
#else
goto nonlocal;
#endif
}
}
#ifndef NO_OPTIMIZE
if (yold != -1 && xold != -1
&& ((newcost = relative_move(NullResult, yold, xold, ynew, xnew,
ovw)) != INFINITY)
&& newcost < usecost) {
tactic = 1;
usecost = newcost;
}
if (yold != -1 && carriage_return
&& ((newcost = relative_move(NullResult, yold, 0, ynew, xnew, ovw))
!= INFINITY)
&& SP->_cr_cost + newcost < usecost) {
tactic = 2;
usecost = SP->_cr_cost + newcost;
}
if (cursor_home
&& ((newcost = relative_move(NullResult, 0, 0, ynew, xnew, ovw)) != INFINITY)
&& SP->_home_cost + newcost < usecost) {
tactic = 3;
usecost = SP->_home_cost + newcost;
}
if (cursor_to_ll
&& ((newcost = relative_move(NullResult, screen_lines - 1, 0, ynew,
xnew, ovw)) != INFINITY)
&& SP->_ll_cost + newcost < usecost) {
tactic = 4;
usecost = SP->_ll_cost + newcost;
}
t5_cr_cost = (xold > 0 ? SP->_cr_cost : 0);
if (auto_left_margin && !eat_newline_glitch
&& yold > 0 && cursor_left
&& ((newcost = relative_move(NullResult, yold - 1, screen_columns -
1, ynew, xnew, ovw)) != INFINITY)
&& t5_cr_cost + SP->_cub1_cost + newcost < usecost) {
tactic = 5;
usecost = t5_cr_cost + SP->_cub1_cost + newcost;
}
if (tactic)
InitResult;
switch (tactic) {
case 1:
(void) relative_move(&result, yold, xold, ynew, xnew, ovw);
break;
case 2:
(void) _nc_safe_strcpy(&result, carriage_return);
(void) relative_move(&result, yold, 0, ynew, xnew, ovw);
break;
case 3:
(void) _nc_safe_strcpy(&result, cursor_home);
(void) relative_move(&result, 0, 0, ynew, xnew, ovw);
break;
case 4:
(void) _nc_safe_strcpy(&result, cursor_to_ll);
(void) relative_move(&result, screen_lines - 1, 0, ynew, xnew, ovw);
break;
case 5:
if (xold > 0)
(void) _nc_safe_strcat(&result, carriage_return);
(void) _nc_safe_strcat(&result, cursor_left);
(void) relative_move(&result, yold - 1, screen_columns - 1, ynew,
xnew, ovw);
break;
}
#endif
nonlocal:
#if defined(MAIN) || defined(NCURSES_TEST)
gettimeofday(&after, NULL);
diff = after.tv_usec - before.tv_usec
+ (after.tv_sec - before.tv_sec) * 1000000;
if (!profiling)
(void) fprintf(stderr,
"onscreen: %d microsec, %f 28.8Kbps char-equivalents\n",
(int) diff, diff / 288);
#endif
if (usecost != INFINITY) {
TPUTS_TRACE("mvcur");
tputs(buffer, 1, _nc_outch);
SP->_cursrow = ynew;
SP->_curscol = xnew;
return (OK);
} else
return (ERR);
}
NCURSES_EXPORT(int)
mvcur(int yold, int xold, int ynew, int xnew)
{
NCURSES_CH_T oldattr;
int code;
TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%d,%d,%d,%d)"),
yold, xold, ynew, xnew));
if (SP == 0) {
code = ERR;
} else if (yold == ynew && xold == xnew) {
code = OK;
} else {
if (xnew >= screen_columns) {
ynew += xnew / screen_columns;
xnew %= screen_columns;
}
oldattr = SCREEN_ATTRS(SP);
if ((AttrOf(oldattr) & A_ALTCHARSET)
|| (AttrOf(oldattr) && !move_standout_mode)) {
TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move",
(unsigned long) AttrOf(oldattr),
_traceattr(AttrOf(oldattr))));
(void) VIDATTR(A_NORMAL, 0);
}
if (xold >= screen_columns) {
int l;
if (SP->_nl) {
l = (xold + 1) / screen_columns;
yold += l;
if (yold >= screen_lines)
l -= (yold - screen_lines - 1);
if (l > 0) {
if (carriage_return) {
TPUTS_TRACE("carriage_return");
putp(carriage_return);
} else
_nc_outch('\r');
xold = 0;
while (l > 0) {
if (newline) {
TPUTS_TRACE("newline");
putp(newline);
} else
_nc_outch('\n');
l--;
}
}
} else {
xold = -1;
yold = -1;
}
}
if (yold > screen_lines - 1)
yold = screen_lines - 1;
if (ynew > screen_lines - 1)
ynew = screen_lines - 1;
code = onscreen_mvcur(yold, xold, ynew, xnew, TRUE);
if (!SameAttrOf(oldattr, SCREEN_ATTRS(SP))) {
TR(TRACE_CHARPUT, ("turning on (%#lx) %s after move",
(unsigned long) AttrOf(oldattr),
_traceattr(AttrOf(oldattr))));
(void) VIDATTR(AttrOf(oldattr), GetPair(oldattr));
}
}
returnCode(code);
}
#if defined(TRACE) || defined(NCURSES_TEST)
NCURSES_EXPORT_VAR(int) _nc_optimize_enable = OPTIMIZE_ALL;
#endif
#if defined(MAIN) || defined(NCURSES_TEST)
#include <tic.h>
#include <dump_entry.h>
#include <time.h>
NCURSES_EXPORT_VAR(const char *) _nc_progname = "mvcur";
static unsigned long xmits;
NCURSES_EXPORT(int)
tputs(const char *string, int affcnt GCC_UNUSED, int (*outc) (int) GCC_UNUSED)
{
if (profiling)
xmits += strlen(string);
else
(void) fputs(_nc_visbuf(string), stdout);
return (OK);
}
NCURSES_EXPORT(int)
putp(const char *string)
{
return (tputs(string, 1, _nc_outch));
}
NCURSES_EXPORT(int)
_nc_outch(int ch)
{
putc(ch, stdout);
return OK;
}
NCURSES_EXPORT(int)
delay_output(int ms GCC_UNUSED)
{
return OK;
}
static char tname[PATH_MAX];
static void
load_term(void)
{
(void) setupterm(tname, STDOUT_FILENO, NULL);
}
static int
roll(int n)
{
int i, j;
i = (RAND_MAX / n) * n;
while ((j = rand()) >= i)
continue;
return (j % n);
}
int
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
{
strcpy(tname, getenv("TERM"));
load_term();
_nc_setupscreen(lines, columns, stdout, FALSE, 0);
baudrate();
_nc_mvcur_init();
NC_BUFFERED(FALSE);
(void) puts("The mvcur tester. Type ? for help");
fputs("smcup:", stdout);
putchar('\n');
for (;;) {
int fy, fx, ty, tx, n, i;
char buf[BUFSIZ], capname[BUFSIZ];
(void) fputs("> ", stdout);
(void) fgets(buf, sizeof(buf), stdin);
if (buf[0] == '?') {
(void) puts("? -- display this help message");
(void)
puts("fy fx ty tx -- (4 numbers) display (fy,fx)->(ty,tx) move");
(void) puts("s[croll] n t b m -- display scrolling sequence");
(void)
printf("r[eload] -- reload terminal info for %s\n",
termname());
(void)
puts("l[oad] <term> -- load terminal info for type <term>");
(void) puts("d[elete] <cap> -- delete named capability");
(void) puts("i[nspect] -- display terminal capabilities");
(void)
puts("c[ost] -- dump cursor-optimization cost table");
(void) puts("o[optimize] -- toggle movement optimization");
(void)
puts("t[orture] <num> -- torture-test with <num> random moves");
(void) puts("q[uit] -- quit the program");
} else if (sscanf(buf, "%d %d %d %d", &fy, &fx, &ty, &tx) == 4) {
struct timeval before, after;
putchar('"');
gettimeofday(&before, NULL);
mvcur(fy, fx, ty, tx);
gettimeofday(&after, NULL);
printf("\" (%ld msec)\n",
(long) (after.tv_usec - before.tv_usec
+ (after.tv_sec - before.tv_sec)
* 1000000));
} else if (sscanf(buf, "s %d %d %d %d", &fy, &fx, &ty, &tx) == 4) {
struct timeval before, after;
putchar('"');
gettimeofday(&before, NULL);
_nc_scrolln(fy, fx, ty, tx);
gettimeofday(&after, NULL);
printf("\" (%ld msec)\n",
(long) (after.tv_usec - before.tv_usec + (after.tv_sec -
before.tv_sec)
* 1000000));
} else if (buf[0] == 'r') {
(void) strcpy(tname, termname());
load_term();
} else if (sscanf(buf, "l %s", tname) == 1) {
load_term();
} else if (sscanf(buf, "d %s", capname) == 1) {
struct name_table_entry const *np = _nc_find_entry(capname,
_nc_get_hash_table(FALSE));
if (np == NULL)
(void) printf("No such capability as \"%s\"\n", capname);
else {
switch (np->nte_type) {
case BOOLEAN:
cur_term->type.Booleans[np->nte_index] = FALSE;
(void)
printf("Boolean capability `%s' (%d) turned off.\n",
np->nte_name, np->nte_index);
break;
case NUMBER:
cur_term->type.Numbers[np->nte_index] = ABSENT_NUMERIC;
(void) printf("Number capability `%s' (%d) set to -1.\n",
np->nte_name, np->nte_index);
break;
case STRING:
cur_term->type.Strings[np->nte_index] = ABSENT_STRING;
(void) printf("String capability `%s' (%d) deleted.\n",
np->nte_name, np->nte_index);
break;
}
}
} else if (buf[0] == 'i') {
dump_init((char *) NULL, F_TERMINFO, S_TERMINFO, 70, 0, FALSE);
dump_entry(&cur_term->type, FALSE, TRUE, 0, 0);
putchar('\n');
} else if (buf[0] == 'o') {
if (_nc_optimize_enable & OPTIMIZE_MVCUR) {
_nc_optimize_enable &= ~OPTIMIZE_MVCUR;
(void) puts("Optimization is now off.");
} else {
_nc_optimize_enable |= OPTIMIZE_MVCUR;
(void) puts("Optimization is now on.");
}
}
else if (sscanf(buf, "t %d", &n) == 1) {
float cumtime = 0.0, perchar;
int speeds[] =
{2400, 9600, 14400, 19200, 28800, 38400, 0};
srand((unsigned) (getpid() + time((time_t *) 0)));
profiling = TRUE;
xmits = 0;
for (i = 0; i < n; i++) {
#ifdef FIND_COREDUMP
int from_y = roll(lines);
int to_y = roll(lines);
int from_x = roll(columns);
int to_x = roll(columns);
printf("(%d,%d) -> (%d,%d)\n", from_y, from_x, to_y, to_x);
mvcur(from_y, from_x, to_y, to_x);
#else
mvcur(roll(lines), roll(columns), roll(lines), roll(columns));
#endif
if (diff)
cumtime += diff;
}
profiling = FALSE;
perchar = cumtime / n;
(void) printf("%d moves (%ld chars) in %d msec, %f msec each:\n",
n, xmits, (int) cumtime, perchar);
for (i = 0; speeds[i]; i++) {
float totalest = cumtime + xmits * 9 * 1e6 / speeds[i];
float overhead = speeds[i] * perchar / 1e6;
(void)
printf("%6d bps: %3.2f char-xmits overhead; total estimated time %15.2f\n",
speeds[i], overhead, totalest);
}
} else if (buf[0] == 'c') {
(void) printf("char padding: %d\n", SP->_char_padding);
(void) printf("cr cost: %d\n", SP->_cr_cost);
(void) printf("cup cost: %d\n", SP->_cup_cost);
(void) printf("home cost: %d\n", SP->_home_cost);
(void) printf("ll cost: %d\n", SP->_ll_cost);
#if USE_HARD_TABS
(void) printf("ht cost: %d\n", SP->_ht_cost);
(void) printf("cbt cost: %d\n", SP->_cbt_cost);
#endif
(void) printf("cub1 cost: %d\n", SP->_cub1_cost);
(void) printf("cuf1 cost: %d\n", SP->_cuf1_cost);
(void) printf("cud1 cost: %d\n", SP->_cud1_cost);
(void) printf("cuu1 cost: %d\n", SP->_cuu1_cost);
(void) printf("cub cost: %d\n", SP->_cub_cost);
(void) printf("cuf cost: %d\n", SP->_cuf_cost);
(void) printf("cud cost: %d\n", SP->_cud_cost);
(void) printf("cuu cost: %d\n", SP->_cuu_cost);
(void) printf("hpa cost: %d\n", SP->_hpa_cost);
(void) printf("vpa cost: %d\n", SP->_vpa_cost);
} else if (buf[0] == 'x' || buf[0] == 'q')
break;
else
(void) puts("Invalid command.");
}
(void) fputs("rmcup:", stdout);
_nc_mvcur_wrap();
putchar('\n');
return (0);
}
#endif