-
Notifications
You must be signed in to change notification settings - Fork 6
/
0002-Use-historical-conventions-for-delays-and-XCASE-spec.patch
191 lines (182 loc) · 4.81 KB
/
0002-Use-historical-conventions-for-delays-and-XCASE-spec.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
From fd626eb5526886e34da7a0ecbc090ab1c044c1c1 Mon Sep 17 00:00:00 2001
From: Hugh Pyle <[email protected]>
Date: Fri, 6 Dec 2019 23:42:11 +0000
Subject: [PATCH 2/2] Use historical conventions for delays and XCASE special
characters
Updates the implementation to match historical practice, where
XCASE has special handling for common punctuation that is not
available in ASCII-63 terminals:
\^ ==> ~
\! ==> |
\( ==> {
\) ==> }
\' ==> `
NL delays use two fill charcaters, and
CR delays use two (CR1, suitable for tty33 and tn300 terminals)
or four (CR2, suitable for tty37 and ti700) fill characters.
Also, if ONLRET, newline performs the carriage-return function
and should also use the carriage-return delays.
---
drivers/tty/n_tty.c | 100 ++++++++++++++++++++++++++++++++++----------
1 file changed, 78 insertions(+), 22 deletions(-)
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index fca85cb134e2..859aaa46ef2d 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -27,7 +27,7 @@
* Also fixed a bug in BLOCKING mode where n_tty_write returns
* EAGAIN
*
- * 2019/12/03 Experimental implementation of CRDLY, NLDLY and XCASE
+ * 2019/12/07 Experimental implementation of CRDLY, NLDLY and XCASE
* for mechanical terminals - Hugh Pyle <[email protected]>
*/
@@ -417,20 +417,21 @@ static inline int is_continuation(unsigned char c, struct tty_struct *tty)
* no space left.⏎
*/
-static inline int do_output_nl(struct tty_struct *tty, int space)
+static inline int do_output_withnldelay(unsigned char c, struct tty_struct *tty, int space)
{
if (!space)
return -1;
+ tty_put_char(tty, c);
if (unlikely(O_NLDLY(tty) && O_OFILL(tty))) {
- if (space < 2)
+ if (space < 3)
return -1;
if (O_OFDEL(tty))
- tty->ops->write(tty, "\n\177", 2);
+ tty->ops->write(tty, "\177\177", 2);
else
- tty->ops->write(tty, "\n\0", 2);
- return 2;
+ tty->ops->write(tty, "\0\0", 2);
+ return 3;
}
- return tty_put_char(tty, '\n');
+ return 1;
}
/**
@@ -440,30 +441,43 @@ static inline int do_output_nl(struct tty_struct *tty, int space)
* no space left.
*/
-static inline int do_output_cr(struct tty_struct *tty, int space)
+static inline int do_output_withcrdelay(unsigned char c, struct tty_struct *tty, int space)
{
struct n_tty_data *ldata = tty->disc_data;
- int delays;
+ int nchars;
if (!space)
return -1;
+ tty_put_char(tty, c);
if (unlikely(O_CRDLY(tty) && O_OFILL(tty))) {
- // insert filler bytes after CR, based on the delay (CR1, CR2, CR3)
- delays = 1;
- if (O_CRDLY(tty) == CR2)
- delays = 2;
- if (O_CRDLY(tty) == CR3)
- delays = 3;
- if (space < delays+1)
+ nchars = 1;
+ if (O_CRDLY(tty) == CR1) /* tty33, tn300 */
+ nchars = 2;
+ if (O_CRDLY(tty) == CR2) /* tty37, ti700 */
+ nchars = 4;
+ if (space < nchars+1)
return -1;
ldata->canon_column = ldata->column = 0;
if (O_OFDEL(tty))
- tty->ops->write(tty, "\r\177\177\177", delays+1);
+ tty->ops->write(tty, "\177\177\177\177", nchars);
else
- tty->ops->write(tty, "\r\0\0\0", delays+1);
- return delays;
+ tty->ops->write(tty, "\0\0\0\0", nchars);
+ return nchars + 1;
}
ldata->canon_column = ldata->column = 0;
- return tty_put_char(tty, '\r');
+ return 1;
+}
+
+static inline int do_output_nl(struct tty_struct *tty, int space)
+{
+ if (unlikely(O_ONLRET(tty)))
+ return do_output_withcrdelay('\n', tty, space);
+ else
+ return do_output_withnldelay('\n', tty, space);
+}
+
+static inline int do_output_cr(struct tty_struct *tty, int space)
+{
+ return do_output_withcrdelay('\r', tty, space);
}
/**
@@ -543,13 +557,36 @@ static int do_output_char(unsigned char c, struct tty_struct *tty, int space)
if (!iscntrl(c)) {
if (L_XCASE(tty) && L_ICANON(tty))
{
+ unsigned char c1 = '\0';
if (isupper(c) && !is_continuation(c, tty))
+ c1 = c;
+ else
+ {
+ switch (c) {
+ case '~':
+ c1 = '^';
+ break;
+ case '|':
+ c1 = '!';
+ break;
+ case '{':
+ c1 = '(';
+ break;
+ case '}':
+ c1 = ')';
+ break;
+ case '`':
+ c1 = '\'';
+ break;
+ }
+ }
+ if (c1)
{
if (space < 2)
return -1;
tty_put_char(tty, '\\');
ldata->column++;
- tty_put_char(tty, c);
+ tty_put_char(tty, c1);
ldata->column++;
return 2;
}
@@ -1603,7 +1640,26 @@ n_tty_receive_char_xcase(struct tty_struct *tty, unsigned char c, char flag)
if (likely(flag == TTY_NORMAL)) {
if (I_ISTRIP(tty))
c &= 0x7f;
- c = toupper(c);
+ switch (c) {
+ case '^':
+ c = '~';
+ break;
+ case '!':
+ c = '|';
+ break;
+ case '(':
+ c = '{';
+ break;
+ case ')':
+ c = '}';
+ break;
+ case '\'':
+ c = '`';
+ break;
+ default:
+ c = toupper(c);
+ break;
+ }
n_tty_receive_char(tty, c);
} else
n_tty_receive_char_flagged(tty, c, flag);
--
2.20.1