From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on sa.int.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.5 Date: Sun, 15 Nov 2009 16:34:16 +0100 From: Michael Schutte To: kbd@lists.altlinux.org Message-ID: <20091115153416.GA7780@graeme> Mail-Followup-To: kbd@lists.altlinux.org MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2fHTh5uZTiUOsy+g" Content-Disposition: inline Jabber-ID: michi@uiae.at User-Agent: Mutt/1.5.17 (2007-11-01) Subject: [kbd] [PATCH] loadkeys -u: Switch to Unicode mode, if necessary X-BeenThere: kbd@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Linux console tools development discussion List-Id: Linux console tools development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Nov 2009 15:34:40 -0000 Archived-At: List-Archive: --2fHTh5uZTiUOsy+g Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Make defkeys() KDSKBMODE to K_UNICODE before it starts to do KDSKBENT ioctls. Switch back to the preceding keyboard mode after defining keys. This change is introduced for compatibility reasons, see . As a minor difference, the warning message telling users to run =E2=80=9Ckbd_mode -u=E2=80=9D is printed whene= ver =E2=80=9Cloadkeys -u=E2=80=9D is used, not only when actual Unicode keysyms are loaded. Signed-off-by: Michael Schutte --- man/man1/loadkeys.1.in | 16 ++++++++++++- src/loadkeys.y | 54 ++++++++++++++++++++++++++++++++++++--------= --- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/man/man1/loadkeys.1.in b/man/man1/loadkeys.1.in index 7e168e4..e39eb76 100644 --- a/man/man1/loadkeys.1.in +++ b/man/man1/loadkeys.1.in @@ -160,9 +160,21 @@ The .I -u (or .IR --unicode ) -switch tells +switch forces .B loadkeys -to bypass the check and assume that the console is in Unicode mode. +to convert all keymaps to Unicode. If the keyboard is in a +non-Unicode mode, such as XLATE, +.B loadkeys +will change it to Unicode for the time of its execution. A +warning message will be printed in this case. +.LP +It is recommended to run +.BR kbd_mode (1) +before +.B loadkeys +instead of using the +.I -u +option. .SH "OTHER OPTIONS" .TP .B \-h \-\-help diff --git a/src/loadkeys.y b/src/loadkeys.y index 6beba09..03654ac 100644 --- a/src/loadkeys.y +++ b/src/loadkeys.y @@ -68,7 +68,7 @@ static void killkey(int index, int table); static void compose(int diacr, int base, int res); static void do_constant(void); static void do_constant_key (int, u_short); -static void loadkeys(char *console); +static void loadkeys(char *console, int kbd_mode); static void mktable(void); static void bkeymap(void); static void strings_as_usual(void); @@ -293,6 +293,7 @@ int optb =3D 0; int optd =3D 0; int optm =3D 0; int opts =3D 0; +int optu =3D 0; int verbose =3D 0; int quiet =3D 0; int nocompose =3D 0; @@ -316,7 +317,8 @@ main(int argc, char *argv[]) { }; int c; int fd; - int mode; + int kbd_mode; + int kd_mode; char *console =3D NULL; =20 set_progname(argv[0]); @@ -348,7 +350,7 @@ main(int argc, char *argv[]) { opts =3D 1; break; case 'u': - prefer_unicode =3D 1; + optu =3D 1; break; case 'q': quiet =3D 1; @@ -364,16 +366,26 @@ main(int argc, char *argv[]) { } } =20 - if (!optm && !prefer_unicode) { - /* no -u option: auto-enable it if console is in Unicode mode */ + prefer_unicode =3D optu; + if (!optm) { + /* check whether the keyboard is in Unicode mode */ fd =3D getfd(NULL); - if (ioctl(fd, KDGKBMODE, &mode)) { + if (ioctl(fd, KDGKBMODE, &kbd_mode)) { perror("KDGKBMODE"); - fprintf(stderr, _("loadkeys: error reading keyboard mode\n")); + fprintf(stderr, _("%s: error reading keyboard mode\n"), progname); exit(1); } - if (mode =3D=3D K_UNICODE) + + if (kbd_mode =3D=3D K_UNICODE) { prefer_unicode =3D 1; + /* reset -u option if keyboard is in K_UNICODE anyway */ + optu =3D 0; + } + else if (optu && (ioctl(fd, KDGETMODE, &kd_mode) || (kd_mode !=3D KD_GRA= PHICS))) + fprintf(stderr, _("%s: warning: loading Unicode keymap on non-Unicode c= onsole\n" + " (perhaps you want to do `kbd_mode -u'?)\n"), + progname); + close(fd); } =20 @@ -402,14 +414,14 @@ main(int argc, char *argv[]) { char ch =3D *e; *e =3D '\0'; if (verbose) printf("%s\n", s); - loadkeys(s); + loadkeys(s, kbd_mode); *e =3D ch; s =3D e; } free(buf); } else - loadkeys(NULL); + loadkeys(NULL, kbd_mode); exit(0); } =20 @@ -847,11 +859,20 @@ compose(int diacr, int base, int res) { } =20 static int -defkeys(int fd) { +defkeys(int fd, int kbd_mode) { struct kbentry ke; int ct =3D 0; int i,j,fail; =20 + if (optu) { + /* temporarily switch to K_UNICODE while defining keys */ + if (ioctl(fd, KDSKBMODE, K_UNICODE)) { + perror("KDSKBMODE"); + fprintf(stderr, _("%s: could not switch to Unicode mode\n"), progname); + exit(1); + } + } + for(i=3D0; i