]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tty/lib_mvcur.c
ncurses 5.0
[ncurses.git] / ncurses / tty / lib_mvcur.c
similarity index 94%
rename from ncurses/lib_mvcur.c
rename to ncurses/tty/lib_mvcur.c
index 2e9948f9721a0ee56029826e27fe5b47d17b9da2..955eb8c6cd84b99ed4356c96193e002f043646f9 100644 (file)
 #include <term.h>
 #include <ctype.h>
 
-MODULE_ID("$Id: lib_mvcur.c,v 1.50 1998/02/11 12:13:56 tom Exp $")
+MODULE_ID("$Id: lib_mvcur.c,v 1.60 1999/10/03 01:08:27 Alexander.V.Lukyanov Exp $")
 
 #define STRLEN(s)       (s != 0) ? strlen(s) : 0
 
@@ -175,6 +175,24 @@ static float diff;
 
 static int normalized_cost(const char *const cap, int affcnt);
 
+#if !HAVE_STRSTR
+char * _nc_strstr(const char *haystack, const char *needle)
+{
+       size_t len1 = strlen(haystack);
+       size_t len2 = strlen(needle);
+       char *result = 0;
+
+       while ((len1 != 0) && (len1-- >= len2)) {
+               if (!strncmp(haystack, needle, len2)) {
+                       result = haystack;
+                       break;
+               }
+               haystack++;
+       }
+       return result;
+}
+#endif
+
 /****************************************************************************
  *
  * Initialization/wrapup (including cost pre-computation)
@@ -228,10 +246,10 @@ int _nc_msec_cost(const char *const cap, int affcnt)
                {
                    if (isdigit(*cp))
                        number = number * 10 + (*cp - '0');
-                   else if (*cp == '.')
-                       number += (*++cp - 10) / 10.0;
                    else if (*cp == '*')
                        number *= affcnt;
+                   else if (*cp == '.' && (*++cp != '>') && isdigit(*cp))
+                       number += (*cp - '0') / 10.0;
                }
 
                cum_cost += number * 10;
@@ -284,7 +302,7 @@ void _nc_mvcur_resume(void)
      */
     reset_scroll_region();
     SP->_cursrow = SP->_curscol = -1;
-    
+
     /* restore cursor shape */
     if (SP->_cursor != -1)
     {
@@ -318,6 +336,13 @@ void _nc_mvcur_init(void)
     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);
+    }
+
     /*
      * Assumption: if the terminal has memory_relative addressing, the
      * initialization strings or smcup will set single-page mode so we
@@ -379,6 +404,20 @@ void _nc_mvcur_init(void)
     SP->_cursor_home_length     = STRLEN(cursor_home);
     SP->_cursor_to_ll_length    = STRLEN(cursor_to_ll);
 
+    /*
+     * If save_cursor is used within enter_ca_mode, we should not use it for
+     * scrolling optimization, since the corresponding restore_cursor is not
+     * nested on the various terminals (vt100, xterm, etc.) which use this
+     * feature.
+     */
+    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;
+    }
+
     /*
      * A different, possibly better way to arrange this would be to set
      * SP->_endwin = TRUE at window initialization time and let this be
@@ -567,6 +606,20 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw)
 #endif /* USE_HARD_TABS */
 
 #if defined(REAL_ATTR) && defined(WANT_CHAR)
+#ifdef BSD_TPUTS
+               /*
+                * If we're allowing BSD-style padding in tputs, don't generate
+                * a string with a leading digit.  Otherwise, that will be
+                * interpreted as a padding value rather than sent to the
+                * screen.
+                */
+               if (ovw
+                && n > 0
+                && vcost == 0
+                && str[0] == '\0'
+                && isdigit(TextOf(WANT_CHAR(to_y, from_x))))
+                       ovw = FALSE;
+#endif
                /*
                 * If we have no attribute changes, overwrite is cheaper.
                 * Note: must suppress this by passing in ovw = FALSE whenever
@@ -597,7 +650,7 @@ relative_move(char *result, int from_y,int from_x,int to_y,int to_x, bool ovw)
                        *sp++ = WANT_CHAR(to_y, from_x + i);
                    *sp = '\0';
                    lhcost += n * SP->_char_padding;
-               }
+               }
                else
 #endif /* defined(REAL_ATTR) && defined(WANT_CHAR) */
                {
@@ -681,6 +734,7 @@ onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw)
 {
     char       use[OPT_SIZE], *sp;
     int                tactic = 0, newcost, usecost = INFINITY;
+    int                t5_cr_cost;
 
 #if defined(MAIN) || defined(NCURSES_TEST)
     struct timeval before, after;
@@ -764,13 +818,14 @@ onscreen_mvcur(int yold,int xold,int ynew,int xnew, bool ovw)
      * tactic #5: use left margin for wrap to right-hand side,
      * unless strange wrap behavior indicated by xenl might hose us.
      */
+    t5_cr_cost = (xold>0 ? SP->_cr_cost : 0);
     if (auto_left_margin && !eat_newline_glitch
        && yold > 0 && cursor_left
        && ((newcost=relative_move(NULL, yold-1, screen_columns-1, ynew, xnew, ovw)) != INFINITY)
-       && SP->_cr_cost + SP->_cub1_cost + newcost + newcost < usecost)
+       && t5_cr_cost + SP->_cub1_cost + newcost < usecost)
     {
        tactic = 5;
-       usecost = SP->_cr_cost + SP->_cub1_cost + newcost;
+       usecost = t5_cr_cost + SP->_cub1_cost + newcost;
     }
 
     /*
@@ -890,6 +945,10 @@ int mvcur(int yold, int xold, int ynew, int xnew)
     return(onscreen_mvcur(yold, xold, ynew, xnew, TRUE));
 }
 
+#if defined(TRACE) || defined(NCURSES_TEST)
+int _nc_optimize_enable = OPTIMIZE_ALL;
+#endif
+
 #if defined(MAIN) || defined(NCURSES_TEST)
 /****************************************************************************
  *
@@ -950,17 +1009,7 @@ int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED)
     baudrate();
 
     _nc_mvcur_init();
-#if HAVE_SETVBUF || HAVE_SETBUFFER
-    /*
-     * Undo the effects of our optimization hack, otherwise our interactive
-     * prompts don't flush properly.
-     */
-#if HAVE_SETVBUF
-    (void) setvbuf(SP->_ofp, malloc(BUFSIZ), _IOLBF, BUFSIZ);
-#elif HAVE_SETBUFFER
-    (void) setbuffer(SP->_ofp, malloc(BUFSIZ), BUFSIZ);
-#endif
-#endif /* HAVE_SETVBUF || HAVE_SETBUFFER */
+    NC_BUFFERED(FALSE);
 
     (void) puts("The mvcur tester.  Type ? for help");
 
@@ -1057,8 +1106,8 @@ int main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED)
        }
        else if (buf[0] == 'i')
        {
-            dump_init((char *)NULL, F_TERMINFO, S_TERMINFO, 70, 0);
-            dump_entry(&cur_term->type, 0, 0);
+            dump_init((char *)NULL, F_TERMINFO, S_TERMINFO, 70, 0, FALSE);
+            dump_entry(&cur_term->type, FALSE, TRUE, 0);
             putchar('\n');
        }
        else if (buf[0] == 'o')