Deleted Added
full compact
tty.c (256281) tty.c (268782)
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Christos Zoulas of Cornell University.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Christos Zoulas of Cornell University.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $NetBSD: tty.c,v 1.25 2006/03/18 09:09:41 christos Exp $
32 * $NetBSD: tty.c,v 1.31 2009/07/22 15:58:09 christos Exp $
33 */
34
35#if !defined(lint) && !defined(SCCSID)
36static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
37#endif /* not lint && not SCCSID */
38#include <sys/cdefs.h>
33 */
34
35#if !defined(lint) && !defined(SCCSID)
36static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
37#endif /* not lint && not SCCSID */
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: stable/10/lib/libedit/tty.c 237448 2012-06-22 18:01:22Z pfg $");
39__FBSDID("$FreeBSD: stable/10/lib/libedit/tty.c 268782 2014-07-17 02:14:25Z pfg $");
40
41/*
42 * tty.c: tty interface stuff
43 */
44#include <assert.h>
45#include "sys.h"
46#include "tty.h"
47#include "el.h"

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

438#if defined(VTIME)
439 {"time", C_SH(C_TIME), MD_CHAR},
440#endif /* VTIME */
441 {NULL, 0, -1},
442};
443
444
445
40
41/*
42 * tty.c: tty interface stuff
43 */
44#include <assert.h>
45#include "sys.h"
46#include "tty.h"
47#include "el.h"

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

438#if defined(VTIME)
439 {"time", C_SH(C_TIME), MD_CHAR},
440#endif /* VTIME */
441 {NULL, 0, -1},
442};
443
444
445
446#define tty_getty(el, td) tcgetattr((el)->el_infd, (td))
447#define tty_setty(el, td) tcsetattr((el)->el_infd, TCSADRAIN, (td))
448
449#define tty__gettabs(td) ((((td)->c_oflag & TAB3) == TAB3) ? 0 : 1)
450#define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8)
451#define tty__cooked_mode(td) ((td)->c_lflag & ICANON)
452
446#define tty__gettabs(td) ((((td)->c_oflag & TAB3) == TAB3) ? 0 : 1)
447#define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8)
448#define tty__cooked_mode(td) ((td)->c_lflag & ICANON)
449
450private int tty_getty(EditLine *, struct termios *);
451private int tty_setty(EditLine *, int, const struct termios *);
453private int tty__getcharindex(int);
454private void tty__getchar(struct termios *, unsigned char *);
455private void tty__setchar(struct termios *, unsigned char *);
456private speed_t tty__getspeed(struct termios *);
457private int tty_setup(EditLine *);
458
459#define t_qu t_ts
460
452private int tty__getcharindex(int);
453private void tty__getchar(struct termios *, unsigned char *);
454private void tty__setchar(struct termios *, unsigned char *);
455private speed_t tty__getspeed(struct termios *);
456private int tty_setup(EditLine *);
457
458#define t_qu t_ts
459
460/* tty_getty():
461 * Wrapper for tcgetattr to handle EINTR
462 */
463private int
464tty_getty(EditLine *el, struct termios *t)
465{
466 int rv;
467 while ((rv = tcgetattr(el->el_infd, t)) == -1 && errno == EINTR)
468 continue;
469 return rv;
470}
461
471
472/* tty_setty():
473 * Wrapper for tcsetattr to handle EINTR
474 */
475private int
476tty_setty(EditLine *el, int action, const struct termios *t)
477{
478 int rv;
479 while ((rv = tcsetattr(el->el_infd, action, t)) == -1 && errno == EINTR)
480 continue;
481 return rv;
482}
483
462/* tty_setup():
463 * Get the tty parameters and initialize the editing state
464 */
465private int
466tty_setup(EditLine *el)
467{
468 int rst = 1;
469

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

991 }
992 }
993 }
994 }
995
996 if (el->el_tty.t_mode == EX_IO)
997 el->el_tty.t_ex = el->el_tty.t_ts;
998
484/* tty_setup():
485 * Get the tty parameters and initialize the editing state
486 */
487private int
488tty_setup(EditLine *el)
489{
490 int rst = 1;
491

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

1013 }
1014 }
1015 }
1016 }
1017
1018 if (el->el_tty.t_mode == EX_IO)
1019 el->el_tty.t_ex = el->el_tty.t_ts;
1020
999 if (tty_setty(el, &el->el_tty.t_ed) == -1) {
1021 if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
1000#ifdef DEBUG_TTY
1001 (void) fprintf(el->el_errfile, "tty_rawmode: tty_setty: %s\n",
1002 strerror(errno));
1003#endif /* DEBUG_TTY */
1004 return (-1);
1005 }
1006 el->el_tty.t_mode = ED_IO;
1007 return (0);

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

