"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libedit/tty.c" between
tnftp-20151004.tar.gz and tnftp-20200705.tar.gz

About: tnftp is an enhanced ftp client (prior name "lukemftp").

tty.c  (tnftp-20151004):tty.c  (tnftp-20200705)
/* $NetBSD: tty.c,v 1.7 2005/06/09 16:48:58 lukem Exp $ */ /* $NetBSD: tty.c,v 1.10 2020/07/04 13:43:21 lukem Exp $ */
/* from NetBSD: tty.c,v 1.22 2005/05/29 03:55:37 christos Exp */ /* from NetBSD: tty.c,v 1.69 2020/05/31 23:24:23 christos Exp */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* This code is derived from software contributed to Berkeley by * This code is derived from software contributed to Berkeley by
* Christos Zoulas of Cornell University. * Christos Zoulas of Cornell University.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
skipping to change at line 36 skipping to change at line 36
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * 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 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include "tnftp.h" #include "config.h"
#include "sys.h"
#if 0 /* tnftp */
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID(" NetBSD: tty.c,v 1.69 2020/05/31 23:24:23 christos Exp ");
#endif
#endif /* not lint && not SCCSID */
#endif /* tnftp */
/* /*
* tty.c: tty interface stuff * tty.c: tty interface stuff
*/ */
#if 0 /* tnftp */
#include <assert.h> #include <assert.h>
#include "tty.h" #include <errno.h>
#include <stdlib.h> /* for abort */
#include <string.h>
#include <strings.h> /* for ffs */
#include <unistd.h> /* for isatty */
#endif /* tnftp */
#include "el.h" #include "el.h"
#include "fcns.h"
#include "parse.h"
typedef struct ttymodes_t { typedef struct ttymodes_t {
const char *m_name; const char *m_name;
unsigned int m_value; unsigned int m_value;
int m_type; int m_type;
} ttymodes_t; } ttymodes_t;
typedef struct ttymap_t { typedef struct ttymap_t {
int nch, och; /* Internal and termio rep of chars */ wint_t nch, och; /* Internal and termio rep of chars */
el_action_t bind[3]; /* emacs, vi, and vi-cmd */ el_action_t bind[3]; /* emacs, vi, and vi-cmd */
} ttymap_t; } ttymap_t;
private const ttyperm_t ttyperm = { static const ttyperm_t ttyperm = {
{ {
{"iflag:", ICRNL, (INLCR | IGNCR)}, {"iflag:", ICRNL, (INLCR | IGNCR)},
{"oflag:", (OPOST | ONLCR), ONLRET}, {"oflag:", (OPOST | ONLCR), ONLRET},
{"cflag:", 0, 0}, {"cflag:", 0, 0},
{"lflag:", (ISIG | ICANON | ECHO | ECHOE | ECHOCTL | IEXTEN), {"lflag:", (ISIG | ICANON | ECHO | ECHOE | ECHOCTL | IEXTEN),
(NOFLSH | ECHONL | EXTPROC | FLUSHO)}, (NOFLSH | ECHONL | EXTPROC | FLUSHO)},
{"chars:", 0, 0}, {"chars:", 0, 0},
}, },
{ {
{"iflag:", (INLCR | ICRNL), IGNCR}, {"iflag:", (INLCR | ICRNL), IGNCR},
skipping to change at line 85 skipping to change at line 103
}, },
{ {
{"iflag:", 0, IXON | IXOFF | INLCR | ICRNL}, {"iflag:", 0, IXON | IXOFF | INLCR | ICRNL},
{"oflag:", 0, 0}, {"oflag:", 0, 0},
{"cflag:", 0, 0}, {"cflag:", 0, 0},
{"lflag:", 0, ISIG | IEXTEN}, {"lflag:", 0, ISIG | IEXTEN},
{"chars:", 0, 0}, {"chars:", 0, 0},
} }
}; };
private const ttychar_t ttychar = { static const ttychar_t ttychar = {
{ {
CINTR, CQUIT, CERASE, CKILL, CINTR, CQUIT, CERASE, CKILL,
CEOF, CEOL, CEOL2, CSWTCH, CEOF, CEOL, CEOL2, CSWTCH,
CDSWTCH, CERASE2, CSTART, CSTOP, CDSWTCH, CERASE2, CSTART, CSTOP,
CWERASE, CSUSP, CDSUSP, CREPRINT, CWERASE, CSUSP, CDSUSP, CREPRINT,
CDISCARD, CLNEXT, CSTATUS, CPAGE, CDISCARD, CLNEXT, CSTATUS, CPAGE,
CPGOFF, CKILL2, CBRK, CMIN, CPGOFF, CKILL2, CBRK, CMIN,
CTIME CTIME
}, },
{ {
skipping to change at line 115 skipping to change at line 133
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0 0
} }
}; };
private const ttymap_t tty_map[] = { static const ttymap_t tty_map[] = {
#ifdef VERASE #ifdef VERASE
{C_ERASE, VERASE, {C_ERASE, VERASE,
{EM_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}}, {EM_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}},
#endif /* VERASE */ #endif /* VERASE */
#ifdef VERASE2 #ifdef VERASE2
{C_ERASE2, VERASE2, {C_ERASE2, VERASE2,
{EM_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}}, {EM_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}},
#endif /* VERASE2 */ #endif /* VERASE2 */
#ifdef VKILL #ifdef VKILL
{C_KILL, VKILL, {C_KILL, VKILL,
skipping to change at line 148 skipping to change at line 166
{ED_DELETE_PREV_WORD, ED_DELETE_PREV_WORD, ED_PREV_WORD}}, {ED_DELETE_PREV_WORD, ED_DELETE_PREV_WORD, ED_PREV_WORD}},
#endif /* VWERASE */ #endif /* VWERASE */
#ifdef VREPRINT #ifdef VREPRINT
{C_REPRINT, VREPRINT, {C_REPRINT, VREPRINT,
{ED_REDISPLAY, ED_INSERT, ED_REDISPLAY}}, {ED_REDISPLAY, ED_INSERT, ED_REDISPLAY}},
#endif /* VREPRINT */ #endif /* VREPRINT */
#ifdef VLNEXT #ifdef VLNEXT
{C_LNEXT, VLNEXT, {C_LNEXT, VLNEXT,
{ED_QUOTED_INSERT, ED_QUOTED_INSERT, ED_UNASSIGNED}}, {ED_QUOTED_INSERT, ED_QUOTED_INSERT, ED_UNASSIGNED}},
#endif /* VLNEXT */ #endif /* VLNEXT */
{-1, -1, {(wint_t)-1, (wint_t)-1,
{ED_UNASSIGNED, ED_UNASSIGNED, ED_UNASSIGNED}} {ED_UNASSIGNED, ED_UNASSIGNED, ED_UNASSIGNED}}
}; };
private const ttymodes_t ttymodes[] = { static const ttymodes_t ttymodes[] = {
#ifdef IGNBRK #ifdef IGNBRK
{"ignbrk", IGNBRK, MD_INP}, {"ignbrk", IGNBRK, MD_INP},
#endif /* IGNBRK */ #endif /* IGNBRK */
#ifdef BRKINT #ifdef BRKINT
{"brkint", BRKINT, MD_INP}, {"brkint", BRKINT, MD_INP},
#endif /* BRKINT */ #endif /* BRKINT */
#ifdef IGNPAR #ifdef IGNPAR
{"ignpar", IGNPAR, MD_INP}, {"ignpar", IGNPAR, MD_INP},
#endif /* IGNPAR */ #endif /* IGNPAR */
#ifdef PARMRK #ifdef PARMRK
skipping to change at line 440 skipping to change at line 458
#endif /* VBRK */ #endif /* VBRK */
#if defined(VMIN) #if defined(VMIN)
{"min", C_SH(C_MIN), MD_CHAR}, {"min", C_SH(C_MIN), MD_CHAR},
#endif /* VMIN */ #endif /* VMIN */
#if defined(VTIME) #if defined(VTIME)
{"time", C_SH(C_TIME), MD_CHAR}, {"time", C_SH(C_TIME), MD_CHAR},
#endif /* VTIME */ #endif /* VTIME */
{NULL, 0, -1}, {NULL, 0, -1},
}; };
#define tty_getty(el, td) tcgetattr((el)->el_infd, (td))
#define tty_setty(el, td) tcsetattr((el)->el_infd, TCSADRAIN, (td))
#define tty__gettabs(td) ((((td)->c_oflag & TAB3) == TAB3) ? 0 : 1 ) #define tty__gettabs(td) ((((td)->c_oflag & TAB3) == TAB3) ? 0 : 1 )
#define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8) #define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8)
#define tty__cooked_mode(td) ((td)->c_lflag & ICANON) #define tty__cooked_mode(td) ((td)->c_lflag & ICANON)
private int tty__getcharindex(int); static int tty_getty(EditLine *, struct termios *);
private void tty__getchar(struct termios *, unsigned char *); static int tty_setty(EditLine *, int, const struct termios *);
private void tty__setchar(struct termios *, unsigned char *); static int tty__getcharindex(int);
private speed_t tty__getspeed(struct termios *); static void tty__getchar(struct termios *, unsigned char *);
private int tty_setup(EditLine *); static void tty__setchar(struct termios *, unsigned char *);
static speed_t tty__getspeed(struct termios *);
static int tty_setup(EditLine *);
static void tty_setup_flags(EditLine *, struct termios *, int);
#define t_qu t_ts #define t_qu t_ts
/* tty_getty():
* Wrapper for tcgetattr to handle EINTR
*/
static int
tty_getty(EditLine *el, struct termios *t)
{
int rv;
while ((rv = tcgetattr(el->el_infd, t)) == -1 && errno == EINTR)
continue;
return rv;
}
/* tty_setty():
* Wrapper for tcsetattr to handle EINTR
*/
static int
tty_setty(EditLine *el, int action, const struct termios *t)
{
int rv;
while ((rv = tcsetattr(el->el_infd, action, t)) == -1 && errno == EINTR)
continue;
return rv;
}
/* tty_setup(): /* tty_setup():
* Get the tty parameters and initialize the editing state * Get the tty parameters and initialize the editing state
*/ */
private int static int
tty_setup(EditLine *el) tty_setup(EditLine *el)
{ {
int rst = 1; int rst = (el->el_flags & NO_RESET) == 0;
if (el->el_flags & EDIT_DISABLED) if (el->el_flags & EDIT_DISABLED)
return (0); return 0;
if (tty_getty(el, &el->el_tty.t_ed) == -1) { if (el->el_tty.t_initialized)
return -1;
if (!isatty(el->el_outfd)) {
#ifdef DEBUG_TTY #ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, (void) fprintf(el->el_errfile, "%s: isatty: %s\n", __func__,
"tty_setup: tty_getty: %s\n", strerror(errno)); strerror(errno));
#endif /* DEBUG_TTY */ #endif /* DEBUG_TTY */
return (-1); return -1;
} }
el->el_tty.t_ts = el->el_tty.t_ex = el->el_tty.t_ed; if (tty_getty(el, &el->el_tty.t_or) == -1) {
#ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, "%s: tty_getty: %s\n", __func__,
strerror(errno));
#endif /* DEBUG_TTY */
return -1;
}
el->el_tty.t_ts = el->el_tty.t_ex = el->el_tty.t_ed = el->el_tty.t_or;
el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ex); el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ex);
el->el_tty.t_tabs = tty__gettabs(&el->el_tty.t_ex); el->el_tty.t_tabs = tty__gettabs(&el->el_tty.t_ex);
el->el_tty.t_eight = tty__geteightbit(&el->el_tty.t_ex); el->el_tty.t_eight = tty__geteightbit(&el->el_tty.t_ex);
el->el_tty.t_ex.c_iflag &= ~el->el_tty.t_t[EX_IO][MD_INP].t_clrmask; tty_setup_flags(el, &el->el_tty.t_ex, EX_IO);
el->el_tty.t_ex.c_iflag |= el->el_tty.t_t[EX_IO][MD_INP].t_setmask;
el->el_tty.t_ex.c_oflag &= ~el->el_tty.t_t[EX_IO][MD_OUT].t_clrmask;
el->el_tty.t_ex.c_oflag |= el->el_tty.t_t[EX_IO][MD_OUT].t_setmask;
el->el_tty.t_ex.c_cflag &= ~el->el_tty.t_t[EX_IO][MD_CTL].t_clrmask;
el->el_tty.t_ex.c_cflag |= el->el_tty.t_t[EX_IO][MD_CTL].t_setmask;
el->el_tty.t_ex.c_lflag &= ~el->el_tty.t_t[EX_IO][MD_LIN].t_clrmask;
el->el_tty.t_ex.c_lflag |= el->el_tty.t_t[EX_IO][MD_LIN].t_setmask;
/* /*
* Reset the tty chars to reasonable defaults * Reset the tty chars to reasonable defaults
* If they are disabled, then enable them. * If they are disabled, then enable them.
*/ */
if (rst) { if (rst) {
if (tty__cooked_mode(&el->el_tty.t_ts)) { if (tty__cooked_mode(&el->el_tty.t_ts)) {
tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]); tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]);
/* /*
* Don't affect CMIN and CTIME for the editor mode * Don't affect CMIN and CTIME for the editor mode
skipping to change at line 515 skipping to change at line 557
el->el_tty.t_vdisable) el->el_tty.t_vdisable)
el->el_tty.t_c[ED_IO][rst] = el->el_tty.t_c[ED_IO][rst] =
el->el_tty.t_c[TS_IO][rst]; el->el_tty.t_c[TS_IO][rst];
for (rst = 0; rst < C_NCC; rst++) for (rst = 0; rst < C_NCC; rst++)
if (el->el_tty.t_c[TS_IO][rst] != if (el->el_tty.t_c[TS_IO][rst] !=
el->el_tty.t_vdisable) el->el_tty.t_vdisable)
el->el_tty.t_c[EX_IO][rst] = el->el_tty.t_c[EX_IO][rst] =
el->el_tty.t_c[TS_IO][rst]; el->el_tty.t_c[TS_IO][rst];
} }
tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]); tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
if (tty_setty(el, &el->el_tty.t_ex) == -1) { if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
#ifdef DEBUG_TTY #ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n",
"tty_setup: tty_setty: %s\n", __func__, strerror(errno));
strerror(errno));
#endif /* DEBUG_TTY */ #endif /* DEBUG_TTY */
return (-1); return -1;
} }
} else }
tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
el->el_tty.t_ed.c_iflag &= ~el->el_tty.t_t[ED_IO][MD_INP].t_clrmask;
el->el_tty.t_ed.c_iflag |= el->el_tty.t_t[ED_IO][MD_INP].t_setmask;
el->el_tty.t_ed.c_oflag &= ~el->el_tty.t_t[ED_IO][MD_OUT].t_clrmask;
el->el_tty.t_ed.c_oflag |= el->el_tty.t_t[ED_IO][MD_OUT].t_setmask;
el->el_tty.t_ed.c_cflag &= ~el->el_tty.t_t[ED_IO][MD_CTL].t_clrmask;
el->el_tty.t_ed.c_cflag |= el->el_tty.t_t[ED_IO][MD_CTL].t_setmask;
el->el_tty.t_ed.c_lflag &= ~el->el_tty.t_t[ED_IO][MD_LIN].t_clrmask; tty_setup_flags(el, &el->el_tty.t_ed, ED_IO);
el->el_tty.t_ed.c_lflag |= el->el_tty.t_t[ED_IO][MD_LIN].t_setmask;
tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]); tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]);
tty_bind_char(el, 1); tty_bind_char(el, 1);
return (0); el->el_tty.t_initialized = 1;
return 0;
} }
protected int libedit_private int
tty_init(EditLine *el) tty_init(EditLine *el)
{ {
el->el_tty.t_mode = EX_IO; el->el_tty.t_mode = EX_IO;
el->el_tty.t_vdisable = _POSIX_VDISABLE; el->el_tty.t_vdisable = _POSIX_VDISABLE;
el->el_tty.t_initialized = 0;
(void) memcpy(el->el_tty.t_t, ttyperm, sizeof(ttyperm_t)); (void) memcpy(el->el_tty.t_t, ttyperm, sizeof(ttyperm_t));
(void) memcpy(el->el_tty.t_c, ttychar, sizeof(ttychar_t)); (void) memcpy(el->el_tty.t_c, ttychar, sizeof(ttychar_t));
return (tty_setup(el)); return tty_setup(el);
} }
/* tty_end(): /* tty_end():
* Restore the tty to its original settings * Restore the tty to its original settings
*/ */
protected void libedit_private void
/*ARGSUSED*/ /*ARGSUSED*/
tty_end(EditLine *el __attribute__((__unused__))) tty_end(EditLine *el, int how)
{ {
if (el->el_flags & EDIT_DISABLED)
return;
/* XXX: Maybe reset to an initial state? */ if (!el->el_tty.t_initialized)
return;
if (tty_setty(el, how, &el->el_tty.t_or) == -1)
{
#ifdef DEBUG_TTY
(void) fprintf(el->el_errfile,
"%s: tty_setty: %s\n", __func__, strerror(errno));
#endif /* DEBUG_TTY */
}
} }
/* tty__getspeed(): /* tty__getspeed():
* Get the tty speed * Get the tty speed
*/ */
private speed_t static speed_t
tty__getspeed(struct termios *td) tty__getspeed(struct termios *td)
{ {
speed_t spd; speed_t spd;
if ((spd = cfgetispeed(td)) == 0) if ((spd = cfgetispeed(td)) == 0)
spd = cfgetospeed(td); spd = cfgetospeed(td);
return (spd); return spd;
} }
/* tty__getspeed(): /* tty__getspeed():
* Return the index of the asked char in the c_cc array * Return the index of the asked char in the c_cc array
*/ */
private int static int
tty__getcharindex(int i) tty__getcharindex(int i)
{ {
switch (i) { switch (i) {
#ifdef VINTR #ifdef VINTR
case C_INTR: case C_INTR:
return VINTR; return VINTR;
#endif /* VINTR */ #endif /* VINTR */
#ifdef VQUIT #ifdef VQUIT
case C_QUIT: case C_QUIT:
return VQUIT; return VQUIT;
skipping to change at line 689 skipping to change at line 732
return VTIME; return VTIME;
#endif /* VTIME */ #endif /* VTIME */
default: default:
return -1; return -1;
} }
} }
/* tty__getchar(): /* tty__getchar():
* Get the tty characters * Get the tty characters
*/ */
private void static void
tty__getchar(struct termios *td, unsigned char *s) tty__getchar(struct termios *td, unsigned char *s)
{ {
#ifdef VINTR #ifdef VINTR
s[C_INTR] = td->c_cc[VINTR]; s[C_INTR] = td->c_cc[VINTR];
#endif /* VINTR */ #endif /* VINTR */
#ifdef VQUIT #ifdef VQUIT
s[C_QUIT] = td->c_cc[VQUIT]; s[C_QUIT] = td->c_cc[VQUIT];
#endif /* VQUIT */ #endif /* VQUIT */
#ifdef VERASE #ifdef VERASE
skipping to change at line 770 skipping to change at line 813
s[C_MIN] = td->c_cc[VMIN]; s[C_MIN] = td->c_cc[VMIN];
#endif /* VMIN */ #endif /* VMIN */
#ifdef VTIME #ifdef VTIME
s[C_TIME] = td->c_cc[VTIME]; s[C_TIME] = td->c_cc[VTIME];
#endif /* VTIME */ #endif /* VTIME */
} /* tty__getchar */ } /* tty__getchar */
/* tty__setchar(): /* tty__setchar():
* Set the tty characters * Set the tty characters
*/ */
private void static void
tty__setchar(struct termios *td, unsigned char *s) tty__setchar(struct termios *td, unsigned char *s)
{ {
#ifdef VINTR #ifdef VINTR
td->c_cc[VINTR] = s[C_INTR]; td->c_cc[VINTR] = s[C_INTR];
#endif /* VINTR */ #endif /* VINTR */
#ifdef VQUIT #ifdef VQUIT
td->c_cc[VQUIT] = s[C_QUIT]; td->c_cc[VQUIT] = s[C_QUIT];
#endif /* VQUIT */ #endif /* VQUIT */
#ifdef VERASE #ifdef VERASE
skipping to change at line 851 skipping to change at line 894
td->c_cc[VMIN] = s[C_MIN]; td->c_cc[VMIN] = s[C_MIN];
#endif /* VMIN */ #endif /* VMIN */
#ifdef VTIME #ifdef VTIME
td->c_cc[VTIME] = s[C_TIME]; td->c_cc[VTIME] = s[C_TIME];
#endif /* VTIME */ #endif /* VTIME */
} /* tty__setchar */ } /* tty__setchar */
/* tty_bind_char(): /* tty_bind_char():
* Rebind the editline functions * Rebind the editline functions
*/ */
protected void libedit_private void
tty_bind_char(EditLine *el, int force) tty_bind_char(EditLine *el, int force)
{ {
unsigned char *t_n = el->el_tty.t_c[ED_IO]; unsigned char *t_n = el->el_tty.t_c[ED_IO];
unsigned char *t_o = el->el_tty.t_ed.c_cc; unsigned char *t_o = el->el_tty.t_ed.c_cc;
unsigned char new[2], old[2]; wchar_t new[2], old[2];
const ttymap_t *tp; const ttymap_t *tp;
el_action_t *map, *alt; el_action_t *map, *alt;
const el_action_t *dmap, *dalt; const el_action_t *dmap, *dalt;
new[1] = old[1] = '\0'; new[1] = old[1] = '\0';
map = el->el_map.key; map = el->el_map.key;
alt = el->el_map.alt; alt = el->el_map.alt;
if (el->el_map.type == MAP_VI) { if (el->el_map.type == MAP_VI) {
dmap = el->el_map.vii; dmap = el->el_map.vii;
dalt = el->el_map.vic; dalt = el->el_map.vic;
} else { } else {
dmap = el->el_map.emacs; dmap = el->el_map.emacs;
dalt = NULL; dalt = NULL;
} }
for (tp = tty_map; tp->nch != -1; tp++) { for (tp = tty_map; tp->nch != (wint_t)-1; tp++) {
new[0] = t_n[tp->nch]; new[0] = (wchar_t)t_n[tp->nch];
old[0] = t_o[tp->och]; old[0] = (wchar_t)t_o[tp->och];
if (new[0] == old[0] && !force) if (new[0] == old[0] && !force)
continue; continue;
/* Put the old default binding back, and set the new binding */ /* Put the old default binding back, and set the new binding */
key_clear(el, map, (char *)old); keymacro_clear(el, map, old);
map[old[0]] = dmap[old[0]]; map[(unsigned char)old[0]] = dmap[(unsigned char)old[0]];
key_clear(el, map, (char *)new); keymacro_clear(el, map, new);
/* MAP_VI == 1, MAP_EMACS == 0... */ /* MAP_VI == 1, MAP_EMACS == 0... */
map[new[0]] = tp->bind[el->el_map.type]; map[(unsigned char)new[0]] = tp->bind[el->el_map.type];
if (dalt) { if (dalt) {
key_clear(el, alt, (char *)old); keymacro_clear(el, alt, old);
alt[old[0]] = dalt[old[0]]; alt[(unsigned char)old[0]] =
key_clear(el, alt, (char *)new); dalt[(unsigned char)old[0]];
alt[new[0]] = tp->bind[el->el_map.type + 1]; keymacro_clear(el, alt, new);
alt[(unsigned char)new[0]] =
tp->bind[el->el_map.type + 1];
} }
} }
} }
static tcflag_t *
tty__get_flag(struct termios *t, int kind) {
switch (kind) {
case MD_INP:
return &t->c_iflag;
case MD_OUT:
return &t->c_oflag;
case MD_CTL:
return &t->c_cflag;
case MD_LIN:
return &t->c_lflag;
default:
abort();
/*NOTREACHED*/
}
}
static tcflag_t
tty_update_flag(EditLine *el, tcflag_t f, int mode, int kind)
{
f &= ~el->el_tty.t_t[mode][kind].t_clrmask;
f |= el->el_tty.t_t[mode][kind].t_setmask;
return f;
}
static void
tty_update_flags(EditLine *el, int kind)
{
tcflag_t *tt, *ed, *ex;
tt = tty__get_flag(&el->el_tty.t_ts, kind);
ed = tty__get_flag(&el->el_tty.t_ed, kind);
ex = tty__get_flag(&el->el_tty.t_ex, kind);
if (*tt != *ex && (kind != MD_CTL || *tt != *ed)) {
*ed = tty_update_flag(el, *tt, ED_IO, kind);
*ex = tty_update_flag(el, *tt, EX_IO, kind);
}
}
static void
tty_update_char(EditLine *el, int mode, int c) {
if (!((el->el_tty.t_t[mode][MD_CHAR].t_setmask & C_SH(c)))
&& (el->el_tty.t_c[TS_IO][c] != el->el_tty.t_c[EX_IO][c]))
el->el_tty.t_c[mode][c] = el->el_tty.t_c[TS_IO][c];
if (el->el_tty.t_t[mode][MD_CHAR].t_clrmask & C_SH(c))
el->el_tty.t_c[mode][c] = el->el_tty.t_vdisable;
}
/* tty_rawmode(): /* tty_rawmode():
* Set terminal into 1 character at a time mode. * Set terminal into 1 character at a time mode.
*/ */
protected int libedit_private int
tty_rawmode(EditLine *el) tty_rawmode(EditLine *el)
{ {
if (el->el_tty.t_mode == ED_IO || el->el_tty.t_mode == QU_IO) if (el->el_tty.t_mode == ED_IO || el->el_tty.t_mode == QU_IO)
return (0); return 0;
if (el->el_flags & EDIT_DISABLED) if (el->el_flags & EDIT_DISABLED)
return (0); return 0;
if (tty_getty(el, &el->el_tty.t_ts) == -1) { if (tty_getty(el, &el->el_tty.t_ts) == -1) {
#ifdef DEBUG_TTY #ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, "tty_rawmode: tty_getty: %s\n", (void) fprintf(el->el_errfile, "%s: tty_getty: %s\n", __func__,
strerror(errno)); strerror(errno));
#endif /* DEBUG_TTY */ #endif /* DEBUG_TTY */
return (-1); return -1;
} }
/* /*
* We always keep up with the eight bit setting and the speed of the * We always keep up with the eight bit setting and the speed of the
* tty. But only we only believe changes that are made to cooked mode! * tty. But we only believe changes that are made to cooked mode!
*/ */
el->el_tty.t_eight = tty__geteightbit(&el->el_tty.t_ts); el->el_tty.t_eight = tty__geteightbit(&el->el_tty.t_ts);
el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ts); el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ts);
if (tty__getspeed(&el->el_tty.t_ex) != el->el_tty.t_speed || if (tty__getspeed(&el->el_tty.t_ex) != el->el_tty.t_speed ||
tty__getspeed(&el->el_tty.t_ed) != el->el_tty.t_speed) { tty__getspeed(&el->el_tty.t_ed) != el->el_tty.t_speed) {
(void) cfsetispeed(&el->el_tty.t_ex, el->el_tty.t_speed); (void) cfsetispeed(&el->el_tty.t_ex, el->el_tty.t_speed);
(void) cfsetospeed(&el->el_tty.t_ex, el->el_tty.t_speed); (void) cfsetospeed(&el->el_tty.t_ex, el->el_tty.t_speed);
(void) cfsetispeed(&el->el_tty.t_ed, el->el_tty.t_speed); (void) cfsetispeed(&el->el_tty.t_ed, el->el_tty.t_speed);
(void) cfsetospeed(&el->el_tty.t_ed, el->el_tty.t_speed); (void) cfsetospeed(&el->el_tty.t_ed, el->el_tty.t_speed);
} }
if (tty__cooked_mode(&el->el_tty.t_ts)) { if (tty__cooked_mode(&el->el_tty.t_ts)) {
if (el->el_tty.t_ts.c_cflag != el->el_tty.t_ex.c_cflag) { int i;
el->el_tty.t_ex.c_cflag =
el->el_tty.t_ts.c_cflag; for (i = MD_INP; i <= MD_LIN; i++)
el->el_tty.t_ex.c_cflag &= tty_update_flags(el, i);
~el->el_tty.t_t[EX_IO][MD_CTL].t_clrmask;
el->el_tty.t_ex.c_cflag |=
el->el_tty.t_t[EX_IO][MD_CTL].t_setmask;
el->el_tty.t_ed.c_cflag =
el->el_tty.t_ts.c_cflag;
el->el_tty.t_ed.c_cflag &=
~el->el_tty.t_t[ED_IO][MD_CTL].t_clrmask;
el->el_tty.t_ed.c_cflag |=
el->el_tty.t_t[ED_IO][MD_CTL].t_setmask;
}
if ((el->el_tty.t_ts.c_lflag != el->el_tty.t_ex.c_lflag) &&
(el->el_tty.t_ts.c_lflag != el->el_tty.t_ed.c_lflag)) {
el->el_tty.t_ex.c_lflag =
el->el_tty.t_ts.c_lflag;
el->el_tty.t_ex.c_lflag &=
~el->el_tty.t_t[EX_IO][MD_LIN].t_clrmask;
el->el_tty.t_ex.c_lflag |=
el->el_tty.t_t[EX_IO][MD_LIN].t_setmask;
el->el_tty.t_ed.c_lflag =
el->el_tty.t_ts.c_lflag;
el->el_tty.t_ed.c_lflag &=
~el->el_tty.t_t[ED_IO][MD_LIN].t_clrmask;
el->el_tty.t_ed.c_lflag |=
el->el_tty.t_t[ED_IO][MD_LIN].t_setmask;
}
if ((el->el_tty.t_ts.c_iflag != el->el_tty.t_ex.c_iflag) &&
(el->el_tty.t_ts.c_iflag != el->el_tty.t_ed.c_iflag)) {
el->el_tty.t_ex.c_iflag =
el->el_tty.t_ts.c_iflag;
el->el_tty.t_ex.c_iflag &=
~el->el_tty.t_t[EX_IO][MD_INP].t_clrmask;
el->el_tty.t_ex.c_iflag |=
el->el_tty.t_t[EX_IO][MD_INP].t_setmask;
el->el_tty.t_ed.c_iflag =
el->el_tty.t_ts.c_iflag;
el->el_tty.t_ed.c_iflag &=
~el->el_tty.t_t[ED_IO][MD_INP].t_clrmask;
el->el_tty.t_ed.c_iflag |=
el->el_tty.t_t[ED_IO][MD_INP].t_setmask;
}
if ((el->el_tty.t_ts.c_oflag != el->el_tty.t_ex.c_oflag) &&
(el->el_tty.t_ts.c_oflag != el->el_tty.t_ed.c_oflag)) {
el->el_tty.t_ex.c_oflag =
el->el_tty.t_ts.c_oflag;
el->el_tty.t_ex.c_oflag &=
~el->el_tty.t_t[EX_IO][MD_OUT].t_clrmask;
el->el_tty.t_ex.c_oflag |=
el->el_tty.t_t[EX_IO][MD_OUT].t_setmask;
el->el_tty.t_ed.c_oflag =
el->el_tty.t_ts.c_oflag;
el->el_tty.t_ed.c_oflag &=
~el->el_tty.t_t[ED_IO][MD_OUT].t_clrmask;
el->el_tty.t_ed.c_oflag |=
el->el_tty.t_t[ED_IO][MD_OUT].t_setmask;
}
if (tty__gettabs(&el->el_tty.t_ex) == 0) if (tty__gettabs(&el->el_tty.t_ex) == 0)
el->el_tty.t_tabs = 0; el->el_tty.t_tabs = 0;
else else
el->el_tty.t_tabs = EL_CAN_TAB ? 1 : 0; el->el_tty.t_tabs = EL_CAN_TAB ? 1 : 0;
{ tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]);
int i; /*
* Check if the user made any changes.
* If he did, then propagate the changes to the
* edit and execute data structures.
*/
for (i = 0; i < C_NCC; i++)
if (el->el_tty.t_c[TS_IO][i] !=
el->el_tty.t_c[EX_IO][i])
break;
tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]); if (i != C_NCC) {
/* /*
* Check if the user made any changes. * Propagate changes only to the unlibedit_private
* If he did, then propagate the changes to the * chars that have been modified just now.
* edit and execute data structures. */
*/
for (i = 0; i < C_NCC; i++) for (i = 0; i < C_NCC; i++)
if (el->el_tty.t_c[TS_IO][i] != tty_update_char(el, ED_IO, i);
el->el_tty.t_c[EX_IO][i])
break; tty_bind_char(el, 0);
tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]);
if (i != C_NCC) {
/* for (i = 0; i < C_NCC; i++)
* Propagate changes only to the unprotected tty_update_char(el, EX_IO, i);
* chars that have been modified just now.
*/ tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
for (i = 0; i < C_NCC; i++) {
if (!((el->el_tty.t_t[ED_IO][MD_CHAR].t_s
etmask & C_SH(i)))
&& (el->el_tty.t_c[TS_IO][i] != el->e
l_tty.t_c[EX_IO][i]))
el->el_tty.t_c[ED_IO][i] = el->el
_tty.t_c[TS_IO][i];
if (el->el_tty.t_t[ED_IO][MD_CHAR].t_clrm
ask & C_SH(i))
el->el_tty.t_c[ED_IO][i] = el->el
_tty.t_vdisable;
}
tty_bind_char(el, 0);
tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_
IO]);
for (i = 0; i < C_NCC; i++) {
if (!((el->el_tty.t_t[EX_IO][MD_CHAR].t_s
etmask & C_SH(i)))
&& (el->el_tty.t_c[TS_IO][i] != el->e
l_tty.t_c[EX_IO][i]))
el->el_tty.t_c[EX_IO][i] = el->el
_tty.t_c[TS_IO][i];
if (el->el_tty.t_t[EX_IO][MD_CHAR].t_clrm
ask & C_SH(i))
el->el_tty.t_c[EX_IO][i] = el->el
_tty.t_vdisable;
}
tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_
IO]);
}
} }
} }
if (tty_setty(el, &el->el_tty.t_ed) == -1) { if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
#ifdef DEBUG_TTY #ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, "tty_rawmode: tty_setty: %s\n", (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
strerror(errno)); strerror(errno));
#endif /* DEBUG_TTY */ #endif /* DEBUG_TTY */
return (-1); return -1;
} }
el->el_tty.t_mode = ED_IO; el->el_tty.t_mode = ED_IO;
return (0); return 0;
} }
/* tty_cookedmode(): /* tty_cookedmode():
* Set the tty back to normal mode * Set the tty back to normal mode
*/ */
protected int libedit_private int
tty_cookedmode(EditLine *el) tty_cookedmode(EditLine *el)
{ /* set tty in normal setup */ { /* set tty in normal setup */
if (el->el_tty.t_mode == EX_IO) if (el->el_tty.t_mode == EX_IO)
return (0); return 0;
if (el->el_flags & EDIT_DISABLED) if (el->el_flags & EDIT_DISABLED)
return (0); return 0;
if (tty_setty(el, &el->el_tty.t_ex) == -1) { if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
#ifdef DEBUG_TTY #ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
"tty_cookedmode: tty_setty: %s\n",
strerror(errno)); strerror(errno));
#endif /* DEBUG_TTY */ #endif /* DEBUG_TTY */
return (-1); return -1;
} }
el->el_tty.t_mode = EX_IO; el->el_tty.t_mode = EX_IO;
return (0); return 0;
} }
/* tty_quotemode(): /* tty_quotemode():
* Turn on quote mode * Turn on quote mode
*/ */
protected int libedit_private int
tty_quotemode(EditLine *el) tty_quotemode(EditLine *el)
{ {
if (el->el_tty.t_mode == QU_IO) if (el->el_tty.t_mode == QU_IO)
return (0); return 0;
el->el_tty.t_qu = el->el_tty.t_ed; el->el_tty.t_qu = el->el_tty.t_ed;
el->el_tty.t_qu.c_iflag &= ~el->el_tty.t_t[QU_IO][MD_INP].t_clrmask; tty_setup_flags(el, &el->el_tty.t_qu, QU_IO);
el->el_tty.t_qu.c_iflag |= el->el_tty.t_t[QU_IO][MD_INP].t_setmask;
el->el_tty.t_qu.c_oflag &= ~el->el_tty.t_t[QU_IO][MD_OUT].t_clrmask;
el->el_tty.t_qu.c_oflag |= el->el_tty.t_t[QU_IO][MD_OUT].t_setmask;
el->el_tty.t_qu.c_cflag &= ~el->el_tty.t_t[QU_IO][MD_CTL].t_clrmask; if (tty_setty(el, TCSADRAIN, &el->el_tty.t_qu) == -1) {
el->el_tty.t_qu.c_cflag |= el->el_tty.t_t[QU_IO][MD_CTL].t_setmask;
el->el_tty.t_qu.c_lflag &= ~el->el_tty.t_t[QU_IO][MD_LIN].t_clrmask;
el->el_tty.t_qu.c_lflag |= el->el_tty.t_t[QU_IO][MD_LIN].t_setmask;
if (tty_setty(el, &el->el_tty.t_qu) == -1) {
#ifdef DEBUG_TTY #ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n", (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
strerror(errno)); strerror(errno));
#endif /* DEBUG_TTY */ #endif /* DEBUG_TTY */
return (-1); return -1;
} }
el->el_tty.t_mode = QU_IO; el->el_tty.t_mode = QU_IO;
return (0); return 0;
} }
/* tty_noquotemode(): /* tty_noquotemode():
* Turn off quote mode * Turn off quote mode
*/ */
protected int libedit_private int
tty_noquotemode(EditLine *el) tty_noquotemode(EditLine *el)
{ {
if (el->el_tty.t_mode != QU_IO) if (el->el_tty.t_mode != QU_IO)
return (0); return 0;
if (tty_setty(el, &el->el_tty.t_ed) == -1) { if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
#ifdef DEBUG_TTY #ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n", (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
strerror(errno)); strerror(errno));
#endif /* DEBUG_TTY */ #endif /* DEBUG_TTY */
return (-1); return -1;
} }
el->el_tty.t_mode = ED_IO; el->el_tty.t_mode = ED_IO;
return (0); return 0;
} }
/* tty_stty(): /* tty_stty():
* Stty builtin * Stty builtin
*/ */
protected int libedit_private int
/*ARGSUSED*/ /*ARGSUSED*/
tty_stty(EditLine *el, int argc __attribute__((__unused__)), const char **argv) tty_stty(EditLine *el, int argc __attribute__((__unused__)),
const wchar_t **argv)
{ {
const ttymodes_t *m; const ttymodes_t *m;
char x; char x;
int aflag = 0; int aflag = 0;
const char *s, *d; const wchar_t *s, *d;
const char *name; char name[EL_BUFSIZ];
struct termios *tios = &el->el_tty.t_ex; struct termios *tios = &el->el_tty.t_ex;
int z = EX_IO; int z = EX_IO;
if (argv == NULL) if (argv == NULL)
return (-1); return -1;
name = *argv++; strlcpy(name, ct_encode_string(*argv++, &el->el_scratch), sizeof(name));
while (argv && *argv && argv[0][0] == '-' && argv[0][2] == '\0') while (argv && *argv && argv[0][0] == '-' && argv[0][2] == '\0')
switch (argv[0][1]) { switch (argv[0][1]) {
case 'a': case 'a':
aflag++; aflag++;
argv++; argv++;
break; break;
case 'd': case 'd':
argv++; argv++;
tios = &el->el_tty.t_ed; tios = &el->el_tty.t_ed;
skipping to change at line 1168 skipping to change at line 1181
tios = &el->el_tty.t_ex; tios = &el->el_tty.t_ex;
z = EX_IO; z = EX_IO;
break; break;
case 'q': case 'q':
argv++; argv++;
tios = &el->el_tty.t_ts; tios = &el->el_tty.t_ts;
z = QU_IO; z = QU_IO;
break; break;
default: default:
(void) fprintf(el->el_errfile, (void) fprintf(el->el_errfile,
"%s: Unknown switch `%c'.\n", "%s: Unknown switch `%lc'.\n",
name, argv[0][1]); name, (wint_t)argv[0][1]);
return (-1); return -1;
} }
if (!argv || !*argv) { if (!argv || !*argv) {
int i = -1; int i = -1;
int len = 0, st = 0, cu; size_t len = 0, st = 0, cu;
for (m = ttymodes; m->m_name; m++) { for (m = ttymodes; m->m_name; m++) {
if (m->m_type != i) { if (m->m_type != i) {
(void) fprintf(el->el_outfile, "%s%s", (void) fprintf(el->el_outfile, "%s%s",
i != -1 ? "\n" : "", i != -1 ? "\n" : "",
el->el_tty.t_t[z][m->m_type].t_name); el->el_tty.t_t[z][m->m_type].t_name);
i = m->m_type; i = m->m_type;
st = len = st = len =
strlen(el->el_tty.t_t[z][m->m_type].t_name); strlen(el->el_tty.t_t[z][m->m_type].t_name);
} }
x = (el->el_tty.t_t[z][i].t_setmask & m->m_value) if (i != -1) {
? '+' : '\0'; x = (el->el_tty.t_t[z][i].t_setmask & m->m_value)
x = (el->el_tty.t_t[z][i].t_clrmask & m->m_value) ? '+' : '\0';
? '-' : x;
if (el->el_tty.t_t[z][i].t_clrmask & m->m_value)
x = '-';
} else {
x = '\0';
}
if (x != '\0' || aflag) { if (x != '\0' || aflag) {
cu = strlen(m->m_name) + (x != '\0') + 1; cu = strlen(m->m_name) + (x != '\0') + 1;
if (len + cu >= el->el_term.t_size.h) { if (len + cu >=
(size_t)el->el_terminal.t_size.h) {
(void) fprintf(el->el_outfile, "\n%*s", (void) fprintf(el->el_outfile, "\n%*s",
st, ""); (int)st, "");
len = st + cu; len = st + cu;
} else } else
len += cu; len += cu;
if (x != '\0') if (x != '\0')
(void) fprintf(el->el_outfile, "%c%s ", (void) fprintf(el->el_outfile, "%c%s ",
x, m->m_name); x, m->m_name);
else else
(void) fprintf(el->el_outfile, "%s ", (void) fprintf(el->el_outfile, "%s ",
m->m_name); m->m_name);
} }
} }
(void) fprintf(el->el_outfile, "\n"); (void) fprintf(el->el_outfile, "\n");
return (0); return 0;
} }
while (argv && (s = *argv++)) { while (argv && (s = *argv++)) {
const char *p; const wchar_t *p;
switch (*s) { switch (*s) {
case '+': case '+':
case '-': case '-':
x = *s++; x = (char)*s++;
break; break;
default: default:
x = '\0'; x = '\0';
break; break;
} }
d = s; d = s;
p = strchr(s, '='); p = wcschr(s, L'=');
for (m = ttymodes; m->m_name; m++) for (m = ttymodes; m->m_name; m++)
if ((p ? strncmp(m->m_name, d, (size_t)(p - d)) : if ((p ? strncmp(m->m_name, ct_encode_string(d,
strcmp(m->m_name, d)) == 0 && &el->el_scratch), (size_t)(p - d)) :
strcmp(m->m_name, ct_encode_string(d,
&el->el_scratch))) == 0 &&
(p == NULL || m->m_type == MD_CHAR)) (p == NULL || m->m_type == MD_CHAR))
break; break;
if (!m->m_name) { if (!m->m_name) {
(void) fprintf(el->el_errfile, (void) fprintf(el->el_errfile,
"%s: Invalid argument `%s'.\n", name, d); "%s: Invalid argument `%ls'.\n", name, d);
return (-1); return -1;
} }
if (p) { if (p) {
int c = ffs((int)m->m_value); int c = ffs((int)m->m_value);
int v = *++p ? parse__escape((const char **) &p) : int v = *++p ? parse__escape(&p) :
el->el_tty.t_vdisable; el->el_tty.t_vdisable;
assert(c-- != 0); assert(c != 0);
c--;
c = tty__getcharindex(c); c = tty__getcharindex(c);
assert(c != -1); assert(c != -1);
tios->c_cc[c] = v; tios->c_cc[c] = (cc_t)v;
continue; continue;
} }
switch (x) { switch (x) {
case '+': case '+':
el->el_tty.t_t[z][m->m_type].t_setmask |= m->m_value; el->el_tty.t_t[z][m->m_type].t_setmask |= m->m_value;
el->el_tty.t_t[z][m->m_type].t_clrmask &= ~m->m_value; el->el_tty.t_t[z][m->m_type].t_clrmask &= ~m->m_value;
break; break;
case '-': case '-':
el->el_tty.t_t[z][m->m_type].t_setmask &= ~m->m_value; el->el_tty.t_t[z][m->m_type].t_setmask &= ~m->m_value;
el->el_tty.t_t[z][m->m_type].t_clrmask |= m->m_value; el->el_tty.t_t[z][m->m_type].t_clrmask |= m->m_value;
break; break;
default: default:
el->el_tty.t_t[z][m->m_type].t_setmask &= ~m->m_value; el->el_tty.t_t[z][m->m_type].t_setmask &= ~m->m_value;
el->el_tty.t_t[z][m->m_type].t_clrmask &= ~m->m_value; el->el_tty.t_t[z][m->m_type].t_clrmask &= ~m->m_value;
break; break;
} }
} }
return (0);
tty_setup_flags(el, tios, z);
if (el->el_tty.t_mode == z) {
if (tty_setty(el, TCSADRAIN, tios) == -1) {
#ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, "%s: tty_setty: %s\n",
__func__, strerror(errno));
#endif /* DEBUG_TTY */
return -1;
}
}
return 0;
} }
#ifdef notyet #ifdef notyet
/* tty_printchar(): /* tty_printchar():
* DEbugging routine to print the tty characters * DEbugging routine to print the tty characters
*/ */
private void static void
tty_printchar(EditLine *el, unsigned char *s) tty_printchar(EditLine *el, unsigned char *s)
{ {
ttyperm_t *m; ttyperm_t *m;
int i; int i;
for (i = 0; i < C_NCC; i++) { for (i = 0; i < C_NCC; i++) {
for (m = el->el_tty.t_t; m->m_name; m++) for (m = el->el_tty.t_t; m->m_name; m++)
if (m->m_type == MD_CHAR && C_SH(i) == m->m_value) if (m->m_type == MD_CHAR && C_SH(i) == m->m_value)
break; break;
if (m->m_name) if (m->m_name)
(void) fprintf(el->el_errfile, "%s ^%c ", (void) fprintf(el->el_errfile, "%s ^%c ",
m->m_name, s[i] + 'A' - 1); m->m_name, s[i] + 'A' - 1);
if (i % 5 == 0) if (i % 5 == 0)
(void) fprintf(el->el_errfile, "\n"); (void) fprintf(el->el_errfile, "\n");
} }
(void) fprintf(el->el_errfile, "\n"); (void) fprintf(el->el_errfile, "\n");
} }
#endif /* notyet */ #endif /* notyet */
static void
tty_setup_flags(EditLine *el, struct termios *tios, int mode)
{
int kind;
for (kind = MD_INP; kind <= MD_LIN; kind++) {
tcflag_t *f = tty__get_flag(tios, kind);
*f = tty_update_flag(el, *f, mode, kind);
}
}
libedit_private int
tty_get_signal_character(EditLine *el, int sig)
{
#ifdef ECHOCTL
tcflag_t *ed = tty__get_flag(&el->el_tty.t_ed, MD_INP);
if ((*ed & ECHOCTL) == 0)
return -1;
#endif
switch (sig) {
#ifdef SIGINT
case SIGINT:
return el->el_tty.t_c[ED_IO][VINTR];
#endif
#ifdef SIGQUIT
case SIGQUIT:
return el->el_tty.t_c[ED_IO][VQUIT];
#endif
#ifdef SIGINFO
case SIGINFO:
return el->el_tty.t_c[ED_IO][VSTATUS];
#endif
#ifdef SIGTSTP
case SIGTSTP:
return el->el_tty.t_c[ED_IO][VSUSP];
#endif
default:
return -1;
}
}
 End of changes. 103 change blocks. 
261 lines changed or deleted 283 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)