Add pancyrillic font
[platform/upstream/kbd.git] / src / kbd_mode.c
1 /*
2  * kbd_mode: report and set keyboard mode - aeb, 940406
3  * 
4  * If you make \215A\201 an alias for "kbd_mode -a", and you are
5  * in raw mode, then hitting F7 = (two keys) will return you to sanity.
6  */
7
8 #include <fcntl.h>
9 #include <stdio.h>
10 #include <unistd.h>
11 #include <sys/ioctl.h>
12 #include <linux/types.h>
13 #include <linux/kd.h>
14 #include "getfd.h"
15 #include "nls.h"
16 #include "version.h"
17
18 static void __attribute__ ((noreturn))
19 usage(void){
20     fprintf(stderr, _("usage: kbd_mode [-a|-u|-k|-s] [-C device]\n"));
21     exit(1);
22 }
23
24 int
25 main(int argc, char *argv[]){
26         int fd, mode, c, n = 0;
27         char *console = NULL;
28
29         set_progname(argv[0]);
30
31         setlocale(LC_ALL, "");
32         bindtextdomain(PACKAGE_NAME, LOCALEDIR);
33         textdomain(PACKAGE_NAME);
34
35         if (argc == 2 && !strcmp(argv[1], "-V"))
36             print_version_and_exit();
37
38         while ((c = getopt(argc, argv, "auskC:")) != EOF) {
39                 switch (c) {
40                 case 'a':
41                         if (n > 0)
42                             usage ();
43                         mode = K_XLATE;
44                         n++;
45                         break;
46                 case 'u':
47                         if (n > 0)
48                             usage ();
49                         mode = K_UNICODE;
50                         n++;
51                         break;
52                 case 's':
53                         if (n > 0)
54                             usage ();
55                         mode = K_RAW;
56                         n++;
57                         break;
58                 case 'k':
59                         if (n > 0)
60                             usage ();
61                         mode = K_MEDIUMRAW;
62                         n++;
63                         break;
64                 case 'C':
65                         if (!optarg || !optarg[0])
66                             usage ();
67                         console = optarg;
68                         break;
69                 default:
70                         usage();
71                 }
72         }
73
74         fd = getfd(console);
75
76         if (n == 0) {
77             /* report mode */
78             if (ioctl(fd, KDGKBMODE, &mode)) {
79                 perror("KDGKBMODE");
80                 fprintf(stderr, _("kbd_mode: error reading keyboard mode\n"));
81                 exit(1);
82             }
83             switch(mode) {
84               case K_RAW:
85                 printf(_("The keyboard is in raw (scancode) mode\n"));
86                 break;
87               case K_MEDIUMRAW:
88                 printf(_("The keyboard is in mediumraw (keycode) mode\n"));
89                 break;
90               case K_XLATE:
91                 printf(_("The keyboard is in the default (ASCII) mode\n"));
92                 break;
93               case K_UNICODE:
94                 printf(_("The keyboard is in Unicode (UTF-8) mode\n"));
95                 break;
96               default:
97                 printf(_("The keyboard is in some unknown mode\n"));
98             }
99             exit(0);
100         }
101
102         if (ioctl(fd, KDSKBMODE, mode)) {
103                 perror("KDSKBMODE");
104                 fprintf(stderr, _("%s: error setting keyboard mode\n"), progname);
105                 exit(1);
106         }
107         exit(0);
108 }