1016{ /* set tty in normal setup */
1017
1018 if (el->el_tty.t_mode == EX_IO)
1019 return (0);
1020
1021 if (el->el_flags & EDIT_DISABLED)
1022 return (0);
1023
1022#ifdef DEBUG_TTY
1023 (void) fprintf(el->el_errfile, "tty_rawmode: tty_setty: %s\n",
1024 strerror(errno));
1025#endif /* DEBUG_TTY */
1026 return (-1);
1027 }
1028 el->el_tty.t_mode = ED_IO;
1029 return (0);

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

1038{ /* set tty in normal setup */
1039
1040 if (el->el_tty.t_mode == EX_IO)
1041 return (0);
1042
1043 if (el->el_flags & EDIT_DISABLED)
1044 return (0);
1045
1024 if (tty_setty(el, &el->el_tty.t_ex) == -1) {
1046 if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
1025#ifdef DEBUG_TTY
1026 (void) fprintf(el->el_errfile,
1027 "tty_cookedmode: tty_setty: %s\n",
1028 strerror(errno));
1029#endif /* DEBUG_TTY */
1030 return (-1);
1031 }
1032 el->el_tty.t_mode = EX_IO;

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

1052 el->el_tty.t_qu.c_oflag |= el->el_tty.t_t[QU_IO][MD_OUT].t_setmask;
1053
1054 el->el_tty.t_qu.c_cflag &= ~el->el_tty.t_t[QU_IO][MD_CTL].t_clrmask;
1055 el->el_tty.t_qu.c_cflag |= el->el_tty.t_t[QU_IO][MD_CTL].t_setmask;
1056
1057 el->el_tty.t_qu.c_lflag &= ~el->el_tty.t_t[QU_IO][MD_LIN].t_clrmask;
1058 el->el_tty.t_qu.c_lflag |= el->el_tty.t_t[QU_IO][MD_LIN].t_setmask;
1059
1047#ifdef DEBUG_TTY
1048 (void) fprintf(el->el_errfile,
1049 "tty_cookedmode: tty_setty: %s\n",
1050 strerror(errno));
1051#endif /* DEBUG_TTY */
1052 return (-1);
1053 }
1054 el->el_tty.t_mode = EX_IO;

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

