]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tty/lib_mvcur.c
ncurses 5.7 - patch 20090418
[ncurses.git] / ncurses / tty / lib_mvcur.c
index e80a40b5134c4959583366f160d68da67d72ebeb..3961f4571fa1d77c89211d8567b5a0fe08723bfd 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -30,6 +30,7 @@
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
  *     and: Thomas E. Dickey                        1996-on                 *
+ *     and: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
  * we'll consider nonlocal.
  */
 #define NOT_LOCAL(fy, fx, ty, tx)      ((tx > LONG_DIST) \
-                && (tx < screen_columns - 1 - LONG_DIST) \
+                && (tx < screen_columns(CURRENT_SCREEN) - 1 - LONG_DIST) \
                 && (abs(ty-fy) + abs(tx-fx) > LONG_DIST))
 
 /****************************************************************************
 #include <term.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: lib_mvcur.c,v 1.109 2007/05/05 21:47:03 tom Exp $")
+MODULE_ID("$Id: lib_mvcur.c,v 1.115 2009/04/18 19:03:05 tom Exp $")
 
 #define WANT_CHAR(y, x)        SP->_newscr->_line[y].text[x]   /* desired state */
 #define BAUDRATE       cur_term->_baudrate     /* bits per second */
@@ -230,7 +231,7 @@ _nc_msec_cost(const char *const cap, int affcnt)
                }
 
 #if NCURSES_NO_PADDING
-               if (!(SP->_no_padding))
+               if (!GetNoPadding(SP))
 #endif
                    cum_cost += number * 10;
            } else
@@ -257,7 +258,7 @@ reset_scroll_region(void)
 {
     if (change_scroll_region) {
        TPUTS_TRACE("change_scroll_region");
-       putp(TPARM_2(change_scroll_region, 0, screen_lines - 1));
+       putp(TPARM_2(change_scroll_region, 0, screen_lines(CURRENT_SCREEN) - 1));
     }
 }
 
