| 1/* $FreeBSD: head/contrib/libreadline/terminal.c 58314 2000-03-19 22:00:57Z ache $ */
|
1/* terminal.c -- controlling the terminal with termcap. */ 2 3/* Copyright (C) 1996 Free Software Foundation, Inc. 4 5 This file is part of the GNU Readline Library, a library for 6 reading lines of text with interactive input and history editing. 7 8 The GNU Readline Library is free software; you can redistribute it 9 and/or modify it under the terms of the GNU General Public License
| 2/* terminal.c -- controlling the terminal with termcap. */ 3 4/* Copyright (C) 1996 Free Software Foundation, Inc. 5 6 This file is part of the GNU Readline Library, a library for 7 reading lines of text with interactive input and history editing. 8 9 The GNU Readline Library is free software; you can redistribute it 10 and/or modify it under the terms of the GNU General Public License
|
10 as published by the Free Software Foundation; either version 1, or
| 11 as published by the Free Software Foundation; either version 2, or
|
11 (at your option) any later version. 12 13 The GNU Readline Library is distributed in the hope that it will be 14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 15 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 The GNU General Public License is often shipped with GNU software, and 19 is generally kept in a file called COPYING or LICENSE. If you do not 20 have a copy of the license, write to the Free Software Foundation,
| 12 (at your option) any later version. 13 14 The GNU Readline Library is distributed in the hope that it will be 15 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 16 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 The GNU General Public License is often shipped with GNU software, and 20 is generally kept in a file called COPYING or LICENSE. If you do not 21 have a copy of the license, write to the Free Software Foundation,
|
21 675 Mass Ave, Cambridge, MA 02139, USA. */
| 22 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
|
22#define READLINE_LIBRARY 23 24#if defined (HAVE_CONFIG_H) 25# include <config.h> 26#endif 27 28#include <sys/types.h> 29#include "posixstat.h" 30#include <fcntl.h> 31#if defined (HAVE_SYS_FILE_H) 32# include <sys/file.h> 33#endif /* HAVE_SYS_FILE_H */ 34 35#if defined (HAVE_UNISTD_H) 36# include <unistd.h> 37#endif /* HAVE_UNISTD_H */ 38 39#if defined (HAVE_STDLIB_H) 40# include <stdlib.h> 41#else 42# include "ansi_stdlib.h" 43#endif /* HAVE_STDLIB_H */ 44 45#if defined (HAVE_LOCALE_H) 46# include <locale.h> 47#endif 48
| 23#define READLINE_LIBRARY 24 25#if defined (HAVE_CONFIG_H) 26# include <config.h> 27#endif 28 29#include <sys/types.h> 30#include "posixstat.h" 31#include <fcntl.h> 32#if defined (HAVE_SYS_FILE_H) 33# include <sys/file.h> 34#endif /* HAVE_SYS_FILE_H */ 35 36#if defined (HAVE_UNISTD_H) 37# include <unistd.h> 38#endif /* HAVE_UNISTD_H */ 39 40#if defined (HAVE_STDLIB_H) 41# include <stdlib.h> 42#else 43# include "ansi_stdlib.h" 44#endif /* HAVE_STDLIB_H */ 45 46#if defined (HAVE_LOCALE_H) 47# include <locale.h> 48#endif 49
|
49#include <signal.h>
| |
50#include <stdio.h>
| 50#include <stdio.h>
|
51#include <setjmp.h>
| |
52 53/* System-specific feature definitions and include files. */ 54#include "rldefs.h" 55 56#if defined (GWINSZ_IN_SYS_IOCTL) && !defined (TIOCGWINSZ) 57# include <sys/ioctl.h> 58#endif /* GWINSZ_IN_SYS_IOCTL && !TIOCGWINSZ */ 59 60#include "rltty.h" 61#include "tcap.h" 62 63/* Some standard library routines. */ 64#include "readline.h" 65#include "history.h" 66
| 51 52/* System-specific feature definitions and include files. */ 53#include "rldefs.h" 54 55#if defined (GWINSZ_IN_SYS_IOCTL) && !defined (TIOCGWINSZ) 56# include <sys/ioctl.h> 57#endif /* GWINSZ_IN_SYS_IOCTL && !TIOCGWINSZ */ 58 59#include "rltty.h" 60#include "tcap.h" 61 62/* Some standard library routines. */ 63#include "readline.h" 64#include "history.h" 65
|
67/* Variables and functions imported from readline.c */ 68extern FILE *_rl_in_stream, *_rl_out_stream; 69extern int readline_echoing_p; 70extern int _rl_bell_preference; 71extern Keymap _rl_keymap;
| 66#include "rlprivate.h" 67#include "rlshell.h"
|
72
| 68
|
73/* Functions imported from bind.c */ 74extern void _rl_bind_if_unbound (); 75 76/* Functions imported from shell.c */ 77extern void set_lines_and_columns (); 78extern char *get_env_value (); 79
| |
80/* **************************************************************** */ 81/* */ 82/* Terminal and Termcap */ 83/* */ 84/* **************************************************************** */ 85 86static char *term_buffer = (char *)NULL; 87static char *term_string_buffer = (char *)NULL; 88 89static int tcap_initialized; 90 91/* Non-zero means this terminal can't really do anything. */ 92static int dumb_term; 93 94#if !defined (__linux__) 95# if defined (__EMX__) || defined (NEED_EXTERN_PC) 96extern 97# endif /* __EMX__ || NEED_EXTERN_PC */ 98char PC, *BC, *UP; 99#endif /* __linux__ */ 100 101/* Some strings to control terminal actions. These are output by tputs (). */ 102char *term_goto, *term_clreol, *term_cr, *term_clrpag, *term_backspace; 103char *term_pc; 104 105/* Non-zero if we determine that the terminal can do character insertion. */ 106int terminal_can_insert = 0; 107 108/* How to insert characters. */ 109char *term_im, *term_ei, *term_ic, *term_ip, *term_IC; 110 111/* How to delete characters. */ 112char *term_dc, *term_DC; 113 114#if defined (HACK_TERMCAP_MOTION) 115char *term_forward_char; 116#endif /* HACK_TERMCAP_MOTION */ 117 118/* How to go up a line. */ 119char *term_up; 120 121/* A visible bell, if the terminal can be made to flash the screen. */ 122static char *visible_bell; 123 124/* Non-zero means the terminal can auto-wrap lines. */ 125int _rl_term_autowrap; 126 127/* Non-zero means that this terminal has a meta key. */ 128static int term_has_meta; 129 130/* The sequences to write to turn on and off the meta key, if this 131 terminal has one. */ 132static char *term_mm, *term_mo; 133 134/* The key sequences output by the arrow keys, if this terminal has any. */ 135static char *term_ku, *term_kd, *term_kr, *term_kl; 136 137/* How to initialize and reset the arrow keys, if this terminal has any. */ 138static char *term_ks, *term_ke; 139 140/* The key sequences sent by the Home and End keys, if any. */ 141static char *term_kh, *term_kH; 142 143/* Variables that hold the screen dimensions, used by the display code. */ 144int screenwidth, screenheight, screenchars; 145 146/* Non-zero means the user wants to enable the keypad. */ 147int _rl_enable_keypad; 148 149/* Non-zero means the user wants to enable a meta key. */ 150int _rl_enable_meta = 1; 151
| 69/* **************************************************************** */ 70/* */ 71/* Terminal and Termcap */ 72/* */ 73/* **************************************************************** */ 74 75static char *term_buffer = (char *)NULL; 76static char *term_string_buffer = (char *)NULL; 77 78static int tcap_initialized; 79 80/* Non-zero means this terminal can't really do anything. */ 81static int dumb_term; 82 83#if !defined (__linux__) 84# if defined (__EMX__) || defined (NEED_EXTERN_PC) 85extern 86# endif /* __EMX__ || NEED_EXTERN_PC */ 87char PC, *BC, *UP; 88#endif /* __linux__ */ 89 90/* Some strings to control terminal actions. These are output by tputs (). */ 91char *term_goto, *term_clreol, *term_cr, *term_clrpag, *term_backspace; 92char *term_pc; 93 94/* Non-zero if we determine that the terminal can do character insertion. */ 95int terminal_can_insert = 0; 96 97/* How to insert characters. */ 98char *term_im, *term_ei, *term_ic, *term_ip, *term_IC; 99 100/* How to delete characters. */ 101char *term_dc, *term_DC; 102 103#if defined (HACK_TERMCAP_MOTION) 104char *term_forward_char; 105#endif /* HACK_TERMCAP_MOTION */ 106 107/* How to go up a line. */ 108char *term_up; 109 110/* A visible bell, if the terminal can be made to flash the screen. */ 111static char *visible_bell; 112 113/* Non-zero means the terminal can auto-wrap lines. */ 114int _rl_term_autowrap; 115 116/* Non-zero means that this terminal has a meta key. */ 117static int term_has_meta; 118 119/* The sequences to write to turn on and off the meta key, if this 120 terminal has one. */ 121static char *term_mm, *term_mo; 122 123/* The key sequences output by the arrow keys, if this terminal has any. */ 124static char *term_ku, *term_kd, *term_kr, *term_kl; 125 126/* How to initialize and reset the arrow keys, if this terminal has any. */ 127static char *term_ks, *term_ke; 128 129/* The key sequences sent by the Home and End keys, if any. */ 130static char *term_kh, *term_kH; 131 132/* Variables that hold the screen dimensions, used by the display code. */ 133int screenwidth, screenheight, screenchars; 134 135/* Non-zero means the user wants to enable the keypad. */ 136int _rl_enable_keypad; 137 138/* Non-zero means the user wants to enable a meta key. */ 139int _rl_enable_meta = 1; 140
|
| 141#if defined (__EMX__) 142static void 143_emx_get_screensize (swp, shp) 144 int *swp, *shp; 145{ 146 int sz[2]; 147 148 _scrsize (sz); 149 150 if (swp) 151 *swp = sz[0]; 152 if (shp) 153 *shp = sz[1]; 154} 155#endif 156
|
152/* Get readline's idea of the screen size. TTY is a file descriptor open 153 to the terminal. If IGNORE_ENV is true, we do not pay attention to the 154 values of $LINES and $COLUMNS. The tests for TERM_STRING_BUFFER being 155 non-null serve to check whether or not we have initialized termcap. */ 156void 157_rl_get_screen_size (tty, ignore_env) 158 int tty, ignore_env; 159{ 160 char *ss; 161#if defined (TIOCGWINSZ) 162 struct winsize window_size; 163#endif /* TIOCGWINSZ */
| 157/* Get readline's idea of the screen size. TTY is a file descriptor open 158 to the terminal. If IGNORE_ENV is true, we do not pay attention to the 159 values of $LINES and $COLUMNS. The tests for TERM_STRING_BUFFER being 160 non-null serve to check whether or not we have initialized termcap. */ 161void 162_rl_get_screen_size (tty, ignore_env) 163 int tty, ignore_env; 164{ 165 char *ss; 166#if defined (TIOCGWINSZ) 167 struct winsize window_size; 168#endif /* TIOCGWINSZ */
|
164#if defined (__EMX__) 165 int sz[2]; 166#endif
| |
167 168#if defined (TIOCGWINSZ) 169 if (ioctl (tty, TIOCGWINSZ, &window_size) == 0) 170 { 171 screenwidth = (int) window_size.ws_col; 172 screenheight = (int) window_size.ws_row; 173 } 174#endif /* TIOCGWINSZ */ 175 176#if defined (__EMX__)
| 169 170#if defined (TIOCGWINSZ) 171 if (ioctl (tty, TIOCGWINSZ, &window_size) == 0) 172 { 173 screenwidth = (int) window_size.ws_col; 174 screenheight = (int) window_size.ws_row; 175 } 176#endif /* TIOCGWINSZ */ 177 178#if defined (__EMX__)
|
177 _scrsize (sz); 178 screenwidth = sz[0]; 179 screenheight = sz[1];
| 179 _emx_get_screensize (&screenwidth, &screenheight);
|
180#endif 181 182 /* Environment variable COLUMNS overrides setting of "co" if IGNORE_ENV 183 is unset. */ 184 if (screenwidth <= 0) 185 { 186 if (ignore_env == 0 && (ss = get_env_value ("COLUMNS"))) 187 screenwidth = atoi (ss); 188
| 180#endif 181 182 /* Environment variable COLUMNS overrides setting of "co" if IGNORE_ENV 183 is unset. */ 184 if (screenwidth <= 0) 185 { 186 if (ignore_env == 0 && (ss = get_env_value ("COLUMNS"))) 187 screenwidth = atoi (ss); 188
|
| 189#if !defined (__DJGPP__)
|
189 if (screenwidth <= 0 && term_string_buffer) 190 screenwidth = tgetnum ("co");
| 190 if (screenwidth <= 0 && term_string_buffer) 191 screenwidth = tgetnum ("co");
|
| 192#endif
|
191 } 192 193 /* Environment variable LINES overrides setting of "li" if IGNORE_ENV 194 is unset. */ 195 if (screenheight <= 0) 196 { 197 if (ignore_env == 0 && (ss = get_env_value ("LINES"))) 198 screenheight = atoi (ss); 199
| 193 } 194 195 /* Environment variable LINES overrides setting of "li" if IGNORE_ENV 196 is unset. */ 197 if (screenheight <= 0) 198 { 199 if (ignore_env == 0 && (ss = get_env_value ("LINES"))) 200 screenheight = atoi (ss); 201
|
| 202#if !defined (__DJGPP__)
|
200 if (screenheight <= 0 && term_string_buffer) 201 screenheight = tgetnum ("li");
| 203 if (screenheight <= 0 && term_string_buffer) 204 screenheight = tgetnum ("li");
|
| 205#endif
|
202 } 203 204 /* If all else fails, default to 80x24 terminal. */ 205 if (screenwidth <= 1) 206 screenwidth = 80; 207 208 if (screenheight <= 0) 209 screenheight = 24; 210 211 /* If we're being compiled as part of bash, set the environment 212 variables $LINES and $COLUMNS to new values. Otherwise, just 213 do a pair of putenv () or setenv () calls. */ 214 set_lines_and_columns (screenheight, screenwidth); 215
| 206 } 207 208 /* If all else fails, default to 80x24 terminal. */ 209 if (screenwidth <= 1) 210 screenwidth = 80; 211 212 if (screenheight <= 0) 213 screenheight = 24; 214 215 /* If we're being compiled as part of bash, set the environment 216 variables $LINES and $COLUMNS to new values. Otherwise, just 217 do a pair of putenv () or setenv () calls. */ 218 set_lines_and_columns (screenheight, screenwidth); 219
|
216 if (!_rl_term_autowrap)
| 220 if (_rl_term_autowrap == 0)
|
217 screenwidth--; 218 219 screenchars = screenwidth * screenheight; 220} 221 222void 223_rl_set_screen_size (rows, cols) 224 int rows, cols; 225{ 226 screenheight = rows; 227 screenwidth = cols; 228 229 if (_rl_term_autowrap == 0) 230 screenwidth--; 231 232 screenchars = screenwidth * screenheight; 233} 234 235void 236rl_resize_terminal () 237{ 238 if (readline_echoing_p) 239 { 240 _rl_get_screen_size (fileno (rl_instream), 1); 241 _rl_redisplay_after_sigwinch (); 242 } 243} 244 245struct _tc_string { 246 char *tc_var; 247 char **tc_value; 248}; 249 250/* This should be kept sorted, just in case we decide to change the 251 search algorithm to something smarter. */ 252static struct _tc_string tc_strings[] = 253{
| 221 screenwidth--; 222 223 screenchars = screenwidth * screenheight; 224} 225 226void 227_rl_set_screen_size (rows, cols) 228 int rows, cols; 229{ 230 screenheight = rows; 231 screenwidth = cols; 232 233 if (_rl_term_autowrap == 0) 234 screenwidth--; 235 236 screenchars = screenwidth * screenheight; 237} 238 239void 240rl_resize_terminal () 241{ 242 if (readline_echoing_p) 243 { 244 _rl_get_screen_size (fileno (rl_instream), 1); 245 _rl_redisplay_after_sigwinch (); 246 } 247} 248 249struct _tc_string { 250 char *tc_var; 251 char **tc_value; 252}; 253 254/* This should be kept sorted, just in case we decide to change the 255 search algorithm to something smarter. */ 256static struct _tc_string tc_strings[] = 257{
|
254 "DC", &term_DC, 255 "IC", &term_IC, 256 "ce", &term_clreol, 257 "cl", &term_clrpag, 258 "cr", &term_cr, 259 "dc", &term_dc, 260 "ei", &term_ei, 261 "ic", &term_ic, 262 "im", &term_im, 263 "kd", &term_kd, 264 "kh", &term_kh, /* home */ 265 "@7", &term_kH, /* end */ 266 "kl", &term_kl, 267 "kr", &term_kr, 268 "ku", &term_ku, 269 "ks", &term_ks, 270 "ke", &term_ke, 271 "le", &term_backspace, 272 "mm", &term_mm, 273 "mo", &term_mo,
| 258 { "DC", &term_DC }, 259 { "IC", &term_IC }, 260 { "ce", &term_clreol }, 261 { "cl", &term_clrpag }, 262 { "cr", &term_cr }, 263 { "dc", &term_dc }, 264 { "ei", &term_ei }, 265 { "ic", &term_ic }, 266 { "im", &term_im }, 267 { "kd", &term_kd }, 268 { "kh", &term_kh }, /* home */ 269 { "@7", &term_kH }, /* end */ 270 { "kl", &term_kl }, 271 { "kr", &term_kr }, 272 { "ku", &term_ku }, 273 { "ks", &term_ks }, 274 { "ke", &term_ke }, 275 { "le", &term_backspace }, 276 { "mm", &term_mm }, 277 { "mo", &term_mo },
|
274#if defined (HACK_TERMCAP_MOTION)
| 278#if defined (HACK_TERMCAP_MOTION)
|
275 "nd", &term_forward_char,
| 279 { "nd", &term_forward_char },
|
276#endif
| 280#endif
|
277 "pc", &term_pc, 278 "up", &term_up, 279 "vb", &visible_bell,
| 281 { "pc", &term_pc }, 282 { "up", &term_up }, 283 { "vb", &visible_bell },
|
280}; 281 282#define NUM_TC_STRINGS (sizeof (tc_strings) / sizeof (struct _tc_string)) 283 284/* Read the desired terminal capability strings into BP. The capabilities 285 are described in the TC_STRINGS table. */ 286static void 287get_term_capabilities (bp) 288 char **bp; 289{
| 284}; 285 286#define NUM_TC_STRINGS (sizeof (tc_strings) / sizeof (struct _tc_string)) 287 288/* Read the desired terminal capability strings into BP. The capabilities 289 are described in the TC_STRINGS table. */ 290static void 291get_term_capabilities (bp) 292 char **bp; 293{
|
| 294#if !defined (__DJGPP__) /* XXX - doesn't DJGPP have a termcap library? */
|
290 register int i; 291 292 for (i = 0; i < NUM_TC_STRINGS; i++) 293 *(tc_strings[i].tc_value) = tgetstr (tc_strings[i].tc_var, bp);
| 295 register int i; 296 297 for (i = 0; i < NUM_TC_STRINGS; i++) 298 *(tc_strings[i].tc_value) = tgetstr (tc_strings[i].tc_var, bp);
|
| 299#endif
|
294 tcap_initialized = 1; 295} 296
| 300 tcap_initialized = 1; 301} 302
|
| 303#define CUSTOM_REDISPLAY_FUNC() (rl_redisplay_function != rl_redisplay) 304#define CUSTOM_INPUT_FUNC() (rl_getc_function != rl_getc) 305
|
297int 298_rl_init_terminal_io (terminal_name) 299 char *terminal_name; 300{
| 306int 307_rl_init_terminal_io (terminal_name) 308 char *terminal_name; 309{
|
301#if defined (__GO32__) 302 screenwidth = ScreenCols (); 303 screenheight = ScreenRows (); 304 screenchars = screenwidth * screenheight; 305 term_cr = "\r"; 306 term_im = term_ei = term_ic = term_IC = (char *)NULL; 307 term_up = term_dc = term_DC = visible_bell = (char *)NULL; 308 309 /* Does the __GO32__ have a meta key? I don't know. */ 310 term_has_meta = 0; 311 term_mm = term_mo = (char *)NULL; 312 313 /* It probably has arrow keys, but I don't know what they are. */ 314 term_ku = term_kd = term_kr = term_kl = (char *)NULL; 315 316#if defined (HACK_TERMCAP_MOTION) 317 term_forward_char = (char *)NULL; 318#endif /* HACK_TERMCAP_MOTION */ 319 terminal_can_insert = _rl_term_autowrap = 0; 320 return; 321#else /* !__GO32__ */ 322
| |
323 char *term, *buffer;
| 310 char *term, *buffer;
|
324 int tty;
| 311 int tty, tgetent_ret;
|
325 Keymap xkeymap; 326 327 term = terminal_name ? terminal_name : get_env_value ("TERM");
| 312 Keymap xkeymap; 313 314 term = terminal_name ? terminal_name : get_env_value ("TERM");
|
| 315 term_clrpag = term_cr = term_clreol = (char *)NULL; 316 tty = rl_instream ? fileno (rl_instream) : 0; 317 screenwidth = screenheight = 0;
|
328
| 318
|
329 if (term_string_buffer == 0) 330 term_string_buffer = xmalloc (2032);
| 319 if (term == 0) 320 term = "dumb";
|
331
| 321
|
332 if (term_buffer == 0) 333 term_buffer = xmalloc (4080);
| 322 /* I've separated this out for later work on not calling tgetent at all 323 if the calling application has supplied a custom redisplay function, 324 (and possibly if the application has supplied a custom input function). */ 325 if (CUSTOM_REDISPLAY_FUNC()) 326 { 327 tgetent_ret = -1; 328 } 329 else 330 { 331 if (term_string_buffer == 0) 332 term_string_buffer = xmalloc(2032);
|
334
| 333
|
335 buffer = term_string_buffer;
| 334 if (term_buffer == 0) 335 term_buffer = xmalloc(4080);
|
336
| 336
|
337 term_clrpag = term_cr = term_clreol = (char *)NULL;
| 337 buffer = term_string_buffer;
|
338
| 338
|
339 if (term == 0) 340 term = "dumb";
| 339 tgetent_ret = tgetent (term_buffer, term); 340 }
|
341
| 341
|
342 if (tgetent (term_buffer, term) <= 0)
| 342 if (tgetent_ret <= 0)
|
343 {
| 343 {
|
| 344 FREE (term_string_buffer); 345 FREE (term_buffer); 346 buffer = term_buffer = term_string_buffer = (char *)NULL; 347
|
344 dumb_term = 1;
| 348 dumb_term = 1;
|
345 screenwidth = 79; 346 screenheight = 24; 347 screenchars = 79 * 24;
| 349 _rl_term_autowrap = 0; /* used by _rl_get_screen_size */ 350 351#if defined (__EMX__) 352 _emx_get_screensize (&screenwidth, &screenheight); 353 screenwidth--; 354#else /* !__EMX__ */ 355 _rl_get_screen_size (tty, 0); 356#endif /* !__EMX__ */ 357 358 /* Defaults. */ 359 if (screenwidth <= 0 || screenheight <= 0) 360 { 361 screenwidth = 79; 362 screenheight = 24; 363 } 364 365 /* Everything below here is used by the redisplay code (tputs). */ 366 screenchars = screenwidth * screenheight;
|
348 term_cr = "\r"; 349 term_im = term_ei = term_ic = term_IC = (char *)NULL; 350 term_up = term_dc = term_DC = visible_bell = (char *)NULL; 351 term_ku = term_kd = term_kl = term_kr = (char *)NULL;
| 367 term_cr = "\r"; 368 term_im = term_ei = term_ic = term_IC = (char *)NULL; 369 term_up = term_dc = term_DC = visible_bell = (char *)NULL; 370 term_ku = term_kd = term_kl = term_kr = (char *)NULL;
|
| 371 term_mm = term_mo = (char *)NULL;
|
352#if defined (HACK_TERMCAP_MOTION) 353 term_forward_char = (char *)NULL; 354#endif
| 372#if defined (HACK_TERMCAP_MOTION) 373 term_forward_char = (char *)NULL; 374#endif
|
355 terminal_can_insert = 0;
| 375 terminal_can_insert = term_has_meta = 0; 376 377 /* Reasonable defaults for tgoto(). Readline currently only uses 378 tgoto if term_IC or term_DC is defined, but just in case we 379 change that later... */ 380 PC = '\0'; 381 BC = term_backspace = "\b"; 382 UP = term_up; 383
|
356 return 0; 357 } 358 359 get_term_capabilities (&buffer); 360 361 /* Set up the variables that the termcap library expects the application 362 to provide. */ 363 PC = term_pc ? *term_pc : 0; 364 BC = term_backspace; 365 UP = term_up; 366 367 if (!term_cr) 368 term_cr = "\r"; 369
| 384 return 0; 385 } 386 387 get_term_capabilities (&buffer); 388 389 /* Set up the variables that the termcap library expects the application 390 to provide. */ 391 PC = term_pc ? *term_pc : 0; 392 BC = term_backspace; 393 UP = term_up; 394 395 if (!term_cr) 396 term_cr = "\r"; 397
|
370 tty = rl_instream ? fileno (rl_instream) : 0; 371 372 screenwidth = screenheight = 0; 373
| |
374 _rl_term_autowrap = tgetflag ("am") && tgetflag ("xn"); 375 376 _rl_get_screen_size (tty, 0); 377 378 /* "An application program can assume that the terminal can do 379 character insertion if *any one of* the capabilities `IC', 380 `im', `ic' or `ip' is provided." But we can't do anything if 381 only `ip' is provided, so... */ 382 terminal_can_insert = (term_IC || term_im || term_ic); 383 384 /* Check to see if this terminal has a meta key and clear the capability 385 variables if there is none. */ 386 term_has_meta = (tgetflag ("km") || tgetflag ("MT")); 387 if (!term_has_meta) 388 term_mm = term_mo = (char *)NULL; 389 390 /* Attempt to find and bind the arrow keys. Do not override already 391 bound keys in an overzealous attempt, however. */ 392 xkeymap = _rl_keymap; 393 394 _rl_keymap = emacs_standard_keymap; 395 _rl_bind_if_unbound (term_ku, rl_get_previous_history); 396 _rl_bind_if_unbound (term_kd, rl_get_next_history); 397 _rl_bind_if_unbound (term_kr, rl_forward); 398 _rl_bind_if_unbound (term_kl, rl_backward); 399 400 _rl_bind_if_unbound (term_kh, rl_beg_of_line); /* Home */ 401 _rl_bind_if_unbound (term_kH, rl_end_of_line); /* End */ 402 403#if defined (VI_MODE) 404 _rl_keymap = vi_movement_keymap; 405 _rl_bind_if_unbound (term_ku, rl_get_previous_history); 406 _rl_bind_if_unbound (term_kd, rl_get_next_history); 407 _rl_bind_if_unbound (term_kr, rl_forward); 408 _rl_bind_if_unbound (term_kl, rl_backward); 409 410 _rl_bind_if_unbound (term_kh, rl_beg_of_line); /* Home */ 411 _rl_bind_if_unbound (term_kH, rl_end_of_line); /* End */ 412#endif /* VI_MODE */ 413 414 _rl_keymap = xkeymap; 415
| 398 _rl_term_autowrap = tgetflag ("am") && tgetflag ("xn"); 399 400 _rl_get_screen_size (tty, 0); 401 402 /* "An application program can assume that the terminal can do 403 character insertion if *any one of* the capabilities `IC', 404 `im', `ic' or `ip' is provided." But we can't do anything if 405 only `ip' is provided, so... */ 406 terminal_can_insert = (term_IC || term_im || term_ic); 407 408 /* Check to see if this terminal has a meta key and clear the capability 409 variables if there is none. */ 410 term_has_meta = (tgetflag ("km") || tgetflag ("MT")); 411 if (!term_has_meta) 412 term_mm = term_mo = (char *)NULL; 413 414 /* Attempt to find and bind the arrow keys. Do not override already 415 bound keys in an overzealous attempt, however. */ 416 xkeymap = _rl_keymap; 417 418 _rl_keymap = emacs_standard_keymap; 419 _rl_bind_if_unbound (term_ku, rl_get_previous_history); 420 _rl_bind_if_unbound (term_kd, rl_get_next_history); 421 _rl_bind_if_unbound (term_kr, rl_forward); 422 _rl_bind_if_unbound (term_kl, rl_backward); 423 424 _rl_bind_if_unbound (term_kh, rl_beg_of_line); /* Home */ 425 _rl_bind_if_unbound (term_kH, rl_end_of_line); /* End */ 426 427#if defined (VI_MODE) 428 _rl_keymap = vi_movement_keymap; 429 _rl_bind_if_unbound (term_ku, rl_get_previous_history); 430 _rl_bind_if_unbound (term_kd, rl_get_next_history); 431 _rl_bind_if_unbound (term_kr, rl_forward); 432 _rl_bind_if_unbound (term_kl, rl_backward); 433 434 _rl_bind_if_unbound (term_kh, rl_beg_of_line); /* Home */ 435 _rl_bind_if_unbound (term_kH, rl_end_of_line); /* End */ 436#endif /* VI_MODE */ 437 438 _rl_keymap = xkeymap; 439
|
416#endif /* !__GO32__ */
| |
417 return 0; 418} 419 420char * 421rl_get_termcap (cap) 422 char *cap; 423{ 424 register int i; 425 426 if (tcap_initialized == 0) 427 return ((char *)NULL); 428 for (i = 0; i < NUM_TC_STRINGS; i++) 429 { 430 if (tc_strings[i].tc_var[0] == cap[0] && strcmp (tc_strings[i].tc_var, cap) == 0) 431 return *(tc_strings[i].tc_value); 432 } 433 return ((char *)NULL); 434} 435 436/* Re-initialize the terminal considering that the TERM/TERMCAP variable 437 has changed. */ 438int 439rl_reset_terminal (terminal_name) 440 char *terminal_name; 441{ 442 _rl_init_terminal_io (terminal_name); 443 return 0; 444} 445 446/* A function for the use of tputs () */ 447#ifdef _MINIX 448void 449_rl_output_character_function (c) 450 int c; 451{ 452 putc (c, _rl_out_stream); 453} 454#else /* !_MINIX */ 455int 456_rl_output_character_function (c) 457 int c; 458{ 459 return putc (c, _rl_out_stream); 460} 461#endif /* !_MINIX */
| 440 return 0; 441} 442 443char * 444rl_get_termcap (cap) 445 char *cap; 446{ 447 register int i; 448 449 if (tcap_initialized == 0) 450 return ((char *)NULL); 451 for (i = 0; i < NUM_TC_STRINGS; i++) 452 { 453 if (tc_strings[i].tc_var[0] == cap[0] && strcmp (tc_strings[i].tc_var, cap) == 0) 454 return *(tc_strings[i].tc_value); 455 } 456 return ((char *)NULL); 457} 458 459/* Re-initialize the terminal considering that the TERM/TERMCAP variable 460 has changed. */ 461int 462rl_reset_terminal (terminal_name) 463 char *terminal_name; 464{ 465 _rl_init_terminal_io (terminal_name); 466 return 0; 467} 468 469/* A function for the use of tputs () */ 470#ifdef _MINIX 471void 472_rl_output_character_function (c) 473 int c; 474{ 475 putc (c, _rl_out_stream); 476} 477#else /* !_MINIX */ 478int 479_rl_output_character_function (c) 480 int c; 481{ 482 return putc (c, _rl_out_stream); 483} 484#endif /* !_MINIX */
|
| 485
|
462/* Write COUNT characters from STRING to the output stream. */ 463void 464_rl_output_some_chars (string, count) 465 char *string; 466 int count; 467{ 468 fwrite (string, 1, count, _rl_out_stream); 469} 470 471/* Move the cursor back. */ 472int 473_rl_backspace (count) 474 int count; 475{ 476 register int i; 477
| 486/* Write COUNT characters from STRING to the output stream. */ 487void 488_rl_output_some_chars (string, count) 489 char *string; 490 int count; 491{ 492 fwrite (string, 1, count, _rl_out_stream); 493} 494 495/* Move the cursor back. */ 496int 497_rl_backspace (count) 498 int count; 499{ 500 register int i; 501
|
478#if !defined (__GO32__)
| |
479 if (term_backspace) 480 for (i = 0; i < count; i++) 481 tputs (term_backspace, 1, _rl_output_character_function); 482 else
| 502 if (term_backspace) 503 for (i = 0; i < count; i++) 504 tputs (term_backspace, 1, _rl_output_character_function); 505 else
|
483#endif /* !__GO32__ */
| |
484 for (i = 0; i < count; i++) 485 putc ('\b', _rl_out_stream); 486 return 0; 487} 488 489/* Move to the start of the next line. */ 490int 491crlf () 492{ 493#if defined (NEW_TTY_DRIVER) 494 if (term_cr) 495 tputs (term_cr, 1, _rl_output_character_function); 496#endif /* NEW_TTY_DRIVER */ 497 putc ('\n', _rl_out_stream); 498 return 0; 499} 500 501/* Ring the terminal bell. */ 502int 503ding () 504{ 505 if (readline_echoing_p) 506 {
| 506 for (i = 0; i < count; i++) 507 putc ('\b', _rl_out_stream); 508 return 0; 509} 510 511/* Move to the start of the next line. */ 512int 513crlf () 514{ 515#if defined (NEW_TTY_DRIVER) 516 if (term_cr) 517 tputs (term_cr, 1, _rl_output_character_function); 518#endif /* NEW_TTY_DRIVER */ 519 putc ('\n', _rl_out_stream); 520 return 0; 521} 522 523/* Ring the terminal bell. */ 524int 525ding () 526{ 527 if (readline_echoing_p) 528 {
|
507#if !defined (__GO32__)
| |
508 switch (_rl_bell_preference) 509 { 510 case NO_BELL: 511 default: 512 break; 513 case VISIBLE_BELL: 514 if (visible_bell) 515 { 516 tputs (visible_bell, 1, _rl_output_character_function); 517 break; 518 } 519 /* FALLTHROUGH */ 520 case AUDIBLE_BELL: 521 fprintf (stderr, "\007"); 522 fflush (stderr); 523 break; 524 }
| 529 switch (_rl_bell_preference) 530 { 531 case NO_BELL: 532 default: 533 break; 534 case VISIBLE_BELL: 535 if (visible_bell) 536 { 537 tputs (visible_bell, 1, _rl_output_character_function); 538 break; 539 } 540 /* FALLTHROUGH */ 541 case AUDIBLE_BELL: 542 fprintf (stderr, "\007"); 543 fflush (stderr); 544 break; 545 }
|
525#else /* __GO32__ */ 526 fprintf (stderr, "\007"); 527 fflush (stderr); 528#endif /* __GO32__ */
| |
529 return (0); 530 } 531 return (-1); 532} 533 534/* **************************************************************** */ 535/* */ 536/* Controlling the Meta Key and Keypad */ 537/* */ 538/* **************************************************************** */ 539 540void 541_rl_enable_meta_key () 542{
| 546 return (0); 547 } 548 return (-1); 549} 550 551/* **************************************************************** */ 552/* */ 553/* Controlling the Meta Key and Keypad */ 554/* */ 555/* **************************************************************** */ 556 557void 558_rl_enable_meta_key () 559{
|
| 560#if !defined (__DJGPP__)
|
543 if (term_has_meta && term_mm) 544 tputs (term_mm, 1, _rl_output_character_function);
| 561 if (term_has_meta && term_mm) 562 tputs (term_mm, 1, _rl_output_character_function);
|
| 563#endif
|
545} 546 547void 548_rl_control_keypad (on) 549 int on; 550{
| 564} 565 566void 567_rl_control_keypad (on) 568 int on; 569{
|
| 570#if !defined (__DJGPP__)
|
551 if (on && term_ks) 552 tputs (term_ks, 1, _rl_output_character_function); 553 else if (!on && term_ke) 554 tputs (term_ke, 1, _rl_output_character_function);
| 571 if (on && term_ks) 572 tputs (term_ks, 1, _rl_output_character_function); 573 else if (!on && term_ke) 574 tputs (term_ke, 1, _rl_output_character_function);
|
| 575#endif
|
555}
| 576}
|