14 * define the command functions for the controller pad.
17 #define CMD_PAD(b, B) \
18 static int (cmd_ ## b)(int c, char **v) \
19 { pad_set((PAD_ ## B), v[0][0] == '+'); return 0; } \
20 static int (cmd_ ## b)(int c, char **v)
25 CMD_PAD(right
, RIGHT
);
28 CMD_PAD(start
, START
);
29 CMD_PAD(select
, SELECT
);
33 * the set command is used to set rc-exported variables.
36 static int cmd_set(int argc
, char **argv
)
40 return rc_setvar(argv
[1], argc
-2, argv
+2);
44 * the toggle command is used to switch rc-exported bool variables.
47 static int cmd_toggle(int argc
, char **argv
)
49 static const char* bools
[] = {"0", "1", 0};
52 return rc_setvar(argv
[1], 1, rc_getint(argv
[1])?bools
:bools
+1);
57 * the following commands allow keys to be bound to perform rc commands.
60 static int cmd_bind(int argc
, char **argv
)
64 return rc_bindkey(argv
[1], argv
[2]);
67 static int cmd_unbind(int argc
, char **argv
)
71 return rc_unbindkey(argv
[1]);
74 static int cmd_unbindall()
80 static int cmd_source(int argc
, char **argv
)
84 return rc_sourcefile(argv
[1]);
93 static int cmd_reset()
99 static int cmd_savestate(int argc
, char **argv
)
101 state_save(argc
> 1 ? atoi(argv
[1]) : -1);
105 static int cmd_loadstate(int argc
, char **argv
)
107 state_load(argc
> 1 ? atoi(argv
[1]) : -1);
114 * table of command names and the corresponding functions to be called
120 RCC("toggle", cmd_toggle
),
121 RCC("bind", cmd_bind
),
122 RCC("unbind", cmd_unbind
),
123 RCC("unbindall", cmd_unbindall
),
124 RCC("source", cmd_source
),
125 RCC("reset", cmd_reset
),
126 RCC("quit", cmd_quit
),
127 RCC("savestate", cmd_savestate
),
128 RCC("loadstate", cmd_loadstate
),
132 RCC("+down", cmd_down
),
133 RCC("-down", cmd_down
),
134 RCC("+left", cmd_left
),
135 RCC("-left", cmd_left
),
136 RCC("+right", cmd_right
),
137 RCC("-right", cmd_right
),
142 RCC("+start", cmd_start
),
143 RCC("-start", cmd_start
),
144 RCC("+select", cmd_select
),
145 RCC("-select", cmd_select
),
154 int rc_command(char *line
)
157 char *argv
[128], *linecopy
;
159 linecopy
= malloc(strlen(line
)+1);
160 strcpy(linecopy
, line
);
162 argc
= splitline(argv
, (sizeof argv
)/(sizeof argv
[0]), linecopy
);
169 for (i
= 0; rccmds
[i
].name
; i
++)
171 if (!strcmp(argv
[0], rccmds
[i
].name
))
173 ret
= rccmds
[i
].func(argc
, argv
);
179 /* printf("unknown command: %s\n", argv[0]); */