Deleted Added
full compact
1/* $FreeBSD: head/contrib/libreadline/terminal.c 75409 2001-04-11 03:15:56Z ache $ */
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

--- 5 unchanged lines hidden (view full) ---

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,
22 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
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"

--- 29 unchanged lines hidden (view full) ---

60#include "tcap.h"
61
62/* Some standard library routines. */
63#include "readline.h"
64#include "history.h"
65
66#include "rlprivate.h"
67#include "rlshell.h"
68
69/* **************************************************************** */
70/* */
71/* Terminal and Termcap */
72/* */
73/* **************************************************************** */
74
75static char *term_buffer = (char *)NULL;
76static char *term_string_buffer = (char *)NULL;

--- 58 unchanged lines hidden (view full) ---

135
136/* How to initialize and reset the arrow keys, if this terminal has any. */
137static char *_rl_term_ks;
138static char *_rl_term_ke;
139
140/* The key sequences sent by the Home and End keys, if any. */
141static char *_rl_term_kh;
142static char *_rl_term_kH;
143
144/* Variables that hold the screen dimensions, used by the display code. */
145int _rl_screenwidth, _rl_screenheight, _rl_screenchars;
146
147/* Non-zero means the user wants to enable the keypad. */
148int _rl_enable_keypad;
149
150/* Non-zero means the user wants to enable a meta key. */
151int _rl_enable_meta = 1;

--- 117 unchanged lines hidden (view full) ---

