]> code.delx.au - gnu-emacs/blobdiff - src/cm.c
*** empty log message ***
[gnu-emacs] / src / cm.c
index f88acff48f14303f9f57d1a40c3a90430f86e54d..dd25c112630779dfe5405062c2ba55799905c200 100644 (file)
--- a/src/cm.c
+++ b/src/cm.c
@@ -1,12 +1,13 @@
 /* Cursor motion subroutines for GNU Emacs.
 /* Cursor motion subroutines for GNU Emacs.
-   Copyright (C) 1985 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1995, 2002, 2003, 2004,
+                 2005, 2006 Free Software Foundation, Inc.
     based primarily on public domain code written by Chris Torek
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
     based primarily on public domain code written by Chris Torek
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 1, or (at your option)
+the Free Software Foundation; either version 2, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -16,37 +17,50 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 
 
 
-#include "config.h"
+#include <config.h>
 #include <stdio.h>
 #include "cm.h"
 #include "termhooks.h"
 
 #include <stdio.h>
 #include "cm.h"
 #include "termhooks.h"
 
+/* For now, don't try to include termcap.h.  On some systems,
+   configure finds a non-standard termcap.h that the main build
+   won't find.  */
+
+#if defined HAVE_TERMCAP_H && 0
+#include <termcap.h>
+#else
+extern void tputs P_ ((const char *, int, int (*)(int)));
+extern char *tgoto P_ ((const char *, int, int));
+#endif
+
 #define        BIG     9999            /* 9999 good on VAXen.  For 16 bit machines
                                   use about 2000.... */
 
 #define        BIG     9999            /* 9999 good on VAXen.  For 16 bit machines
                                   use about 2000.... */
 
-char *tgoto ();
-
 extern char *BC, *UP;
 
 int cost;              /* sums up costs */
 
 /* ARGSUSED */
 extern char *BC, *UP;
 
 int cost;              /* sums up costs */
 
 /* ARGSUSED */
+int
 evalcost (c)
      char c;
 {
   cost++;
 evalcost (c)
      char c;
 {
   cost++;
+  return c;
 }
 
 }
 
-void
+int
 cmputc (c)
      char c;
 {
   if (termscript)
     fputc (c & 0177, termscript);
   putchar (c & 0177);
 cmputc (c)
      char c;
 {
   if (termscript)
     fputc (c & 0177, termscript);
   putchar (c & 0177);
+  return c;
 }
 
 /* NEXT TWO ARE DONE WITH MACROS */
 }
 
 /* NEXT TWO ARE DONE WITH MACROS */
@@ -98,12 +112,42 @@ addcol (n) {
 }
 #endif
 
 }
 #endif
 
+/*
+ * Terminals with magicwrap (xn) don't all behave identically.
+ * The VT100 leaves the cursor in the last column but will wrap before
+ * printing the next character.  I hear that the Concept terminal does
+ * the wrap immediately but ignores the next newline it sees.  And some
+ * terminals just have buggy firmware, and think that the cursor is still
+ * in limbo if we use direct cursor addressing from the phantom column.
+ * The only guaranteed safe thing to do is to emit a CRLF immediately
+ * after we reach the last column; this takes us to a known state.
+ */
+void
+cmcheckmagic ()
+{
+  if (curX == FrameCols)
+    {
+      if (!MagicWrap || curY >= FrameRows - 1)
+       abort ();
+      if (termscript)
+       putc ('\r', termscript);
+      putchar ('\r');
+      if (termscript)
+       putc ('\n', termscript);
+      putchar ('\n');
+      curX = 0;
+      curY++;
+    }
+}
+
+
 /*
  * (Re)Initialize the cost factors, given the output speed of the terminal
  * in the variable ospeed.  (Note: this holds B300, B9600, etc -- ie stuff
  * out of <sgtty.h>.)
  */
 
 /*
  * (Re)Initialize the cost factors, given the output speed of the terminal
  * in the variable ospeed.  (Note: this holds B300, B9600, etc -- ie stuff
  * out of <sgtty.h>.)
  */
 
