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