7fbc0b480178272bed97b247a552139b3594cede
[busybox-power] / debian / patches / showkey-default-option.patch
1 Make the showkey's "-a" option default instead of "-k"
2
3 By Dennis Groenen <tj.groenen@gmail.com> - 2011-08-19
4 ---
5
6 --- a/console-tools/showkey.c
7 +++ b/console-tools/showkey.c
8 @@ -11,8 +11,8 @@
9  //usage:       "[-a | -k | -s]"
10  //usage:#define showkey_full_usage "\n\n"
11  //usage:       "Show keys pressed\n"
12 -//usage:     "\n       -a      Display decimal/octal/hex values of the keys"
13 -//usage:     "\n       -k      Display interpreted keycodes (default)"
14 +//usage:     "\n       -a      Display decimal/octal/hex values of the keys (default)"
15 +//usage:     "\n       -k      Display interpreted keycodes"
16  //usage:     "\n       -s      Display raw scan-codes"
17  
18  #include "libbb.h"
19 @@ -54,8 +54,8 @@ int showkey_main(int argc, char **argv)
20  int showkey_main(int argc UNUSED_PARAM, char **argv)
21  {
22         enum {
23 -               OPT_a = (1<<0), // display the decimal/octal/hex values of the keys
24 -               OPT_k = (1<<1), // display only the interpreted keycodes (default)
25 +               OPT_a = (1<<0), // display the decimal/octal/hex values of the keys (default)
26 +               OPT_k = (1<<1), // display only the interpreted keycodes
27                 OPT_s = (1<<2), // display only the raw scan-codes
28         };
29  
30 @@ -71,20 +71,7 @@ int showkey_main(int argc UNUSED_PARAM,
31  
32  #define press_keys "Press any keys, program terminates %s:\r\n\n"
33  
34 -       if (option_mask32 & OPT_a) {
35 -               // just read stdin char by char
36 -               unsigned char c;
37 -
38 -               printf(press_keys, "on EOF (ctrl-D)");
39 -
40 -               // read and show byte values
41 -               while (1 == read(STDIN_FILENO, &c, 1)) {
42 -                       printf("%3u 0%03o 0x%02x\r\n", c, c, c);
43 -                       if (04 /*CTRL-D*/ == c)
44 -                               break;
45 -               }
46 -
47 -       } else {
48 +       if (option_mask32 & OPT_k || option_mask32 & OPT_s) {
49                 // we assume a PC keyboard
50                 xioctl(STDIN_FILENO, KDGKBMODE, &kbmode);
51                 printf("Keyboard mode was %s.\r\n\n",
52 @@ -141,6 +128,19 @@ int showkey_main(int argc UNUSED_PARAM,
53  
54                 // restore keyboard mode
55                 xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)kbmode);
56 +
57 +       } else {
58 +               // just read stdin char by char
59 +               unsigned char c;
60 +
61 +               printf(press_keys, "on EOF (ctrl-D)");
62 +
63 +               // read and show byte values
64 +               while (1 == read(STDIN_FILENO, &c, 1)) {
65 +                       printf("%3u 0%03o 0x%02x\r\n", c, c, c);
66 +                       if (04 /*CTRL-D*/ == c)
67 +                               break;
68 +               }
69         }
70  
71         // restore console settings