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