2017-01-30 23:00:51 +00:00
|
|
|
/* $NetBSD: terminal.c,v 1.24 2016/03/22 01:38:17 christos Exp $ */
|
2015-01-09 07:40:56 +00:00
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Christos Zoulas of Cornell University.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2005-08-07 20:55:59 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-27 05:00:24 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
#include "config.h"
|
1994-05-27 05:00:24 +00:00
|
|
|
#if !defined(lint) && !defined(SCCSID)
|
2015-01-09 07:40:56 +00:00
|
|
|
#if 0
|
1995-10-22 18:49:04 +00:00
|
|
|
static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
|
2015-01-09 07:40:56 +00:00
|
|
|
#else
|
2017-01-30 23:00:51 +00:00
|
|
|
__RCSID("$NetBSD: terminal.c,v 1.24 2016/03/22 01:38:17 christos Exp $");
|
2015-01-09 07:40:56 +00:00
|
|
|
#endif
|
1994-05-27 05:00:24 +00:00
|
|
|
#endif /* not lint && not SCCSID */
|
2001-10-01 08:41:27 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
/*
|
2015-01-09 07:40:56 +00:00
|
|
|
* terminal.c: Editor/termcap-curses interface
|
|
|
|
* We have to declare a static variable here, since the
|
|
|
|
* termcap putchar routine does not take an argument!
|
1994-05-27 05:00:24 +00:00
|
|
|
*/
|
2017-01-30 22:11:53 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <limits.h>
|
2016-03-06 21:32:54 +00:00
|
|
|
#include <signal.h>
|
2017-01-30 22:11:53 +00:00
|
|
|
#include <stdio.h>
|
2016-03-06 21:32:54 +00:00
|
|
|
#include <stdlib.h>
|
2017-01-30 22:11:53 +00:00
|
|
|
#include <string.h>
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <unistd.h>
|
2015-01-09 07:40:56 +00:00
|
|
|
#ifdef HAVE_TERMCAP_H
|
1995-08-04 09:26:10 +00:00
|
|
|
#include <termcap.h>
|
2015-01-09 07:40:56 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_CURSES_H
|
2005-08-07 20:55:59 +00:00
|
|
|
#include <curses.h>
|
2015-01-09 07:40:56 +00:00
|
|
|
#elif HAVE_NCURSES_H
|
2005-08-07 20:55:59 +00:00
|
|
|
#include <ncurses.h>
|
2015-01-09 07:40:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Solaris's term.h does horrid things. */
|
|
|
|
#if defined(HAVE_TERM_H) && !defined(__sun) && !defined(HAVE_TERMCAP_H)
|
2005-08-07 20:55:59 +00:00
|
|
|
#include <term.h>
|
2015-01-09 07:40:56 +00:00
|
|
|
#endif
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
#ifdef _REENTRANT
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
#include "el.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IMPORTANT NOTE: these routines are allowed to look at the current screen
|
2015-01-09 07:40:56 +00:00
|
|
|
* and the current position assuming that it is correct. If this is not
|
1994-05-27 05:00:24 +00:00
|
|
|
* true, then the update will be WRONG! This is (should be) a valid
|
|
|
|
* assumption...
|
|
|
|
*/
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
#define TC_BUFSIZE ((size_t)2048)
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
#define GoodStr(a) (el->el_terminal.t_str[a] != NULL && \
|
|
|
|
el->el_terminal.t_str[a][0] != '\0')
|
|
|
|
#define Str(a) el->el_terminal.t_str[a]
|
|
|
|
#define Val(a) el->el_terminal.t_val[a]
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
private const struct termcapstr {
|
|
|
|
const char *name;
|
|
|
|
const char *long_name;
|
|
|
|
} tstr[] = {
|
|
|
|
#define T_al 0
|
|
|
|
{ "al", "add new blank line" },
|
|
|
|
#define T_bl 1
|
|
|
|
{ "bl", "audible bell" },
|
|
|
|
#define T_cd 2
|
|
|
|
{ "cd", "clear to bottom" },
|
|
|
|
#define T_ce 3
|
|
|
|
{ "ce", "clear to end of line" },
|
|
|
|
#define T_ch 4
|
|
|
|
{ "ch", "cursor to horiz pos" },
|
|
|
|
#define T_cl 5
|
|
|
|
{ "cl", "clear screen" },
|
1994-05-27 05:00:24 +00:00
|
|
|
#define T_dc 6
|
2001-10-01 08:41:27 +00:00
|
|
|
{ "dc", "delete a character" },
|
1994-05-27 05:00:24 +00:00
|
|
|
#define T_dl 7
|
2001-10-01 08:41:27 +00:00
|
|
|
{ "dl", "delete a line" },
|
1994-05-27 05:00:24 +00:00
|
|
|
#define T_dm 8
|
2001-10-01 08:41:27 +00:00
|
|
|
{ "dm", "start delete mode" },
|
1994-05-27 05:00:24 +00:00
|
|
|
#define T_ed 9
|
2001-10-01 08:41:27 +00:00
|
|
|
{ "ed", "end delete mode" },
|
1994-05-27 05:00:24 +00:00
|
|
|
#define T_ei 10
|
2001-10-01 08:41:27 +00:00
|
|
|
{ "ei", "end insert mode" },
|
1994-05-27 05:00:24 +00:00
|
|
|
#define T_fs 11
|
2001-10-01 08:41:27 +00:00
|
|
|
{ "fs", "cursor from status line" },
|
1994-05-27 05:00:24 +00:00
|
|
|
#define T_ho 12
|
2001-10-01 08:41:27 +00:00
|
|
|
{ "ho", "home cursor" },
|
1994-05-27 05:00:24 +00:00
|
|
|
#define T_ic 13
|
2001-10-01 08:41:27 +00:00
|
|
|
{ "ic", "insert character" },
|
1995-05-30 05:51:47 +00:00
|
|
|
#define T_im 14
|
2001-10-01 08:41:27 +00:00
|
|
|
{ "im", "start insert mode" },
|
1994-05-27 05:00:24 +00:00
|
|
|
#define T_ip 15
|
2001-10-01 08:41:27 +00:00
|
|
|
{ "ip", "insert padding" },
|
1994-05-27 05:00:24 +00:00
|
|
|
#define T_kd 16
|
2001-10-01 08:41:27 +00:00
|
|
|
{ "kd", "sends cursor down" },
|
1994-05-27 05:00:24 +00:00
|
|
|
#define T_kl 17
|
2001-10-01 08:41:27 +00:00
|
|
|
{ "kl", "sends cursor left" },
|
|
|
|
#define T_kr 18
|
|
|
|
{ "kr", "sends cursor right" },
|
|
|
|
#define T_ku 19
|
|
|
|
{ "ku", "sends cursor up" },
|
|
|
|
#define T_md 20
|
|
|
|
{ "md", "begin bold" },
|
|
|
|
#define T_me 21
|
|
|
|
{ "me", "end attributes" },
|
|
|
|
#define T_nd 22
|
|
|
|
{ "nd", "non destructive space" },
|
|
|
|
#define T_se 23
|
|
|
|
{ "se", "end standout" },
|
|
|
|
#define T_so 24
|
|
|
|
{ "so", "begin standout" },
|
|
|
|
#define T_ts 25
|
|
|
|
{ "ts", "cursor to status line" },
|
|
|
|
#define T_up 26
|
|
|
|
{ "up", "cursor up one" },
|
|
|
|
#define T_us 27
|
|
|
|
{ "us", "begin underline" },
|
|
|
|
#define T_ue 28
|
|
|
|
{ "ue", "end underline" },
|
|
|
|
#define T_vb 29
|
|
|
|
{ "vb", "visible bell" },
|
|
|
|
#define T_DC 30
|
|
|
|
{ "DC", "delete multiple chars" },
|
|
|
|
#define T_DO 31
|
|
|
|
{ "DO", "cursor down multiple" },
|
|
|
|
#define T_IC 32
|
|
|
|
{ "IC", "insert multiple chars" },
|
|
|
|
#define T_LE 33
|
|
|
|
{ "LE", "cursor left multiple" },
|
|
|
|
#define T_RI 34
|
|
|
|
{ "RI", "cursor right multiple" },
|
|
|
|
#define T_UP 35
|
|
|
|
{ "UP", "cursor up multiple" },
|
|
|
|
#define T_kh 36
|
|
|
|
{ "kh", "send cursor home" },
|
|
|
|
#define T_at7 37
|
|
|
|
{ "@7", "send cursor end" },
|
2010-09-05 16:12:10 +00:00
|
|
|
#define T_kD 38
|
|
|
|
{ "kD", "send cursor delete" },
|
|
|
|
#define T_str 39
|
2001-10-01 08:41:27 +00:00
|
|
|
{ NULL, NULL }
|
1994-05-27 05:00:24 +00:00
|
|
|
};
|
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
private const struct termcapval {
|
|
|
|
const char *name;
|
|
|
|
const char *long_name;
|
1994-05-27 05:00:24 +00:00
|
|
|
} tval[] = {
|
2001-10-01 08:41:27 +00:00
|
|
|
#define T_am 0
|
|
|
|
{ "am", "has automatic margins" },
|
|
|
|
#define T_pt 1
|
|
|
|
{ "pt", "has physical tabs" },
|
|
|
|
#define T_li 2
|
|
|
|
{ "li", "Number of lines" },
|
|
|
|
#define T_co 3
|
|
|
|
{ "co", "Number of columns" },
|
|
|
|
#define T_km 4
|
|
|
|
{ "km", "Has meta key" },
|
|
|
|
#define T_xt 5
|
|
|
|
{ "xt", "Tab chars destructive" },
|
|
|
|
#define T_xn 6
|
|
|
|
{ "xn", "newline ignored at right margin" },
|
|
|
|
#define T_MT 7
|
|
|
|
{ "MT", "Has meta key" }, /* XXX? */
|
|
|
|
#define T_val 8
|
|
|
|
{ NULL, NULL, }
|
1994-05-27 05:00:24 +00:00
|
|
|
};
|
|
|
|
/* do two or more of the attributes use me */
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
private void terminal_setflags(EditLine *);
|
|
|
|
private int terminal_rebuffer_display(EditLine *);
|
|
|
|
private void terminal_free_display(EditLine *);
|
|
|
|
private int terminal_alloc_display(EditLine *);
|
|
|
|
private void terminal_alloc(EditLine *, const struct termcapstr *,
|
|
|
|
const char *);
|
|
|
|
private void terminal_init_arrow(EditLine *);
|
|
|
|
private void terminal_reset_arrow(EditLine *);
|
|
|
|
private int terminal_putc(int);
|
|
|
|
private void terminal_tputs(EditLine *, const char *, int);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2012-06-22 18:01:22 +00:00
|
|
|
#ifdef _REENTRANT
|
2015-01-09 07:40:56 +00:00
|
|
|
private pthread_mutex_t terminal_mutex = PTHREAD_MUTEX_INITIALIZER;
|
2012-06-22 18:01:22 +00:00
|
|
|
#endif
|
2015-01-09 07:40:56 +00:00
|
|
|
private FILE *terminal_outfile = NULL;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_setflags():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Set the terminal capability flags
|
|
|
|
*/
|
|
|
|
private void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_setflags(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
EL_FLAGS = 0;
|
|
|
|
if (el->el_tty.t_tabs)
|
|
|
|
EL_FLAGS |= (Val(T_pt) && !Val(T_xt)) ? TERM_CAN_TAB : 0;
|
|
|
|
|
|
|
|
EL_FLAGS |= (Val(T_km) || Val(T_MT)) ? TERM_HAS_META : 0;
|
|
|
|
EL_FLAGS |= GoodStr(T_ce) ? TERM_CAN_CEOL : 0;
|
|
|
|
EL_FLAGS |= (GoodStr(T_dc) || GoodStr(T_DC)) ? TERM_CAN_DELETE : 0;
|
|
|
|
EL_FLAGS |= (GoodStr(T_im) || GoodStr(T_ic) || GoodStr(T_IC)) ?
|
|
|
|
TERM_CAN_INSERT : 0;
|
|
|
|
EL_FLAGS |= (GoodStr(T_up) || GoodStr(T_UP)) ? TERM_CAN_UP : 0;
|
|
|
|
EL_FLAGS |= Val(T_am) ? TERM_HAS_AUTO_MARGINS : 0;
|
|
|
|
EL_FLAGS |= Val(T_xn) ? TERM_HAS_MAGIC_MARGINS : 0;
|
|
|
|
|
|
|
|
if (GoodStr(T_me) && GoodStr(T_ue))
|
|
|
|
EL_FLAGS |= (strcmp(Str(T_me), Str(T_ue)) == 0) ?
|
|
|
|
TERM_CAN_ME : 0;
|
|
|
|
else
|
|
|
|
EL_FLAGS &= ~TERM_CAN_ME;
|
|
|
|
if (GoodStr(T_me) && GoodStr(T_se))
|
|
|
|
EL_FLAGS |= (strcmp(Str(T_me), Str(T_se)) == 0) ?
|
|
|
|
TERM_CAN_ME : 0;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_SCREEN
|
2001-10-01 08:41:27 +00:00
|
|
|
if (!EL_CAN_UP) {
|
|
|
|
(void) fprintf(el->el_errfile,
|
|
|
|
"WARNING: Your terminal cannot move up.\n");
|
|
|
|
(void) fprintf(el->el_errfile,
|
|
|
|
"Editing may be odd for long lines.\n");
|
|
|
|
}
|
|
|
|
if (!EL_CAN_CEOL)
|
|
|
|
(void) fprintf(el->el_errfile, "no clear EOL capability.\n");
|
|
|
|
if (!EL_CAN_DELETE)
|
|
|
|
(void) fprintf(el->el_errfile, "no delete char capability.\n");
|
|
|
|
if (!EL_CAN_INSERT)
|
|
|
|
(void) fprintf(el->el_errfile, "no insert char capability.\n");
|
1994-05-27 05:00:24 +00:00
|
|
|
#endif /* DEBUG_SCREEN */
|
|
|
|
}
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_init():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Initialize the terminal stuff
|
|
|
|
*/
|
|
|
|
protected int
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_init(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_terminal.t_buf = el_malloc(TC_BUFSIZE *
|
|
|
|
sizeof(*el->el_terminal.t_buf));
|
|
|
|
if (el->el_terminal.t_buf == NULL)
|
2017-01-30 22:11:53 +00:00
|
|
|
goto fail1;
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_terminal.t_cap = el_malloc(TC_BUFSIZE *
|
|
|
|
sizeof(*el->el_terminal.t_cap));
|
|
|
|
if (el->el_terminal.t_cap == NULL)
|
2017-01-30 22:11:53 +00:00
|
|
|
goto fail2;
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_terminal.t_fkey = el_malloc(A_K_NKEYS *
|
|
|
|
sizeof(*el->el_terminal.t_fkey));
|
|
|
|
if (el->el_terminal.t_fkey == NULL)
|
2017-01-30 22:11:53 +00:00
|
|
|
goto fail3;
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_terminal.t_loc = 0;
|
|
|
|
el->el_terminal.t_str = el_malloc(T_str *
|
|
|
|
sizeof(*el->el_terminal.t_str));
|
|
|
|
if (el->el_terminal.t_str == NULL)
|
2017-01-30 22:11:53 +00:00
|
|
|
goto fail4;
|
2015-01-09 07:40:56 +00:00
|
|
|
(void) memset(el->el_terminal.t_str, 0, T_str *
|
|
|
|
sizeof(*el->el_terminal.t_str));
|
|
|
|
el->el_terminal.t_val = el_malloc(T_val *
|
|
|
|
sizeof(*el->el_terminal.t_val));
|
|
|
|
if (el->el_terminal.t_val == NULL)
|
2017-01-30 22:11:53 +00:00
|
|
|
goto fail5;
|
2015-01-09 07:40:56 +00:00
|
|
|
(void) memset(el->el_terminal.t_val, 0, T_val *
|
|
|
|
sizeof(*el->el_terminal.t_val));
|
|
|
|
(void) terminal_set(el, NULL);
|
|
|
|
terminal_init_arrow(el);
|
|
|
|
return 0;
|
2017-01-30 22:11:53 +00:00
|
|
|
fail5:
|
|
|
|
free(el->el_terminal.t_str);
|
|
|
|
el->el_terminal.t_str = NULL;
|
|
|
|
fail4:
|
|
|
|
free(el->el_terminal.t_fkey);
|
|
|
|
el->el_terminal.t_fkey = NULL;
|
|
|
|
fail3:
|
|
|
|
free(el->el_terminal.t_cap);
|
|
|
|
el->el_terminal.t_cap = NULL;
|
|
|
|
fail2:
|
|
|
|
free(el->el_terminal.t_buf);
|
|
|
|
el->el_terminal.t_buf = NULL;
|
|
|
|
fail1:
|
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
2005-08-07 20:55:59 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_end():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Clean up the terminal stuff
|
|
|
|
*/
|
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_end(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
el_free(el->el_terminal.t_buf);
|
|
|
|
el->el_terminal.t_buf = NULL;
|
|
|
|
el_free(el->el_terminal.t_cap);
|
|
|
|
el->el_terminal.t_cap = NULL;
|
|
|
|
el->el_terminal.t_loc = 0;
|
|
|
|
el_free(el->el_terminal.t_str);
|
|
|
|
el->el_terminal.t_str = NULL;
|
|
|
|
el_free(el->el_terminal.t_val);
|
|
|
|
el->el_terminal.t_val = NULL;
|
|
|
|
el_free(el->el_terminal.t_fkey);
|
|
|
|
el->el_terminal.t_fkey = NULL;
|
|
|
|
terminal_free_display(el);
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_alloc():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Maintain a string pool for termcap strings
|
|
|
|
*/
|
|
|
|
private void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
char termbuf[TC_BUFSIZE];
|
2012-06-22 18:01:22 +00:00
|
|
|
size_t tlen, clen;
|
2015-01-09 07:40:56 +00:00
|
|
|
char **tlist = el->el_terminal.t_str;
|
2001-10-01 08:41:27 +00:00
|
|
|
char **tmp, **str = &tlist[t - tstr];
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
(void) memset(termbuf, 0, sizeof(termbuf));
|
2001-10-01 08:41:27 +00:00
|
|
|
if (cap == NULL || *cap == '\0') {
|
|
|
|
*str = NULL;
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
clen = strlen(cap);
|
|
|
|
|
|
|
|
tlen = *str == NULL ? 0 : strlen(*str);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* New string is shorter; no need to allocate space
|
|
|
|
*/
|
|
|
|
if (clen <= tlen) {
|
Merge the following changes from NetBSD:
chared.h 1.17, common.c 1.19, emacs.c 1.21, key.c 1.18, key.h 1.9, map.c 1.23,
term.c 1.42, term.h 1.17, vi.c 1.25:
# Print the actual eofc, instead of ^D\b\b.
# Change internal character decoding to prevent buffer oveflows.
key.c 1.19, key.h 1.10:
# move declaration to header file.
term.c 1.43:
# Coverity CID 806: Prevent NULL deref
term.c 1.44:
# Coverity CID 1668: Plug memory leak.
term.c 1.45:
# Fix compilation.
MFC after: 3 weeks
2007-03-11 18:30:22 +00:00
|
|
|
if (*str)
|
|
|
|
(void) strcpy(*str, cap); /* XXX strcpy is safe */
|
2001-10-01 08:41:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* New string is longer; see if we have enough space to append
|
|
|
|
*/
|
2015-01-09 07:40:56 +00:00
|
|
|
if (el->el_terminal.t_loc + 3 < TC_BUFSIZE) {
|
2001-10-01 08:41:27 +00:00
|
|
|
/* XXX strcpy is safe */
|
2015-01-09 07:40:56 +00:00
|
|
|
(void) strcpy(*str = &el->el_terminal.t_buf[
|
|
|
|
el->el_terminal.t_loc], cap);
|
|
|
|
el->el_terminal.t_loc += clen + 1; /* one for \0 */
|
2001-10-01 08:41:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Compact our buffer; no need to check compaction, cause we know it
|
|
|
|
* fits...
|
|
|
|
*/
|
|
|
|
tlen = 0;
|
|
|
|
for (tmp = tlist; tmp < &tlist[T_str]; tmp++)
|
2017-01-30 23:00:51 +00:00
|
|
|
if (*tmp != NULL && **tmp != '\0' && *tmp != *str) {
|
2001-10-01 08:41:27 +00:00
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
for (ptr = *tmp; *ptr != '\0'; termbuf[tlen++] = *ptr++)
|
|
|
|
continue;
|
|
|
|
termbuf[tlen++] = '\0';
|
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
memcpy(el->el_terminal.t_buf, termbuf, TC_BUFSIZE);
|
|
|
|
el->el_terminal.t_loc = tlen;
|
|
|
|
if (el->el_terminal.t_loc + 3 >= TC_BUFSIZE) {
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_errfile,
|
|
|
|
"Out of termcap string space.\n");
|
|
|
|
return;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
/* XXX strcpy is safe */
|
2015-01-09 07:40:56 +00:00
|
|
|
(void) strcpy(*str = &el->el_terminal.t_buf[el->el_terminal.t_loc],
|
|
|
|
cap);
|
|
|
|
el->el_terminal.t_loc += (size_t)clen + 1; /* one for \0 */
|
1994-05-27 05:00:24 +00:00
|
|
|
return;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_rebuffer_display():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Rebuffer the display after the screen changed size
|
|
|
|
*/
|
2001-10-01 08:41:27 +00:00
|
|
|
private int
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_rebuffer_display(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
coord_t *c = &el->el_terminal.t_size;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_free_display(el);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
c->h = Val(T_co);
|
|
|
|
c->v = Val(T_li);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
if (terminal_alloc_display(el) == -1)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_alloc_display():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Allocate a new display.
|
|
|
|
*/
|
2001-10-01 08:41:27 +00:00
|
|
|
private int
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_alloc_display(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
int i;
|
2015-01-09 07:40:56 +00:00
|
|
|
Char **b;
|
|
|
|
coord_t *c = &el->el_terminal.t_size;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
b = el_malloc(sizeof(*b) * (size_t)(c->v + 1));
|
2001-10-01 08:41:27 +00:00
|
|
|
if (b == NULL)
|
2017-01-30 22:11:53 +00:00
|
|
|
goto done;
|
2001-10-01 08:41:27 +00:00
|
|
|
for (i = 0; i < c->v; i++) {
|
2015-01-09 07:40:56 +00:00
|
|
|
b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1));
|
Merge the following changes from NetBSD:
chared.h 1.17, common.c 1.19, emacs.c 1.21, key.c 1.18, key.h 1.9, map.c 1.23,
term.c 1.42, term.h 1.17, vi.c 1.25:
# Print the actual eofc, instead of ^D\b\b.
# Change internal character decoding to prevent buffer oveflows.
key.c 1.19, key.h 1.10:
# move declaration to header file.
term.c 1.43:
# Coverity CID 806: Prevent NULL deref
term.c 1.44:
# Coverity CID 1668: Plug memory leak.
term.c 1.45:
# Fix compilation.
MFC after: 3 weeks
2007-03-11 18:30:22 +00:00
|
|
|
if (b[i] == NULL) {
|
|
|
|
while (--i >= 0)
|
2015-01-09 07:40:56 +00:00
|
|
|
el_free(b[i]);
|
|
|
|
el_free(b);
|
2017-01-30 22:11:53 +00:00
|
|
|
goto done;
|
Merge the following changes from NetBSD:
chared.h 1.17, common.c 1.19, emacs.c 1.21, key.c 1.18, key.h 1.9, map.c 1.23,
term.c 1.42, term.h 1.17, vi.c 1.25:
# Print the actual eofc, instead of ^D\b\b.
# Change internal character decoding to prevent buffer oveflows.
key.c 1.19, key.h 1.10:
# move declaration to header file.
term.c 1.43:
# Coverity CID 806: Prevent NULL deref
term.c 1.44:
# Coverity CID 1668: Plug memory leak.
term.c 1.45:
# Fix compilation.
MFC after: 3 weeks
2007-03-11 18:30:22 +00:00
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
b[c->v] = NULL;
|
|
|
|
el->el_display = b;
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
b = el_malloc(sizeof(*b) * (size_t)(c->v + 1));
|
2001-10-01 08:41:27 +00:00
|
|
|
if (b == NULL)
|
2017-01-30 22:11:53 +00:00
|
|
|
goto done;
|
2001-10-01 08:41:27 +00:00
|
|
|
for (i = 0; i < c->v; i++) {
|
2015-01-09 07:40:56 +00:00
|
|
|
b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1));
|
Merge the following changes from NetBSD:
chared.h 1.17, common.c 1.19, emacs.c 1.21, key.c 1.18, key.h 1.9, map.c 1.23,
term.c 1.42, term.h 1.17, vi.c 1.25:
# Print the actual eofc, instead of ^D\b\b.
# Change internal character decoding to prevent buffer oveflows.
key.c 1.19, key.h 1.10:
# move declaration to header file.
term.c 1.43:
# Coverity CID 806: Prevent NULL deref
term.c 1.44:
# Coverity CID 1668: Plug memory leak.
term.c 1.45:
# Fix compilation.
MFC after: 3 weeks
2007-03-11 18:30:22 +00:00
|
|
|
if (b[i] == NULL) {
|
|
|
|
while (--i >= 0)
|
2015-01-09 07:40:56 +00:00
|
|
|
el_free(b[i]);
|
|
|
|
el_free(b);
|
2017-01-30 22:11:53 +00:00
|
|
|
goto done;
|
Merge the following changes from NetBSD:
chared.h 1.17, common.c 1.19, emacs.c 1.21, key.c 1.18, key.h 1.9, map.c 1.23,
term.c 1.42, term.h 1.17, vi.c 1.25:
# Print the actual eofc, instead of ^D\b\b.
# Change internal character decoding to prevent buffer oveflows.
key.c 1.19, key.h 1.10:
# move declaration to header file.
term.c 1.43:
# Coverity CID 806: Prevent NULL deref
term.c 1.44:
# Coverity CID 1668: Plug memory leak.
term.c 1.45:
# Fix compilation.
MFC after: 3 weeks
2007-03-11 18:30:22 +00:00
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
b[c->v] = NULL;
|
|
|
|
el->el_vdisplay = b;
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
2017-01-30 22:11:53 +00:00
|
|
|
done:
|
|
|
|
terminal_free_display(el);
|
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_free_display():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Free the display buffers
|
|
|
|
*/
|
|
|
|
private void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_free_display(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
Char **b;
|
|
|
|
Char **bufp;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
b = el->el_display;
|
|
|
|
el->el_display = NULL;
|
|
|
|
if (b != NULL) {
|
|
|
|
for (bufp = b; *bufp != NULL; bufp++)
|
2015-01-09 07:40:56 +00:00
|
|
|
el_free(*bufp);
|
|
|
|
el_free(b);
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
b = el->el_vdisplay;
|
|
|
|
el->el_vdisplay = NULL;
|
|
|
|
if (b != NULL) {
|
|
|
|
for (bufp = b; *bufp != NULL; bufp++)
|
2015-01-09 07:40:56 +00:00
|
|
|
el_free(*bufp);
|
|
|
|
el_free(b);
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_move_to_line():
|
1994-05-27 05:00:24 +00:00
|
|
|
* move to line <where> (first line == 0)
|
2017-01-30 22:11:53 +00:00
|
|
|
* as efficiently as possible
|
1994-05-27 05:00:24 +00:00
|
|
|
*/
|
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_move_to_line(EditLine *el, int where)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
int del;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (where == el->el_cursor.v)
|
|
|
|
return;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
if (where > el->el_terminal.t_size.v) {
|
1994-05-27 05:00:24 +00:00
|
|
|
#ifdef DEBUG_SCREEN
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_errfile,
|
2017-01-30 22:11:53 +00:00
|
|
|
"%s: where is ridiculous: %d\r\n", __func__, where);
|
1994-05-27 05:00:24 +00:00
|
|
|
#endif /* DEBUG_SCREEN */
|
2001-10-01 08:41:27 +00:00
|
|
|
return;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
if ((del = where - el->el_cursor.v) > 0) {
|
|
|
|
while (del > 0) {
|
|
|
|
if (EL_HAS_AUTO_MARGINS &&
|
|
|
|
el->el_display[el->el_cursor.v][0] != '\0') {
|
2015-01-09 07:40:56 +00:00
|
|
|
size_t h = (size_t)
|
|
|
|
(el->el_terminal.t_size.h - 1);
|
|
|
|
#ifdef WIDECHAR
|
|
|
|
for (; h > 0 &&
|
|
|
|
el->el_display[el->el_cursor.v][h] ==
|
|
|
|
MB_FILL_CHAR;
|
|
|
|
h--)
|
|
|
|
continue;
|
|
|
|
#endif
|
2001-10-01 08:41:27 +00:00
|
|
|
/* move without newline */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_move_to_char(el, (int)h);
|
|
|
|
terminal_overwrite(el, &el->el_display
|
2012-06-22 18:01:22 +00:00
|
|
|
[el->el_cursor.v][el->el_cursor.h],
|
2015-01-09 07:40:56 +00:00
|
|
|
(size_t)(el->el_terminal.t_size.h -
|
2012-06-22 18:01:22 +00:00
|
|
|
el->el_cursor.h));
|
2001-10-01 08:41:27 +00:00
|
|
|
/* updates Cursor */
|
|
|
|
del--;
|
|
|
|
} else {
|
|
|
|
if ((del > 1) && GoodStr(T_DO)) {
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, tgoto(Str(T_DO), del,
|
2012-06-22 18:01:22 +00:00
|
|
|
del), del);
|
2001-10-01 08:41:27 +00:00
|
|
|
del = 0;
|
|
|
|
} else {
|
|
|
|
for (; del > 0; del--)
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal__putc(el, '\n');
|
2001-10-01 08:41:27 +00:00
|
|
|
/* because the \n will become \r\n */
|
|
|
|
el->el_cursor.h = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* del < 0 */
|
|
|
|
if (GoodStr(T_UP) && (-del > 1 || !GoodStr(T_up)))
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, tgoto(Str(T_UP), -del, -del), -del);
|
2001-10-01 08:41:27 +00:00
|
|
|
else {
|
|
|
|
if (GoodStr(T_up))
|
|
|
|
for (; del < 0; del++)
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_up), 1);
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_cursor.v = where;/* now where is here */
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_move_to_char():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Move to the character position specified
|
|
|
|
*/
|
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_move_to_char(EditLine *el, int where)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
int del, i;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
mc_again:
|
2001-10-01 08:41:27 +00:00
|
|
|
if (where == el->el_cursor.h)
|
|
|
|
return;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
if (where > el->el_terminal.t_size.h) {
|
1994-05-27 05:00:24 +00:00
|
|
|
#ifdef DEBUG_SCREEN
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_errfile,
|
2017-01-30 22:11:53 +00:00
|
|
|
"%s: where is ridiculous: %d\r\n", __func__, where);
|
1994-05-27 05:00:24 +00:00
|
|
|
#endif /* DEBUG_SCREEN */
|
2001-10-01 08:41:27 +00:00
|
|
|
return;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
if (!where) { /* if where is first column */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal__putc(el, '\r'); /* do a CR */
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_cursor.h = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
del = where - el->el_cursor.h;
|
|
|
|
|
|
|
|
if ((del < -4 || del > 4) && GoodStr(T_ch))
|
|
|
|
/* go there directly */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, tgoto(Str(T_ch), where, where), where);
|
2001-10-01 08:41:27 +00:00
|
|
|
else {
|
|
|
|
if (del > 0) { /* moving forward */
|
|
|
|
if ((del > 4) && GoodStr(T_RI))
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, tgoto(Str(T_RI), del, del),
|
|
|
|
del);
|
2001-10-01 08:41:27 +00:00
|
|
|
else {
|
|
|
|
/* if I can do tabs, use them */
|
|
|
|
if (EL_CAN_TAB) {
|
|
|
|
if ((el->el_cursor.h & 0370) !=
|
2015-01-09 07:40:56 +00:00
|
|
|
(where & ~0x7)
|
|
|
|
#ifdef WIDECHAR
|
|
|
|
&& (el->el_display[
|
|
|
|
el->el_cursor.v][where & 0370] !=
|
|
|
|
MB_FILL_CHAR)
|
|
|
|
#endif
|
|
|
|
) {
|
2001-10-01 08:41:27 +00:00
|
|
|
/* if not within tab stop */
|
|
|
|
for (i =
|
|
|
|
(el->el_cursor.h & 0370);
|
2012-06-22 18:01:22 +00:00
|
|
|
i < (where & ~0x7);
|
2001-10-01 08:41:27 +00:00
|
|
|
i += 8)
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal__putc(el,
|
2017-01-30 22:11:53 +00:00
|
|
|
'\t');
|
2001-10-01 08:41:27 +00:00
|
|
|
/* then tab over */
|
2012-06-22 18:01:22 +00:00
|
|
|
el->el_cursor.h = where & ~0x7;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* it's usually cheaper to just write the
|
|
|
|
* chars, so we do.
|
|
|
|
*/
|
|
|
|
/*
|
2015-01-09 07:40:56 +00:00
|
|
|
* NOTE THAT terminal_overwrite() WILL CHANGE
|
2001-10-01 08:41:27 +00:00
|
|
|
* el->el_cursor.h!!!
|
|
|
|
*/
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_overwrite(el, &el->el_display[
|
2012-06-22 18:01:22 +00:00
|
|
|
el->el_cursor.v][el->el_cursor.h],
|
|
|
|
(size_t)(where - el->el_cursor.h));
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
} else { /* del < 0 := moving backward */
|
|
|
|
if ((-del > 4) && GoodStr(T_LE))
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, tgoto(Str(T_LE), -del, -del),
|
2012-06-22 18:01:22 +00:00
|
|
|
-del);
|
2001-10-01 08:41:27 +00:00
|
|
|
else { /* can't go directly there */
|
|
|
|
/*
|
|
|
|
* if the "cost" is greater than the "cost"
|
|
|
|
* from col 0
|
|
|
|
*/
|
|
|
|
if (EL_CAN_TAB ?
|
2005-08-07 20:55:59 +00:00
|
|
|
((unsigned int)-del >
|
|
|
|
(((unsigned int) where >> 3) +
|
2001-10-01 08:41:27 +00:00
|
|
|
(where & 07)))
|
|
|
|
: (-del > where)) {
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal__putc(el, '\r');/* do a CR */
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_cursor.h = 0;
|
|
|
|
goto mc_again; /* and try again */
|
|
|
|
}
|
|
|
|
for (i = 0; i < -del; i++)
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal__putc(el, '\b');
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_cursor.h = where; /* now where is here */
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_overwrite():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Overstrike num characters
|
2015-01-09 07:40:56 +00:00
|
|
|
* Assumes MB_FILL_CHARs are present to keep the column count correct
|
1994-05-27 05:00:24 +00:00
|
|
|
*/
|
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_overwrite(EditLine *el, const Char *cp, size_t n)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2012-06-22 18:01:22 +00:00
|
|
|
if (n == 0)
|
|
|
|
return;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
if (n > (size_t)el->el_terminal.t_size.h) {
|
1994-05-27 05:00:24 +00:00
|
|
|
#ifdef DEBUG_SCREEN
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_errfile,
|
2017-01-30 23:00:51 +00:00
|
|
|
"%s: n is ridiculous: %zu\r\n", __func__, n);
|
1994-05-27 05:00:24 +00:00
|
|
|
#endif /* DEBUG_SCREEN */
|
2001-10-01 08:41:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-06-22 18:01:22 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
do {
|
|
|
|
/* terminal__putc() ignores any MB_FILL_CHARs */
|
|
|
|
terminal__putc(el, *cp++);
|
|
|
|
el->el_cursor.h++;
|
|
|
|
} while (--n);
|
2001-10-01 08:41:27 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
if (el->el_cursor.h >= el->el_terminal.t_size.h) { /* wrap? */
|
2001-10-01 08:41:27 +00:00
|
|
|
if (EL_HAS_AUTO_MARGINS) { /* yes */
|
|
|
|
el->el_cursor.h = 0;
|
|
|
|
el->el_cursor.v++;
|
|
|
|
if (EL_HAS_MAGIC_MARGINS) {
|
|
|
|
/* force the wrap to avoid the "magic"
|
|
|
|
* situation */
|
2015-01-09 07:40:56 +00:00
|
|
|
Char c;
|
|
|
|
if ((c = el->el_display[el->el_cursor.v]
|
|
|
|
[el->el_cursor.h]) != '\0') {
|
|
|
|
terminal_overwrite(el, &c, (size_t)1);
|
|
|
|
#ifdef WIDECHAR
|
|
|
|
while (el->el_display[el->el_cursor.v]
|
|
|
|
[el->el_cursor.h] == MB_FILL_CHAR)
|
|
|
|
el->el_cursor.h++;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
terminal__putc(el, ' ');
|
2012-06-22 18:01:22 +00:00
|
|
|
el->el_cursor.h = 1;
|
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
} else /* no wrap, but cursor stays on screen */
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_cursor.h = el->el_terminal.t_size.h - 1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_deletechars():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Delete num characters
|
|
|
|
*/
|
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_deletechars(EditLine *el, int num)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
if (num <= 0)
|
|
|
|
return;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (!EL_CAN_DELETE) {
|
1994-05-27 05:00:24 +00:00
|
|
|
#ifdef DEBUG_EDIT
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_errfile, " ERROR: cannot delete \n");
|
1994-05-27 05:00:24 +00:00
|
|
|
#endif /* DEBUG_EDIT */
|
2001-10-01 08:41:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
if (num > el->el_terminal.t_size.h) {
|
1994-05-27 05:00:24 +00:00
|
|
|
#ifdef DEBUG_SCREEN
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_errfile,
|
2017-01-30 22:11:53 +00:00
|
|
|
"%s: num is ridiculous: %d\r\n", __func__, num);
|
1994-05-27 05:00:24 +00:00
|
|
|
#endif /* DEBUG_SCREEN */
|
2001-10-01 08:41:27 +00:00
|
|
|
return;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
if (GoodStr(T_DC)) /* if I have multiple delete */
|
|
|
|
if ((num > 1) || !GoodStr(T_dc)) { /* if dc would be more
|
|
|
|
* expen. */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, tgoto(Str(T_DC), num, num), num);
|
2001-10-01 08:41:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (GoodStr(T_dm)) /* if I have delete mode */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_dm), 1);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (GoodStr(T_dc)) /* else do one at a time */
|
|
|
|
while (num--)
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_dc), 1);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (GoodStr(T_ed)) /* if I have delete mode */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_ed), 1);
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_insertwrite():
|
1995-05-30 05:51:47 +00:00
|
|
|
* Puts terminal in insert character mode or inserts num
|
|
|
|
* characters in the line
|
2015-01-09 07:40:56 +00:00
|
|
|
* Assumes MB_FILL_CHARs are present to keep column count correct
|
1994-05-27 05:00:24 +00:00
|
|
|
*/
|
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_insertwrite(EditLine *el, Char *cp, int num)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
if (num <= 0)
|
|
|
|
return;
|
|
|
|
if (!EL_CAN_INSERT) {
|
1994-05-27 05:00:24 +00:00
|
|
|
#ifdef DEBUG_EDIT
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_errfile, " ERROR: cannot insert \n");
|
1994-05-27 05:00:24 +00:00
|
|
|
#endif /* DEBUG_EDIT */
|
2001-10-01 08:41:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
if (num > el->el_terminal.t_size.h) {
|
1994-05-27 05:00:24 +00:00
|
|
|
#ifdef DEBUG_SCREEN
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_errfile,
|
2017-01-30 22:11:53 +00:00
|
|
|
"%s: num is ridiculous: %d\r\n", __func__, num);
|
1994-05-27 05:00:24 +00:00
|
|
|
#endif /* DEBUG_SCREEN */
|
2001-10-01 08:41:27 +00:00
|
|
|
return;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
if (GoodStr(T_IC)) /* if I have multiple insert */
|
|
|
|
if ((num > 1) || !GoodStr(T_ic)) {
|
|
|
|
/* if ic would be more expensive */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, tgoto(Str(T_IC), num, num), num);
|
|
|
|
terminal_overwrite(el, cp, (size_t)num);
|
2001-10-01 08:41:27 +00:00
|
|
|
/* this updates el_cursor.h */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (GoodStr(T_im) && GoodStr(T_ei)) { /* if I have insert mode */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_im), 1);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_cursor.h += num;
|
|
|
|
do
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal__putc(el, *cp++);
|
2001-10-01 08:41:27 +00:00
|
|
|
while (--num);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (GoodStr(T_ip)) /* have to make num chars insert */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_ip), 1);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_ei), 1);
|
2001-10-01 08:41:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
if (GoodStr(T_ic)) /* have to make num chars insert */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_ic), 1);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal__putc(el, *cp++);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_cursor.h++;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (GoodStr(T_ip)) /* have to make num chars insert */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_ip), 1);
|
2001-10-01 08:41:27 +00:00
|
|
|
/* pad the inserted char */
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
} while (--num);
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_clear_EOL():
|
1995-05-30 05:51:47 +00:00
|
|
|
* clear to end of line. There are num characters to clear
|
1994-05-27 05:00:24 +00:00
|
|
|
*/
|
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_clear_EOL(EditLine *el, int num)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
int i;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (EL_CAN_CEOL && GoodStr(T_ce))
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_ce), 1);
|
2001-10-01 08:41:27 +00:00
|
|
|
else {
|
|
|
|
for (i = 0; i < num; i++)
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal__putc(el, ' ');
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_cursor.h += num; /* have written num spaces */
|
|
|
|
}
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_clear_screen():
|
1995-05-30 05:51:47 +00:00
|
|
|
* Clear the screen
|
1994-05-27 05:00:24 +00:00
|
|
|
*/
|
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_clear_screen(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{ /* clear the whole screen and home */
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
if (GoodStr(T_cl))
|
|
|
|
/* send the clear screen code */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_cl), Val(T_li));
|
2001-10-01 08:41:27 +00:00
|
|
|
else if (GoodStr(T_ho) && GoodStr(T_cd)) {
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_ho), Val(T_li)); /* home */
|
2001-10-01 08:41:27 +00:00
|
|
|
/* clear to bottom of screen */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_cd), Val(T_li));
|
2001-10-01 08:41:27 +00:00
|
|
|
} else {
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal__putc(el, '\r');
|
|
|
|
terminal__putc(el, '\n');
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_beep():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Beep the way the terminal wants us
|
|
|
|
*/
|
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_beep(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
if (GoodStr(T_bl))
|
|
|
|
/* what termcap says we should use */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, Str(T_bl), 1);
|
2001-10-01 08:41:27 +00:00
|
|
|
else
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal__putc(el, '\007'); /* an ASCII bell; ^G */
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_get(EditLine *el, const char **term)
|
2005-08-07 20:55:59 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
*term = el->el_terminal.t_name;
|
2005-08-07 20:55:59 +00:00
|
|
|
}
|
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_set():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Read in the terminal capabilities from the requested terminal
|
|
|
|
*/
|
|
|
|
protected int
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_set(EditLine *el, const char *term)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
int i;
|
|
|
|
char buf[TC_BUFSIZE];
|
|
|
|
char *area;
|
|
|
|
const struct termcapstr *t;
|
|
|
|
sigset_t oset, nset;
|
|
|
|
int lins, cols;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) sigemptyset(&nset);
|
|
|
|
(void) sigaddset(&nset, SIGWINCH);
|
|
|
|
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
area = buf;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (term == NULL)
|
|
|
|
term = getenv("TERM");
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (!term || !term[0])
|
|
|
|
term = "dumb";
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (strcmp(term, "emacs") == 0)
|
|
|
|
el->el_flags |= EDIT_DISABLED;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
(void) memset(el->el_terminal.t_cap, 0, TC_BUFSIZE);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
i = tgetent(el->el_terminal.t_cap, term);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (i <= 0) {
|
|
|
|
if (i == -1)
|
|
|
|
(void) fprintf(el->el_errfile,
|
|
|
|
"Cannot read termcap database;\n");
|
|
|
|
else if (i == 0)
|
|
|
|
(void) fprintf(el->el_errfile,
|
|
|
|
"No entry for terminal type \"%s\";\n", term);
|
|
|
|
(void) fprintf(el->el_errfile,
|
|
|
|
"using dumb terminal settings.\n");
|
|
|
|
Val(T_co) = 80; /* do a dumb terminal */
|
|
|
|
Val(T_pt) = Val(T_km) = Val(T_li) = 0;
|
|
|
|
Val(T_xt) = Val(T_MT);
|
|
|
|
for (t = tstr; t->name != NULL; t++)
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_alloc(el, t, NULL);
|
2001-10-01 08:41:27 +00:00
|
|
|
} else {
|
|
|
|
/* auto/magic margins */
|
|
|
|
Val(T_am) = tgetflag("am");
|
|
|
|
Val(T_xn) = tgetflag("xn");
|
|
|
|
/* Can we tab */
|
|
|
|
Val(T_pt) = tgetflag("pt");
|
|
|
|
Val(T_xt) = tgetflag("xt");
|
|
|
|
/* do we have a meta? */
|
|
|
|
Val(T_km) = tgetflag("km");
|
|
|
|
Val(T_MT) = tgetflag("MT");
|
|
|
|
/* Get the size */
|
|
|
|
Val(T_co) = tgetnum("co");
|
|
|
|
Val(T_li) = tgetnum("li");
|
2005-08-07 20:55:59 +00:00
|
|
|
for (t = tstr; t->name != NULL; t++) {
|
2005-08-08 07:08:35 +00:00
|
|
|
/* XXX: some systems' tgetstr needs non const */
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_alloc(el, t, tgetstr(strchr(t->name, *t->name),
|
2005-08-07 20:55:59 +00:00
|
|
|
&area));
|
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (Val(T_co) < 2)
|
|
|
|
Val(T_co) = 80; /* just in case */
|
|
|
|
if (Val(T_li) < 1)
|
|
|
|
Val(T_li) = 24;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_terminal.t_size.v = Val(T_co);
|
|
|
|
el->el_terminal.t_size.h = Val(T_li);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_setflags(el);
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
/* get the correct window size */
|
2015-01-09 07:40:56 +00:00
|
|
|
(void) terminal_get_size(el, &lins, &cols);
|
|
|
|
if (terminal_change_size(el, lins, cols) == -1)
|
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_bind_arrow(el);
|
|
|
|
el->el_terminal.t_name = term;
|
|
|
|
return i <= 0 ? -1 : 0;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_get_size():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Return the new window size in lines and cols, and
|
1995-05-30 05:51:47 +00:00
|
|
|
* true if the size was changed.
|
1994-05-27 05:00:24 +00:00
|
|
|
*/
|
|
|
|
protected int
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_get_size(EditLine *el, int *lins, int *cols)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
*cols = Val(T_co);
|
|
|
|
*lins = Val(T_li);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
#ifdef TIOCGWINSZ
|
2001-10-01 08:41:27 +00:00
|
|
|
{
|
|
|
|
struct winsize ws;
|
2015-01-09 07:40:56 +00:00
|
|
|
if (ioctl(el->el_infd, TIOCGWINSZ, &ws) != -1) {
|
2001-10-01 08:41:27 +00:00
|
|
|
if (ws.ws_col)
|
|
|
|
*cols = ws.ws_col;
|
|
|
|
if (ws.ws_row)
|
|
|
|
*lins = ws.ws_row;
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef TIOCGSIZE
|
2001-10-01 08:41:27 +00:00
|
|
|
{
|
|
|
|
struct ttysize ts;
|
2015-01-09 07:40:56 +00:00
|
|
|
if (ioctl(el->el_infd, TIOCGSIZE, &ts) != -1) {
|
2001-10-01 08:41:27 +00:00
|
|
|
if (ts.ts_cols)
|
|
|
|
*cols = ts.ts_cols;
|
|
|
|
if (ts.ts_lines)
|
|
|
|
*lins = ts.ts_lines;
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-01-09 07:40:56 +00:00
|
|
|
return Val(T_co) != *cols || Val(T_li) != *lins;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_change_size():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Change the size of the terminal
|
|
|
|
*/
|
2001-10-01 08:41:27 +00:00
|
|
|
protected int
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_change_size(EditLine *el, int lins, int cols)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
/*
|
|
|
|
* Just in case
|
|
|
|
*/
|
|
|
|
Val(T_co) = (cols < 2) ? 80 : cols;
|
|
|
|
Val(T_li) = (lins < 1) ? 24 : lins;
|
|
|
|
|
|
|
|
/* re-make display buffers */
|
2015-01-09 07:40:56 +00:00
|
|
|
if (terminal_rebuffer_display(el) == -1)
|
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
re_clear_display(el);
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_init_arrow():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Initialize the arrow key bindings from termcap
|
|
|
|
*/
|
|
|
|
private void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_init_arrow(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
funckey_t *arrow = el->el_terminal.t_fkey;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
arrow[A_K_DN].name = STR("down");
|
2001-10-01 08:41:27 +00:00
|
|
|
arrow[A_K_DN].key = T_kd;
|
|
|
|
arrow[A_K_DN].fun.cmd = ED_NEXT_HISTORY;
|
|
|
|
arrow[A_K_DN].type = XK_CMD;
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
arrow[A_K_UP].name = STR("up");
|
2001-10-01 08:41:27 +00:00
|
|
|
arrow[A_K_UP].key = T_ku;
|
|
|
|
arrow[A_K_UP].fun.cmd = ED_PREV_HISTORY;
|
|
|
|
arrow[A_K_UP].type = XK_CMD;
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
arrow[A_K_LT].name = STR("left");
|
2001-10-01 08:41:27 +00:00
|
|
|
arrow[A_K_LT].key = T_kl;
|
|
|
|
arrow[A_K_LT].fun.cmd = ED_PREV_CHAR;
|
|
|
|
arrow[A_K_LT].type = XK_CMD;
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
arrow[A_K_RT].name = STR("right");
|
2001-10-01 08:41:27 +00:00
|
|
|
arrow[A_K_RT].key = T_kr;
|
|
|
|
arrow[A_K_RT].fun.cmd = ED_NEXT_CHAR;
|
|
|
|
arrow[A_K_RT].type = XK_CMD;
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
arrow[A_K_HO].name = STR("home");
|
2001-10-01 08:41:27 +00:00
|
|
|
arrow[A_K_HO].key = T_kh;
|
|
|
|
arrow[A_K_HO].fun.cmd = ED_MOVE_TO_BEG;
|
|
|
|
arrow[A_K_HO].type = XK_CMD;
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
arrow[A_K_EN].name = STR("end");
|
2001-10-01 08:41:27 +00:00
|
|
|
arrow[A_K_EN].key = T_at7;
|
|
|
|
arrow[A_K_EN].fun.cmd = ED_MOVE_TO_END;
|
|
|
|
arrow[A_K_EN].type = XK_CMD;
|
2010-09-05 16:12:10 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
arrow[A_K_DE].name = STR("delete");
|
2010-09-05 16:12:10 +00:00
|
|
|
arrow[A_K_DE].key = T_kD;
|
|
|
|
arrow[A_K_DE].fun.cmd = ED_DELETE_NEXT_CHAR;
|
|
|
|
arrow[A_K_DE].type = XK_CMD;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_reset_arrow():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Reset arrow key bindings
|
|
|
|
*/
|
|
|
|
private void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_reset_arrow(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
funckey_t *arrow = el->el_terminal.t_fkey;
|
|
|
|
static const Char strA[] = {033, '[', 'A', '\0'};
|
|
|
|
static const Char strB[] = {033, '[', 'B', '\0'};
|
|
|
|
static const Char strC[] = {033, '[', 'C', '\0'};
|
|
|
|
static const Char strD[] = {033, '[', 'D', '\0'};
|
|
|
|
static const Char strH[] = {033, '[', 'H', '\0'};
|
|
|
|
static const Char strF[] = {033, '[', 'F', '\0'};
|
|
|
|
static const Char stOA[] = {033, 'O', 'A', '\0'};
|
|
|
|
static const Char stOB[] = {033, 'O', 'B', '\0'};
|
|
|
|
static const Char stOC[] = {033, 'O', 'C', '\0'};
|
|
|
|
static const Char stOD[] = {033, 'O', 'D', '\0'};
|
|
|
|
static const Char stOH[] = {033, 'O', 'H', '\0'};
|
|
|
|
static const Char stOF[] = {033, 'O', 'F', '\0'};
|
|
|
|
|
|
|
|
keymacro_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
|
|
|
|
keymacro_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
|
|
|
|
keymacro_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
|
|
|
|
keymacro_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
|
|
|
|
keymacro_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
|
|
|
|
keymacro_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
|
|
|
|
keymacro_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
|
|
|
|
keymacro_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
|
|
|
|
keymacro_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
|
|
|
|
keymacro_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
|
|
|
|
keymacro_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
|
|
|
|
keymacro_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
|
|
|
|
|
|
|
|
if (el->el_map.type != MAP_VI)
|
|
|
|
return;
|
|
|
|
keymacro_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
|
|
|
|
keymacro_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
|
|
|
|
keymacro_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
|
|
|
|
keymacro_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
|
|
|
|
keymacro_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
|
|
|
|
keymacro_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
|
|
|
|
keymacro_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
|
|
|
|
keymacro_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
|
|
|
|
keymacro_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
|
|
|
|
keymacro_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
|
|
|
|
keymacro_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
|
|
|
|
keymacro_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_set_arrow():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Set an arrow key binding
|
|
|
|
*/
|
|
|
|
protected int
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_set_arrow(EditLine *el, const Char *name, keymacro_value_t *fun,
|
|
|
|
int type)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
funckey_t *arrow = el->el_terminal.t_fkey;
|
2001-10-01 08:41:27 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < A_K_NKEYS; i++)
|
2015-01-09 07:40:56 +00:00
|
|
|
if (Strcmp(name, arrow[i].name) == 0) {
|
2001-10-01 08:41:27 +00:00
|
|
|
arrow[i].fun = *fun;
|
|
|
|
arrow[i].type = type;
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_clear_arrow():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Clear an arrow key binding
|
|
|
|
*/
|
|
|
|
protected int
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_clear_arrow(EditLine *el, const Char *name)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
funckey_t *arrow = el->el_terminal.t_fkey;
|
2001-10-01 08:41:27 +00:00
|
|
|
int i;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
for (i = 0; i < A_K_NKEYS; i++)
|
2015-01-09 07:40:56 +00:00
|
|
|
if (Strcmp(name, arrow[i].name) == 0) {
|
2001-10-01 08:41:27 +00:00
|
|
|
arrow[i].type = XK_NOD;
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_print_arrow():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Print the arrow key bindings
|
|
|
|
*/
|
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_print_arrow(EditLine *el, const Char *name)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
int i;
|
2015-01-09 07:40:56 +00:00
|
|
|
funckey_t *arrow = el->el_terminal.t_fkey;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
for (i = 0; i < A_K_NKEYS; i++)
|
2015-01-09 07:40:56 +00:00
|
|
|
if (*name == '\0' || Strcmp(name, arrow[i].name) == 0)
|
2001-10-01 08:41:27 +00:00
|
|
|
if (arrow[i].type != XK_NOD)
|
2015-01-09 07:40:56 +00:00
|
|
|
keymacro_kprint(el, arrow[i].name,
|
|
|
|
&arrow[i].fun, arrow[i].type);
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_bind_arrow():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Bind the arrow keys
|
|
|
|
*/
|
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_bind_arrow(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
el_action_t *map;
|
|
|
|
const el_action_t *dmap;
|
|
|
|
int i, j;
|
|
|
|
char *p;
|
2015-01-09 07:40:56 +00:00
|
|
|
funckey_t *arrow = el->el_terminal.t_fkey;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
/* Check if the components needed are initialized */
|
2015-01-09 07:40:56 +00:00
|
|
|
if (el->el_terminal.t_buf == NULL || el->el_map.key == NULL)
|
2001-10-01 08:41:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
map = el->el_map.type == MAP_VI ? el->el_map.alt : el->el_map.key;
|
|
|
|
dmap = el->el_map.type == MAP_VI ? el->el_map.vic : el->el_map.emacs;
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_reset_arrow(el);
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
for (i = 0; i < A_K_NKEYS; i++) {
|
2015-01-09 07:40:56 +00:00
|
|
|
Char wt_str[VISUAL_WIDTH_MAX];
|
|
|
|
Char *px;
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
p = el->el_terminal.t_str[arrow[i].key];
|
|
|
|
if (!p || !*p)
|
|
|
|
continue;
|
|
|
|
for (n = 0; n < VISUAL_WIDTH_MAX && p[n]; ++n)
|
|
|
|
wt_str[n] = p[n];
|
|
|
|
while (n < VISUAL_WIDTH_MAX)
|
|
|
|
wt_str[n++] = '\0';
|
|
|
|
px = wt_str;
|
|
|
|
j = (unsigned char) *p;
|
|
|
|
/*
|
|
|
|
* Assign the arrow keys only if:
|
|
|
|
*
|
|
|
|
* 1. They are multi-character arrow keys and the user
|
|
|
|
* has not re-assigned the leading character, or
|
|
|
|
* has re-assigned the leading character to be
|
|
|
|
* ED_SEQUENCE_LEAD_IN
|
|
|
|
* 2. They are single arrow keys pointing to an
|
|
|
|
* unassigned key.
|
|
|
|
*/
|
|
|
|
if (arrow[i].type == XK_NOD)
|
|
|
|
keymacro_clear(el, map, px);
|
|
|
|
else {
|
|
|
|
if (p[1] && (dmap[j] == map[j] ||
|
|
|
|
map[j] == ED_SEQUENCE_LEAD_IN)) {
|
|
|
|
keymacro_add(el, px, &arrow[i].fun,
|
|
|
|
arrow[i].type);
|
|
|
|
map[j] = ED_SEQUENCE_LEAD_IN;
|
|
|
|
} else if (map[j] == ED_UNASSIGNED) {
|
|
|
|
keymacro_clear(el, map, px);
|
|
|
|
if (arrow[i].type == XK_CMD)
|
|
|
|
map[j] = arrow[i].fun.cmd;
|
|
|
|
else
|
|
|
|
keymacro_add(el, px, &arrow[i].fun,
|
2001-10-01 08:41:27 +00:00
|
|
|
arrow[i].type);
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_putc():
|
2012-06-22 18:01:22 +00:00
|
|
|
* Add a character
|
|
|
|
*/
|
|
|
|
private int
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_putc(int c)
|
2012-06-22 18:01:22 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
if (terminal_outfile == NULL)
|
2012-06-22 18:01:22 +00:00
|
|
|
return -1;
|
2015-01-09 07:40:56 +00:00
|
|
|
return fputc(c, terminal_outfile);
|
2012-06-22 18:01:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(EditLine *el, const char *cap, int affcnt)
|
2012-06-22 18:01:22 +00:00
|
|
|
{
|
|
|
|
#ifdef _REENTRANT
|
2015-01-09 07:40:56 +00:00
|
|
|
pthread_mutex_lock(&terminal_mutex);
|
2012-06-22 18:01:22 +00:00
|
|
|
#endif
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_outfile = el->el_outfile;
|
|
|
|
(void)tputs(cap, affcnt, terminal_putc);
|
2012-06-22 18:01:22 +00:00
|
|
|
#ifdef _REENTRANT
|
2015-01-09 07:40:56 +00:00
|
|
|
pthread_mutex_unlock(&terminal_mutex);
|
2012-06-22 18:01:22 +00:00
|
|
|
#endif
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal__putc():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Add a character
|
|
|
|
*/
|
1995-08-04 09:26:10 +00:00
|
|
|
protected int
|
2017-01-30 22:11:53 +00:00
|
|
|
terminal__putc(EditLine *el, wint_t c)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
char buf[MB_LEN_MAX +1];
|
|
|
|
ssize_t i;
|
2017-01-30 22:11:53 +00:00
|
|
|
if (c == (wint_t)MB_FILL_CHAR)
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
2017-01-30 22:11:53 +00:00
|
|
|
i = ct_encode_char(buf, (size_t)MB_LEN_MAX, (Char)c);
|
2015-01-09 07:40:56 +00:00
|
|
|
if (i <= 0)
|
|
|
|
return (int)i;
|
|
|
|
buf[i] = '\0';
|
|
|
|
return fputs(buf, el->el_outfile);
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal__flush():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Flush output
|
|
|
|
*/
|
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal__flush(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
|
2012-06-22 18:01:22 +00:00
|
|
|
(void) fflush(el->el_outfile);
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_writec():
|
Merge the following changes from NetBSD:
chared.h 1.17, common.c 1.19, emacs.c 1.21, key.c 1.18, key.h 1.9, map.c 1.23,
term.c 1.42, term.h 1.17, vi.c 1.25:
# Print the actual eofc, instead of ^D\b\b.
# Change internal character decoding to prevent buffer oveflows.
key.c 1.19, key.h 1.10:
# move declaration to header file.
term.c 1.43:
# Coverity CID 806: Prevent NULL deref
term.c 1.44:
# Coverity CID 1668: Plug memory leak.
term.c 1.45:
# Fix compilation.
MFC after: 3 weeks
2007-03-11 18:30:22 +00:00
|
|
|
* Write the given character out, in a human readable form
|
|
|
|
*/
|
|
|
|
protected void
|
2017-01-30 22:11:53 +00:00
|
|
|
terminal_writec(EditLine *el, wint_t c)
|
Merge the following changes from NetBSD:
chared.h 1.17, common.c 1.19, emacs.c 1.21, key.c 1.18, key.h 1.9, map.c 1.23,
term.c 1.42, term.h 1.17, vi.c 1.25:
# Print the actual eofc, instead of ^D\b\b.
# Change internal character decoding to prevent buffer oveflows.
key.c 1.19, key.h 1.10:
# move declaration to header file.
term.c 1.43:
# Coverity CID 806: Prevent NULL deref
term.c 1.44:
# Coverity CID 1668: Plug memory leak.
term.c 1.45:
# Fix compilation.
MFC after: 3 weeks
2007-03-11 18:30:22 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
Char visbuf[VISUAL_WIDTH_MAX +1];
|
2017-01-30 22:11:53 +00:00
|
|
|
ssize_t vcnt = ct_visual_char(visbuf, VISUAL_WIDTH_MAX, (Char)c);
|
2015-01-09 07:40:56 +00:00
|
|
|
if (vcnt < 0)
|
|
|
|
vcnt = 0;
|
|
|
|
visbuf[vcnt] = '\0';
|
|
|
|
terminal_overwrite(el, visbuf, (size_t)vcnt);
|
|
|
|
terminal__flush(el);
|
Merge the following changes from NetBSD:
chared.h 1.17, common.c 1.19, emacs.c 1.21, key.c 1.18, key.h 1.9, map.c 1.23,
term.c 1.42, term.h 1.17, vi.c 1.25:
# Print the actual eofc, instead of ^D\b\b.
# Change internal character decoding to prevent buffer oveflows.
key.c 1.19, key.h 1.10:
# move declaration to header file.
term.c 1.43:
# Coverity CID 806: Prevent NULL deref
term.c 1.44:
# Coverity CID 1668: Plug memory leak.
term.c 1.45:
# Fix compilation.
MFC after: 3 weeks
2007-03-11 18:30:22 +00:00
|
|
|
}
|
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_telltc():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Print the current termcap characteristics
|
|
|
|
*/
|
|
|
|
protected int
|
|
|
|
/*ARGSUSED*/
|
2017-01-30 22:11:53 +00:00
|
|
|
terminal_telltc(EditLine *el, int argc __attribute__((__unused__)),
|
2015-01-09 07:40:56 +00:00
|
|
|
const Char **argv __attribute__((__unused__)))
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
const struct termcapstr *t;
|
|
|
|
char **ts;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_outfile, "\n\tYour terminal has the\n");
|
|
|
|
(void) fprintf(el->el_outfile, "\tfollowing characteristics:\n\n");
|
|
|
|
(void) fprintf(el->el_outfile, "\tIt has %d columns and %d lines\n",
|
1994-05-27 05:00:24 +00:00
|
|
|
Val(T_co), Val(T_li));
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_outfile,
|
|
|
|
"\tIt has %s meta key\n", EL_HAS_META ? "a" : "no");
|
|
|
|
(void) fprintf(el->el_outfile,
|
|
|
|
"\tIt can%suse tabs\n", EL_CAN_TAB ? " " : "not ");
|
|
|
|
(void) fprintf(el->el_outfile, "\tIt %s automatic margins\n",
|
|
|
|
EL_HAS_AUTO_MARGINS ? "has" : "does not have");
|
|
|
|
if (EL_HAS_AUTO_MARGINS)
|
|
|
|
(void) fprintf(el->el_outfile, "\tIt %s magic margins\n",
|
|
|
|
EL_HAS_MAGIC_MARGINS ? "has" : "does not have");
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
for (t = tstr, ts = el->el_terminal.t_str; t->name != NULL; t++, ts++) {
|
Merge the following changes from NetBSD:
chared.h 1.17, common.c 1.19, emacs.c 1.21, key.c 1.18, key.h 1.9, map.c 1.23,
term.c 1.42, term.h 1.17, vi.c 1.25:
# Print the actual eofc, instead of ^D\b\b.
# Change internal character decoding to prevent buffer oveflows.
key.c 1.19, key.h 1.10:
# move declaration to header file.
term.c 1.43:
# Coverity CID 806: Prevent NULL deref
term.c 1.44:
# Coverity CID 1668: Plug memory leak.
term.c 1.45:
# Fix compilation.
MFC after: 3 weeks
2007-03-11 18:30:22 +00:00
|
|
|
const char *ub;
|
|
|
|
if (*ts && **ts) {
|
2015-01-09 07:40:56 +00:00
|
|
|
ub = ct_encode_string(ct_visual_string(
|
|
|
|
ct_decode_string(*ts, &el->el_scratch)),
|
|
|
|
&el->el_scratch);
|
Merge the following changes from NetBSD:
chared.h 1.17, common.c 1.19, emacs.c 1.21, key.c 1.18, key.h 1.9, map.c 1.23,
term.c 1.42, term.h 1.17, vi.c 1.25:
# Print the actual eofc, instead of ^D\b\b.
# Change internal character decoding to prevent buffer oveflows.
key.c 1.19, key.h 1.10:
# move declaration to header file.
term.c 1.43:
# Coverity CID 806: Prevent NULL deref
term.c 1.44:
# Coverity CID 1668: Plug memory leak.
term.c 1.45:
# Fix compilation.
MFC after: 3 weeks
2007-03-11 18:30:22 +00:00
|
|
|
} else {
|
2015-01-09 07:40:56 +00:00
|
|
|
ub = "(empty)";
|
Merge the following changes from NetBSD:
chared.h 1.17, common.c 1.19, emacs.c 1.21, key.c 1.18, key.h 1.9, map.c 1.23,
term.c 1.42, term.h 1.17, vi.c 1.25:
# Print the actual eofc, instead of ^D\b\b.
# Change internal character decoding to prevent buffer oveflows.
key.c 1.19, key.h 1.10:
# move declaration to header file.
term.c 1.43:
# Coverity CID 806: Prevent NULL deref
term.c 1.44:
# Coverity CID 1668: Plug memory leak.
term.c 1.45:
# Fix compilation.
MFC after: 3 weeks
2007-03-11 18:30:22 +00:00
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_outfile, "\t%25s (%s) == %s\n",
|
Merge the following changes from NetBSD:
chared.h 1.17, common.c 1.19, emacs.c 1.21, key.c 1.18, key.h 1.9, map.c 1.23,
term.c 1.42, term.h 1.17, vi.c 1.25:
# Print the actual eofc, instead of ^D\b\b.
# Change internal character decoding to prevent buffer oveflows.
key.c 1.19, key.h 1.10:
# move declaration to header file.
term.c 1.43:
# Coverity CID 806: Prevent NULL deref
term.c 1.44:
# Coverity CID 1668: Plug memory leak.
term.c 1.45:
# Fix compilation.
MFC after: 3 weeks
2007-03-11 18:30:22 +00:00
|
|
|
t->long_name, t->name, ub);
|
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fputc('\n', el->el_outfile);
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_settc():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Change the current terminal characteristics
|
|
|
|
*/
|
|
|
|
protected int
|
|
|
|
/*ARGSUSED*/
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_settc(EditLine *el, int argc __attribute__((__unused__)),
|
|
|
|
const Char **argv)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
const struct termcapstr *ts;
|
|
|
|
const struct termcapval *tv;
|
2015-01-09 07:40:56 +00:00
|
|
|
char what[8], how[8];
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
if (argv == NULL || argv[1] == NULL || argv[2] == NULL)
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
strncpy(what, ct_encode_string(argv[1], &el->el_scratch), sizeof(what));
|
|
|
|
what[sizeof(what) - 1] = '\0';
|
|
|
|
strncpy(how, ct_encode_string(argv[2], &el->el_scratch), sizeof(how));
|
|
|
|
how[sizeof(how) - 1] = '\0';
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the strings first
|
|
|
|
*/
|
|
|
|
for (ts = tstr; ts->name != NULL; ts++)
|
|
|
|
if (strcmp(ts->name, what) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (ts->name != NULL) {
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_alloc(el, ts, how);
|
|
|
|
terminal_setflags(el);
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
return 0;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
/*
|
|
|
|
* Do the numeric ones second
|
|
|
|
*/
|
|
|
|
for (tv = tval; tv->name != NULL; tv++)
|
|
|
|
if (strcmp(tv->name, what) == 0)
|
|
|
|
break;
|
|
|
|
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
if (tv->name != NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (tv == &tval[T_pt] || tv == &tval[T_km] ||
|
|
|
|
tv == &tval[T_am] || tv == &tval[T_xn]) {
|
|
|
|
if (strcmp(how, "yes") == 0)
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_terminal.t_val[tv - tval] = 1;
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
else if (strcmp(how, "no") == 0)
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_terminal.t_val[tv - tval] = 0;
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
else {
|
|
|
|
(void) fprintf(el->el_errfile,
|
2015-01-09 07:40:56 +00:00
|
|
|
"" FSTR ": Bad value `%s'.\n", argv[0], how);
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_setflags(el);
|
|
|
|
if (terminal_change_size(el, Val(T_li), Val(T_co)) == -1)
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
long i;
|
|
|
|
char *ep;
|
|
|
|
|
|
|
|
i = strtol(how, &ep, 10);
|
|
|
|
if (*ep != '\0') {
|
|
|
|
(void) fprintf(el->el_errfile,
|
2015-01-09 07:40:56 +00:00
|
|
|
"" FSTR ": Bad value `%s'.\n", argv[0], how);
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_terminal.t_val[tv - tval] = (int) i;
|
|
|
|
el->el_terminal.t_size.v = Val(T_co);
|
|
|
|
el->el_terminal.t_size.h = Val(T_li);
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
if (tv == &tval[T_co] || tv == &tval[T_li])
|
2015-01-09 07:40:56 +00:00
|
|
|
if (terminal_change_size(el, Val(T_li), Val(T_co))
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
== -1)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_gettc():
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
* Get the current terminal characteristics
|
|
|
|
*/
|
|
|
|
protected int
|
|
|
|
/*ARGSUSED*/
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_gettc(EditLine *el, int argc __attribute__((__unused__)), char **argv)
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
{
|
|
|
|
const struct termcapstr *ts;
|
|
|
|
const struct termcapval *tv;
|
|
|
|
char *what;
|
|
|
|
void *how;
|
|
|
|
|
|
|
|
if (argv == NULL || argv[1] == NULL || argv[2] == NULL)
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
|
|
|
|
what = argv[1];
|
|
|
|
how = argv[2];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the strings first
|
|
|
|
*/
|
|
|
|
for (ts = tstr; ts->name != NULL; ts++)
|
|
|
|
if (strcmp(ts->name, what) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (ts->name != NULL) {
|
2015-01-09 07:40:56 +00:00
|
|
|
*(char **)how = el->el_terminal.t_str[ts - tstr];
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Do the numeric ones second
|
|
|
|
*/
|
|
|
|
for (tv = tval; tv->name != NULL; tv++)
|
|
|
|
if (strcmp(tv->name, what) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (tv->name == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (tv == &tval[T_pt] || tv == &tval[T_km] ||
|
|
|
|
tv == &tval[T_am] || tv == &tval[T_xn]) {
|
|
|
|
static char yes[] = "yes";
|
|
|
|
static char no[] = "no";
|
2015-01-09 07:40:56 +00:00
|
|
|
if (el->el_terminal.t_val[tv - tval])
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
*(char **)how = yes;
|
|
|
|
else
|
|
|
|
*(char **)how = no;
|
|
|
|
return 0;
|
|
|
|
} else {
|
2015-01-09 07:40:56 +00:00
|
|
|
*(int *)how = el->el_terminal.t_val[tv - tval];
|
Merge NetBSD changes, among them:
el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.
el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.
Note: The latter change breaks the ABI of the el_get() function.
Approved by: re (kensmith)
2007-06-10 19:06:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* terminal_echotc():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Print the termcap string out with variable substitution
|
|
|
|
*/
|
|
|
|
protected int
|
|
|
|
/*ARGSUSED*/
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_echotc(EditLine *el, int argc __attribute__((__unused__)),
|
|
|
|
const Char **argv)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
char *cap, *scap;
|
|
|
|
Char *ep;
|
2001-10-01 08:41:27 +00:00
|
|
|
int arg_need, arg_cols, arg_rows;
|
|
|
|
int verbose = 0, silent = 0;
|
|
|
|
char *area;
|
|
|
|
static const char fmts[] = "%s\n", fmtd[] = "%d\n";
|
|
|
|
const struct termcapstr *t;
|
|
|
|
char buf[TC_BUFSIZE];
|
|
|
|
long i;
|
|
|
|
|
|
|
|
area = buf;
|
|
|
|
|
|
|
|
if (argv == NULL || argv[1] == NULL)
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
1994-05-27 05:00:24 +00:00
|
|
|
argv++;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
if (argv[0][0] == '-') {
|
|
|
|
switch (argv[0][1]) {
|
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
silent = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* stderror(ERR_NAME | ERR_TCUSAGE); */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
if (!*argv || *argv[0] == '\0')
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
|
|
|
if (Strcmp(*argv, STR("tabs")) == 0) {
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_outfile, fmts, EL_CAN_TAB ? "yes" : "no");
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
|
|
|
} else if (Strcmp(*argv, STR("meta")) == 0) {
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_outfile, fmts, Val(T_km) ? "yes" : "no");
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
|
|
|
} else if (Strcmp(*argv, STR("xn")) == 0) {
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_outfile, fmts, EL_HAS_MAGIC_MARGINS ?
|
|
|
|
"yes" : "no");
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
|
|
|
} else if (Strcmp(*argv, STR("am")) == 0) {
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_outfile, fmts, EL_HAS_AUTO_MARGINS ?
|
|
|
|
"yes" : "no");
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
|
|
|
} else if (Strcmp(*argv, STR("baud")) == 0) {
|
2005-08-07 20:55:59 +00:00
|
|
|
(void) fprintf(el->el_outfile, fmtd, (int)el->el_tty.t_speed);
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
|
|
|
} else if (Strcmp(*argv, STR("rows")) == 0 ||
|
|
|
|
Strcmp(*argv, STR("lines")) == 0) {
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_outfile, fmtd, Val(T_li));
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
|
|
|
} else if (Strcmp(*argv, STR("cols")) == 0) {
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_outfile, fmtd, Val(T_co));
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Try to use our local definition first
|
|
|
|
*/
|
|
|
|
scap = NULL;
|
|
|
|
for (t = tstr; t->name != NULL; t++)
|
2015-01-09 07:40:56 +00:00
|
|
|
if (strcmp(t->name,
|
|
|
|
ct_encode_string(*argv, &el->el_scratch)) == 0) {
|
|
|
|
scap = el->el_terminal.t_str[t - tstr];
|
2001-10-01 08:41:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-08-07 20:55:59 +00:00
|
|
|
if (t->name == NULL) {
|
2005-08-08 07:08:35 +00:00
|
|
|
/* XXX: some systems' tgetstr needs non const */
|
2015-01-09 07:40:56 +00:00
|
|
|
scap = tgetstr(ct_encode_string(*argv, &el->el_scratch), &area);
|
2005-08-07 20:55:59 +00:00
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
if (!scap || scap[0] == '\0') {
|
|
|
|
if (!silent)
|
|
|
|
(void) fprintf(el->el_errfile,
|
2015-01-09 07:40:56 +00:00
|
|
|
"echotc: Termcap parameter `" FSTR "' not found.\n",
|
2001-10-01 08:41:27 +00:00
|
|
|
*argv);
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
/*
|
|
|
|
* Count home many values we need for this capability.
|
|
|
|
*/
|
|
|
|
for (cap = scap, arg_need = 0; *cap; cap++)
|
|
|
|
if (*cap == '%')
|
|
|
|
switch (*++cap) {
|
|
|
|
case 'd':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '.':
|
|
|
|
case '+':
|
|
|
|
arg_need++;
|
|
|
|
break;
|
|
|
|
case '%':
|
|
|
|
case '>':
|
|
|
|
case 'i':
|
|
|
|
case 'r':
|
|
|
|
case 'n':
|
|
|
|
case 'B':
|
|
|
|
case 'D':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* hpux has lot's of them...
|
|
|
|
*/
|
|
|
|
if (verbose)
|
|
|
|
(void) fprintf(el->el_errfile,
|
|
|
|
"echotc: Warning: unknown termcap %% `%c'.\n",
|
|
|
|
*cap);
|
|
|
|
/* This is bad, but I won't complain */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (arg_need) {
|
|
|
|
case 0:
|
|
|
|
argv++;
|
|
|
|
if (*argv && *argv[0]) {
|
|
|
|
if (!silent)
|
|
|
|
(void) fprintf(el->el_errfile,
|
2015-01-09 07:40:56 +00:00
|
|
|
"echotc: Warning: Extra argument `" FSTR "'.\n",
|
2001-10-01 08:41:27 +00:00
|
|
|
*argv);
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, scap, 1);
|
1994-05-27 05:00:24 +00:00
|
|
|
break;
|
2001-10-01 08:41:27 +00:00
|
|
|
case 1:
|
|
|
|
argv++;
|
|
|
|
if (!*argv || *argv[0] == '\0') {
|
|
|
|
if (!silent)
|
|
|
|
(void) fprintf(el->el_errfile,
|
|
|
|
"echotc: Warning: Missing argument.\n");
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
arg_cols = 0;
|
2015-01-09 07:40:56 +00:00
|
|
|
i = Strtol(*argv, &ep, 10);
|
2001-10-01 08:41:27 +00:00
|
|
|
if (*ep != '\0' || i < 0) {
|
|
|
|
if (!silent)
|
|
|
|
(void) fprintf(el->el_errfile,
|
2015-01-09 07:40:56 +00:00
|
|
|
"echotc: Bad value `" FSTR "' for rows.\n",
|
2001-10-01 08:41:27 +00:00
|
|
|
*argv);
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
arg_rows = (int) i;
|
|
|
|
argv++;
|
|
|
|
if (*argv && *argv[0]) {
|
|
|
|
if (!silent)
|
|
|
|
(void) fprintf(el->el_errfile,
|
2015-01-09 07:40:56 +00:00
|
|
|
"echotc: Warning: Extra argument `" FSTR
|
|
|
|
"'.\n", *argv);
|
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, tgoto(scap, arg_cols, arg_rows), 1);
|
1994-05-27 05:00:24 +00:00
|
|
|
break;
|
2001-10-01 08:41:27 +00:00
|
|
|
default:
|
|
|
|
/* This is wrong, but I will ignore it... */
|
1994-05-27 05:00:24 +00:00
|
|
|
if (verbose)
|
2001-10-01 08:41:27 +00:00
|
|
|
(void) fprintf(el->el_errfile,
|
|
|
|
"echotc: Warning: Too many required arguments (%d).\n",
|
|
|
|
arg_need);
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 2:
|
|
|
|
argv++;
|
|
|
|
if (!*argv || *argv[0] == '\0') {
|
|
|
|
if (!silent)
|
|
|
|
(void) fprintf(el->el_errfile,
|
|
|
|
"echotc: Warning: Missing argument.\n");
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
i = Strtol(*argv, &ep, 10);
|
2001-10-01 08:41:27 +00:00
|
|
|
if (*ep != '\0' || i < 0) {
|
|
|
|
if (!silent)
|
|
|
|
(void) fprintf(el->el_errfile,
|
2015-01-09 07:40:56 +00:00
|
|
|
"echotc: Bad value `" FSTR "' for cols.\n",
|
2001-10-01 08:41:27 +00:00
|
|
|
*argv);
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
arg_cols = (int) i;
|
|
|
|
argv++;
|
|
|
|
if (!*argv || *argv[0] == '\0') {
|
|
|
|
if (!silent)
|
|
|
|
(void) fprintf(el->el_errfile,
|
|
|
|
"echotc: Warning: Missing argument.\n");
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
i = Strtol(*argv, &ep, 10);
|
2001-10-01 08:41:27 +00:00
|
|
|
if (*ep != '\0' || i < 0) {
|
|
|
|
if (!silent)
|
|
|
|
(void) fprintf(el->el_errfile,
|
2015-01-09 07:40:56 +00:00
|
|
|
"echotc: Bad value `" FSTR "' for rows.\n",
|
2001-10-01 08:41:27 +00:00
|
|
|
*argv);
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
arg_rows = (int) i;
|
|
|
|
if (*ep != '\0') {
|
|
|
|
if (!silent)
|
|
|
|
(void) fprintf(el->el_errfile,
|
2015-01-09 07:40:56 +00:00
|
|
|
"echotc: Bad value `" FSTR "'.\n", *argv);
|
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
argv++;
|
|
|
|
if (*argv && *argv[0]) {
|
|
|
|
if (!silent)
|
|
|
|
(void) fprintf(el->el_errfile,
|
2015-01-09 07:40:56 +00:00
|
|
|
"echotc: Warning: Extra argument `" FSTR
|
|
|
|
"'.\n", *argv);
|
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
terminal_tputs(el, tgoto(scap, arg_cols, arg_rows), arg_rows);
|
1994-05-27 05:00:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|