269}
270
271void
272rl_resize_terminal ()
273{
274 if (readline_echoing_p)
275 {
276 _rl_get_screen_size (fileno (rl_instream), 1);
277 _rl_redisplay_after_sigwinch ();
278 }
279}
280
281struct _tc_string {
282 const char *tc_var;
283 char **tc_value;
284};
285
286/* This should be kept sorted, just in case we decide to change the
287 search algorithm to something smarter. */
288static struct _tc_string tc_strings[] =
289{
290 { "DC", &_rl_term_DC },
291 { "IC", &_rl_term_IC },
292 { "ce", &_rl_term_clreol },
293 { "cl", &_rl_term_clrpag },
294 { "cr", &_rl_term_cr },
295 { "dc", &_rl_term_dc },
296 { "ei", &_rl_term_ei },
297 { "ic", &_rl_term_ic },
298 { "im", &_rl_term_im },
299 { "kd", &_rl_term_kd },
300 { "kh", &_rl_term_kh }, /* home */
301 { "@7", &_rl_term_kH }, /* end */
302 { "kl", &_rl_term_kl },
303 { "kr", &_rl_term_kr },
304 { "ku", &_rl_term_ku },
305 { "ks", &_rl_term_ks },
306 { "ke", &_rl_term_ke },
307 { "le", &_rl_term_backspace },
308 { "mm", &_rl_term_mm },
309 { "mo", &_rl_term_mo },
310#if defined (HACK_TERMCAP_MOTION)
311 { "nd", &_rl_term_forward_char },
312#endif
313 { "pc", &_rl_term_pc },
314 { "up", &_rl_term_up },
315 { "vb", &_rl_visible_bell },
316};
317
318#define NUM_TC_STRINGS (sizeof (tc_strings) / sizeof (struct _tc_string))
319
320/* Read the desired terminal capability strings into BP. The capabilities
321 are described in the TC_STRINGS table. */
322static void
323get_term_capabilities (bp)
324 char **bp;
325{
326#if !defined (__DJGPP__) /* XXX - doesn't DJGPP have a termcap library? */
327 register int i;
328
329 for (i = 0; i < NUM_TC_STRINGS; i++)
330 *(tc_strings[i].tc_value) = tgetstr (tc_strings[i].tc_var, bp);
331#endif
332 tcap_initialized = 1;
333}
334
335#define CUSTOM_REDISPLAY_FUNC() (rl_redisplay_function != rl_redisplay)
336#define CUSTOM_INPUT_FUNC() (rl_getc_function != rl_getc)
337
338int
339_rl_init_terminal_io (terminal_name)
340 const char *terminal_name;
341{
342 const char *term;
343 char *buffer;
344 int tty, tgetent_ret;
345 Keymap xkeymap;
346
347 term = terminal_name ? terminal_name : sh_get_env_value ("TERM");
348 _rl_term_clrpag = _rl_term_cr = _rl_term_clreol = (char *)NULL;
349 tty = rl_instream ? fileno (rl_instream) : 0;
350 _rl_screenwidth = _rl_screenheight = 0;
351
352 if (term == 0)
353 term = "dumb";
354
355 /* I've separated this out for later work on not calling tgetent at all
356 if the calling application has supplied a custom redisplay function,
357 (and possibly if the application has supplied a custom input function). */
358 if (CUSTOM_REDISPLAY_FUNC())
359 {
360 tgetent_ret = -1;
361 }
362 else
363 {
364 if (term_string_buffer == 0)
365 term_string_buffer = xmalloc(2032);
366
367 if (term_buffer == 0)
368 term_buffer = xmalloc(4080);
369
370 buffer = term_string_buffer;
371
372 tgetent_ret = tgetent (term_buffer, term);
373 }
374
375 if (tgetent_ret <= 0)
376 {

--- 18 unchanged lines hidden (view full) ---

395 }
396
397 /* Everything below here is used by the redisplay code (tputs). */
398 _rl_screenchars = _rl_screenwidth * _rl_screenheight;
399 _rl_term_cr = "\r";
400 _rl_term_im = _rl_term_ei = _rl_term_ic = _rl_term_IC = (char *)NULL;
401 _rl_term_up = _rl_term_dc = _rl_term_DC = _rl_visible_bell = (char *)NULL;
402 _rl_term_ku = _rl_term_kd = _rl_term_kl = _rl_term_kr = (char *)NULL;
403 _rl_term_mm = _rl_term_mo = (char *)NULL;
404#if defined (HACK_TERMCAP_MOTION)
405 term_forward_char = (char *)NULL;
406#endif
407 _rl_terminal_can_insert = term_has_meta = 0;
408
409 /* Reasonable defaults for tgoto(). Readline currently only uses
410 tgoto if _rl_term_IC or _rl_term_DC is defined, but just in case we
411 change that later... */

--- 28 unchanged lines hidden (view full) ---

440 /* Check to see if this terminal has a meta key and clear the capability
441 variables if there is none. */
442 term_has_meta = (tgetflag ("km") || tgetflag ("MT"));
443 if (!term_has_meta)
444 _rl_term_mm = _rl_term_mo = (char *)NULL;
445
446 /* Attempt to find and bind the arrow keys. Do not override already
447 bound keys in an overzealous attempt, however. */
448 xkeymap = _rl_keymap;
449
450 _rl_keymap = emacs_standard_keymap;
451 _rl_bind_if_unbound (_rl_term_ku, rl_get_previous_history);
452 _rl_bind_if_unbound (_rl_term_kd, rl_get_next_history);
453 _rl_bind_if_unbound (_rl_term_kr, rl_forward);
454 _rl_bind_if_unbound (_rl_term_kl, rl_backward);
455
456 _rl_bind_if_unbound (_rl_term_kh, rl_beg_of_line); /* Home */
457 _rl_bind_if_unbound (_rl_term_kH, rl_end_of_line); /* End */
458
459#if defined (VI_MODE)
460 _rl_keymap = vi_movement_keymap;
461 _rl_bind_if_unbound (_rl_term_ku, rl_get_previous_history);
462 _rl_bind_if_unbound (_rl_term_kd, rl_get_next_history);
463 _rl_bind_if_unbound (_rl_term_kr, rl_forward);
464 _rl_bind_if_unbound (_rl_term_kl, rl_backward);
465
466 _rl_bind_if_unbound (_rl_term_kh, rl_beg_of_line); /* Home */
467 _rl_bind_if_unbound (_rl_term_kH, rl_end_of_line); /* End */
468#endif /* VI_MODE */
469
470 _rl_keymap = xkeymap;
471
472 return 0;
473}
474
475char *
476rl_get_termcap (cap)
477 const char *cap;
478{
479 register int i;
480

--- 120 unchanged lines hidden (view full) ---

601{
602#if !defined (__DJGPP__)
603 if (on && _rl_term_ks)
604 tputs (_rl_term_ks, 1, _rl_output_character_function);
605 else if (!on && _rl_term_ke)
606 tputs (_rl_term_ke, 1, _rl_output_character_function);
607#endif
608}