blob: 16149571926856eb22e3d9140b3965e4935ee5a8 [file] [log] [blame]
Denis Vlasenkoaa7a8882007-10-20 00:17:34 +00001/* vi: set sw=4 ts=4: */
2/*
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +00003 * Mini kbd_mode implementation for busybox
Denis Vlasenkoaa7a8882007-10-20 00:17:34 +00004 *
5 * Copyright (C) 2007 Loïc Grenié <loic.grenie@gmail.com>
6 * written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from
7 * console-utils v0.2.3, licensed under GNU GPLv2
8 *
9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 *
11 */
12
Denis Vlasenkoaa7a8882007-10-20 00:17:34 +000013#include "libbb.h"
14#include <linux/kd.h>
15
16int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000017int kbd_mode_main(int ATTRIBUTE_UNUSED argc, char **argv)
Denis Vlasenkoaa7a8882007-10-20 00:17:34 +000018{
Denis Vlasenkoaa7a8882007-10-20 00:17:34 +000019 int fd;
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000020 unsigned opt;
21 enum {
22 SCANCODE = (1<<0),
23 ASCII = (1<<1),
24 MEDIUMRAW= (1<<2),
25 UNICODE = (1<<3)
26 };
27 static const char KD_xxx[] ALIGN1 = "saku";
28 opt = getopt32(argv, KD_xxx);
Denis Vlasenkoaa7a8882007-10-20 00:17:34 +000029 fd = get_console_fd();
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000030/* if (fd < 0)
Denis Vlasenkoaa7a8882007-10-20 00:17:34 +000031 return EXIT_FAILURE;
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000032*/
33 if (!opt) { /* print current setting */
34 const char *mode = "unknown";
35 int m;
Denis Vlasenkoaa7a8882007-10-20 00:17:34 +000036
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000037 ioctl(fd, KDGKBMODE, &m);
38 if (m == K_RAW)
39 mode = "raw (scancode)";
40 else if (m == K_XLATE)
41 mode = "default (ASCII)";
42 else if (m == K_MEDIUMRAW)
43 mode = "mediumraw (keycode)";
44 else if (m == K_UNICODE)
45 mode = "Unicode (UTF-8)";
46 printf("The keyboard is in %s mode\n", mode);
47 } else {
48 opt = opt & UNICODE ? 3 : opt >> 1;
49 xioctl(fd, KDSKBMODE, &opt);
Denis Vlasenkoaa7a8882007-10-20 00:17:34 +000050 }
51
52 if (ENABLE_FEATURE_CLEAN_UP)
53 close(fd);
54 return EXIT_SUCCESS;
55}