Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1614426 > unrolled thread
| Started by | Adam Borowski <kilobyte@angband.pl> |
|---|---|
| First post | 2017-04-01 11:50 +0200 |
| Last post | 2017-04-01 11:50 +0200 |
| Articles | 2 — 1 participant |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 1/4] n_tty: don't mangle tty codes in OLCUC mode Adam Borowski <kilobyte@angband.pl> - 2017-04-01 11:50 +0200
[PATCH 4/4] n_tty: wrap all OLCUC code in a config option Adam Borowski <kilobyte@angband.pl> - 2017-04-01 11:50 +0200
| From | Adam Borowski <kilobyte@angband.pl> |
|---|---|
| Date | 2017-04-01 11:50 +0200 |
| Subject | [PATCH 1/4] n_tty: don't mangle tty codes in OLCUC mode |
| Message-ID | <trnPr-Pj-5@gated-at.bofh.it> |
Any terminal younger than ~40 years requires lowercase commands, thus they
need to be exempt from uppercasing. And Linux doesn't really support
ancient all-uppercase terminals anyway (no XCASE, etc) even if someone made
the effort to somehow connect them electrically.
This bug is reproducible as of Linux 0.11 and I see it in 0.01 sources
(whose images fail to boot for me, I didn't try very hard). It was less of
a failure then as the shell didn't produce tty codes for normal operation.
Signed-off-by: Adam Borowski <kilobyte@angband.pl>
---
drivers/tty/n_tty.c | 58 ++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 46 insertions(+), 12 deletions(-)
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index bdf0e6e89991..bbc9f07c19fa 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -87,6 +87,8 @@
# define n_tty_trace(f, args...)
#endif
+enum { ESnormal, ESesc, EScsi, ESsetG };
+
struct n_tty_data {
/* producer-published */
size_t read_head;
@@ -121,6 +123,7 @@ struct n_tty_data {
unsigned int column;
unsigned int canon_column;
size_t echo_tail;
+ unsigned int vt_state;
struct mutex atomic_read_lock;
struct mutex output_lock;
@@ -392,6 +395,40 @@ static inline int is_continuation(unsigned char c, struct tty_struct *tty)
return I_IUTF8(tty) && is_utf8_continuation(c);
}
+/* process one OLCUC char (possibly partial unicode)
+ *
+ * We need to partially parse ANSI sequences to avoid uppercasing them;
+ * only some commands require lowercase.
+ */
+
+static int do_olcuc_char(unsigned char c, struct tty_struct *tty)
+{
+ struct n_tty_data *ldata = tty->disc_data;
+
+ switch (ldata->vt_state) {
+ case ESesc:
+ ldata->vt_state = (c == '[') ? EScsi :
+ strchr("%()*+-./", c) ? ESsetG : ESnormal;
+ break;
+ case EScsi:
+ if (!strchr("?;0123456789>!c$\" \\", c))
+ ldata->vt_state = ESnormal;
+ break;
+ case ESsetG:
+ ldata->vt_state = ESnormal;
+ break;
+ default:
+ if (c == '\e')
+ ldata->vt_state = ESesc;
+ else if (c >= 'a' && c <= 'z')
+ c -= 32;
+ }
+ if (!iscntrl(c) && !is_continuation(c, tty))
+ ldata->column++;
+ tty_put_char(tty, c);
+ return 1;
+}
+
/**
* do_output_char - output one character
* @c: character (or partial unicode symbol)
@@ -462,12 +499,10 @@ static int do_output_char(unsigned char c, struct tty_struct *tty, int space)
ldata->column--;
break;
default:
- if (!iscntrl(c)) {
- if (O_OLCUC(tty))
- c = toupper(c);
- if (!is_continuation(c, tty))
- ldata->column++;
- }
+ if (O_OLCUC(tty))
+ return do_olcuc_char(c, tty);
+ if (!iscntrl(c) && !is_continuation(c, tty))
+ ldata->column++;
break;
}
@@ -568,12 +603,10 @@ static ssize_t process_output_block(struct tty_struct *tty,
ldata->column--;
break;
default:
- if (!iscntrl(c)) {
- if (O_OLCUC(tty))
- goto break_out;
- if (!is_continuation(c, tty))
- ldata->column++;
- }
+ if (O_OLCUC(tty))
+ goto break_out;
+ if (!iscntrl(c) && !is_continuation(c, tty))
+ ldata->column++;
break;
}
}
@@ -1895,6 +1928,7 @@ static int n_tty_open(struct tty_struct *tty)
ldata->num_overrun = 0;
ldata->no_room = 0;
ldata->lnext = 0;
+ ldata->vt_state = ESnormal;
tty->closing = 0;
/* indicate buffer work may resume */
clear_bit(TTY_LDISC_HALTED, &tty->flags);
--
2.11.0
[toc] | [next] | [standalone]
| From | Adam Borowski <kilobyte@angband.pl> |
|---|---|
| Date | 2017-04-01 11:50 +0200 |
| Subject | [PATCH 4/4] n_tty: wrap all OLCUC code in a config option |
| Message-ID | <trnPr-Pj-9@gated-at.bofh.it> |
| In reply to | #1614426 |
Setting it to N, beside dropping runes, also disables old-style support
for all-caps OLCUC. To get those 40 years old terminals to work, set
CONFIG_TTY_RUNES=y which will DTRT when stty iutf8 is off.
Signed-off-by: Adam Borowski <kilobyte@angband.pl>
---
drivers/tty/Kconfig | 17 +++++++++++++++++
drivers/tty/n_tty.c | 10 ++++++++++
2 files changed, 27 insertions(+)
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 95103054c0e4..cfeed2b196e5 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -151,6 +151,23 @@ config LEGACY_PTY_COUNT
When not in use, each legacy PTY occupies 12 bytes on 32-bit
architectures and 24 bytes on 64-bit architectures.
+config TTY_RUNES
+ bool "Runes on OLCUC"
+ default y
+ ---help---
+ Certain terminals from the days of Unix' infancy supported only
+ all-caps, so-called "Great Runes". Linux still has rudimentary
+ support for those, although how can you connect one is another
+ matter; you enable that via "stty olcuc".
+
+ On anything modern, though (as in "stty iutf8"), you do get actual
+ runes. You need userspace fonts for that; modern distributions
+ tend to install both raster (xterm/rxvt) and TrueType (most
+ terminals) fonts on their default GUI setups. Alas, this is not
+ the case on console due to sharply limited character sets.
+
+ C'mon, you know you want to say Y!
+
config BFIN_JTAG_COMM
tristate "Blackfin JTAG Communication"
depends on BLACKFIN
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 3b8b745eb7cf..14d090576f09 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -123,7 +123,9 @@ struct n_tty_data {
unsigned int column;
unsigned int canon_column;
size_t echo_tail;
+#ifdef CONFIG_TTY_RUNES
unsigned int vt_state;
+#endif
struct mutex atomic_read_lock;
struct mutex output_lock;
@@ -395,6 +397,7 @@ static inline int is_continuation(unsigned char c, struct tty_struct *tty)
return I_IUTF8(tty) && is_utf8_continuation(c);
}
+#ifdef CONFIG_TTY_RUNES
/* process one OLCUC char (possibly partial unicode)
*
* We need to partially parse ANSI sequences to avoid uppercasing them;
@@ -475,6 +478,7 @@ static int do_olcuc_char(unsigned char c, struct tty_struct *tty, int space)
tty_put_char(tty, c);
return 1;
}
+#endif
/**
* do_output_char - output one character
@@ -546,8 +550,10 @@ static int do_output_char(unsigned char c, struct tty_struct *tty, int space)
ldata->column--;
break;
default:
+#ifdef CONFIG_TTY_RUNES
if (O_OLCUC(tty))
return do_olcuc_char(c, tty, space);
+#endif
if (!iscntrl(c) && !is_continuation(c, tty))
ldata->column++;
break;
@@ -650,8 +656,10 @@ static ssize_t process_output_block(struct tty_struct *tty,
ldata->column--;
break;
default:
+#ifdef CONFIG_TTY_RUNES
if (O_OLCUC(tty))
goto break_out;
+#endif
if (!iscntrl(c) && !is_continuation(c, tty))
ldata->column++;
break;
@@ -1975,7 +1983,9 @@ static int n_tty_open(struct tty_struct *tty)
ldata->num_overrun = 0;
ldata->no_room = 0;
ldata->lnext = 0;
+#ifdef CONFIG_TTY_RUNES
ldata->vt_state = ESnormal;
+#endif
tty->closing = 0;
/* indicate buffer work may resume */
clear_bit(TTY_LDISC_HALTED, &tty->flags);
--
2.11.0
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web