@@ -423,11 +424,14 @@ _nc_mvcur_wrap(void)
 /* wrap up cursor-addressing mode */
 {
     /* leave cursor at screen bottom */
-    mvcur(-1, -1, screen_lines - 1, 0);
+    mvcur(-1, -1, screen_lines(CURRENT_SCREEN) - 1, 0);
 
     /* set cursor to normal mode */
-    if (SP->_cursor != -1)
+    if (SP->_cursor != -1) {
+       int cursor = SP->_cursor;
        curs_set(1);
+       SP->_cursor = cursor;
+    }
 
     if (exit_ca_mode) {
        TPUTS_TRACE("exit_ca_mode");
@@ -628,7 +632,8 @@ relative_move(string_desc * target, int from_y, int from_x, int to_y, int
                    int i;
 
                    for (i = 0; i < n; i++)
-                       *check.s_tail++ = CharOf(WANT_CHAR(to_y, from_x + 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;
@@ -776,7 +781,8 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
 
     /* tactic #4: use home-down + local movement */
     if (cursor_to_ll
-       && ((newcost = relative_move(NullResult, screen_lines - 1, 0, ynew,
+       && ((newcost = relative_move(NullResult,
+                                    screen_lines(CURRENT_SCREEN) - 1, 0, ynew,
                                     xnew, ovw)) != INFINITY)
        && SP->_ll_cost + newcost < usecost) {
        tactic = 4;
@@ -790,8 +796,12 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
     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)
+       && ((newcost = relative_move(NullResult,
+                                    yold - 1,
+                                    screen_columns(CURRENT_SCREEN) - 1,
+                                    ynew,
+                                    xnew,
+                                    ovw)) != INFINITY)
        && t5_cr_cost + SP->_cub1_cost + newcost < usecost) {
        tactic = 5;
        usecost = t5_cr_cost + SP->_cub1_cost + newcost;
@@ -816,14 +826,23 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
        break;
     case 4:
        (void) _nc_safe_strcpy(&result, cursor_to_ll);
-       (void) relative_move(&result, screen_lines - 1, 0, ynew, xnew, ovw);
+       (void) relative_move(&result,
+                            screen_lines(CURRENT_SCREEN) - 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);
+       (void) relative_move(&result,
+                            yold - 1,
+                            screen_columns(CURRENT_SCREEN) - 1,
+                            ynew,
+                            xnew,
+                            ovw);
        break;
     }
 #endif /* !NO_OPTIMIZE */
@@ -849,9 +868,10 @@ onscreen_mvcur(int yold, int xold, int ynew, int xnew, bool ovw)
        return (ERR);
 }
 
-NCURSES_EXPORT(int)
-mvcur(int yold, int xold, int ynew, int xnew)
 /* optimized cursor move from (yold, xold) to (ynew, xnew) */
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(mvcur) (NCURSES_SP_DCLx
+                       int yold, int xold, int ynew, int xnew)
 {
     NCURSES_CH_T oldattr;
     int code;
@@ -859,7 +879,7 @@ mvcur(int yold, int xold, int ynew, int xnew)
     TR(TRACE_CALLS | TRACE_MOVE, (T_CALLED("mvcur(%d,%d,%d,%d)"),
                                  yold, xold, ynew, xnew));
 
-    if (SP == 0) {
+    if (SP_PARM == 0) {
        code = ERR;
     } else if (yold == ynew && xold == xnew) {
        code = OK;
@@ -870,9 +890,9 @@ mvcur(int yold, int xold, int ynew, int xnew)
         * column position implied by wraparound or the lack thereof and
         * rolling up the screen to get ynew on the screen.
         */
-       if (xnew >= screen_columns) {
-           ynew += xnew / screen_columns;
-           xnew %= screen_columns;
+       if (xnew >= screen_columns(CURRENT_SCREEN)) {
+           ynew += xnew / screen_columns(CURRENT_SCREEN);
+           xnew %= screen_columns(CURRENT_SCREEN);
        }
 
        /*
@@ -880,7 +900,7 @@ mvcur(int yold, int xold, int ynew, int xnew)
         * character set -- these have a strong tendency to screw up the CR &
         * LF used for local character motions!
         */
-       oldattr = SCREEN_ATTRS(SP);
+       oldattr = SCREEN_ATTRS(SP_PARM);
        if ((AttrOf(oldattr) & A_ALTCHARSET)
            || (AttrOf(oldattr) && !move_standout_mode)) {
            TR(TRACE_CHARPUT, ("turning off (%#lx) %s before move",
@@ -889,14 +909,14 @@ mvcur(int yold, int xold, int ynew, int xnew)
            (void) VIDATTR(A_NORMAL, 0);
        }
 
-       if (xold >= screen_columns) {
+       if (xold >= screen_columns(CURRENT_SCREEN)) {
            int l;
 
-           if (SP->_nl) {
-               l = (xold + 1) / screen_columns;
+           if (SP_PARM->_nl) {
+               l = (xold + 1) / screen_columns(CURRENT_SCREEN);
                yold += l;
-               if (yold >= screen_lines)
-                   l -= (yold - screen_lines - 1);
+               if (yold >= screen_lines(CURRENT_SCREEN))
+                   l -= (yold - screen_lines(CURRENT_SCREEN) - 1);
 
                if (l > 0) {
                    if (carriage_return) {
@@ -925,10 +945,10 @@ mvcur(int yold, int xold, int ynew, int xnew)
            }
        }
 
-       if (yold > screen_lines - 1)
-           yold = screen_lines - 1;
-       if (ynew > screen_lines - 1)
-           ynew = screen_lines - 1;
+       if (yold > screen_lines(CURRENT_SCREEN) - 1)
+           yold = screen_lines(CURRENT_SCREEN) - 1;
+       if (ynew > screen_lines(CURRENT_SCREEN) - 1)
+           ynew = screen_lines(CURRENT_SCREEN) - 1;
 
        /* destination location is on screen now */
        code = onscreen_mvcur(yold, xold, ynew, xnew, TRUE);
@@ -936,7 +956,7 @@ mvcur(int yold, int xold, int ynew, int xnew)
        /*
         * Restore attributes if we disabled them before moving.
         */
-       if (!SameAttrOf(oldattr, SCREEN_ATTRS(SP))) {
+       if (!SameAttrOf(oldattr, SCREEN_ATTRS(SP_PARM))) {
            TR(TRACE_CHARPUT, ("turning on (%#lx) %s after move",
                               (unsigned long) AttrOf(oldattr),
                               _traceattr(AttrOf(oldattr))));
@@ -946,6 +966,14 @@ mvcur(int yold, int xold, int ynew, int xnew)
     returnCode(code);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+mvcur(int yold, int xold, int ynew, int xnew)
+{
+    return NCURSES_SP_NAME(mvcur) (CURRENT_SCREEN, yold, xold, ynew, xnew);
+}
+#endif
+
 #if defined(TRACE) || defined(NCURSES_TEST)
 NCURSES_EXPORT_VAR(int) _nc_optimize_enable = OPTIMIZE_ALL;
 #endif
@@ -1089,7 +1117,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
            load_term();
        } else if (sscanf(buf, "d %s", capname) == 1) {
            struct name_table_entry const *np = _nc_find_entry(capname,
-                                                              _nc_info_hash_table);
+                                                              _nc_get_hash_table(FALSE));
 
            if (np == NULL)
                (void) printf("No such capability as \"%s\"\n", capname);