btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / bin / modifiers.cpp
bloba9bd96498cc13874c0fc11246ba87ea697358317
1 /*
2 * modifiers - asserts (un)pressed modifier keys
3 * (c) 2002, Francois Revol, revol@free.fr
4 * for OpenBeOS
5 * compile with:
6 * LDFLAGS=-lbe make modifiers
7 */
9 #include <OS.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <strings.h>
13 #include <InterfaceDefs.h>
16 int32 modifier_bits[] = {
17 B_SHIFT_KEY,
18 B_COMMAND_KEY,
19 B_CONTROL_KEY,
20 B_CAPS_LOCK,
21 B_SCROLL_LOCK,
22 B_NUM_LOCK,
23 B_OPTION_KEY,
24 B_MENU_KEY,
25 B_LEFT_SHIFT_KEY,
26 B_RIGHT_SHIFT_KEY,
27 B_LEFT_COMMAND_KEY,
28 B_RIGHT_COMMAND_KEY,
29 B_LEFT_CONTROL_KEY,
30 B_RIGHT_CONTROL_KEY,
31 B_LEFT_OPTION_KEY,
32 B_RIGHT_OPTION_KEY,
37 const char *modifier_names[] = { "shift", "command", "control", "capslock", "scrolllock", "numlock", "option", "menu", "lshift", "rshift", "lcommand", "rcommand", "lcontrol", "rcontrol", "loption", "roption", NULL };
40 int
41 usage(char *progname, int error)
43 FILE *outstr;
44 outstr = error?stderr:stdout;
45 fprintf(outstr, "Usage: %s [-help] [-list] [-/+][[|l|r][shift|control|command|option]|capslock|scrolllock|numlock|menu]\n", progname);
46 fprintf(outstr, "\t- asserts unpressed modifier,\n");
47 fprintf(outstr, "\t+ asserts pressed modifier,\n");
48 return error;
52 int
53 list_modifiers(int mods)
55 int i;
56 int gotone = 0;
57 for (i=0; modifier_names[i]; i++) {
58 if (mods & modifier_bits[i]) {
59 if (gotone)
60 printf(",");
61 gotone = 0;
62 printf("%s", modifier_names[i]);
63 gotone = 1;
65 if (modifier_names[i+1] == NULL)
66 printf("\n");
68 return 0;
72 int
73 main(int argc, char **argv)
75 int32 mods;
76 int32 mask_xor = 0x0;
77 int32 mask_and = 0x0;
78 int i, j;
80 mods = modifiers();
81 if (argc == 1)
82 return usage(argv[0], 1);
83 for (i=1; i<argc; i++) {
84 if (!strncmp(argv[i], "-h", 2))
85 return usage(argv[0], 0);
86 else if (!strcmp(argv[i], "-list"))
87 return list_modifiers(mods);
88 else if (strlen(argv[i]) > 1 && (*argv[i] == '-' || *argv[i] == '+')) {
89 for (j=0; modifier_names[j]; j++) {
90 if (!strcmp(argv[i]+1, modifier_names[j])) {
91 if (*argv[i] == '-')
92 mask_and |= modifier_bits[j];
93 else
94 mask_xor |= modifier_bits[j];
95 break;
98 if (modifier_names[j] == NULL)
99 return usage(argv[0], 1);
100 } else
101 return usage(argv[0], 1);
103 mask_and |= mask_xor;
104 return (((mods & mask_and) ^ mask_xor) != 0);