*** empty log message ***
[bpt/emacs.git] / src / cm.c
index da09ac2..144baa8 100644 (file)
--- a/src/cm.c
+++ b/src/cm.c
@@ -1,12 +1,12 @@
 /* Cursor motion subroutines for GNU Emacs.
-   Copyright (C) 1985 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1995 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
-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,
@@ -16,7 +16,8 @@ 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
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 
 #include <config.h>
@@ -24,29 +25,37 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "cm.h"
 #include "termhooks.h"
 
+#ifdef HAVE_TERMCAP_H
+#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.... */
 
-char *tgoto ();
-
 extern char *BC, *UP;
 
 int cost;              /* sums up costs */
 
 /* ARGSUSED */
+int
 evalcost (c)
      char c;
 {
   cost++;
+  return c;
 }
 
-void
+int
 cmputc (c)
      char c;
 {
   if (termscript)
     fputc (c & 0177, termscript);
   putchar (c & 0177);
+  return c;
 }
 
 /* NEXT TWO ARE DONE WITH MACROS */
@@ -98,12 +107,42 @@ addcol (n) {
 }
 #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>.)
  */
 
+void
 cmcostinit ()
 {
     char *p;
@@ -143,7 +182,7 @@ cmcostinit ()
  * actually perform the motion.
  */
 
-static
+static int
 calccost (srcy, srcx, dsty, dstx, doit)
 {
     register int    deltay,
@@ -278,6 +317,7 @@ losecursor ()
 #define        USELL   2
 #define        USECR   3
 
+void
 cmgoto (row, col)
 {
     int     homecost,
@@ -380,6 +420,7 @@ cmgoto (row, col)
    Used before copying into it the info on the actual terminal.
  */
 
+void
 Wcm_clear ()
 {
   bzero (&Wcm, sizeof Wcm);
@@ -394,6 +435,7 @@ Wcm_clear ()
  * Return -2 if size not specified.
  */
 
+int
 Wcm_init ()
 {
 #if 0