Mercurial > mplayer.hg
annotate input/input.c @ 4432:5105f5da01d6
Added lirc support in input
author | albeu |
---|---|
date | Thu, 31 Jan 2002 09:39:11 +0000 |
parents | 8141d2c399e4 |
children | 83128eed25f1 |
rev | line source |
---|---|
4418
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
1 #include "../config.h" |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
2 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
3 #ifdef HAVE_NEW_INPUT |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
4 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
5 #include <stdlib.h> |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
6 #include <string.h> |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
7 #include <stdio.h> |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
8 #include <unistd.h> |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
9 #include <errno.h> |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
10 #include <signal.h> |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
11 #include <sys/types.h> |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
12 #include <fcntl.h> |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
13 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
14 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
15 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
16 #include "input.h" |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
17 #ifdef MP_DEBUG |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
18 #include <assert.h> |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
19 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
20 #include "../linux/getch2.h" |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
21 #include "../linux/keycodes.h" |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
22 #include "../linux/timer.h" |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
23 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
24 #ifdef HAVE_JOYSTICK |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
25 #include "joystick.h" |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
26 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
27 |
4432 | 28 #ifdef HAVE_LIRC |
29 #include "lirc.h" | |
30 #endif | |
31 | |
4418
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
32 // If the args field is not NULL, the command will only be passed if |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
33 // an argument exist. |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
34 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
35 static mp_cmd_t mp_cmds[] = { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
36 { MP_CMD_SEEK, "seek", 1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
37 { MP_CMD_AUDIO_DELAY, "audio_delay", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
38 { MP_CMD_QUIT, "quit", 0, { {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
39 { MP_CMD_PAUSE, "pause", 0, { {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
40 { MP_CMD_GRAB_FRAMES, "grap_frames",0, { {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
41 { MP_CMD_PLAY_TREE_STEP, "pt_step",1, { { MP_CMD_ARG_INT ,{0}}, {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
42 { MP_CMD_PLAY_TREE_UP_STEP, "pt_up_step",1, { { MP_CMD_ARG_INT,{0} }, {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
43 { MP_CMD_PLAY_ALT_SRC_STEP, "alt_src_step",1, { { MP_CMD_ARG_INT,{0} }, {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
44 { MP_CMD_SUB_DELAY, "sub_delay",1, { {MP_CMD_ARG_FLOAT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
45 { MP_CMD_OSD, "osd",0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
46 { MP_CMD_VOLUME, "volume", 1, { { MP_CMD_ARG_INT,{0} }, {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
47 { MP_CMD_MIXER_USEMASTER, "use_master", 0, { {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
48 { MP_CMD_CONTRAST, "contrast",1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
49 { MP_CMD_BRIGHTNESS, "brightness",1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
50 { MP_CMD_HUE, "hue",1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
51 { MP_CMD_SATURATION, "saturation",1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
52 { MP_CMD_FRAMEDROPPING, "frame_drop",0, { { MP_CMD_ARG_INT,{-1} }, {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
53 #ifdef USE_TV |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
54 { MP_CMD_TV_STEP_CHANNEL, "tv_step_channel", 1, { { MP_CMD_ARG_INT ,{0}}, {-1,{0}} }}, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
55 { MP_CMD_TV_STEP_NORM, "tv_step_norm",0, { {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
56 { MP_CMD_TV_STEP_CHANNEL_LIST, "tv_step_chanlist", 0, { {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
57 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
58 { 0, NULL, 0, {} } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
59 }; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
60 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
61 static mp_cmd_bind_t key_names[] = { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
62 { ' ', "SPACE" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
63 { KEY_ENTER, "ENTER" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
64 { KEY_TAB, "TAB" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
65 { KEY_CTRL, "CTRL" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
66 { KEY_BACKSPACE, "BS" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
67 { KEY_DELETE, "DEL" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
68 { KEY_INSERT, "INS" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
69 { KEY_HOME, "HOME" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
70 { KEY_END, "END" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
71 { KEY_PAGE_UP, "PGUP" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
72 { KEY_PAGE_DOWN, "PGDWN" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
73 { KEY_ESC, "ESC" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
74 { KEY_RIGHT, "RIGHT" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
75 { KEY_LEFT, "LEFT" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
76 { KEY_DOWN, "DOWN" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
77 { KEY_UP, "UP" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
78 #ifdef HAVE_JOYSTICK |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
79 { JOY_UP, "JOY_UP" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
80 { JOY_DOWN, "JOY_DOWN" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
81 { JOY_LEFT, "JOY_LEFT" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
82 { JOY_RIGHT, "JOY_RIGHT" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
83 { JOY_BTN0, "JOY_BTN0" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
84 { JOY_BTN1, "JOY_BTN1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
85 { JOY_BTN2, "JOY_BTN2" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
86 { JOY_BTN3, "JOY_BTN3" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
87 { JOY_BTN4, "JOY_BTN4" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
88 { JOY_BTN5, "JOY_BTN5" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
89 { JOY_BTN6, "JOY_BTN6" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
90 { JOY_BTN7, "JOY_BTN7" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
91 { JOY_BTN8, "JOY_BTN8" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
92 { JOY_BTN9, "JOY_BTN9" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
93 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
94 { 0, NULL } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
95 }; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
96 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
97 // This is the default binding we use when no config file is here |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
98 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
99 static mp_cmd_bind_t def_cmd_binds[] = { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
100 { KEY_RIGHT, "seek 10" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
101 { KEY_LEFT, "seek -10" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
102 { KEY_UP, "seek 60" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
103 { KEY_DOWN, "seek -60" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
104 { KEY_PAGE_UP, "seek 600" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
105 { KEY_PAGE_DOWN, "seek -600" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
106 { '+', "audio_delay 0.100" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
107 { '-', "audio_delay -0.100" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
108 { 'q', "quit" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
109 { KEY_ESC, "quit" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
110 { 'p', "pause" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
111 { ' ', "pause" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
112 { KEY_HOME, "pt_up_step 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
113 { KEY_END, "pt_up_step -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
114 { '>', "pt_step 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
115 { '<', "pt_step -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
116 { KEY_INS, "alt_src_step 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
117 { KEY_DEL, "alt_src_step -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
118 { 'o', "osd" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
119 { 'z', "sub_delay -0.1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
120 { 'x', "sub_delay +0.1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
121 { '9', "volume -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
122 { '/', "volume -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
123 { '0', "volume 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
124 { '*', "volume 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
125 { 'm', "use_master" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
126 { '1', "contrast -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
127 { '2', "contrast 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
128 { '3', "brightness -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
129 { '4', "brightness 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
130 { '5', "hue -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
131 { '6', "hue 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
132 { '7', "saturation -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
133 { '8', "saturation 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
134 { 'd', "frame_drop" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
135 #ifdef USE_TV |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
136 { 'h', "tv_step_channel 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
137 { 'l', "tv_step_channel -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
138 { 'n', "tv_step_norm" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
139 { 'b', "tv_step_chanlist" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
140 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
141 { 0, NULL } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
142 }; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
143 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
144 #ifndef MP_MAX_KEY_FD |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
145 #define MP_MAX_KEY_FD 10 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
146 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
147 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
148 #ifndef MP_MAX_CMD_FD |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
149 #define MP_MAX_CMD_FD 10 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
150 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
151 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
152 #define MP_FD_EOF (1<<0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
153 #define MP_FD_DROP (1<<1) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
154 #define MP_FD_DEAD (1<<2) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
155 #define MP_FD_GOT_CMD (1<<3) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
156 #define MP_FD_NO_SELECT (1<<4) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
157 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
158 typedef struct mp_input_fd { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
159 int fd; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
160 void* read_func; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
161 mp_close_func_t close_func; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
162 int flags; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
163 // This fields are for the cmd fds |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
164 char* buffer; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
165 int pos,size; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
166 } mp_input_fd_t; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
167 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
168 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
169 static mp_cmd_bind_t* cmd_binds = def_cmd_binds; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
170 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
171 static mp_input_fd_t key_fds[MP_MAX_KEY_FD]; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
172 static unsigned int num_key_fd = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
173 static mp_input_fd_t cmd_fds[MP_MAX_CMD_FD]; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
174 static unsigned int num_cmd_fd = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
175 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
176 static int key_max_fd = -1, cmd_max_fd = -1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
177 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
178 static int |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
179 mp_input_default_key_func(int fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
180 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
181 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
182 int |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
183 mp_input_add_cmd_fd(int fd, int select, mp_cmd_func_t read_func, mp_close_func_t close_func) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
184 if(num_cmd_fd == MP_MAX_CMD_FD) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
185 printf("Too much command fd, unable to register fd %d\n",fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
186 return 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
187 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
188 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
189 memset(&cmd_fds[num_cmd_fd],0,sizeof(mp_input_fd_t)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
190 cmd_fds[num_cmd_fd].fd = fd; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
191 cmd_fds[num_cmd_fd].read_func = read_func ? read_func : (mp_cmd_func_t)read; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
192 cmd_fds[num_cmd_fd].close_func = close_func; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
193 if(!select) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
194 cmd_fds[num_cmd_fd].flags = MP_FD_NO_SELECT; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
195 num_cmd_fd++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
196 if(fd > cmd_max_fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
197 cmd_max_fd = fd; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
198 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
199 return 1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
200 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
201 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
202 void |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
203 mp_input_rm_cmd_fd(int fd) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
204 unsigned int i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
205 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
206 for(i = 0; i < num_cmd_fd; i++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
207 if(cmd_fds[i].fd == fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
208 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
209 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
210 if(i == num_cmd_fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
211 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
212 if(cmd_fds[i].close_func) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
213 cmd_fds[i].close_func(cmd_fds[i].fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
214 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
215 if(i + 1 < num_cmd_fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
216 memmove(&cmd_fds[i],&cmd_fds[i+1],(num_cmd_fd - i - 1)*sizeof(mp_input_fd_t)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
217 num_cmd_fd--; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
218 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
219 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
220 void |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
221 mp_input_rm_key_fd(int fd) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
222 unsigned int i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
223 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
224 for(i = 0; i < num_key_fd; i++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
225 if(key_fds[i].fd == fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
226 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
227 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
228 if(i == num_key_fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
229 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
230 if(key_fds[i].close_func) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
231 key_fds[i].close_func(key_fds[i].fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
232 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
233 if(i + 1 < num_key_fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
234 memmove(&key_fds[i],&key_fds[i+1],(num_key_fd - i - 1)*sizeof(mp_input_fd_t)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
235 num_key_fd--; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
236 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
237 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
238 int |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
239 mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t close_func) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
240 if(num_key_fd == MP_MAX_KEY_FD) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
241 printf("Too much key fd, unable to register fd %d\n",fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
242 return 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
243 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
244 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
245 memset(&key_fds[num_key_fd],0,sizeof(mp_input_fd_t)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
246 key_fds[num_key_fd].fd = fd; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
247 key_fds[num_key_fd].read_func = read_func ? read_func : mp_input_default_key_func; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
248 key_fds[num_key_fd].close_func = close_func; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
249 if(!select) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
250 key_fds[num_key_fd].flags |= MP_FD_NO_SELECT; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
251 num_key_fd++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
252 if(fd > key_max_fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
253 key_max_fd = fd; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
254 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
255 return 1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
256 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
257 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
258 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
259 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
260 static mp_cmd_t* |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
261 mp_input_parse_cmd(char* str) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
262 int i,l; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
263 char *ptr,*e; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
264 mp_cmd_t *cmd, *cmd_def; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
265 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
266 #ifdef MP_DEBUG |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
267 assert(str != NULL); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
268 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
269 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
270 ptr = strchr(str,' '); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
271 if(ptr) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
272 l = ptr-str; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
273 else |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
274 l = strlen(str); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
275 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
276 if(l == 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
277 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
278 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
279 for(i=0; mp_cmds[i].name != NULL; i++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
280 if(strncasecmp(mp_cmds[i].name,str,l) == 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
281 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
282 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
283 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
284 if(mp_cmds[i].name == NULL) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
285 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
286 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
287 cmd_def = &mp_cmds[i]; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
288 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
289 cmd = (mp_cmd_t*)malloc(sizeof(mp_cmd_t)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
290 cmd->id = cmd_def->id; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
291 cmd->name = strdup(cmd_def->name); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
292 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
293 ptr = str; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
294 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
295 for(i=0; ptr && i < MP_CMD_MAX_ARGS; i++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
296 ptr = strchr(ptr,' '); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
297 if(!ptr) break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
298 while(ptr[0] == ' ') ptr++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
299 if(ptr[0] == '\0') break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
300 switch(cmd_def->args[i].type) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
301 case MP_CMD_ARG_INT: |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
302 errno = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
303 cmd->args[i].v.i = atoi(ptr); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
304 if(errno != 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
305 printf("Command %s : argument %d isn't an integer\n",cmd_def->name,i+1); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
306 ptr = NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
307 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
308 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
309 case MP_CMD_ARG_FLOAT: |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
310 errno = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
311 cmd->args[i].v.f = atof(ptr); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
312 if(errno != 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
313 printf("Command %s : argument %d isn't a float\n",cmd_def->name,i+1); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
314 ptr = NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
315 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
316 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
317 case MP_CMD_ARG_STRING: |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
318 e = strchr(ptr,' '); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
319 if(!e) e = ptr+strlen(ptr); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
320 l = e-ptr; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
321 cmd->args[i].v.s = (char*)malloc((l+1)*sizeof(char)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
322 strncpy(cmd->args[i].v.s,ptr,l); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
323 cmd->args[i].v.s[l] = '\0'; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
324 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
325 case -1: |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
326 ptr = NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
327 default : |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
328 printf("Unknow argument %d\n",i); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
329 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
330 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
331 cmd->nargs = i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
332 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
333 if(cmd_def->nargs > cmd->nargs) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
334 printf("Got [%s] but\n",str); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
335 printf("Command %s require at least %d arguments, we found only %d so far\n",cmd_def->name,cmd_def->nargs,cmd->nargs); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
336 mp_cmd_free(cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
337 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
338 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
339 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
340 for( ; i < MP_CMD_MAX_ARGS && cmd_def->args[i].type != -1 ; i++) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
341 memcpy(&cmd->args[i].v,&cmd_def->args[i].v,sizeof(mp_cmd_arg_value_t)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
342 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
343 return cmd; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
344 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
345 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
346 static int |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
347 mp_input_default_key_func(int fd) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
348 int r,code=0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
349 unsigned int l; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
350 l = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
351 while(l < sizeof(int)) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
352 r = read(fd,(&code)+l,sizeof(int)-l); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
353 if(r <= 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
354 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
355 l +=r; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
356 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
357 return code; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
358 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
359 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
360 #define MP_CMD_MAX_SIZE 256 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
361 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
362 static int |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
363 mp_input_read_cmd(mp_input_fd_t* mp_fd, char** ret) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
364 char* end; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
365 (*ret) = NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
366 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
367 if(!mp_fd->buffer) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
368 mp_fd->buffer = (char*)malloc(MP_CMD_MAX_SIZE*sizeof(char)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
369 mp_fd->pos = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
370 mp_fd->size = MP_CMD_MAX_SIZE; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
371 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
372 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
373 if(mp_fd->size - mp_fd->pos == 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
374 printf("Cmd buffer of fd %d is full : dropping content\n",mp_fd->fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
375 mp_fd->pos = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
376 mp_fd->flags |= MP_FD_DROP; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
377 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
378 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
379 while( !(mp_fd->flags & MP_FD_EOF) && (mp_fd->size - mp_fd->pos > 1) ) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
380 int r = ((mp_cmd_func_t)mp_fd->read_func)(mp_fd->fd,mp_fd->buffer+mp_fd->pos,mp_fd->size - 1 - mp_fd->pos); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
381 if(r < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
382 if(errno == EINTR) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
383 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
384 else if(errno == EAGAIN) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
385 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
386 printf("Error while reading cmd fd %d : %s\n",mp_fd->fd,strerror(errno)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
387 return MP_INPUT_ERROR; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
388 } else if(r == 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
389 mp_fd->flags |= MP_FD_EOF; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
390 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
391 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
392 mp_fd->pos += r; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
393 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
394 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
395 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
396 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
397 while(1) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
398 int l = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
399 mp_fd->buffer[mp_fd->pos] = '\0'; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
400 end = strchr(mp_fd->buffer,'\n'); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
401 if(!end) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
402 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
403 else if((*ret)) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
404 mp_fd->flags |= MP_FD_GOT_CMD; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
405 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
406 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
407 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
408 l = end - mp_fd->buffer; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
409 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
410 if( ! (mp_fd->flags & MP_FD_DROP)) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
411 (*ret) = (char*)malloc((l+1)*sizeof(char)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
412 strncpy((*ret),mp_fd->buffer,l); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
413 (*ret)[l] = '\0'; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
414 } else { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
415 mp_fd->flags &= ~MP_FD_DROP; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
416 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
417 if( mp_fd->pos - (l+1) > 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
418 memmove(mp_fd->buffer,end,mp_fd->pos-(l+1)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
419 mp_fd->pos -= l+1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
420 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
421 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
422 if(*ret) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
423 return 1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
424 else |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
425 return MP_INPUT_NOTHING; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
426 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
427 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
428 static mp_cmd_t* |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
429 mp_input_read_keys(int time,int paused) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
430 fd_set fds; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
431 struct timeval tv; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
432 int i,n=0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
433 static int last_loop = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
434 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
435 if(num_key_fd == 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
436 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
437 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
438 FD_ZERO(&fds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
439 for(i = 0; (unsigned int)i < num_key_fd; i++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
440 if( (key_fds[i].flags & MP_FD_DEAD) ) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
441 mp_input_rm_key_fd(key_fds[i].fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
442 i--; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
443 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
444 } else if(key_fds[i].flags & MP_FD_NO_SELECT) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
445 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
446 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
447 FD_SET(key_fds[i].fd,&fds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
448 n++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
449 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
450 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
451 if(n > 0 ) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
452 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
453 tv.tv_sec=time/1000; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
454 tv.tv_usec = (time%1000)*1000; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
455 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
456 while(1) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
457 if(select(key_max_fd+1,&fds,NULL,NULL,&tv) < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
458 if(errno == EINTR) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
459 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
460 printf("Select error : %s\n",strerror(errno)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
461 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
462 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
463 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
464 } else { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
465 FD_ZERO(&fds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
466 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
467 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
468 for(i = last_loop + 1 ; i != last_loop ; i++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
469 int code = -1,j; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
470 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
471 if((unsigned int)i >= num_key_fd) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
472 i = -1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
473 last_loop++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
474 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
475 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
476 if(! (key_fds[i].flags & MP_FD_NO_SELECT) && ! FD_ISSET(key_fds[i].fd,&fds)) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
477 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
478 if(key_fds[i].fd == 0) { // stdin is handled by getch2 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
479 code = getch2(time); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
480 if(code < 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
481 code = MP_INPUT_NOTHING; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
482 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
483 else |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
484 code = ((mp_key_func_t)key_fds[i].read_func)(key_fds[i].fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
485 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
486 if(code < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
487 if(code == MP_INPUT_ERROR) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
488 printf("Error on key input fd %d\n",key_fds[i].fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
489 else if(code == MP_INPUT_DEAD) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
490 printf("Dead key input on fd %d\n",key_fds[i].fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
491 key_fds[i].flags |= MP_FD_DEAD; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
492 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
493 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
494 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
495 if(paused) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
496 return mp_input_parse_cmd("pause"); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
497 for(j = 0; cmd_binds[j].cmd != NULL; j++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
498 if(cmd_binds[j].input == code) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
499 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
500 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
501 if(cmd_binds[j].cmd == NULL) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
502 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
503 last_loop = i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
504 return mp_input_parse_cmd(cmd_binds[j].cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
505 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
506 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
507 last_loop = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
508 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
509 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
510 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
511 static mp_cmd_t* |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
512 mp_input_read_cmds(int time) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
513 fd_set fds; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
514 struct timeval tv; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
515 int i,n = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
516 mp_cmd_t* ret; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
517 static int last_loop = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
518 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
519 if(num_cmd_fd == 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
520 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
521 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
522 FD_ZERO(&fds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
523 for(i = 0; (unsigned int)i < num_cmd_fd ; i++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
524 if( (cmd_fds[i].flags & MP_FD_DEAD) || (cmd_fds[i].flags & MP_FD_EOF) ) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
525 mp_input_rm_cmd_fd(cmd_fds[i].fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
526 i--; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
527 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
528 } else if(cmd_fds[i].flags & MP_FD_NO_SELECT) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
529 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
530 FD_SET(cmd_fds[i].fd,&fds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
531 n++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
532 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
533 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
534 if(n > 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
535 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
536 tv.tv_sec=time/1000; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
537 tv.tv_usec = (time%1000)*1000; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
538 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
539 while(1) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
540 if((i = select(cmd_max_fd+1,&fds,NULL,NULL,&tv)) <= 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
541 if(i < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
542 if(errno == EINTR) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
543 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
544 printf("Select error : %s\n",strerror(errno)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
545 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
546 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
547 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
548 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
549 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
550 } else { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
551 FD_ZERO(&fds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
552 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
553 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
554 for(i = last_loop + 1; i != last_loop ; i++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
555 int r = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
556 char* cmd; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
557 if((unsigned int)i >= num_cmd_fd) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
558 i = -1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
559 last_loop++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
560 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
561 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
562 if( ! (cmd_fds[i].flags & MP_FD_NO_SELECT) && ! FD_ISSET(cmd_fds[i].fd,&fds) && ! (cmd_fds[i].flags & MP_FD_GOT_CMD) ) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
563 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
564 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
565 r = mp_input_read_cmd(&cmd_fds[i],&cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
566 if(r < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
567 if(r == MP_INPUT_ERROR) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
568 printf("Error on cmd fd %d\n",cmd_fds[i].fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
569 else if(r == MP_INPUT_DEAD) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
570 cmd_fds[i].flags |= MP_FD_DEAD; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
571 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
572 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
573 ret = mp_input_parse_cmd(cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
574 free(cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
575 if(!ret) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
576 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
577 last_loop = i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
578 return ret; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
579 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
580 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
581 last_loop = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
582 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
583 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
584 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
585 mp_cmd_t* |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
586 mp_input_get_cmd(int time, int paused) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
587 mp_cmd_t* ret; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
588 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
589 ret = mp_input_read_keys(time,paused); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
590 if(ret) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
591 return ret; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
592 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
593 return mp_input_read_cmds(time); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
594 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
595 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
596 void |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
597 mp_cmd_free(mp_cmd_t* cmd) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
598 int i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
599 #ifdef MP_DEBUG |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
600 assert(cmd != NULL); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
601 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
602 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
603 if(cmd->name) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
604 free(cmd->name); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
605 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
606 for(i=0; i < MP_CMD_MAX_ARGS && cmd->args[i].type != -1; i++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
607 if(cmd->args[i].type == MP_CMD_ARG_STRING) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
608 free(cmd->args[i].v.s); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
609 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
610 free(cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
611 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
612 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
613 static int |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
614 mp_input_get_key_from_name(char* name) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
615 int i,ret = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
616 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
617 if(strlen(name) == 1) { // Direct key code |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
618 (char)ret = name[0]; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
619 return ret; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
620 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
621 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
622 for(i = 0; key_names[i].cmd != NULL; i++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
623 if(strcasecmp(key_names[i].cmd,name) == 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
624 return key_names[i].input; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
625 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
626 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
627 return -1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
628 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
629 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
630 static void |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
631 mp_input_free_binds(mp_cmd_bind_t* binds) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
632 int i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
633 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
634 if(!binds) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
635 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
636 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
637 for(i = 0; binds[i].cmd != NULL; i++) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
638 free(binds[i].cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
639 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
640 free(binds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
641 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
642 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
643 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
644 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
645 #define BS_MAX 256 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
646 #define SPACE_CHAR " \n\r\t" |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
647 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
648 static void |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
649 mp_input_parse_config(char *file) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
650 int fd,code=-1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
651 int bs = 0,r,eof = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
652 char *iter,*end; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
653 char buffer[BS_MAX]; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
654 int n_binds = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
655 mp_cmd_bind_t* binds = NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
656 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
657 fd = open(file,O_RDONLY); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
658 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
659 if(fd < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
660 printf("Can't open input config file %s : %s\n",file,strerror(errno)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
661 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
662 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
663 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
664 printf("Parsing input config file %s\n",file); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
665 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
666 while(1) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
667 if(! eof && bs < BS_MAX-1) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
668 if(bs > 0) bs--; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
669 r = read(fd,buffer+bs,BS_MAX-1-bs); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
670 if(r < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
671 if(errno == EINTR) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
672 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
673 printf("Error while reading input config file %s : %s\n",file,strerror(errno)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
674 mp_input_free_binds(binds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
675 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
676 } else if(r == 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
677 eof = 1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
678 else { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
679 bs += r+1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
680 buffer[bs-1] = '\0'; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
681 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
682 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
683 // Empty buffer : return |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
684 if(bs <= 1) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
685 printf("Input config file %s parsed : %d binds\n",file,n_binds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
686 if(binds) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
687 cmd_binds = binds; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
688 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
689 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
690 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
691 iter = buffer; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
692 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
693 // Find the wanted key |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
694 if(code < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
695 // Jump beginnig space |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
696 for( ; iter[0] != '\0' && strchr(SPACE_CHAR,iter[0]) != NULL ; iter++) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
697 /* NOTHING */; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
698 if(iter[0] == '\0') { // Buffer was full of space char |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
699 bs = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
700 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
701 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
702 // Find the end of the key code name |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
703 for(end = iter; end[0] != '\0' && strchr(SPACE_CHAR,end[0]) == NULL ; end++) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
704 /*NOTHING */; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
705 if(end[0] == '\0') { // Key name don't fit in the buffer |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
706 if(buffer == iter) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
707 if(eof && (buffer-iter) == bs) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
708 printf("Unfinished binding %s\n",iter); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
709 else |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
710 printf("Buffer is too small for this key name : %s\n",iter); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
711 mp_input_free_binds(binds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
712 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
713 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
714 memmove(buffer,iter,end-iter); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
715 bs = end-iter; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
716 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
717 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
718 { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
719 char name[end-iter+1]; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
720 strncpy(name,iter,end-iter); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
721 name[end-iter] = '\0'; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
722 code = mp_input_get_key_from_name(name); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
723 if(code < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
724 printf("Unknow key %s\n",name); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
725 mp_input_free_binds(binds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
726 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
727 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
728 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
729 if( bs > (end-buffer)) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
730 memmove(buffer,end,bs - (end-buffer)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
731 bs -= end-buffer; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
732 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
733 } else { // Get the command |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
734 while(iter[0] == ' ' || iter[0] == '\t') iter++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
735 // Found new line |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
736 if(iter[0] == '\n' || iter[0] == '\r') { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
737 printf("No command found for key (TODO)\n" /*mp_input_get_key_name(code)*/); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
738 code = -1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
739 if(iter > buffer) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
740 memmove(buffer,iter,bs- (iter-buffer)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
741 bs -= (iter-buffer); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
742 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
743 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
744 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
745 for(end = iter ; end[0] != '\n' && end[0] != '\r' && end[0] != '\0' ; end++) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
746 /* NOTHING */; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
747 if(end[0] == '\0' && ! (eof && (end - buffer) == bs)) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
748 if(iter == buffer) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
749 printf("Buffer is too small for command %s\n",buffer); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
750 mp_input_free_binds(binds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
751 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
752 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
753 memmove(buffer,iter,end - iter); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
754 bs = end - iter; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
755 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
756 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
757 { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
758 char cmd[end-iter+1]; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
759 strncpy(cmd,iter,end-iter); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
760 cmd[end-iter] = '\0'; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
761 //printf("Set bind %d => %s\n",code,cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
762 binds = (mp_cmd_bind_t*)realloc(binds,(n_binds+2)*sizeof(mp_cmd_bind_t)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
763 binds[n_binds].input = code; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
764 binds[n_binds].cmd = strdup(cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
765 n_binds++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
766 memset(&binds[n_binds],0,sizeof(mp_cmd_bind_t)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
767 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
768 code = -1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
769 if(bs > (end-buffer)) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
770 memmove(buffer,end,bs-(end-buffer)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
771 bs -= (end-buffer); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
772 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
773 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
774 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
775 printf("What are we doing here ?\n"); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
776 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
777 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
778 extern char *get_path(char *filename); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
779 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
780 void |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
781 mp_input_init(void) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
782 char* file; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
783 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
784 file = get_path("input.conf"); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
785 if(!file) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
786 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
787 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
788 mp_input_parse_config(file); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
789 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
790 #ifdef HAVE_JOYSTICK |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
791 { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
792 int fd = mp_input_joystick_init(NULL); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
793 if(fd < 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
794 printf("Can't init input joystick\n"); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
795 else |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
796 mp_input_add_key_fd(fd,1,mp_input_joystick_read,(mp_close_func_t)close); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
797 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
798 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
799 |
4432 | 800 #ifdef HAVE_LIRC |
801 { | |
802 int fd = mp_input_lirc_init(); | |
803 if(fd > 0) | |
804 mp_input_add_cmd_fd(fd,1,NULL,(mp_close_func_t)close); | |
805 } | |
806 #endif | |
807 | |
808 } | |
809 | |
810 void | |
811 mp_input_uninit(void) { | |
812 | |
813 #ifdef HAVE_LIRC | |
814 mp_input_lirc_uninit(); | |
815 #endif | |
816 | |
4418
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
817 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
818 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
819 #endif /* HAVE_NEW_INPUT */ |