1074 el->el_tty.t_qu.c_oflag |= el->el_tty.t_t[QU_IO][MD_OUT].t_setmask;
1075
1076 el->el_tty.t_qu.c_cflag &= ~el->el_tty.t_t[QU_IO][MD_CTL].t_clrmask;
1077 el->el_tty.t_qu.c_cflag |= el->el_tty.t_t[QU_IO][MD_CTL].t_setmask;
1078
1079 el->el_tty.t_qu.c_lflag &= ~el->el_tty.t_t[QU_IO][MD_LIN].t_clrmask;
1080 el->el_tty.t_qu.c_lflag |= el->el_tty.t_t[QU_IO][MD_LIN].t_setmask;
1081
1060 if (tty_setty(el, &el->el_tty.t_qu) == -1) {
1082 if (tty_setty(el, TCSADRAIN, &el->el_tty.t_qu) == -1) {
1061#ifdef DEBUG_TTY
1062 (void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n",
1063 strerror(errno));
1064#endif /* DEBUG_TTY */
1065 return (-1);
1066 }
1067 el->el_tty.t_mode = QU_IO;
1068 return (0);

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

1073 * Turn off quote mode
1074 */
1075protected int
1076tty_noquotemode(EditLine *el)
1077{
1078
1079 if (el->el_tty.t_mode != QU_IO)
1080 return (0);
1083#ifdef DEBUG_TTY
1084 (void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n",
1085 strerror(errno));
1086#endif /* DEBUG_TTY */
1087 return (-1);
1088 }
1089 el->el_tty.t_mode = QU_IO;
1090 return (0);

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

1095 * Turn off quote mode
1096 */
1097protected int
1098tty_noquotemode(EditLine *el)
1099{
1100
1101 if (el->el_tty.t_mode != QU_IO)
1102 return (0);
1081 if (tty_setty(el, &el->el_tty.t_ed) == -1) {
1103 if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
1082#ifdef DEBUG_TTY
1083 (void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n",
1084 strerror(errno));
1085#endif /* DEBUG_TTY */
1086 return (-1);
1087 }
1088 el->el_tty.t_mode = ED_IO;
1089 return (0);

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

1134 (void) fprintf(el->el_errfile,
1135 "%s: Unknown switch `%c'.\n",
1136 name, argv[0][1]);
1137 return (-1);
1138 }
1139
1140 if (!argv || !*argv) {
1141 int i = -1;
1104#ifdef DEBUG_TTY
1105 (void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n",
1106 strerror(errno));
1107#endif /* DEBUG_TTY */
1108 return (-1);
1109 }
1110 el->el_tty.t_mode = ED_IO;
1111 return (0);

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

1156 (void) fprintf(el->el_errfile,
1157 "%s: Unknown switch `%c'.\n",
1158 name, argv[0][1]);
1159 return (-1);
1160 }
1161
1162 if (!argv || !*argv) {
1163 int i = -1;
1142 int len = 0, st = 0, cu;
1164 size_t len = 0, st = 0, cu;
1143 for (m = ttymodes; m->m_name; m++) {
1144 if (m->m_type != i) {
1145 (void) fprintf(el->el_outfile, "%s%s",
1146 i != -1 ? "\n" : "",
1147 el->el_tty.t_t[z][m->m_type].t_name);
1148 i = m->m_type;
1149 st = len =
1150 strlen(el->el_tty.t_t[z][m->m_type].t_name);

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

1157 } else {
1158 x = '\0';
1159 }
1160
1161 if (x != '\0' || aflag) {
1162
1163 cu = strlen(m->m_name) + (x != '\0') + 1;
1164
1165 for (m = ttymodes; m->m_name; m++) {
1166 if (m->m_type != i) {
1167 (void) fprintf(el->el_outfile, "%s%s",
1168 i != -1 ? "\n" : "",
1169 el->el_tty.t_t[z][m->m_type].t_name);
1170 i = m->m_type;
1171 st = len =
1172 strlen(el->el_tty.t_t[z][m->m_type].t_name);

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

1179 } else {
1180 x = '\0';
1181 }
1182
1183 if (x != '\0' || aflag) {
1184
1185 cu = strlen(m->m_name) + (x != '\0') + 1;
1186
1165 if (len + cu >= el->el_term.t_size.h) {
1187 if (len + cu >= (size_t)el->el_term.t_size.h) {
1166 (void) fprintf(el->el_outfile, "\n%*s",
1188 (void) fprintf(el->el_outfile, "\n%*s",
1167 st, "");
1189 (int)st, "");
1168 len = st + cu;
1169 } else
1170 len += cu;
1171
1172 if (x != '\0')
1173 (void) fprintf(el->el_outfile, "%c%s ",
1174 x, m->m_name);
1175 else

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

1203 (void) fprintf(el->el_errfile,
1204 "%s: Invalid argument `%s'.\n", name, d);
1205 return (-1);
1206 }
1207 if (p) {
1208 int c = ffs((int)m->m_value);
1209 int v = *++p ? parse__escape((const char **) &p) :
1210 el->el_tty.t_vdisable;
1190 len = st + cu;
1191 } else
1192 len += cu;
1193
1194 if (x != '\0')
1195 (void) fprintf(el->el_outfile, "%c%s ",
1196 x, m->m_name);
1197 else

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

1225 (void) fprintf(el->el_errfile,
1226 "%s: Invalid argument `%s'.\n", name, d);
1227 return (-1);
1228 }
1229 if (p) {
1230 int c = ffs((int)m->m_value);
1231 int v = *++p ? parse__escape((const char **) &p) :
1232 el->el_tty.t_vdisable;
1211 assert(c-- != 0);
1233 assert(c != 0);
1234 c--;
1212 c = tty__getcharindex(c);
1213 assert(c != -1);
1214 tios->c_cc[c] = v;
1215 continue;
1216 }
1217 switch (x) {
1218 case '+':
1219 el->el_tty.t_t[z][m->m_type].t_setmask |= m->m_value;

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

1224 el->el_tty.t_t[z][m->m_type].t_clrmask |= m->m_value;
1225 break;
1226 default:
1227 el->el_tty.t_t[z][m->m_type].t_setmask &= ~m->m_value;
1228 el->el_tty.t_t[z][m->m_type].t_clrmask &= ~m->m_value;
1229 break;
1230 }
1231 }
1235 c = tty__getcharindex(c);
1236 assert(c != -1);
1237 tios->c_cc[c] = v;
1238 continue;
1239 }
1240 switch (x) {
1241 case '+':
1242 el->el_tty.t_t[z][m->m_type].t_setmask |= m->m_value;

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

1247 el->el_tty.t_t[z][m->m_type].t_clrmask |= m->m_value;
1248 break;
1249 default:
1250 el->el_tty.t_t[z][m->m_type].t_setmask &= ~m->m_value;
1251 el->el_tty.t_t[z][m->m_type].t_clrmask &= ~m->m_value;
1252 break;
1253 }
1254 }
1255
1256 if (el->el_tty.t_mode == z) {
1257 if (tty_setty(el, TCSADRAIN, tios) == -1) {
1258#ifdef DEBUG_TTY
1259 (void) fprintf(el->el_errfile,
1260 "tty_stty: tty_setty: %s\n", strerror(errno));
1261#endif /* DEBUG_TTY */
1262 return (-1);
1263 }
1264 }
1265
1232 return (0);
1233}
1234
1235
1236#ifdef notyet
1237/* tty_printchar():
1238 * DEbugging routine to print the tty characters
1239 */

--- 19 unchanged lines hidden ---
1266 return (0);
1267}
1268
1269
1270#ifdef notyet
1271/* tty_printchar():
1272 * DEbugging routine to print the tty characters
1273 */

--- 19 unchanged lines hidden ---