Build Fix -- compatibility issue with newer autoconf
[sxemacs] / src / ui / TTY / console-tty.h
1 /* Define TTY specific console, device, and frame object for XEmacs.
2    Copyright (C) 1995 Board of Trustees, University of Illinois.
3    Copyright (C) 1996 Ben Wing.
4    Copyright (C) 2007 Nelson Ferreira
5
6 This file is part of SXEmacs
7
8 SXEmacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 SXEmacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
20
21
22 /* Synched up with: Not in FSF. */
23
24 /* Written by Chuck Thompson, Ben Wing and Nelson Ferreira */
25
26 /* NOTE: Currently each TTY console can have only one device.
27    Therefore, all stuff for both input and output is lumped into
28    the console structure.  If it ever becomes meaningful to
29    have more than one device on a TTY console, the output stuff
30    will have to get separated out. */
31
32 #ifndef INCLUDED_console_tty_h_
33 #define INCLUDED_console_tty_h_
34
35 #include "ui/console.h"
36 #include "syssignal.h"          /* Always include before systty.h */
37 #include "systty.h"
38
39 DECLARE_CONSOLE_TYPE(tty);
40
41 struct tty_console {
42         int infd, outfd;
43         Lisp_Object instream, outstream;
44         Lisp_Object terminal_type;
45         Lisp_Object controlling_process;
46         Lisp_Object term_cmap;
47         Lisp_Object term_crgb;
48
49         char *term_entry_buffer;
50
51         /* Physical location of cursor on this console. */
52         int cursor_x;
53         int cursor_y;
54
55         /* The real location of the cursor.  The above physical location may
56            be ahead of where we really are. */
57         int real_cursor_x;
58         int real_cursor_y;
59
60         int final_cursor_x;
61         int final_cursor_y;
62
63         int height;
64         int width;
65
66         int maxcolors;
67         int maxpairs;
68
69         /* The count of frame number. */
70         int frame_count;
71
72         /* flags indicating presence, absence or value of various features */
73         struct {
74                 /* terminal inserts nulls, not
75                    spaces to fill whitespace on
76                    screen
77                 */
78                 unsigned int must_write_spaces:1;
79
80                 /* cursor movement commands
81                    work while in insert mode
82                 */
83                 unsigned int insert_mode_motion:1;
84
85                 /* cursor movement is graceful
86                    in standout or underline mode */
87                 unsigned int standout_motion:1;
88
89                 /* display retained above screen */
90                 unsigned int memory_above_frame:1;
91
92                 /* display retained below screen */
93                 unsigned int memory_below_frame:1;
94                 unsigned int meta_key:2;        /* 0 == mask off top bit;
95                                                    1 == top bit is meta;
96                                                    2 == top bit is useful as
97                                                    character info */
98                 unsigned int flow_control:1;    /* Nonzero means use ^S/^Q as
99                                                    cretinous flow control.  */
100                 int standout_width;     /* # of spaces printed when
101                                            change to standout mode */
102                 int underline_width;    /* # of spaces printed when
103                                            change to underline mode */
104         } flags;
105
106         /* cursor motion entries - each entry is commented with the terminfo
107            and the termcap entry */
108         struct {
109                 /* local cursor movement */
110                 const char *up; /* cuu1, up */
111                 const char *down;       /* cud1, do */
112                 const char *left;       /* cub1, le */
113                 const char *right;      /* cuf1, nd */
114                 const char *home;       /* home, ho */
115                 const char *low_left;   /* ll, ll */
116                 const char *car_return; /* cr, cr */
117
118                 /* parameterized local cursor movement */
119                 const char *multi_up;    /* cuu, UP */
120                 const char *multi_down;  /* cud, DO */
121                 const char *multi_left;  /* cub, LE */
122                 const char *multi_right; /* cuf, RI */
123
124                 /* absolute cursor motion */
125                 const char *abs;        /* cup, cm */
126                 const char *hor_abs;    /* hpa, ch */
127                 const char *ver_abs;    /* vpa, cv */
128
129                 /* scrolling */
130                 const char *scroll_forw;        /* ind, sf */
131                 const char *scroll_back;        /* ri, sr */
132                 const char *multi_scroll_forw;  /* indn, SF */
133                 const char *multi_scroll_back;  /* rin, SR */
134                 const char *set_scroll_region;  /* csr, cs */
135
136         } cm;
137
138         /* screen editing entries - each entry is commented with the
139            terminfo and the termcap entry */
140         struct {
141                 /* adding to the screen */
142                 const char *ins_line;   /* il1, al */
143                 const char *multi_ins_line;     /* il, AL */
144                 const char *repeat;     /* rep, rp */
145                 const char *begin_ins_mode;     /* smir, im */
146                 const char *end_ins_mode;       /* rmir, ei */
147                 const char *ins_char;   /* ich1, ic */
148                 const char *multi_ins_char;     /* ich, IC */
149                 const char *insert_pad; /* ip, ip */
150
151                 /* deleting from the screen */
152                 const char *clr_frame;  /* clear, cl */
153                 const char *clr_from_cursor;    /* ed, cd */
154                 const char *clr_to_eol; /* el, ce */
155                 const char *del_line;   /* dl1, dl */
156                 const char *multi_del_line;     /* dl, DL */
157                 const char *del_char;   /* dch1, dc */
158                 const char *multi_del_char;     /* dch, DC */
159                 const char *begin_del_mode;     /* smdc, dm */
160                 const char *end_del_mode;       /* rmdc, ed */
161                 const char *erase_at_cursor;    /* ech, ec */
162         } se;
163
164         /* screen display entries - each entry is commented with the
165            terminfo and termcap entry */
166         struct {
167                 const char *begin_standout_;    /* smso, so */
168                 const char *end_standout_;      /* rmso, se */
169                 const char *begin_underline_;   /* smul, us */
170                 const char *end_underline_;     /* rmul, ue */
171                 const char *begin_alternate_;   /* smacs, as */
172                 const char *end_alternate_;     /* rmacs, ae */
173
174                 const char *turn_on_reverse_;           /* rev, mr */
175                 const char *turn_on_blinking_;          /* blink, mb */
176                 const char *turn_on_bold_;              /* bold, md */
177                 const char *turn_on_dim_;               /* dim, mh */
178                 const char *turn_off_attributes_;       /* sgr0, me */
179
180
181                 const char *visual_bell_;       /* flash, vb */
182                 const char *audio_bell_;        /* bel, bl */
183
184                 const char *cursor_visible_;    /* cvvis, vs */
185                 const char *cursor_invisible_;  /* civis, vi */
186                 const char *cursor_normal_;     /* cnorm, ve */
187                 const char *hard_cursor_;       /* chts, HC */
188                 const char *init_motion_;       /* smcup, ti */
189                 const char *end_motion_;        /* rmcup, te */
190                 const char *keypad_on_;         /* smkx, ks */
191                 const char *keypad_off_;        /* rmkx, ke */
192
193                 /* colors */
194                 const char *set_fore_;  /* setf, Sf */
195                 const char *set_back_;  /* setb, Sb */
196                 /* tparm doesnt want these constant */
197                 char *set_afore_;       /* setaf, AF */
198                 char *set_aback_;       /* setab, AB */
199                 const char *orig_pair_; /* op, op */
200         } sd;
201
202         /* costs of various operations */
203         struct {
204                 int cm_up;
205                 int cm_down;
206                 int cm_left;
207                 int cm_right;
208                 int cm_home;
209                 int cm_low_left;
210                 int cm_car_return;
211                 int cm_abs;
212                 int cm_hor_abs;
213                 int cm_ver_abs;
214         } cost;
215
216         /* The initial tty mode bits */
217         struct emacs_tty old_tty;
218
219         /* Is this TTY our controlling terminal? */
220         unsigned int controlling_terminal:1;
221         unsigned int is_stdio:1;
222
223         /* Some flags relating to expanding the colors */
224         unsigned int is_bold_brighter    :1;
225         unsigned int is_reverse_brighter :1;
226         unsigned int nearest_color       :1;
227 };
228
229 #define CONSOLE_TTY_DATA(c) CONSOLE_TYPE_DATA (c, tty)
230 #define CONSOLE_TTY_CURSOR_X(c) (CONSOLE_TTY_DATA (c)->cursor_x)
231 #define CONSOLE_TTY_CURSOR_Y(c) (CONSOLE_TTY_DATA (c)->cursor_y)
232 #define CONSOLE_TTY_REAL_CURSOR_X(c) (CONSOLE_TTY_DATA (c)->real_cursor_x)
233 #define CONSOLE_TTY_REAL_CURSOR_Y(c) (CONSOLE_TTY_DATA (c)->real_cursor_y)
234 #define CONSOLE_TTY_FINAL_CURSOR_X(c) (CONSOLE_TTY_DATA (c)->final_cursor_x)
235 #define CONSOLE_TTY_FINAL_CURSOR_Y(c) (CONSOLE_TTY_DATA (c)->final_cursor_y)
236
237 #define TTY_CM(c) (CONSOLE_TTY_DATA (c)->cm)
238 #define TTY_SE(c) (CONSOLE_TTY_DATA (c)->se)
239 #define TTY_SD(c) (CONSOLE_TTY_DATA (c)->sd)
240 #define TTY_FLAGS(c) (CONSOLE_TTY_DATA (c)->flags)
241 #define TTY_COST(c) (CONSOLE_TTY_DATA (c)->cost)
242
243 #define TTY_INC_CURSOR_X(c, n) do {                                     \
244   int TICX_n = (n);                                                     \
245   assert (CONSOLE_TTY_CURSOR_X (c) == CONSOLE_TTY_REAL_CURSOR_X (c));   \
246   CONSOLE_TTY_CURSOR_X (c) += TICX_n;                                   \
247   CONSOLE_TTY_REAL_CURSOR_X (c) += TICX_n;                              \
248 } while (0)
249
250 #define TTY_INC_CURSOR_Y(c, n) do {             \
251   int TICY_n = (n);                             \
252   CONSOLE_TTY_CURSOR_Y (c) += TICY_n;           \
253   CONSOLE_TTY_REAL_CURSOR_Y (c) += TICY_n;      \
254 } while (0)
255
256 struct tty_device {
257 #ifdef HAVE_TERMIOS
258         speed_t ospeed;         /* Output speed (from sg_ospeed) */
259 #else
260         short ospeed;           /* Output speed (from sg_ospeed) */
261 #endif
262 };
263
264 #define DEVICE_TTY_DATA(d) DEVICE_TYPE_DATA (d, tty)
265
266 /* termcap requires this to be global */
267 #ifndef HAVE_TERMIOS
268 extern short ospeed;            /* Output speed (from sg_ospeed) */
269 #endif
270
271 extern FILE *termscript;
272
273 EXFUN(Fconsole_tty_controlling_process, 1);
274
275 /******************     Prototypes from cm.c     *******************/
276
277 /* #### Verify that all of these are still needed. */
278
279 void cm_cost_init(struct console *c);
280 void cmputc(int c);
281 void cmgoto(struct frame *f, int row, int col);
282 extern struct console *cmputc_console;
283 void send_string_to_tty_console(struct console *c, unsigned char *str, int len);
284
285 /***************     Prototypes from redisplay-tty.c     ****************/
286
287 enum term_init_status {
288         TTY_UNABLE_OPEN_DATABASE,
289         TTY_TYPE_UNDEFINED,
290         TTY_TYPE_INSUFFICIENT,
291         TTY_SIZE_UNSPECIFIED,
292         TTY_INIT_SUCCESS
293 };
294
295 int init_tty_for_redisplay(struct device *d, char *terminal_type);
296 /* #### These should probably be methods. */
297 void set_tty_modes(struct console *c);
298 void reset_tty_modes(struct console *c);
299
300 /* Used in sysdep.c to properly clear and position the cursor when exiting. */
301 void tty_redisplay_shutdown(struct console *c);
302
303 /* called from console-stream.c */
304 Lisp_Object tty_semi_canonicalize_console_connection(Lisp_Object connection,
305                                                      Error_behavior errb);
306 Lisp_Object tty_canonicalize_console_connection(Lisp_Object connection,
307                                                 Error_behavior errb);
308 Lisp_Object tty_semi_canonicalize_device_connection(Lisp_Object connection,
309                                                     Error_behavior errb);
310 Lisp_Object tty_canonicalize_device_connection(Lisp_Object connection,
311                                                Error_behavior errb);
312 struct console *tty_find_console_from_fd(int fd);
313
314 /* called from redisplay-tty.c */
315 EXFUN(find_tty_color,3);
316
317 #endif                          /* INCLUDED_console_tty_h_ */