Back to index

tetex-bin  3.0
lib_mvcur.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc.              *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /****************************************************************************
00030  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
00031  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
00032  ****************************************************************************/
00033 
00034 /*
00035 **     lib_mvcur.c
00036 **
00037 **     The routines for moving the physical cursor and scrolling:
00038 **
00039 **            void _nc_mvcur_init(void)
00040 **
00041 **            void _nc_mvcur_resume(void)
00042 **
00043 **            int mvcur(int old_y, int old_x, int new_y, int new_x)
00044 **
00045 **            void _nc_mvcur_wrap(void)
00046 **
00047 ** Comparisons with older movement optimizers:
00048 **    SVr3 curses mvcur() can't use cursor_to_ll or auto_left_margin.
00049 **    4.4BSD curses can't use cuu/cud/cuf/cub/hpa/vpa/tab/cbt for local
00050 ** motions.  It doesn't use tactics based on auto_left_margin.  Weirdly
00051 ** enough, it doesn't use its own hardware-scrolling routine to scroll up
00052 ** destination lines for out-of-bounds addresses!
00053 **    old ncurses optimizer: less accurate cost computations (in fact,
00054 ** it was broken and had to be commented out!).
00055 **
00056 ** Compile with -DMAIN to build an interactive tester/timer for the movement
00057 ** optimizer.  You can use it to investigate the optimizer's behavior.
00058 ** You can also use it for tuning the formulas used to determine whether
00059 ** or not full optimization is attempted.
00060 **
00061 ** This code has a nasty tendency to find bugs in terminfo entries, because it
00062 ** exercises the non-cup movement capabilities heavily.  If you think you've
00063 ** found a bug, try deleting subsets of the following capabilities (arranged
00064 ** in decreasing order of suspiciousness): it, tab, cbt, hpa, vpa, cuu, cud,
00065 ** cuf, cub, cuu1, cud1, cuf1, cub1.  It may be that one or more are wrong.
00066 **
00067 ** Note: you should expect this code to look like a resource hog in a profile.
00068 ** That's because it does a lot of I/O, through the tputs() calls.  The I/O
00069 ** cost swamps the computation overhead (and as machines get faster, this
00070 ** will become even more true).  Comments in the test exerciser at the end
00071 ** go into detail about tuning and how you can gauge the optimizer's
00072 ** effectiveness.
00073 **/
00074 
00075 /****************************************************************************
00076  *
00077  * Constants and macros for optimizer tuning.
00078  *
00079  ****************************************************************************/
00080 
00081 /*
00082  * The average overhead of a full optimization computation in character
00083  * transmission times.  If it's too high, the algorithm will be a bit
00084  * over-biased toward using cup rather than local motions; if it's too
00085  * low, the algorithm may spend more time than is strictly optimal
00086  * looking for non-cup motions.  Profile the optimizer using the `t'
00087  * command of the exerciser (see below), and round to the nearest integer.
00088  *
00089  * Yes, I (esr) thought about computing expected overhead dynamically, say
00090  * by derivation from a running average of optimizer times.  But the
00091  * whole point of this optimization is to *decrease* the frequency of
00092  * system calls. :-)
00093  */
00094 #define COMPUTE_OVERHEAD    1      /* I use a 90MHz Pentium @ 9.6Kbps */
00095 
00096 /*
00097  * LONG_DIST is the distance we consider to be just as costly to move over as a
00098  * cup sequence is to emit.  In other words, it's the length of a cup sequence
00099  * adjusted for average computation overhead.  The magic number is the length
00100  * of "\033[yy;xxH", the typical cup sequence these days.
00101  */
00102 #define LONG_DIST           (8 - COMPUTE_OVERHEAD)
00103 
00104 /*
00105  * Tell whether a motion is optimizable by local motions.  Needs to be cheap to
00106  * compute. In general, all the fast moves go to either the right or left edge
00107  * of the screen.  So any motion to a location that is (a) further away than
00108  * LONG_DIST and (b) further inward from the right or left edge than LONG_DIST,
00109  * we'll consider nonlocal.
00110  */
00111 #define NOT_LOCAL(fy, fx, ty, tx)  ((tx > LONG_DIST) \
00112                && (tx < screen_columns - 1 - LONG_DIST) \
00113                && (abs(ty-fy) + abs(tx-fx) > LONG_DIST))
00114 
00115 /****************************************************************************
00116  *
00117  * External interfaces
00118  *
00119  ****************************************************************************/
00120 
00121 /*
00122  * For this code to work OK, the following components must live in the
00123  * screen structure:
00124  *
00125  *     int           _char_padding;       // cost of character put
00126  *     int           _cr_cost;     // cost of (carriage_return)
00127  *     int           _cup_cost;    // cost of (cursor_address)
00128  *     int           _home_cost;   // cost of (cursor_home)
00129  *     int           _ll_cost;     // cost of (cursor_to_ll)
00130  *#if USE_HARD_TABS
00131  *     int           _ht_cost;     // cost of (tab)
00132  *     int           _cbt_cost;    // cost of (back_tab)
00133  *#endif USE_HARD_TABS
00134  *     int           _cub1_cost;   // cost of (cursor_left)
00135  *     int           _cuf1_cost;   // cost of (cursor_right)
00136  *     int           _cud1_cost;   // cost of (cursor_down)
00137  *     int           _cuu1_cost;   // cost of (cursor_up)
00138  *     int           _cub_cost;    // cost of (parm_cursor_left)
00139  *     int           _cuf_cost;    // cost of (parm_cursor_right)
00140  *     int           _cud_cost;    // cost of (parm_cursor_down)
00141  *     int           _cuu_cost;    // cost of (parm_cursor_up)
00142  *     int           _hpa_cost;    // cost of (column_address)
00143  *     int           _vpa_cost;    // cost of (row_address)
00144  *     int           _ech_cost;    // cost of (erase_chars)
00145  *     int           _rep_cost;    // cost of (repeat_char)
00146  *
00147  * The USE_HARD_TABS switch controls whether it is reliable to use tab/backtabs
00148  * for local motions.  On many systems, it's not, due to uncertainties about
00149  * tab delays and whether or not tabs will be expanded in raw mode.  If you
00150  * have parm_right_cursor, tab motions don't win you a lot anyhow.
00151  */
00152 
00153 #include <curses.priv.h>
00154 #include <term.h>
00155 #include <ctype.h>
00156 
00157 MODULE_ID("$Id: lib_mvcur.c,v 1.98 2004/04/03 22:32:24 tom Exp $")
00158 
00159 #define WANT_CHAR(y, x)     SP->_newscr->_line[y].text[x]      /* desired state */
00160 #define BAUDRATE     cur_term->_baudrate  /* bits per second */
00161 
00162 #if defined(MAIN) || defined(NCURSES_TEST)
00163 #include <sys/time.h>
00164 
00165 static bool profiling = FALSE;
00166 static float diff;
00167 #endif /* MAIN */
00168 
00169 #define OPT_SIZE 512
00170 
00171 static int normalized_cost(const char *const cap, int affcnt);
00172 
00173 /****************************************************************************
00174  *
00175  * Initialization/wrapup (including cost pre-computation)
00176  *
00177  ****************************************************************************/
00178 
00179 #ifdef TRACE
00180 static int
00181 trace_cost_of(const char *capname, const char *cap, int affcnt)
00182 {
00183     int result = _nc_msec_cost(cap, affcnt);
00184     TR(TRACE_CHARPUT | TRACE_MOVE,
00185        ("CostOf %s %d %s", capname, result, _nc_visbuf(cap)));
00186     return result;
00187 }
00188 #define CostOf(cap,affcnt) trace_cost_of(#cap,cap,affcnt);
00189 
00190 static int
00191 trace_normalized_cost(const char *capname, const char *cap, int affcnt)
00192 {
00193     int result = normalized_cost(cap, affcnt);
00194     TR(TRACE_CHARPUT | TRACE_MOVE,
00195        ("NormalizedCost %s %d %s", capname, result, _nc_visbuf(cap)));
00196     return result;
00197 }
00198 #define NormalizedCost(cap,affcnt) trace_normalized_cost(#cap,cap,affcnt);
00199 
00200 #else
00201 
00202 #define CostOf(cap,affcnt) _nc_msec_cost(cap,affcnt);
00203 #define NormalizedCost(cap,affcnt) normalized_cost(cap,affcnt);
00204 
00205 #endif
00206 
00207 NCURSES_EXPORT(int)
00208 _nc_msec_cost(const char *const cap, int affcnt)
00209 /* compute the cost of a given operation */
00210 {
00211     if (cap == 0)
00212        return (INFINITY);
00213     else {
00214        const char *cp;
00215        float cum_cost = 0.0;
00216 
00217        for (cp = cap; *cp; cp++) {
00218            /* extract padding, either mandatory or required */
00219            if (cp[0] == '$' && cp[1] == '<' && strchr(cp, '>')) {
00220               float number = 0.0;
00221 
00222               for (cp += 2; *cp != '>'; cp++) {
00223                   if (isdigit(UChar(*cp)))
00224                      number = number * 10 + (*cp - '0');
00225                   else if (*cp == '*')
00226                      number *= affcnt;
00227                   else if (*cp == '.' && (*++cp != '>') && isdigit(UChar(*cp)))
00228                      number += (*cp - '0') / 10.0;
00229               }
00230 
00231 #if NCURSES_NO_PADDING
00232               if (!(SP->_no_padding))
00233 #endif
00234                   cum_cost += number * 10;
00235            } else
00236               cum_cost += SP->_char_padding;
00237        }
00238 
00239        return ((int) cum_cost);
00240     }
00241 }
00242 
00243 static int
00244 normalized_cost(const char *const cap, int affcnt)
00245 /* compute the effective character-count for an operation (round up) */
00246 {
00247     int cost = _nc_msec_cost(cap, affcnt);
00248     if (cost != INFINITY)
00249        cost = (cost + SP->_char_padding - 1) / SP->_char_padding;
00250     return cost;
00251 }
00252 
00253 static void
00254 reset_scroll_region(void)
00255 /* Set the scroll-region to a known state (the default) */
00256 {
00257     if (change_scroll_region) {
00258        TPUTS_TRACE("change_scroll_region");
00259        putp(tparm(change_scroll_region, 0, screen_lines - 1));
00260     }
00261 }
00262 
00263 NCURSES_EXPORT(void)
00264 _nc_mvcur_resume(void)
00265 /* what to do at initialization time and after each shellout */
00266 {
00267     /* initialize screen for cursor access */
00268     if (enter_ca_mode) {
00269        TPUTS_TRACE("enter_ca_mode");
00270        putp(enter_ca_mode);
00271     }
00272 
00273     /*
00274      * Doing this here rather than in _nc_mvcur_wrap() ensures that
00275      * ncurses programs will see a reset scroll region even if a
00276      * program that messed with it died ungracefully.
00277      *
00278      * This also undoes the effects of terminal init strings that assume
00279      * they know the screen size.  This is useful when you're running
00280      * a vt100 emulation through xterm.
00281      */
00282     reset_scroll_region();
00283     SP->_cursrow = SP->_curscol = -1;
00284 
00285     /* restore cursor shape */
00286     if (SP->_cursor != -1) {
00287        int cursor = SP->_cursor;
00288        SP->_cursor = -1;
00289        curs_set(cursor);
00290     }
00291 }
00292 
00293 NCURSES_EXPORT(void)
00294 _nc_mvcur_init(void)
00295 /* initialize the cost structure */
00296 {
00297     if (isatty(fileno(SP->_ofp)))
00298        SP->_char_padding = ((BAUDBYTE * 1000 * 10)
00299                           / (BAUDRATE > 0 ? BAUDRATE : 9600));
00300     else
00301        SP->_char_padding = 1;      /* must be nonzero */
00302     if (SP->_char_padding <= 0)
00303        SP->_char_padding = 1;      /* must be nonzero */
00304     TR(TRACE_CHARPUT | TRACE_MOVE, ("char_padding %d msecs", SP->_char_padding));
00305 
00306     /* non-parameterized local-motion strings */
00307     SP->_cr_cost = CostOf(carriage_return, 0);
00308     SP->_home_cost = CostOf(cursor_home, 0);
00309     SP->_ll_cost = CostOf(cursor_to_ll, 0);
00310 #if USE_HARD_TABS
00311     SP->_ht_cost = CostOf(tab, 0);
00312     SP->_cbt_cost = CostOf(back_tab, 0);
00313 #endif /* USE_HARD_TABS */
00314     SP->_cub1_cost = CostOf(cursor_left, 0);
00315     SP->_cuf1_cost = CostOf(cursor_right, 0);
00316     SP->_cud1_cost = CostOf(cursor_down, 0);
00317     SP->_cuu1_cost = CostOf(cursor_up, 0);
00318 
00319     SP->_smir_cost = CostOf(enter_insert_mode, 0);
00320     SP->_rmir_cost = CostOf(exit_insert_mode, 0);
00321     SP->_ip_cost = 0;
00322     if (insert_padding) {
00323        SP->_ip_cost = CostOf(insert_padding, 0);
00324     }
00325 
00326     /*
00327      * Assumption: if the terminal has memory_relative addressing, the
00328      * initialization strings or smcup will set single-page mode so we
00329      * can treat it like absolute screen addressing.  This seems to be true
00330      * for all cursor_mem_address terminal types in the terminfo database.
00331      */
00332     SP->_address_cursor = cursor_address ? cursor_address : cursor_mem_address;
00333 
00334     /*
00335      * Parametrized local-motion strings.  This static cost computation
00336      * depends on the following assumptions:
00337      *
00338      * (1) They never have * padding.  In the entire master terminfo database
00339      *     as of March 1995, only the obsolete Zenith Z-100 pc violates this.
00340      *     (Proportional padding is found mainly in insert, delete and scroll
00341      *     capabilities).
00342      *
00343      * (2) The average case of cup has two two-digit parameters.  Strictly,
00344      *     the average case for a 24 * 80 screen has ((10*10*(1 + 1)) +
00345      *     (14*10*(1 + 2)) + (10*70*(2 + 1)) + (14*70*4)) / (24*80) = 3.458
00346      *     digits of parameters.  On a 25x80 screen the average is 3.6197.
00347      *     On larger screens the value gets much closer to 4.
00348      *
00349      * (3) The average case of cub/cuf/hpa/ech/rep has 2 digits of parameters
00350      *     (strictly, (((10 * 1) + (70 * 2)) / 80) = 1.8750).
00351      *
00352      * (4) The average case of cud/cuu/vpa has 2 digits of parameters
00353      *     (strictly, (((10 * 1) + (14 * 2)) / 24) = 1.5833).
00354      *
00355      * All these averages depend on the assumption that all parameter values
00356      * are equally probable.
00357      */
00358     SP->_cup_cost = CostOf(tparm(SP->_address_cursor, 23, 23), 1);
00359     SP->_cub_cost = CostOf(tparm(parm_left_cursor, 23), 1);
00360     SP->_cuf_cost = CostOf(tparm(parm_right_cursor, 23), 1);
00361     SP->_cud_cost = CostOf(tparm(parm_down_cursor, 23), 1);
00362     SP->_cuu_cost = CostOf(tparm(parm_up_cursor, 23), 1);
00363     SP->_hpa_cost = CostOf(tparm(column_address, 23), 1);
00364     SP->_vpa_cost = CostOf(tparm(row_address, 23), 1);
00365 
00366     /* non-parameterized screen-update strings */
00367     SP->_ed_cost = NormalizedCost(clr_eos, 1);
00368     SP->_el_cost = NormalizedCost(clr_eol, 1);
00369     SP->_el1_cost = NormalizedCost(clr_bol, 1);
00370     SP->_dch1_cost = NormalizedCost(delete_character, 1);
00371     SP->_ich1_cost = NormalizedCost(insert_character, 1);
00372 
00373     /*
00374      * If this is a bce-terminal, we want to bias the choice so we use clr_eol
00375      * rather than spaces at the end of a line.
00376      */
00377     if (back_color_erase)
00378        SP->_el_cost = 0;
00379 
00380     /* parameterized screen-update strings */
00381     SP->_dch_cost = NormalizedCost(tparm(parm_dch, 23), 1);
00382     SP->_ich_cost = NormalizedCost(tparm(parm_ich, 23), 1);
00383     SP->_ech_cost = NormalizedCost(tparm(erase_chars, 23), 1);
00384     SP->_rep_cost = NormalizedCost(tparm(repeat_char, ' ', 23), 1);
00385 
00386     SP->_cup_ch_cost = NormalizedCost(tparm(SP->_address_cursor, 23, 23), 1);
00387     SP->_hpa_ch_cost = NormalizedCost(tparm(column_address, 23), 1);
00388     SP->_cuf_ch_cost = NormalizedCost(tparm(parm_right_cursor, 23), 1);
00389     SP->_inline_cost = min(SP->_cup_ch_cost,
00390                         min(SP->_hpa_ch_cost,
00391                             SP->_cuf_ch_cost));
00392 
00393     /*
00394      * If save_cursor is used within enter_ca_mode, we should not use it for
00395      * scrolling optimization, since the corresponding restore_cursor is not
00396      * nested on the various terminals (vt100, xterm, etc.) which use this
00397      * feature.
00398      */
00399     if (save_cursor != 0
00400        && enter_ca_mode != 0
00401        && strstr(enter_ca_mode, save_cursor) != 0) {
00402        T(("...suppressed sc/rc capability due to conflict with smcup/rmcup"));
00403        save_cursor = 0;
00404        restore_cursor = 0;
00405     }
00406 
00407     /*
00408      * A different, possibly better way to arrange this would be to set
00409      * SP->_endwin = TRUE at window initialization time and let this be
00410      * called by doupdate's return-from-shellout code.
00411      */
00412     _nc_mvcur_resume();
00413 }
00414 
00415 NCURSES_EXPORT(void)
00416 _nc_mvcur_wrap(void)
00417 /* wrap up cursor-addressing mode */
00418 {
00419     /* leave cursor at screen bottom */
00420     mvcur(-1, -1, screen_lines - 1, 0);
00421 
00422     /* set cursor to normal mode */
00423     if (SP->_cursor != -1)
00424        curs_set(1);
00425 
00426     if (exit_ca_mode) {
00427        TPUTS_TRACE("exit_ca_mode");
00428        putp(exit_ca_mode);
00429     }
00430     /*
00431      * Reset terminal's tab counter.  There's a long-time bug that
00432      * if you exit a "curses" program such as vi or more, tab
00433      * forward, and then backspace, the cursor doesn't go to the
00434      * right place.  The problem is that the kernel counts the
00435      * escape sequences that reset things as column positions.
00436      * Utter a \r to reset this invisibly.
00437      */
00438     _nc_outch('\r');
00439 }
00440 
00441 /****************************************************************************
00442  *
00443  * Optimized cursor movement
00444  *
00445  ****************************************************************************/
00446 
00447 /*
00448  * Perform repeated-append, returning cost
00449  */
00450 static inline int
00451 repeated_append(string_desc * target, int total, int num, int repeat, const char *src)
00452 {
00453     size_t need = repeat * strlen(src);
00454 
00455     if (need < target->s_size) {
00456        while (repeat-- > 0) {
00457            if (_nc_safe_strcat(target, src)) {
00458               total += num;
00459            } else {
00460               total = INFINITY;
00461               break;
00462            }
00463        }
00464     } else {
00465        total = INFINITY;
00466     }
00467     return total;
00468 }
00469 
00470 #ifndef NO_OPTIMIZE
00471 #define NEXTTAB(fr)  (fr + init_tabs - (fr % init_tabs))
00472 
00473 /*
00474  * Assume back_tab (CBT) does not wrap backwards at the left margin, return
00475  * a negative value at that point to simplify the loop.
00476  */
00477 #define LASTTAB(fr)  ((fr > 0) ? ((fr - 1) / init_tabs) * init_tabs : -1)
00478 
00479 static int
00480 relative_move(string_desc * target, int from_y, int from_x, int to_y, int
00481              to_x, bool ovw)
00482 /* move via local motions (cuu/cuu1/cud/cud1/cub1/cub/cuf1/cuf/vpa/hpa) */
00483 {
00484     string_desc save;
00485     int n, vcost = 0, hcost = 0;
00486 
00487     (void) _nc_str_copy(&save, target);
00488 
00489     if (to_y != from_y) {
00490        vcost = INFINITY;
00491 
00492        if (row_address != 0
00493            && _nc_safe_strcat(target, tparm(row_address, to_y))) {
00494            vcost = SP->_vpa_cost;
00495        }
00496 
00497        if (to_y > from_y) {
00498            n = (to_y - from_y);
00499 
00500            if (parm_down_cursor
00501               && SP->_cud_cost < vcost
00502               && _nc_safe_strcat(_nc_str_copy(target, &save),
00503                                tparm(parm_down_cursor, n))) {
00504               vcost = SP->_cud_cost;
00505            }
00506 
00507            if (cursor_down
00508               && (*cursor_down != '\n' || SP->_nl)
00509               && (n * SP->_cud1_cost < vcost)) {
00510               vcost = repeated_append(_nc_str_copy(target, &save), 0,
00511                                    SP->_cud1_cost, n, cursor_down);
00512            }
00513        } else {             /* (to_y < from_y) */
00514            n = (from_y - to_y);
00515 
00516            if (parm_up_cursor
00517               && SP->_cuu_cost < vcost
00518               && _nc_safe_strcat(_nc_str_copy(target, &save),
00519                                tparm(parm_up_cursor, n))) {
00520               vcost = SP->_cuu_cost;
00521            }
00522 
00523            if (cursor_up && (n * SP->_cuu1_cost < vcost)) {
00524               vcost = repeated_append(_nc_str_copy(target, &save), 0,
00525                                    SP->_cuu1_cost, n, cursor_up);
00526            }
00527        }
00528 
00529        if (vcost == INFINITY)
00530            return (INFINITY);
00531     }
00532 
00533     save = *target;
00534 
00535     if (to_x != from_x) {
00536        char str[OPT_SIZE];
00537        string_desc check;
00538 
00539        hcost = INFINITY;
00540 
00541        if (column_address
00542            && _nc_safe_strcat(_nc_str_copy(target, &save),
00543                             tparm(column_address, to_x))) {
00544            hcost = SP->_hpa_cost;
00545        }
00546 
00547        if (to_x > from_x) {
00548            n = to_x - from_x;
00549 
00550            if (parm_right_cursor
00551               && SP->_cuf_cost < hcost
00552               && _nc_safe_strcat(_nc_str_copy(target, &save),
00553                                tparm(parm_right_cursor, n))) {
00554               hcost = SP->_cuf_cost;
00555            }
00556 
00557            if (cursor_right) {
00558               int lhcost = 0;
00559 
00560               (void) _nc_str_init(&check, str, sizeof(str));
00561 
00562 #if USE_HARD_TABS
00563               /* use hard tabs, if we have them, to do as much as possible */
00564               if (init_tabs > 0 && tab) {
00565                   int nxt, fr;
00566 
00567                   for (fr = from_x; (nxt = NEXTTAB(fr)) <= to_x; fr = nxt) {
00568                      lhcost = repeated_append(&check, lhcost,
00569                                            SP->_ht_cost, 1, tab);
00570                      if (lhcost == INFINITY)
00571                          break;
00572                   }
00573 
00574                   n = to_x - fr;
00575                   from_x = fr;
00576               }
00577 #endif /* USE_HARD_TABS */
00578 
00579               if (n <= 0 || n >= (int) check.s_size)
00580                   ovw = FALSE;
00581 #if BSD_TPUTS
00582               /*
00583                * If we're allowing BSD-style padding in tputs, don't generate
00584                * a string with a leading digit.  Otherwise, that will be
00585                * interpreted as a padding value rather than sent to the
00586                * screen.
00587                */
00588               if (ovw
00589                   && n > 0
00590                   && n < (int) check.s_size
00591                   && vcost == 0
00592                   && str[0] == '\0') {
00593                   int wanted = CharOf(WANT_CHAR(to_y, from_x));
00594                   if (is8bits(wanted) && isdigit(wanted))
00595                      ovw = FALSE;
00596               }
00597 #endif
00598               /*
00599                * If we have no attribute changes, overwrite is cheaper.
00600                * Note: must suppress this by passing in ovw = FALSE whenever
00601                * WANT_CHAR would return invalid data.  In particular, this
00602                * is true between the time a hardware scroll has been done
00603                * and the time the structure WANT_CHAR would access has been
00604                * updated.
00605                */
00606               if (ovw) {
00607                   int i;
00608 
00609                   for (i = 0; i < n; i++) {
00610                      NCURSES_CH_T ch = WANT_CHAR(to_y, from_x + i);
00611                      if (AttrOf(ch) != SP->_current_attr
00612 #if USE_WIDEC_SUPPORT
00613                          || !Charable(ch)
00614 #endif
00615                          ) {
00616                          ovw = FALSE;
00617                          break;
00618                      }
00619                   }
00620               }
00621               if (ovw) {
00622                   int i;
00623 
00624                   for (i = 0; i < n; i++)
00625                      *check.s_tail++ = CharOf(WANT_CHAR(to_y, from_x + i));
00626                   *check.s_tail = '\0';
00627                   check.s_size -= n;
00628                   lhcost += n * SP->_char_padding;
00629               } else {
00630                   lhcost = repeated_append(&check, lhcost, SP->_cuf1_cost,
00631                                         n, cursor_right);
00632               }
00633 
00634               if (lhcost < hcost
00635                   && _nc_safe_strcat(_nc_str_copy(target, &save), str)) {
00636                   hcost = lhcost;
00637               }
00638            }
00639        } else {             /* (to_x < from_x) */
00640            n = from_x - to_x;
00641 
00642            if (parm_left_cursor
00643               && SP->_cub_cost < hcost
00644               && _nc_safe_strcat(_nc_str_copy(target, &save),
00645                                tparm(parm_left_cursor, n))) {
00646               hcost = SP->_cub_cost;
00647            }
00648 
00649            if (cursor_left) {
00650               int lhcost = 0;
00651 
00652               (void) _nc_str_init(&check, str, sizeof(str));
00653 
00654 #if USE_HARD_TABS
00655               if (init_tabs > 0 && back_tab) {
00656                   int nxt, fr;
00657 
00658                   for (fr = from_x; (nxt = LASTTAB(fr)) >= to_x; fr = nxt) {
00659                      lhcost = repeated_append(&check, lhcost,
00660                                            SP->_cbt_cost, 1, back_tab);
00661                      if (lhcost == INFINITY)
00662                          break;
00663                   }
00664 
00665                   n = fr - to_x;
00666               }
00667 #endif /* USE_HARD_TABS */
00668 
00669               lhcost = repeated_append(&check, lhcost, SP->_cub1_cost, n, cursor_left);
00670 
00671               if (lhcost < hcost
00672                   && _nc_safe_strcat(_nc_str_copy(target, &save), str)) {
00673                   hcost = lhcost;
00674               }
00675            }
00676        }
00677 
00678        if (hcost == INFINITY)
00679            return (INFINITY);
00680     }
00681 
00682     return (vcost + hcost);
00683 }
00684 #endif /* !NO_OPTIMIZE */
00685 
00686 /*
00687  * With the machinery set up above, it's conceivable that
00688  * onscreen_mvcur could be modified into a recursive function that does
00689  * an alpha-beta search of motion space, as though it were a chess
00690  * move tree, with the weight function being boolean and the search
00691  * depth equated to length of string.  However, this would jack up the
00692  * computation cost a lot, especially on terminals without a cup
00693  * capability constraining the search tree depth.  So we settle for
00694  * the simpler method below.
00695  */
00696 
00697 static inline int
00698 onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
00699 /* onscreen move from (yold, xold) to (ynew, xnew) */
00700 {
00701     string_desc result;
00702     char buffer[OPT_SIZE];
00703     int tactic = 0, newcost, usecost = INFINITY;
00704     int t5_cr_cost;
00705 
00706 #if defined(MAIN) || defined(NCURSES_TEST)
00707     struct timeval before, after;
00708 
00709     gettimeofday(&before, NULL);
00710 #endif /* MAIN */
00711 
00712 #define NullResult _nc_str_null(&result, sizeof(buffer))
00713 #define InitResult _nc_str_init(&result, buffer, sizeof(buffer))
00714 
00715     /* tactic #0: use direct cursor addressing */
00716     if (_nc_safe_strcpy(InitResult, tparm(SP->_address_cursor, ynew, xnew))) {
00717        tactic = 0;
00718        usecost = SP->_cup_cost;
00719 
00720 #if defined(TRACE) || defined(NCURSES_TEST)
00721        if (!(_nc_optimize_enable & OPTIMIZE_MVCUR))
00722            goto nonlocal;
00723 #endif /* TRACE */
00724 
00725        /*
00726         * We may be able to tell in advance that the full optimization
00727         * will probably not be worth its overhead.  Also, don't try to
00728         * use local movement if the current attribute is anything but
00729         * A_NORMAL...there are just too many ways this can screw up
00730         * (like, say, local-movement \n getting mapped to some obscure
00731         * character because A_ALTCHARSET is on).
00732         */
00733        if (yold == -1 || xold == -1 || NOT_LOCAL(yold, xold, ynew, xnew)) {
00734 #if defined(MAIN) || defined(NCURSES_TEST)
00735            if (!profiling) {
00736               (void) fputs("nonlocal\n", stderr);
00737               goto nonlocal;       /* always run the optimizer if profiling */
00738            }
00739 #else
00740            goto nonlocal;
00741 #endif /* MAIN */
00742        }
00743     }
00744 #ifndef NO_OPTIMIZE
00745     /* tactic #1: use local movement */
00746     if (yold != -1 && xold != -1
00747        && ((newcost = relative_move(NullResult, yold, xold, ynew, xnew,
00748                                  ovw)) != INFINITY)
00749        && newcost < usecost) {
00750        tactic = 1;
00751        usecost = newcost;
00752     }
00753 
00754     /* tactic #2: use carriage-return + local movement */
00755     if (yold != -1 && carriage_return
00756        && ((newcost = relative_move(NullResult, yold, 0, ynew, xnew, ovw))
00757            != INFINITY)
00758        && SP->_cr_cost + newcost < usecost) {
00759        tactic = 2;
00760        usecost = SP->_cr_cost + newcost;
00761     }
00762 
00763     /* tactic #3: use home-cursor + local movement */
00764     if (cursor_home
00765        && ((newcost = relative_move(NullResult, 0, 0, ynew, xnew, ovw)) != INFINITY)
00766        && SP->_home_cost + newcost < usecost) {
00767        tactic = 3;
00768        usecost = SP->_home_cost + newcost;
00769     }
00770 
00771     /* tactic #4: use home-down + local movement */
00772     if (cursor_to_ll
00773        && ((newcost = relative_move(NullResult, screen_lines - 1, 0, ynew,
00774                                  xnew, ovw)) != INFINITY)
00775        && SP->_ll_cost + newcost < usecost) {
00776        tactic = 4;
00777        usecost = SP->_ll_cost + newcost;
00778     }
00779 
00780     /*
00781      * tactic #5: use left margin for wrap to right-hand side,
00782      * unless strange wrap behavior indicated by xenl might hose us.
00783      */
00784     t5_cr_cost = (xold > 0 ? SP->_cr_cost : 0);
00785     if (auto_left_margin && !eat_newline_glitch
00786        && yold > 0 && cursor_left
00787        && ((newcost = relative_move(NullResult, yold - 1, screen_columns -
00788                                  1, ynew, xnew, ovw)) != INFINITY)
00789        && t5_cr_cost + SP->_cub1_cost + newcost < usecost) {
00790        tactic = 5;
00791        usecost = t5_cr_cost + SP->_cub1_cost + newcost;
00792     }
00793 
00794     /*
00795      * These cases are ordered by estimated relative frequency.
00796      */
00797     if (tactic)
00798        InitResult;
00799     switch (tactic) {
00800     case 1:
00801        (void) relative_move(&result, yold, xold, ynew, xnew, ovw);
00802        break;
00803     case 2:
00804        (void) _nc_safe_strcpy(&result, carriage_return);
00805        (void) relative_move(&result, yold, 0, ynew, xnew, ovw);
00806        break;
00807     case 3:
00808        (void) _nc_safe_strcpy(&result, cursor_home);
00809        (void) relative_move(&result, 0, 0, ynew, xnew, ovw);
00810        break;
00811     case 4:
00812        (void) _nc_safe_strcpy(&result, cursor_to_ll);
00813        (void) relative_move(&result, screen_lines - 1, 0, ynew, xnew, ovw);
00814        break;
00815     case 5:
00816        if (xold > 0)
00817            (void) _nc_safe_strcat(&result, carriage_return);
00818        (void) _nc_safe_strcat(&result, cursor_left);
00819        (void) relative_move(&result, yold - 1, screen_columns - 1, ynew,
00820                           xnew, ovw);
00821        break;
00822     }
00823 #endif /* !NO_OPTIMIZE */
00824 
00825   nonlocal:
00826 #if defined(MAIN) || defined(NCURSES_TEST)
00827     gettimeofday(&after, NULL);
00828     diff = after.tv_usec - before.tv_usec
00829        + (after.tv_sec - before.tv_sec) * 1000000;
00830     if (!profiling)
00831        (void) fprintf(stderr,
00832                      "onscreen: %d microsec, %f 28.8Kbps char-equivalents\n",
00833                      (int) diff, diff / 288);
00834 #endif /* MAIN */
00835 
00836     if (usecost != INFINITY) {
00837        TPUTS_TRACE("mvcur");
00838        tputs(buffer, 1, _nc_outch);
00839        SP->_cursrow = ynew;
00840        SP->_curscol = xnew;
00841        return (OK);
00842     } else
00843        return (ERR);
00844 }
00845 
00846 NCURSES_EXPORT(int)
00847 mvcur(int yold, int xold, int ynew, int xnew)
00848 /* optimized cursor move from (yold, xold) to (ynew, xnew) */
00849 {
00850     attr_t oldattr;
00851     int code;
00852 
00853     TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%d,%d,%d,%d)"),
00854                               yold, xold, ynew, xnew));
00855 
00856     if (SP == 0) {
00857        code = ERR;
00858     } else if (yold == ynew && xold == xnew) {
00859        code = OK;
00860     } else {
00861 
00862        /*
00863         * Most work here is rounding for terminal boundaries getting the
00864         * column position implied by wraparound or the lack thereof and
00865         * rolling up the screen to get ynew on the screen.
00866         */
00867        if (xnew >= screen_columns) {
00868            ynew += xnew / screen_columns;
00869            xnew %= screen_columns;
00870        }
00871 
00872        /*
00873         * Force restore even if msgr is on when we're in an alternate
00874         * character set -- these have a strong tendency to screw up the CR &
00875         * LF used for local character motions!
00876         */
00877        oldattr = SP->_current_attr;
00878        if ((oldattr & A_ALTCHARSET)
00879            || (oldattr && !move_standout_mode)) {
00880            TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move",
00881                             oldattr, _traceattr(oldattr)));
00882            (void) vidattr(A_NORMAL);
00883        }
00884 
00885        if (xold >= screen_columns) {
00886            int l;
00887 
00888            if (SP->_nl) {
00889               l = (xold + 1) / screen_columns;
00890               yold += l;
00891               if (yold >= screen_lines)
00892                   l -= (yold - screen_lines - 1);
00893 
00894               if (l > 0) {
00895                   if (carriage_return) {
00896                      TPUTS_TRACE("carriage_return");
00897                      putp(carriage_return);
00898                   } else
00899                      _nc_outch('\r');
00900                   xold = 0;
00901 
00902                   while (l > 0) {
00903                      if (newline) {
00904                          TPUTS_TRACE("newline");
00905                          putp(newline);
00906                      } else
00907                          _nc_outch('\n');
00908                      l--;
00909                   }
00910               }
00911            } else {
00912               /*
00913                * If caller set nonl(), we cannot really use newlines to
00914                * position to the next row.
00915                */
00916               xold = -1;
00917               yold = -1;
00918            }
00919        }
00920 
00921        if (yold > screen_lines - 1)
00922            yold = screen_lines - 1;
00923        if (ynew > screen_lines - 1)
00924            ynew = screen_lines - 1;
00925 
00926        /* destination location is on screen now */
00927        code = onscreen_mvcur(yold, xold, ynew, xnew, TRUE);
00928 
00929        /*
00930         * Restore attributes if we disabled them before moving.
00931         */
00932        if (oldattr != SP->_current_attr) {
00933            TR(TRACE_CHARPUT, ("turning on (%#lx) %s after move",
00934                             oldattr, _traceattr(oldattr)));
00935            (void) vidattr(oldattr);
00936        }
00937     }
00938     returnCode(code);
00939 }
00940 
00941 #if defined(TRACE) || defined(NCURSES_TEST)
00942 NCURSES_EXPORT_VAR(int) _nc_optimize_enable = OPTIMIZE_ALL;
00943 #endif
00944 
00945 #if defined(MAIN) || defined(NCURSES_TEST)
00946 /****************************************************************************
00947  *
00948  * Movement optimizer test code
00949  *
00950  ****************************************************************************/
00951 
00952 #include <tic.h>
00953 #include <dump_entry.h>
00954 
00955 NCURSES_EXPORT_VAR(const char *) _nc_progname = "mvcur";
00956 
00957 static unsigned long xmits;
00958 
00959 /* these override lib_tputs.c */
00960 NCURSES_EXPORT(int)
00961 tputs(const char *string, int affcnt GCC_UNUSED, int (*outc) (int) GCC_UNUSED)
00962 /* stub tputs() that dumps sequences in a visible form */
00963 {
00964     if (profiling)
00965        xmits += strlen(string);
00966     else
00967        (void) fputs(_nc_visbuf(string), stdout);
00968     return (OK);
00969 }
00970 
00971 NCURSES_EXPORT(int)
00972 putp(const char *string)
00973 {
00974     return (tputs(string, 1, _nc_outch));
00975 }
00976 
00977 NCURSES_EXPORT(int)
00978 _nc_outch(int ch)
00979 {
00980     putc(ch, stdout);
00981     return OK;
00982 }
00983 
00984 NCURSES_EXPORT(int)
00985 delay_output(int ms GCC_UNUSED)
00986 {
00987     return OK;
00988 }
00989 
00990 static char tname[PATH_MAX];
00991 
00992 static void
00993 load_term(void)
00994 {
00995     (void) setupterm(tname, STDOUT_FILENO, NULL);
00996 }
00997 
00998 static int
00999 roll(int n)
01000 {
01001     int i, j;
01002 
01003     i = (RAND_MAX / n) * n;
01004     while ((j = rand()) >= i)
01005        continue;
01006     return (j % n);
01007 }
01008 
01009 int
01010 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
01011 {
01012     (void) strcpy(tname, termname());
01013     load_term();
01014     _nc_setupscreen(lines, columns, stdout);
01015     baudrate();
01016 
01017     _nc_mvcur_init();
01018     NC_BUFFERED(FALSE);
01019 
01020     (void) puts("The mvcur tester.  Type ? for help");
01021 
01022     fputs("smcup:", stdout);
01023     putchar('\n');
01024 
01025     for (;;) {
01026        int fy, fx, ty, tx, n, i;
01027        char buf[BUFSIZ], capname[BUFSIZ];
01028 
01029        (void) fputs("> ", stdout);
01030        (void) fgets(buf, sizeof(buf), stdin);
01031 
01032        if (buf[0] == '?') {
01033            (void) puts("?                -- display this help message");
01034            (void)
01035               puts("fy fx ty tx      -- (4 numbers) display (fy,fx)->(ty,tx) move");
01036            (void) puts("s[croll] n t b m -- display scrolling sequence");
01037            (void)
01038               printf("r[eload]         -- reload terminal info for %s\n",
01039                      termname());
01040            (void)
01041               puts("l[oad] <term>    -- load terminal info for type <term>");
01042            (void) puts("d[elete] <cap>   -- delete named capability");
01043            (void) puts("i[nspect]        -- display terminal capabilities");
01044            (void)
01045               puts("c[ost]           -- dump cursor-optimization cost table");
01046            (void) puts("o[optimize]      -- toggle movement optimization");
01047            (void)
01048               puts("t[orture] <num>  -- torture-test with <num> random moves");
01049            (void) puts("q[uit]           -- quit the program");
01050        } else if (sscanf(buf, "%d %d %d %d", &fy, &fx, &ty, &tx) == 4) {
01051            struct timeval before, after;
01052 
01053            putchar('"');
01054 
01055            gettimeofday(&before, NULL);
01056            mvcur(fy, fx, ty, tx);
01057            gettimeofday(&after, NULL);
01058 
01059            printf("\" (%ld msec)\n",
01060                  (long) (after.tv_usec - before.tv_usec
01061                         + (after.tv_sec - before.tv_sec)
01062                         * 1000000));
01063        } else if (sscanf(buf, "s %d %d %d %d", &fy, &fx, &ty, &tx) == 4) {
01064            struct timeval before, after;
01065 
01066            putchar('"');
01067 
01068            gettimeofday(&before, NULL);
01069            _nc_scrolln(fy, fx, ty, tx);
01070            gettimeofday(&after, NULL);
01071 
01072            printf("\" (%ld msec)\n",
01073                  (long) (after.tv_usec - before.tv_usec + (after.tv_sec -
01074                                                       before.tv_sec)
01075                         * 1000000));
01076        } else if (buf[0] == 'r') {
01077            (void) strcpy(tname, termname());
01078            load_term();
01079        } else if (sscanf(buf, "l %s", tname) == 1) {
01080            load_term();
01081        } else if (sscanf(buf, "d %s", capname) == 1) {
01082            struct name_table_entry const *np = _nc_find_entry(capname,
01083                                                         _nc_info_hash_table);
01084 
01085            if (np == NULL)
01086               (void) printf("No such capability as \"%s\"\n", capname);
01087            else {
01088               switch (np->nte_type) {
01089               case BOOLEAN:
01090                   cur_term->type.Booleans[np->nte_index] = FALSE;
01091                   (void)
01092                      printf("Boolean capability `%s' (%d) turned off.\n",
01093                             np->nte_name, np->nte_index);
01094                   break;
01095 
01096               case NUMBER:
01097                   cur_term->type.Numbers[np->nte_index] = ABSENT_NUMERIC;
01098                   (void) printf("Number capability `%s' (%d) set to -1.\n",
01099                               np->nte_name, np->nte_index);
01100                   break;
01101 
01102               case STRING:
01103                   cur_term->type.Strings[np->nte_index] = ABSENT_STRING;
01104                   (void) printf("String capability `%s' (%d) deleted.\n",
01105                               np->nte_name, np->nte_index);
01106                   break;
01107               }
01108            }
01109        } else if (buf[0] == 'i') {
01110            dump_init((char *) NULL, F_TERMINFO, S_TERMINFO, 70, 0, FALSE);
01111            dump_entry(&cur_term->type, FALSE, TRUE, 0, 0, 0);
01112            putchar('\n');
01113        } else if (buf[0] == 'o') {
01114            if (_nc_optimize_enable & OPTIMIZE_MVCUR) {
01115               _nc_optimize_enable &= ~OPTIMIZE_MVCUR;
01116               (void) puts("Optimization is now off.");
01117            } else {
01118               _nc_optimize_enable |= OPTIMIZE_MVCUR;
01119               (void) puts("Optimization is now on.");
01120            }
01121        }
01122        /*
01123         * You can use the `t' test to profile and tune the movement
01124         * optimizer.  Use iteration values in three digits or more.
01125         * At above 5000 iterations the profile timing averages are stable
01126         * to within a millisecond or three.
01127         *
01128         * The `overhead' field of the report will help you pick a
01129         * COMPUTE_OVERHEAD figure appropriate for your processor and
01130         * expected line speed.  The `total estimated time' is
01131         * computation time plus a character-transmission time
01132         * estimate computed from the number of transmits and the baud
01133         * rate.
01134         *
01135         * Use this together with the `o' command to get a read on the
01136         * optimizer's effectiveness.  Compare the total estimated times
01137         * for `t' runs of the same length in both optimized and un-optimized
01138         * modes.  As long as the optimized times are less, the optimizer
01139         * is winning.
01140         */
01141        else if (sscanf(buf, "t %d", &n) == 1) {
01142            float cumtime = 0.0, perchar;
01143            int speeds[] =
01144            {2400, 9600, 14400, 19200, 28800, 38400, 0};
01145 
01146            srand((unsigned) (getpid() + time((time_t *) 0)));
01147            profiling = TRUE;
01148            xmits = 0;
01149            for (i = 0; i < n; i++) {
01150               /*
01151                * This does a move test between two random locations,
01152                * Random moves probably short-change the optimizer,
01153                * which will work better on the short moves probably
01154                * typical of doupdate()'s usage pattern.  Still,
01155                * until we have better data...
01156                */
01157 #ifdef FIND_COREDUMP
01158               int from_y = roll(lines);
01159               int to_y = roll(lines);
01160               int from_x = roll(columns);
01161               int to_x = roll(columns);
01162 
01163               printf("(%d,%d) -> (%d,%d)\n", from_y, from_x, to_y, to_x);
01164               mvcur(from_y, from_x, to_y, to_x);
01165 #else
01166               mvcur(roll(lines), roll(columns), roll(lines), roll(columns));
01167 #endif /* FIND_COREDUMP */
01168               if (diff)
01169                   cumtime += diff;
01170            }
01171            profiling = FALSE;
01172 
01173            /*
01174             * Average milliseconds per character optimization time.
01175             * This is the key figure to watch when tuning the optimizer.
01176             */
01177            perchar = cumtime / n;
01178 
01179            (void) printf("%d moves (%ld chars) in %d msec, %f msec each:\n",
01180                        n, xmits, (int) cumtime, perchar);
01181 
01182            for (i = 0; speeds[i]; i++) {
01183               /*
01184                * Total estimated time for the moves, computation and
01185                * transmission both. Transmission time is an estimate
01186                * assuming 9 bits/char, 8 bits + 1 stop bit.
01187                */
01188               float totalest = cumtime + xmits * 9 * 1e6 / speeds[i];
01189 
01190               /*
01191                * Per-character optimization overhead in character transmits
01192                * at the current speed.  Round this to the nearest integer
01193                * to figure COMPUTE_OVERHEAD for the speed.
01194                */
01195               float overhead = speeds[i] * perchar / 1e6;
01196 
01197               (void)
01198                   printf("%6d bps: %3.2f char-xmits overhead; total estimated time %15.2f\n",
01199                         speeds[i], overhead, totalest);
01200            }
01201        } else if (buf[0] == 'c') {
01202            (void) printf("char padding: %d\n", SP->_char_padding);
01203            (void) printf("cr cost: %d\n", SP->_cr_cost);
01204            (void) printf("cup cost: %d\n", SP->_cup_cost);
01205            (void) printf("home cost: %d\n", SP->_home_cost);
01206            (void) printf("ll cost: %d\n", SP->_ll_cost);
01207 #if USE_HARD_TABS
01208            (void) printf("ht cost: %d\n", SP->_ht_cost);
01209            (void) printf("cbt cost: %d\n", SP->_cbt_cost);
01210 #endif /* USE_HARD_TABS */
01211            (void) printf("cub1 cost: %d\n", SP->_cub1_cost);
01212            (void) printf("cuf1 cost: %d\n", SP->_cuf1_cost);
01213            (void) printf("cud1 cost: %d\n", SP->_cud1_cost);
01214            (void) printf("cuu1 cost: %d\n", SP->_cuu1_cost);
01215            (void) printf("cub cost: %d\n", SP->_cub_cost);
01216            (void) printf("cuf cost: %d\n", SP->_cuf_cost);
01217            (void) printf("cud cost: %d\n", SP->_cud_cost);
01218            (void) printf("cuu cost: %d\n", SP->_cuu_cost);
01219            (void) printf("hpa cost: %d\n", SP->_hpa_cost);
01220            (void) printf("vpa cost: %d\n", SP->_vpa_cost);
01221        } else if (buf[0] == 'x' || buf[0] == 'q')
01222            break;
01223        else
01224            (void) puts("Invalid command.");
01225     }
01226 
01227     (void) fputs("rmcup:", stdout);
01228     _nc_mvcur_wrap();
01229     putchar('\n');
01230 
01231     return (0);
01232 }
01233 
01234 #endif /* MAIN */
01235 
01236 /* lib_mvcur.c ends here */