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