From: Jiri Slaby <jslaby@suse.cz>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 19/38] vc: move normal char processing from do_con_write
Date: Mon, 15 Jun 2020 09:48:51 +0200 [thread overview]
Message-ID: <20200615074910.19267-19-jslaby@suse.cz> (raw)
In-Reply-To: <20200615074910.19267-1-jslaby@suse.cz>
vc_con_write_normal now handles the complex normal characters
processing. It is no longer a part of do_con_write. So this patch makes
do_con_write pretty clean and obvious.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
drivers/tty/vt/vt.c | 198 ++++++++++++++++++++++++--------------------
1 file changed, 109 insertions(+), 89 deletions(-)
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 45d32844e61b..893f72dc812c 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -2726,21 +2726,116 @@ static bool vc_is_control(struct vc_data *vc, int tc, int c)
return false;
}
+static int vc_con_write_normal(struct vc_data *vc, int tc, int c,
+ struct vc_draw_region *draw)
+{
+ int next_c;
+ unsigned char vc_attr;
+ u16 himask = vc->vc_hi_font_mask, charmask = himask ? 0x1ff : 0xff;
+ u8 width = 1;
+ bool inverse = false;
+
+ if (vc->vc_utf && !vc->vc_disp_ctrl) {
+ if (is_double_width(c))
+ width = 2;
+ }
+
+ /* Now try to find out how to display it */
+ tc = conv_uni_to_pc(vc, tc);
+ if (tc & ~charmask) {
+ if (tc == -1 || tc == -2)
+ return -1; /* nothing to display */
+
+ /* Glyph not found */
+ if ((!(vc->vc_utf && !vc->vc_disp_ctrl) || c < 128) &&
+ !(c & ~charmask)) {
+ /*
+ * In legacy mode use the glyph we get by a 1:1
+ * mapping.
+ * This would make absolutely no sense with Unicode in
+ * mind, but do this for ASCII characters since a font
+ * may lack Unicode mapping info and we don't want to
+ * end up with having question marks only.
+ */
+ tc = c;
+ } else {
+ /*
+ * Display U+FFFD. If it's not found, display an inverse
+ * question mark.
+ */
+ tc = conv_uni_to_pc(vc, 0xfffd);
+ if (tc < 0) {
+ inverse = true;
+ tc = conv_uni_to_pc(vc, '?');
+ if (tc < 0)
+ tc = '?';
+ }
+ }
+ }
+
+ if (!inverse) {
+ vc_attr = vc->vc_attr;
+ } else {
+ vc_attr = vc_invert_attr(vc);
+ con_flush(vc, draw);
+ }
+
+ next_c = c;
+ while (1) {
+ if (vc->vc_need_wrap || vc->vc_decim)
+ con_flush(vc, draw);
+ if (vc->vc_need_wrap) {
+ cr(vc);
+ lf(vc);
+ }
+ if (vc->vc_decim)
+ insert_char(vc, 1);
+ vc_uniscr_putc(vc, next_c);
+ scr_writew(himask ?
+ ((vc_attr << 8) & ~himask) +
+ ((tc & 0x100) ? himask : 0) + (tc & 0xff) :
+ (vc_attr << 8) + tc,
+ (u16 *)vc->vc_pos);
+ if (con_should_update(vc) && draw->x < 0) {
+ draw->x = vc->state.x;
+ draw->from = vc->vc_pos;
+ }
+ if (vc->state.x == vc->vc_cols - 1) {
+ vc->vc_need_wrap = vc->vc_decawm;
+ draw->to = vc->vc_pos + 2;
+ } else {
+ vc->state.x++;
+ draw->to = (vc->vc_pos += 2);
+ }
+
+ if (!--width)
+ break;
+
+ /* A space is printed in the second column */
+ tc = conv_uni_to_pc(vc, ' ');
+ if (tc < 0)
+ tc = ' ';
+ next_c = ' ';
+ }
+ notify_write(vc, c);
+
+ if (inverse)
+ con_flush(vc, draw);
+
+ return 0;
+}
+
/* acquires console_lock */
static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int count)
{
struct vc_draw_region draw = {
.x = -1,
};
- int c, next_c, tc, n = 0;
+ int c, tc, n = 0;
unsigned int currcons;
struct vc_data *vc;
- unsigned char vc_attr;
struct vt_notifier_param param;
- u16 himask, charmask;
- u8 width;
bool rescan;
- bool inverse;
if (in_interrupt())
return count;
@@ -2761,8 +2856,6 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
return 0;
}
- himask = vc->vc_hi_font_mask;
- charmask = himask ? 0x1ff : 0xff;
/* undraw cursor first */
if (con_is_fg(vc))
@@ -2778,8 +2871,6 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
rescan_last_byte:
c = orig;
rescan = false;
- inverse = false;
- width = 1;
tc = vc_translate(vc, &c, &rescan);
if (tc == -1)
@@ -2790,88 +2881,17 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
¶m) == NOTIFY_STOP)
continue;
- if (!vc_is_control(vc, tc, c)) {
- if (vc->vc_utf && !vc->vc_disp_ctrl) {
- if (is_double_width(c))
- width = 2;
- }
- /* Now try to find out how to display it */
- tc = conv_uni_to_pc(vc, tc);
- if (tc & ~charmask) {
- if (tc == -1 || tc == -2) {
- continue; /* nothing to display */
- }
- /* Glyph not found */
- if ((!(vc->vc_utf && !vc->vc_disp_ctrl) || c < 128) && !(c & ~charmask)) {
- /* In legacy mode use the glyph we get by a 1:1 mapping.
- This would make absolutely no sense with Unicode in mind,
- but do this for ASCII characters since a font may lack
- Unicode mapping info and we don't want to end up with
- having question marks only. */
- tc = c;
- } else {
- /* Display U+FFFD. If it's not found, display an inverse question mark. */
- tc = conv_uni_to_pc(vc, 0xfffd);
- if (tc < 0) {
- inverse = true;
- tc = conv_uni_to_pc(vc, '?');
- if (tc < 0) tc = '?';
- }
- }
- }
-
- if (!inverse) {
- vc_attr = vc->vc_attr;
- } else {
- vc_attr = vc_invert_attr(vc);
- con_flush(vc, &draw);
- }
-
- next_c = c;
- while (1) {
- if (vc->vc_need_wrap || vc->vc_decim)
- con_flush(vc, &draw);
- if (vc->vc_need_wrap) {
- cr(vc);
- lf(vc);
- }
- if (vc->vc_decim)
- insert_char(vc, 1);
- vc_uniscr_putc(vc, next_c);
- scr_writew(himask ?
- ((vc_attr << 8) & ~himask) + ((tc & 0x100) ? himask : 0) + (tc & 0xff) :
- (vc_attr << 8) + tc,
- (u16 *) vc->vc_pos);
- if (con_should_update(vc) && draw.x < 0) {
- draw.x = vc->state.x;
- draw.from = vc->vc_pos;
- }
- if (vc->state.x == vc->vc_cols - 1) {
- vc->vc_need_wrap = vc->vc_decawm;
- draw.to = vc->vc_pos + 2;
- } else {
- vc->state.x++;
- draw.to = (vc->vc_pos += 2);
- }
-
- if (!--width) break;
-
- tc = conv_uni_to_pc(vc, ' '); /* A space is printed in the second column */
- if (tc < 0) tc = ' ';
- next_c = ' ';
- }
- notify_write(vc, c);
-
- if (inverse)
- con_flush(vc, &draw);
-
- if (rescan)
- goto rescan_last_byte;
-
+ if (vc_is_control(vc, tc, c)) {
+ con_flush(vc, &draw);
+ do_con_trol(tty, vc, orig);
continue;
}
- con_flush(vc, &draw);
- do_con_trol(tty, vc, orig);
+
+ if (vc_con_write_normal(vc, tc, c, &draw) < 0)
+ continue;
+
+ if (rescan)
+ goto rescan_last_byte;
}
con_flush(vc, &draw);
vc_uniscr_debug_check(vc);
--
2.27.0
next prev parent reply other threads:[~2020-06-15 7:50 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-15 7:48 [PATCH 01/38] vc: separate state Jiri Slaby
2020-06-15 7:48 ` [PATCH 02/38] vt: introduce enum vc_intensity for intensity Jiri Slaby
2020-06-15 7:48 ` [PATCH 03/38] vc: switch state to bool Jiri Slaby
2020-06-15 7:48 ` [PATCH 04/38] vt: deduplicate setGx code Jiri Slaby
2020-06-15 7:48 ` [PATCH 05/38] vt: switch G0/1_charset to an array Jiri Slaby
2020-06-15 7:48 ` [PATCH 06/38] vt: convert vc_tab_stop to bitmap Jiri Slaby
2020-06-15 7:48 ` [PATCH 07/38] vt: remove 25 years stale comment Jiri Slaby
2020-06-15 7:48 ` [PATCH 08/38] vt: use tty_insert_flip_string in respond_string Jiri Slaby
2020-06-15 7:48 ` [PATCH 09/38] vt: get rid of VT10.ID macros Jiri Slaby
2020-06-15 7:48 ` [PATCH 10/38] vt: move vc_translate to vt.c and rename it Jiri Slaby
2020-06-15 7:48 ` [PATCH 11/38] vt: use modern types in do_con_write Jiri Slaby
2020-06-15 7:48 ` [PATCH 12/38] vt: separate unicode handling into vc_translate_unicode Jiri Slaby
2020-06-15 7:48 ` [PATCH 13/38] vt: rearrange vc_translate_unicode Jiri Slaby
2020-06-15 7:48 ` [PATCH 14/38] vt: extract attribute inversion to vc_invert_attr Jiri Slaby
2020-06-15 7:48 ` [PATCH 15/38] vt: move rescan_last_byte label earlier Jiri Slaby
2020-06-15 7:48 ` [PATCH 16/38] vc: move translation out of do_con_write Jiri Slaby
2020-06-15 7:48 ` [PATCH 17/38] vc: introduce struct vc_draw_region Jiri Slaby
2020-06-15 7:48 ` [PATCH 18/38] vc: extract detecting control characters from do_con_write Jiri Slaby
2020-06-15 7:48 ` Jiri Slaby [this message]
2020-06-15 7:48 ` [PATCH 20/38] vc: simplify condition in vc_con_write_normal Jiri Slaby
2020-06-15 7:48 ` [PATCH 21/38] vt: simplify vc_attr handling " Jiri Slaby
2020-06-15 7:48 ` [PATCH 22/38] vt: make tc write more obvious " Jiri Slaby
2020-06-15 7:48 ` [PATCH 23/38] vt: synchronize types and use min in csi_X Jiri Slaby
2020-06-15 7:48 ` [PATCH 24/38] vt: whitespace and paren cleanup in add_softcursor Jiri Slaby
2020-06-15 7:48 ` [PATCH 25/38] vt: redefine world of cursor macros Jiri Slaby
2020-06-15 7:48 ` [PATCH 26/38] vt: use newly defined CUR_* macros Jiri Slaby
2020-06-15 20:31 ` Helge Deller
2020-06-15 7:48 ` [PATCH 27/38] vt: remove superfluous parens in invert_screen and build_attr Jiri Slaby
2020-06-15 7:49 ` [PATCH 28/38] vt: simplify noncolor attributes in build_attr Jiri Slaby
2020-06-15 7:49 ` [PATCH 29/38] vt_ioctl: eliminate ret & breaks in vt_ioctl Jiri Slaby
2020-06-15 7:49 ` [PATCH 30/38] vt_ioctl: eliminate use of uival and ucval Jiri Slaby
2020-06-15 7:49 ` [PATCH 31/38] vt_ioctl: move K* ioctls to a separate function Jiri Slaby
2020-06-15 7:49 ` [PATCH 32/38] vt_ioctl: move io " Jiri Slaby
2020-06-15 7:49 ` [PATCH 33/38] vt_ioctl: move vt_setactivate out of vt_ioctl Jiri Slaby
2020-06-15 7:49 ` [PATCH 34/38] vt_ioctl: move vt_reldisp " Jiri Slaby
2020-06-15 7:49 ` [PATCH 35/38] vt_ioctl: move vt_resizex " Jiri Slaby
2020-06-15 7:49 ` [PATCH 36/38] vt_ioctl: move vt_io_fontreset out of vt_io_ioctl Jiri Slaby
2020-06-15 7:49 ` [PATCH 37/38] vt_ioctl: move vt_kdsetmode out of vt_k_ioctl Jiri Slaby
2020-06-15 7:49 ` [PATCH 38/38] vt_ioctl: move perm checks level up Jiri Slaby
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200615074910.19267-19-jslaby@suse.cz \
--to=jslaby@suse.cz \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).