annotate src/cm.c @ 82859:393e0dc93fa0

New. Handle PDF layouts through \pdfpagewidth and \pdfpageheight.
author Michaël Cadilhac <michael.cadilhac@lrde.org>
date Sun, 26 Aug 2007 20:24:08 +0000
parents 922696f363b0
children fc2bcd2a8aad 65663fcd2caa f55f9811f5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Cursor motion subroutines for GNU Emacs.
75227
e90d04cd455a Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents: 68651
diff changeset
2 Copyright (C) 1985, 1995, 2001, 2002, 2003, 2004,
e90d04cd455a Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents: 68651
diff changeset
3 2005, 2006, 2007 Free Software Foundation, Inc.
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 based primarily on public domain code written by Chris Torek
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 This file is part of GNU Emacs.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 GNU Emacs is free software; you can redistribute it and/or modify
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
78260
922696f363b0 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75227
diff changeset
10 the Free Software Foundation; either version 3, or (at your option)
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 any later version.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 GNU Emacs is distributed in the hope that it will be useful,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 GNU General Public License for more details.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 along with GNU Emacs; see the file COPYING. If not, write to
64084
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
21 Boston, MA 02110-1301, USA. */
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 484
diff changeset
24 #include <config.h>
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 #include <stdio.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 #include "cm.h"
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 #include "termhooks.h"
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28
33672
a94852aef620 Don't try to include termcap.h; see comment there.
Gerd Moellmann <gerd@gnu.org>
parents: 30915
diff changeset
29 /* For now, don't try to include termcap.h. On some systems,
a94852aef620 Don't try to include termcap.h; see comment there.
Gerd Moellmann <gerd@gnu.org>
parents: 30915
diff changeset
30 configure finds a non-standard termcap.h that the main build
a94852aef620 Don't try to include termcap.h; see comment there.
Gerd Moellmann <gerd@gnu.org>
parents: 30915
diff changeset
31 won't find. */
a94852aef620 Don't try to include termcap.h; see comment there.
Gerd Moellmann <gerd@gnu.org>
parents: 30915
diff changeset
32
a94852aef620 Don't try to include termcap.h; see comment there.
Gerd Moellmann <gerd@gnu.org>
parents: 30915
diff changeset
33 #if defined HAVE_TERMCAP_H && 0
25734
0242362bb1fe (toplevel) [HAVE_TERMCAP_H]: Include termcap.h.
Gerd Moellmann <gerd@gnu.org>
parents: 25333
diff changeset
34 #include <termcap.h>
30915
10dd42348df3 [HAVE_TERMCAP_H]: Include <termcap.h>.
Dave Love <fx@gnu.org>
parents: 29909
diff changeset
35 #else
10dd42348df3 [HAVE_TERMCAP_H]: Include <termcap.h>.
Dave Love <fx@gnu.org>
parents: 29909
diff changeset
36 extern void tputs P_ ((const char *, int, int (*)(int)));
10dd42348df3 [HAVE_TERMCAP_H]: Include <termcap.h>.
Dave Love <fx@gnu.org>
parents: 29909
diff changeset
37 extern char *tgoto P_ ((const char *, int, int));
25734
0242362bb1fe (toplevel) [HAVE_TERMCAP_H]: Include termcap.h.
Gerd Moellmann <gerd@gnu.org>
parents: 25333
diff changeset
38 #endif
0242362bb1fe (toplevel) [HAVE_TERMCAP_H]: Include termcap.h.
Gerd Moellmann <gerd@gnu.org>
parents: 25333
diff changeset
39
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 #define BIG 9999 /* 9999 good on VAXen. For 16 bit machines
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 use about 2000.... */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 extern char *BC, *UP;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 int cost; /* sums up costs */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 /* ARGSUSED */
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 14186
diff changeset
48 int
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 evalcost (c)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 char c;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 cost++;
8985
2825665b8352 (evalcost, cmputc): They now return their arguments.
Richard M. Stallman <rms@gnu.org>
parents: 7107
diff changeset
53 return c;
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 14186
diff changeset
56 int
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 cmputc (c)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 char c;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 if (termscript)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 fputc (c & 0177, termscript);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 putchar (c & 0177);
8985
2825665b8352 (evalcost, cmputc): They now return their arguments.
Richard M. Stallman <rms@gnu.org>
parents: 7107
diff changeset
63 return c;
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 /* NEXT TWO ARE DONE WITH MACROS */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 #if 0
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 /*
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 * Assume the cursor is at row row, column col. Normally used only after
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 * clearing the screen, when the cursor is at (0, 0), but what the heck,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 * let's let the guy put it anywhere.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 static
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 at (row, col) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 curY = row;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 curX = col;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 /*
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 * Add n columns to the current cursor position.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 static
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 addcol (n) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 curX += n;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 /*
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 * If cursor hit edge of screen, what happened?
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 * N.B.: DO NOT!! write past edge of screen. If you do, you
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 * deserve what you get. Furthermore, on terminals with
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 * autowrap (but not magicwrap), don't write in the last column
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 * of the last line.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 if (curX == Wcm.cm_cols) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 /*
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 * Well, if magicwrap, still there, past the edge of the
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 * screen (!). If autowrap, on the col 0 of the next line.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 * Otherwise on last column.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 if (Wcm.cm_magicwrap)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 ; /* "limbo" */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 else if (Wcm.cm_autowrap) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 curX = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 curY++; /* Beware end of screen! */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 else
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 curX--;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 #endif
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 /*
10437
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
116 * Terminals with magicwrap (xn) don't all behave identically.
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
117 * The VT100 leaves the cursor in the last column but will wrap before
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
118 * printing the next character. I hear that the Concept terminal does
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
119 * the wrap immediately but ignores the next newline it sees. And some
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
120 * terminals just have buggy firmware, and think that the cursor is still
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
121 * in limbo if we use direct cursor addressing from the phantom column.
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
122 * The only guaranteed safe thing to do is to emit a CRLF immediately
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
123 * after we reach the last column; this takes us to a known state.
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
124 */
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
125 void
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
126 cmcheckmagic ()
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
127 {
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
128 if (curX == FrameCols)
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
129 {
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
130 if (!MagicWrap || curY >= FrameRows - 1)
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
131 abort ();
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
132 if (termscript)
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
133 putc ('\r', termscript);
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
134 putchar ('\r');
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
135 if (termscript)
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
136 putc ('\n', termscript);
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
137 putchar ('\n');
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
138 curX = 0;
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
139 curY++;
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
140 }
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
141 }
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
142
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
143
3021721d1d69 (cmcheckmagic): New function.
Karl Heuer <kwzh@gnu.org>
parents: 8985
diff changeset
144 /*
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 * (Re)Initialize the cost factors, given the output speed of the terminal
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 * in the variable ospeed. (Note: this holds B300, B9600, etc -- ie stuff
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 * out of <sgtty.h>.)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 14186
diff changeset
150 void
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 cmcostinit ()
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 char *p;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 #define COST(x,e) (x ? (cost = 0, tputs (x, 1, e), cost) : BIG)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 #define CMCOST(x,e) ((x == 0) ? BIG : (p = tgoto(x, 0, 0), COST(p ,e)))
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 Wcm.cc_up = COST (Wcm.cm_up, evalcost);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 Wcm.cc_down = COST (Wcm.cm_down, evalcost);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 Wcm.cc_left = COST (Wcm.cm_left, evalcost);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 Wcm.cc_right = COST (Wcm.cm_right, evalcost);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 Wcm.cc_home = COST (Wcm.cm_home, evalcost);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 Wcm.cc_cr = COST (Wcm.cm_cr, evalcost);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 Wcm.cc_ll = COST (Wcm.cm_ll, evalcost);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 Wcm.cc_tab = Wcm.cm_tabwidth ? COST (Wcm.cm_tab, evalcost) : BIG;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 /*
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 * These last three are actually minimum costs. When (if) they are
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 * candidates for the least-cost motion, the real cost is computed.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 * (Note that "0" is the assumed to generate the minimum cost.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 * While this is not necessarily true, I have yet to see a terminal
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 * for which is not; all the terminals that have variable-cost
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 * cursor motion seem to take straight numeric values. --ACT)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 Wcm.cc_abs = CMCOST (Wcm.cm_abs, evalcost);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 Wcm.cc_habs = CMCOST (Wcm.cm_habs, evalcost);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 Wcm.cc_vabs = CMCOST (Wcm.cm_vabs, evalcost);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 #undef CMCOST
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 #undef COST
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 /*
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 * Calculate the cost to move from (srcy, srcx) to (dsty, dstx) using
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 * up and down, and left and right, motions, and tabs. If doit is set
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 * actually perform the motion.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 14186
diff changeset
190 static int
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 calccost (srcy, srcx, dsty, dstx, doit)
48318
5c1be14cbcac (calccost, cmgoto): Declare all args (per C99).
Dave Love <fx@gnu.org>
parents: 33672
diff changeset
192 int srcy, srcx, dsty, dstx, doit;
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 register int deltay,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 deltax,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 c,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 totalcost;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 int ntabs,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 n2tabs,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 tabx,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 tab2x,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 tabcost;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 register char *p;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 /* If have just wrapped on a terminal with xn,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 don't believe the cursor position: give up here
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 and force use of absolute positioning. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 if (curX == Wcm.cm_cols)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 goto fail;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 totalcost = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 if ((deltay = dsty - srcy) == 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 goto x;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 if (deltay < 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 p = Wcm.cm_up, c = Wcm.cc_up, deltay = -deltay;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 else
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 p = Wcm.cm_down, c = Wcm.cc_down;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 if (c == BIG) { /* caint get thar from here */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 if (doit)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 printf ("OOPS");
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 return c;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 totalcost = c * deltay;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 if (doit)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 while (--deltay >= 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 tputs (p, 1, cmputc);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48318
diff changeset
228 x:
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 if ((deltax = dstx - srcx) == 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 goto done;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 if (deltax < 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 p = Wcm.cm_left, c = Wcm.cc_left, deltax = -deltax;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 goto dodelta; /* skip all the tab junk */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 /* Tabs (the toughie) */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 if (Wcm.cc_tab >= BIG || !Wcm.cm_usetabs)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 goto olddelta; /* forget it! */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48318
diff changeset
239 /*
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 * ntabs is # tabs towards but not past dstx; n2tabs is one more
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 * (ie past dstx), but this is only valid if that is not past the
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 * right edge of the screen. We can check that at the same time
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 * as we figure out where we would be if we use the tabs (which
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 * we will put into tabx (for ntabs) and tab2x (for n2tabs)).
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 ntabs = (deltax + srcx % Wcm.cm_tabwidth) / Wcm.cm_tabwidth;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 n2tabs = ntabs + 1;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 tabx = (srcx / Wcm.cm_tabwidth + ntabs) * Wcm.cm_tabwidth;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 tab2x = tabx + Wcm.cm_tabwidth;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 if (tab2x >= Wcm.cm_cols) /* too far (past edge) */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 n2tabs = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48318
diff changeset
255 /*
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 * Now set tabcost to the cost for using ntabs, and c to the cost
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 * for using n2tabs, then pick the minimum.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 /* cost for ntabs + cost for right motion */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 tabcost = ntabs ? ntabs * Wcm.cc_tab + (dstx - tabx) * Wcm.cc_right
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 : BIG;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 /* cost for n2tabs + cost for left motion */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 c = n2tabs ? n2tabs * Wcm.cc_tab + (tab2x - dstx) * Wcm.cc_left
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 : BIG;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 if (c < tabcost) /* then cheaper to overshoot & back up */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 ntabs = n2tabs, tabcost = c, tabx = tab2x;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 if (tabcost >= BIG) /* caint use tabs */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 goto newdelta;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48318
diff changeset
274 /*
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 * See if tabcost is less than just moving right
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 if (tabcost < (deltax * Wcm.cc_right)) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 totalcost += tabcost; /* use the tabs */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 if (doit)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 while (--ntabs >= 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 tputs (Wcm.cm_tab, 1, cmputc);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 srcx = tabx;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48318
diff changeset
286 /*
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 * Now might as well just recompute the delta.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48318
diff changeset
290 newdelta:
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 if ((deltax = dstx - srcx) == 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 goto done;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48318
diff changeset
293 olddelta:
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 if (deltax > 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 p = Wcm.cm_right, c = Wcm.cc_right;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 else
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 p = Wcm.cm_left, c = Wcm.cc_left, deltax = -deltax;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48318
diff changeset
299 dodelta:
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 if (c == BIG) { /* caint get thar from here */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 fail:
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 if (doit)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 printf ("OOPS");
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 return BIG;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 totalcost += c * deltax;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 if (doit)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 while (--deltax >= 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 tputs (p, 1, cmputc);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48318
diff changeset
310 done:
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 return totalcost;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 #if 0
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 losecursor ()
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 curY = -1;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 #endif
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 #define USEREL 0
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 #define USEHOME 1
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 #define USELL 2
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 #define USECR 3
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 14186
diff changeset
326 void
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 cmgoto (row, col)
48318
5c1be14cbcac (calccost, cmgoto): Declare all args (per C99).
Dave Love <fx@gnu.org>
parents: 33672
diff changeset
328 int row, col;
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 int homecost,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 crcost,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 llcost,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 relcost,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 directcost;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 int use;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 char *p,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 *dcm;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 /* First the degenerate case */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 if (row == curY && col == curX) /* already there */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 return;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 if (curY >= 0 && curX >= 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 /* We may have quick ways to go to the upper-left, bottom-left,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 * start-of-line, or start-of-next-line. Or it might be best to
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 * start where we are. Examine the options, and pick the cheapest.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 relcost = calccost (curY, curX, row, col, 0);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 use = USEREL;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 if ((homecost = Wcm.cc_home) < BIG)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 homecost += calccost (0, 0, row, col, 0);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 if (homecost < relcost)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 relcost = homecost, use = USEHOME;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 if ((llcost = Wcm.cc_ll) < BIG)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 llcost += calccost (Wcm.cm_rows - 1, 0, row, col, 0);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 if (llcost < relcost)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 relcost = llcost, use = USELL;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 if ((crcost = Wcm.cc_cr) < BIG) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 if (Wcm.cm_autolf)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 if (curY + 1 >= Wcm.cm_rows)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 crcost = BIG;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 else
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 crcost += calccost (curY + 1, 0, row, col, 0);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 else
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 crcost += calccost (curY, 0, row, col, 0);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 if (crcost < relcost)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 relcost = crcost, use = USECR;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 directcost = Wcm.cc_abs, dcm = Wcm.cm_abs;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 if (row == curY && Wcm.cc_habs < BIG)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 directcost = Wcm.cc_habs, dcm = Wcm.cm_habs;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 else if (col == curX && Wcm.cc_vabs < BIG)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 directcost = Wcm.cc_vabs, dcm = Wcm.cm_vabs;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 else
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 directcost = 0, relcost = 100000;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 dcm = Wcm.cm_abs;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48318
diff changeset
383 /*
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 * In the following comparison, the = in <= is because when the costs
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 * are the same, it looks nicer (I think) to move directly there.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 if (directcost <= relcost)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 /* compute REAL direct cost */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 cost = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 p = dcm == Wcm.cm_habs ? tgoto (dcm, row, col) :
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 tgoto (dcm, col, row);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 tputs (p, 1, evalcost);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 if (cost <= relcost)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 { /* really is cheaper */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 tputs (p, 1, cmputc);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 curY = row, curX = col;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 return;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 switch (use)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 {
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48318
diff changeset
404 case USEHOME:
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 tputs (Wcm.cm_home, 1, cmputc);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 curY = 0, curX = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 break;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48318
diff changeset
409 case USELL:
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 tputs (Wcm.cm_ll, 1, cmputc);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 curY = Wcm.cm_rows - 1, curX = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 break;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48318
diff changeset
414 case USECR:
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 tputs (Wcm.cm_cr, 1, cmputc);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 if (Wcm.cm_autolf)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 curY++;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 curX = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 break;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 (void) calccost (curY, curX, row, col, 1);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 curY = row, curX = col;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 /* Clear out all terminal info.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 Used before copying into it the info on the actual terminal.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 14186
diff changeset
430 void
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 Wcm_clear ()
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 bzero (&Wcm, sizeof Wcm);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 UP = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 BC = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 /*
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 * Initialized stuff
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 * Return 0 if can do CM.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 * Return -1 if cannot.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 * Return -2 if size not specified.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 14186
diff changeset
445 int
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 Wcm_init ()
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 #if 0
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 if (Wcm.cm_abs && !Wcm.cm_ds)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 return 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 #endif
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 if (Wcm.cm_abs)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 return 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 /* Require up and left, and, if no absolute, down and right */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 if (!Wcm.cm_up || !Wcm.cm_left)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 return - 1;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 if (!Wcm.cm_abs && (!Wcm.cm_down || !Wcm.cm_right))
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 return - 1;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 /* Check that we know the size of the screen.... */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 if (Wcm.cm_rows <= 0 || Wcm.cm_cols <= 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 return - 2;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 return 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
464
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
465 /* arch-tag: bcf64c02-00f6-44ef-94b6-c56eab5b3dc4
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
466 (do not change this comment) */