btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / bin / iroster.cpp
blob023e9a8d83918120311a38e2be0853da170dff7a
1 /*
2 * iroster.cpp
3 * (c) 2002, Carlos Hasan, for OpenBeOS.
4 * Compile: gcc -Wall -Wno-multichar -O2 -o iroster iroster.cpp -lbe
5 */
7 #include <stdio.h>
8 #include <string.h>
9 #include <interface/Input.h>
10 #include <support/List.h>
12 static int list_devices()
14 BList list;
15 BInputDevice *device;
16 int i, n;
17 status_t err;
19 printf(" name type state \n");
20 printf("--------------------------------------------------\n");
22 if ((err = get_input_devices(&list))!=B_OK) {
23 fprintf(stderr, "error while get_input_devices: %s\n", strerror(err));
24 return -1;
27 n = list.CountItems();
28 if (n == 0) {
29 printf("...no input devices found...\n");
32 for (i = 0; i < n; i++) {
33 device = (BInputDevice *) list.ItemAt(i);
35 printf("%23s %18s %7s\n",
36 device->Name(),
37 device->Type() == B_POINTING_DEVICE ? "B_POINTING_DEVICE" :
38 device->Type() == B_KEYBOARD_DEVICE ? "B_KEYBOARD_DEVICE" : "B_UNDEFINED_DEVICE",
39 device->IsRunning() ? "running" : "stopped");
42 return 0;
45 static void start_device(const char *name)
47 BInputDevice *device;
48 status_t status;
50 device = find_input_device(name);
51 if (device == NULL) {
52 printf("Error finding device \"%s\"\n", name);
54 else if ((status = device->Start()) != B_OK) {
55 printf("Error starting device \"%s\" (%" B_PRId32 ")\n", name, status);
57 else {
58 printf("Started device \"%s\"\n", name);
60 if (device != NULL)
61 delete device;
64 static void stop_device(const char *name)
66 BInputDevice *device;
67 status_t status;
69 device = find_input_device(name);
70 if (device == NULL) {
71 printf("Error finding device \"%s\"\n", name);
73 else if ((status = device->Stop()) != B_OK) {
74 printf("Error stopping device \"%s\" (%" B_PRId32 ")\n", name, status);
76 else {
77 printf("Stopped device \"%s\"\n", name);
79 if (device != NULL)
80 delete device;
83 int main(int argc, char *argv[])
85 int i;
86 const char *name;
88 if (argc <= 1) {
89 return list_devices();
91 else {
92 for (i = 1; i < argc; i++) {
93 name = argv[i];
94 if (name[0] == '+') {
95 start_device(name + 1);
97 else if (name[0] == '-') {
98 stop_device(name + 1);
100 else {
101 printf("USAGE: %s [+|-]input_device_name\n", argv[0]);
105 return 0;