summaryrefslogtreecommitdiff
path: root/tty.c
diff options
context:
space:
mode:
Diffstat (limited to 'tty.c')
-rw-r--r--tty.c102
1 files changed, 53 insertions, 49 deletions
diff --git a/tty.c b/tty.c
index 5b9b7dd799dd..2ca785808fe4 100644
--- a/tty.c
+++ b/tty.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tty.c,v 1.59 2016/03/22 01:34:32 christos Exp $ */
+/* $NetBSD: tty.c,v 1.66 2017/09/05 18:07:59 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: tty.c,v 1.59 2016/03/22 01:34:32 christos Exp $");
+__RCSID("$NetBSD: tty.c,v 1.66 2017/09/05 18:07:59 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -52,6 +52,7 @@ __RCSID("$NetBSD: tty.c,v 1.59 2016/03/22 01:34:32 christos Exp $");
#include <unistd.h> /* for isatty */
#include "el.h"
+#include "fcns.h"
#include "parse.h"
typedef struct ttymodes_t {
@@ -66,7 +67,7 @@ typedef struct ttymap_t {
} ttymap_t;
-private const ttyperm_t ttyperm = {
+static const ttyperm_t ttyperm = {
{
{"iflag:", ICRNL, (INLCR | IGNCR)},
{"oflag:", (OPOST | ONLCR), ONLRET},
@@ -94,7 +95,7 @@ private const ttyperm_t ttyperm = {
}
};
-private const ttychar_t ttychar = {
+static const ttychar_t ttychar = {
{
CINTR, CQUIT, CERASE, CKILL,
CEOF, CEOL, CEOL2, CSWTCH,
@@ -124,7 +125,7 @@ private const ttychar_t ttychar = {
}
};
-private const ttymap_t tty_map[] = {
+static const ttymap_t tty_map[] = {
#ifdef VERASE
{C_ERASE, VERASE,
{EM_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}},
@@ -161,7 +162,7 @@ private const ttymap_t tty_map[] = {
{ED_UNASSIGNED, ED_UNASSIGNED, ED_UNASSIGNED}}
};
-private const ttymodes_t ttymodes[] = {
+static const ttymodes_t ttymodes[] = {
#ifdef IGNBRK
{"ignbrk", IGNBRK, MD_INP},
#endif /* IGNBRK */
@@ -455,21 +456,21 @@ private const ttymodes_t ttymodes[] = {
#define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8)
#define tty__cooked_mode(td) ((td)->c_lflag & ICANON)
-private int tty_getty(EditLine *, struct termios *);
-private int tty_setty(EditLine *, int, const struct termios *);
-private int tty__getcharindex(int);
-private void tty__getchar(struct termios *, unsigned char *);
-private void tty__setchar(struct termios *, unsigned char *);
-private speed_t tty__getspeed(struct termios *);
-private int tty_setup(EditLine *);
-private void tty_setup_flags(EditLine *, struct termios *, int);
+static int tty_getty(EditLine *, struct termios *);
+static int tty_setty(EditLine *, int, const struct termios *);
+static int tty__getcharindex(int);
+static void tty__getchar(struct termios *, unsigned char *);
+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
/* tty_getty():
* Wrapper for tcgetattr to handle EINTR
*/
-private int
+static int
tty_getty(EditLine *el, struct termios *t)
{
int rv;
@@ -481,7 +482,7 @@ tty_getty(EditLine *el, struct termios *t)
/* tty_setty():
* Wrapper for tcsetattr to handle EINTR
*/
-private int
+static int
tty_setty(EditLine *el, int action, const struct termios *t)
{
int rv;
@@ -493,10 +494,10 @@ tty_setty(EditLine *el, int action, const struct termios *t)
/* tty_setup():
* Get the tty parameters and initialize the editing state
*/
-private int
+static int
tty_setup(EditLine *el)
{
- int rst = 1;
+ int rst = (el->el_flags & NO_RESET) == 0;
if (el->el_flags & EDIT_DISABLED)
return 0;
@@ -567,7 +568,7 @@ tty_setup(EditLine *el)
return 0;
}
-protected int
+libedit_private int
tty_init(EditLine *el)
{
@@ -583,7 +584,7 @@ tty_init(EditLine *el)
/* tty_end():
* Restore the tty to its original settings
*/
-protected void
+libedit_private void
/*ARGSUSED*/
tty_end(EditLine *el)
{
@@ -605,7 +606,7 @@ tty_end(EditLine *el)
/* tty__getspeed():
* Get the tty speed
*/
-private speed_t
+static speed_t
tty__getspeed(struct termios *td)
{
speed_t spd;
@@ -618,7 +619,7 @@ tty__getspeed(struct termios *td)
/* tty__getspeed():
* Return the index of the asked char in the c_cc array
*/
-private int
+static int
tty__getcharindex(int i)
{
switch (i) {
@@ -726,7 +727,7 @@ tty__getcharindex(int i)
/* tty__getchar():
* Get the tty characters
*/
-private void
+static void
tty__getchar(struct termios *td, unsigned char *s)
{
@@ -808,7 +809,7 @@ tty__getchar(struct termios *td, unsigned char *s)
/* tty__setchar():
* Set the tty characters
*/
-private void
+static void
tty__setchar(struct termios *td, unsigned char *s)
{
@@ -890,13 +891,13 @@ tty__setchar(struct termios *td, unsigned char *s)
/* tty_bind_char():
* Rebind the editline functions
*/
-protected void
+libedit_private void
tty_bind_char(EditLine *el, int force)
{
unsigned char *t_n = el->el_tty.t_c[ED_IO];
unsigned char *t_o = el->el_tty.t_ed.c_cc;
- Char new[2], old[2];
+ wchar_t new[2], old[2];
const ttymap_t *tp;
el_action_t *map, *alt;
const el_action_t *dmap, *dalt;
@@ -913,27 +914,29 @@ tty_bind_char(EditLine *el, int force)
}
for (tp = tty_map; tp->nch != (wint_t)-1; tp++) {
- new[0] = (Char)t_n[tp->nch];
- old[0] = (Char)t_o[tp->och];
+ new[0] = (wchar_t)t_n[tp->nch];
+ old[0] = (wchar_t)t_o[tp->och];
if (new[0] == old[0] && !force)
continue;
/* Put the old default binding back, and set the new binding */
keymacro_clear(el, map, old);
- map[UC(old[0])] = dmap[UC(old[0])];
+ map[(unsigned char)old[0]] = dmap[(unsigned char)old[0]];
keymacro_clear(el, map, new);
/* MAP_VI == 1, MAP_EMACS == 0... */
- map[UC(new[0])] = tp->bind[el->el_map.type];
+ map[(unsigned char)new[0]] = tp->bind[el->el_map.type];
if (dalt) {
keymacro_clear(el, alt, old);
- alt[UC(old[0])] = dalt[UC(old[0])];
+ alt[(unsigned char)old[0]] =
+ dalt[(unsigned char)old[0]];
keymacro_clear(el, alt, new);
- alt[UC(new[0])] = tp->bind[el->el_map.type + 1];
+ alt[(unsigned char)new[0]] =
+ tp->bind[el->el_map.type + 1];
}
}
}
-private tcflag_t *
+static tcflag_t *
tty__get_flag(struct termios *t, int kind) {
switch (kind) {
case MD_INP:
@@ -951,7 +954,7 @@ tty__get_flag(struct termios *t, int kind) {
}
-private tcflag_t
+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;
@@ -960,7 +963,7 @@ tty_update_flag(EditLine *el, tcflag_t f, int mode, int kind)
}
-private void
+static void
tty_update_flags(EditLine *el, int kind)
{
tcflag_t *tt, *ed, *ex;
@@ -975,7 +978,7 @@ tty_update_flags(EditLine *el, int kind)
}
-private void
+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]))
@@ -988,7 +991,7 @@ tty_update_char(EditLine *el, int mode, int c) {
/* tty_rawmode():
* Set terminal into 1 character at a time mode.
*/
-protected int
+libedit_private int
tty_rawmode(EditLine *el)
{
@@ -1043,7 +1046,7 @@ tty_rawmode(EditLine *el)
if (i != C_NCC) {
/*
- * Propagate changes only to the unprotected
+ * Propagate changes only to the unlibedit_private
* chars that have been modified just now.
*/
for (i = 0; i < C_NCC; i++)
@@ -1073,7 +1076,7 @@ tty_rawmode(EditLine *el)
/* tty_cookedmode():
* Set the tty back to normal mode
*/
-protected int
+libedit_private int
tty_cookedmode(EditLine *el)
{ /* set tty in normal setup */
@@ -1098,7 +1101,7 @@ tty_cookedmode(EditLine *el)
/* tty_quotemode():
* Turn on quote mode
*/
-protected int
+libedit_private int
tty_quotemode(EditLine *el)
{
if (el->el_tty.t_mode == QU_IO)
@@ -1123,7 +1126,7 @@ tty_quotemode(EditLine *el)
/* tty_noquotemode():
* Turn off quote mode
*/
-protected int
+libedit_private int
tty_noquotemode(EditLine *el)
{
@@ -1144,14 +1147,15 @@ tty_noquotemode(EditLine *el)
/* tty_stty():
* Stty builtin
*/
-protected int
+libedit_private int
/*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;
char x;
int aflag = 0;
- const Char *s, *d;
+ const wchar_t *s, *d;
char name[EL_BUFSIZ];
struct termios *tios = &el->el_tty.t_ex;
int z = EX_IO;
@@ -1235,7 +1239,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
return 0;
}
while (argv && (s = *argv++)) {
- const Char *p;
+ const wchar_t *p;
switch (*s) {
case '+':
case '-':
@@ -1246,7 +1250,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
break;
}
d = s;
- p = Strchr(s, '=');
+ p = wcschr(s, L'=');
for (m = ttymodes; m->m_name; m++)
if ((p ? strncmp(m->m_name, ct_encode_string(d,
&el->el_scratch), (size_t)(p - d)) :
@@ -1257,7 +1261,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
if (!m->m_name) {
(void) fprintf(el->el_errfile,
- "%s: Invalid argument `" FSTR "'.\n", name, d);
+ "%s: Invalid argument `%ls'.\n", name, d);
return -1;
}
if (p) {
@@ -1306,7 +1310,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
/* tty_printchar():
* DEbugging routine to print the tty characters
*/
-private void
+static void
tty_printchar(EditLine *el, unsigned char *s)
{
ttyperm_t *m;
@@ -1327,7 +1331,7 @@ tty_printchar(EditLine *el, unsigned char *s)
#endif /* notyet */
-private void
+static void
tty_setup_flags(EditLine *el, struct termios *tios, int mode)
{
int kind;