+void
 cmcostinit ()
 {
     char *p;
 cmcostinit ()
 {
     char *p;
@@ -143,8 +187,9 @@ cmcostinit ()
  * actually perform the motion.
  */
 
  * actually perform the motion.
  */
 
-static
+static int
 calccost (srcy, srcx, dsty, dstx, doit)
 calccost (srcy, srcx, dsty, dstx, doit)
+     int srcy, srcx, dsty, dstx, doit;
 {
     register int    deltay,
                     deltax,
 {
     register int    deltay,
                     deltax,
@@ -180,7 +225,7 @@ calccost (srcy, srcx, dsty, dstx, doit)
     if (doit)
        while (--deltay >= 0)
            tputs (p, 1, cmputc);
     if (doit)
        while (--deltay >= 0)
            tputs (p, 1, cmputc);
-x: 
+x:
     if ((deltax = dstx - srcx) == 0)
        goto done;
     if (deltax < 0) {
     if ((deltax = dstx - srcx) == 0)
        goto done;
     if (deltax < 0) {
@@ -191,7 +236,7 @@ x:
     if (Wcm.cc_tab >= BIG || !Wcm.cm_usetabs)
        goto olddelta;          /* forget it! */
 
     if (Wcm.cc_tab >= BIG || !Wcm.cm_usetabs)
        goto olddelta;          /* forget it! */
 
-    /* 
+    /*
      * ntabs is # tabs towards but not past dstx; n2tabs is one more
      * (ie past dstx), but this is only valid if that is not past the
      * right edge of the screen.  We can check that at the same time
      * ntabs is # tabs towards but not past dstx; n2tabs is one more
      * (ie past dstx), but this is only valid if that is not past the
      * right edge of the screen.  We can check that at the same time
@@ -207,7 +252,7 @@ x:
     if (tab2x >= Wcm.cm_cols)  /* too far (past edge) */
        n2tabs = 0;
 
     if (tab2x >= Wcm.cm_cols)  /* too far (past edge) */
        n2tabs = 0;
 
-    /* 
+    /*
      * Now set tabcost to the cost for using ntabs, and c to the cost
      * for using n2tabs, then pick the minimum.
      */
      * Now set tabcost to the cost for using ntabs, and c to the cost
      * for using n2tabs, then pick the minimum.
      */
@@ -226,7 +271,7 @@ x:
     if (tabcost >= BIG)                /* caint use tabs */
        goto newdelta;
 
     if (tabcost >= BIG)                /* caint use tabs */
        goto newdelta;
 
-    /* 
+    /*
      * See if tabcost is less than just moving right
      */
 
      * See if tabcost is less than just moving right
      */
 
@@ -238,20 +283,20 @@ x:
        srcx = tabx;
     }
 
        srcx = tabx;
     }
 
-    /* 
+    /*
      * Now might as well just recompute the delta.
      */
 
      * Now might as well just recompute the delta.
      */
 
-newdelta: 
+newdelta:
     if ((deltax = dstx - srcx) == 0)
        goto done;
     if ((deltax = dstx - srcx) == 0)
        goto done;
-olddelta: 
+olddelta:
     if (deltax > 0)
        p = Wcm.cm_right, c = Wcm.cc_right;
     else
        p = Wcm.cm_left, c = Wcm.cc_left, deltax = -deltax;
 
     if (deltax > 0)
        p = Wcm.cm_right, c = Wcm.cc_right;
     else
        p = Wcm.cm_left, c = Wcm.cc_left, deltax = -deltax;
 
-dodelta: 
+dodelta:
     if (c == BIG) {            /* caint get thar from here */
 fail:
        if (doit)
     if (c == BIG) {            /* caint get thar from here */
 fail:
        if (doit)
@@ -262,7 +307,7 @@ fail:
     if (doit)
        while (--deltax >= 0)
            tputs (p, 1, cmputc);
     if (doit)
        while (--deltax >= 0)
            tputs (p, 1, cmputc);
-done: 
+done:
     return totalcost;
 }
 
     return totalcost;
 }
 
@@ -278,7 +323,9 @@ losecursor ()
 #define        USELL   2
 #define        USECR   3
 
 #define        USELL   2
 #define        USECR   3
 
+void
 cmgoto (row, col)
 cmgoto (row, col)
+     int row, col;
 {
     int     homecost,
             crcost,
 {
     int     homecost,
             crcost,
@@ -333,7 +380,7 @@ cmgoto (row, col)
       dcm = Wcm.cm_abs;
     }
 
       dcm = Wcm.cm_abs;
     }
 
-  /* 
+  /*
    * In the following comparison, the = in <= is because when the costs
    * are the same, it looks nicer (I think) to move directly there.
    */
    * In the following comparison, the = in <= is because when the costs
    * are the same, it looks nicer (I think) to move directly there.
    */
@@ -354,17 +401,17 @@ cmgoto (row, col)
 
   switch (use)
     {
 
   switch (use)
     {
-    case USEHOME: 
+    case USEHOME:
       tputs (Wcm.cm_home, 1, cmputc);
       curY = 0, curX = 0;
       break;
 
       tputs (Wcm.cm_home, 1, cmputc);
       curY = 0, curX = 0;
       break;
 
-    case USELL: 
+    case USELL:
       tputs (Wcm.cm_ll, 1, cmputc);
       curY = Wcm.cm_rows - 1, curX = 0;
       break;
 
       tputs (Wcm.cm_ll, 1, cmputc);
       curY = Wcm.cm_rows - 1, curX = 0;
       break;
 
-    case USECR: 
+    case USECR:
       tputs (Wcm.cm_cr, 1, cmputc);
       if (Wcm.cm_autolf)
        curY++;
       tputs (Wcm.cm_cr, 1, cmputc);
       if (Wcm.cm_autolf)
        curY++;
@@ -380,6 +427,7 @@ cmgoto (row, col)
    Used before copying into it the info on the actual terminal.
  */
 
    Used before copying into it the info on the actual terminal.
  */
 
+void
 Wcm_clear ()
 {
   bzero (&Wcm, sizeof Wcm);
 Wcm_clear ()
 {
   bzero (&Wcm, sizeof Wcm);
@@ -394,6 +442,7 @@ Wcm_clear ()
  * Return -2 if size not specified.
  */
 
  * Return -2 if size not specified.
  */
 
+int
 Wcm_init ()
 {
 #if 0
 Wcm_init ()
 {
 #if 0
@@ -412,3 +461,6 @@ Wcm_init ()
     return - 2;
   return 0;
 }
     return - 2;
   return 0;
 }
+
+/* arch-tag: bcf64c02-00f6-44ef-94b6-c56eab5b3dc4
+   (do not change this comment) */