Mercurial > mplayer.hg
changeset 4821:5a71377d2759
Fixed bug with comments in input.conf parser
Added a command queue to let mplayer send command to himself
author | albeu |
---|---|
date | Sat, 23 Feb 2002 21:13:35 +0000 |
parents | ab6ceeef3904 |
children | 3e2c7bf57035 |
files | input/input.c input/input.h |
diffstat | 2 files changed, 46 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/input/input.c Sat Feb 23 21:11:01 2002 +0000 +++ b/input/input.c Sat Feb 23 21:13:35 2002 +0000 @@ -196,6 +196,8 @@ #define MP_FD_GOT_CMD (1<<3) #define MP_FD_NO_SELECT (1<<4) +#define CMD_QUEUE_SIZE 10 + typedef struct mp_input_fd { int fd; void* read_func; @@ -213,6 +215,8 @@ static unsigned int num_key_fd = 0; static mp_input_fd_t cmd_fds[MP_MAX_CMD_FD]; static unsigned int num_cmd_fd = 0; +static mp_cmd_t* cmd_queue[CMD_QUEUE_SIZE]; +static unsigned int cmd_queue_length = 0,cmd_queue_start = 0, cmd_queue_end = 0; // this is the key currently down static int key_down[MP_MAX_KEY_DOWN]; @@ -757,10 +761,39 @@ return NULL; } +int +mp_input_queue_cmd(mp_cmd_t* cmd) { + if(cmd_queue_length >= CMD_QUEUE_SIZE) + return 0; + cmd_queue[cmd_queue_end] = cmd; + cmd_queue_end = (cmd_queue_end + 1) % CMD_QUEUE_SIZE; + cmd_queue_length++; + return 1; +} + +static mp_cmd_t* +mp_input_get_queued_cmd(void) { + mp_cmd_t* ret; + + if(cmd_queue_length == 0) + return NULL; + + ret = cmd_queue[cmd_queue_start]; + + cmd_queue_length--; + cmd_queue_start = (cmd_queue_start + 1) % CMD_QUEUE_SIZE; + + return ret; +} + mp_cmd_t* mp_input_get_cmd(int time, int paused) { mp_cmd_t* ret; + ret = mp_input_get_queued_cmd(); + if(ret) + return ret; + ret = mp_input_read_keys(time,paused); if(ret) return ret; @@ -811,19 +844,16 @@ mp_input_get_key_name(int key) { int i; - if(key == ' ') - return "SPACE"; - + for(i = 0; key_names[i].name != NULL; i++) { + if(key_names[i].key == key) + return key_names[i].name; + } + if(key >> 8 == 0) { snprintf(key_str,2,"%c",(char)key); return key_str; } - for(i = 0; key_names[i].name != NULL; i++) { - if(key_names[i].key == key) - return key_names[i].name; - } - return NULL; } @@ -924,13 +954,13 @@ } } // Empty buffer : return - if(bs <= 1) { + if(bs <= 0) { printf("Input config file %s parsed : %d binds\n",file,n_binds); if(binds) cmd_binds = binds; return 1; } - + iter = buffer; if(comments) { @@ -1011,7 +1041,7 @@ } for(end = iter ; end[0] != '\n' && end[0] != '\r' && end[0] != '\0' ; end++) /* NOTHING */; - if(end[0] == '\0' && ! (eof && (end - buffer) == bs)) { + if(end[0] == '\0' && ! (eof && ((end+1) - buffer) == bs)) { if(iter == buffer) { printf("Buffer is too small for command %s\n",buffer); mp_input_free_binds(binds); @@ -1033,9 +1063,11 @@ memset(&binds[n_binds],0,sizeof(mp_cmd_bind_t)); } keys[0] = 0; + end++; if(bs > (end-buffer)) memmove(buffer,end,bs-(end-buffer)); bs -= (end-buffer); + buffer[bs-1] = '\0'; continue; } }