#include "../config.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <ctype.h>
#ifdef USE_SETLOCALE
#include <locale.h>
#endif
#include "input.h"
#include "mouse.h"
#ifdef MP_DEBUG
#include <assert.h>
#endif
#include "../osdep/getch2.h"
#include "../osdep/keycodes.h"
#include "../osdep/timer.h"
#include "../mp_msg.h"
#include "../m_config.h"
#include "../m_option.h"
#include "joystick.h"
#ifdef HAVE_LIRC
#include "lirc.h"
#endif
#ifdef HAVE_LIRCC
#include <lirc/lircc.h>
#endif
/// This array defines all known commands.
/// The first field is an id used to recognize the command without too many strcmp.
/// The second is obviously the command name.
/// The third is the minimum number of arguments this command needs.
/// Then comes the definition of each argument, terminated with an arg of type -1.
/// A command can take a maximum of MP_CMD_MAX_ARGS-1 arguments (-1 because of
/// the last one) which is actually 9.
/// For the args, the first field is the type (actually int, float or string), the second
/// is the default value wich is used for optional arguments
static mp_cmd_t mp_cmds[] = {
{ MP_CMD_SEEK, "seek", 1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
#ifdef USE_EDL
{ MP_CMD_EDL_MARK, "edl_mark", 0, { {-1,{0}} } },
#endif
{ MP_CMD_AUDIO_DELAY, "audio_delay", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
{ MP_CMD_SPEED_INCR, "speed_incr", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
{ MP_CMD_SPEED_MULT, "speed_mult", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
{ MP_CMD_SPEED_SET, "speed_set", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
{ MP_CMD_QUIT, "quit", 0, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
{ MP_CMD_PAUSE, "pause", 0, { {-1,{0}} } },
{ MP_CMD_FRAME_STEP, "frame_step", 0, { {-1,{0}} } },
{ MP_CMD_GRAB_FRAMES, "grab_frames",0, { {-1,{0}} } },
{ MP_CMD_PLAY_TREE_STEP, "pt_step",1, { { MP_CMD_ARG_INT ,{0}}, { MP_CMD_ARG_INT ,{0}}, {-1,{0}} } },
{ MP_CMD_PLAY_TREE_UP_STEP, "pt_up_step",1, { { MP_CMD_ARG_INT,{0} }, { M
|