Mercurial > mplayer.hg
comparison input/input.c @ 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 | b85890a5b0e5 |
children | a0e8eac85aca |
comparison
equal
deleted
inserted
replaced
4820:ab6ceeef3904 | 4821:5a71377d2759 |
---|---|
194 #define MP_FD_DROP (1<<1) | 194 #define MP_FD_DROP (1<<1) |
195 #define MP_FD_DEAD (1<<2) | 195 #define MP_FD_DEAD (1<<2) |
196 #define MP_FD_GOT_CMD (1<<3) | 196 #define MP_FD_GOT_CMD (1<<3) |
197 #define MP_FD_NO_SELECT (1<<4) | 197 #define MP_FD_NO_SELECT (1<<4) |
198 | 198 |
199 #define CMD_QUEUE_SIZE 10 | |
200 | |
199 typedef struct mp_input_fd { | 201 typedef struct mp_input_fd { |
200 int fd; | 202 int fd; |
201 void* read_func; | 203 void* read_func; |
202 mp_close_func_t close_func; | 204 mp_close_func_t close_func; |
203 int flags; | 205 int flags; |
211 | 213 |
212 static mp_input_fd_t key_fds[MP_MAX_KEY_FD]; | 214 static mp_input_fd_t key_fds[MP_MAX_KEY_FD]; |
213 static unsigned int num_key_fd = 0; | 215 static unsigned int num_key_fd = 0; |
214 static mp_input_fd_t cmd_fds[MP_MAX_CMD_FD]; | 216 static mp_input_fd_t cmd_fds[MP_MAX_CMD_FD]; |
215 static unsigned int num_cmd_fd = 0; | 217 static unsigned int num_cmd_fd = 0; |
218 static mp_cmd_t* cmd_queue[CMD_QUEUE_SIZE]; | |
219 static unsigned int cmd_queue_length = 0,cmd_queue_start = 0, cmd_queue_end = 0; | |
216 | 220 |
217 // this is the key currently down | 221 // this is the key currently down |
218 static int key_down[MP_MAX_KEY_DOWN]; | 222 static int key_down[MP_MAX_KEY_DOWN]; |
219 static unsigned int num_key_down = 0, last_key_down = 0; | 223 static unsigned int num_key_down = 0, last_key_down = 0; |
220 | 224 |
755 | 759 |
756 last_loop = 0; | 760 last_loop = 0; |
757 return NULL; | 761 return NULL; |
758 } | 762 } |
759 | 763 |
764 int | |
765 mp_input_queue_cmd(mp_cmd_t* cmd) { | |
766 if(cmd_queue_length >= CMD_QUEUE_SIZE) | |
767 return 0; | |
768 cmd_queue[cmd_queue_end] = cmd; | |
769 cmd_queue_end = (cmd_queue_end + 1) % CMD_QUEUE_SIZE; | |
770 cmd_queue_length++; | |
771 return 1; | |
772 } | |
773 | |
774 static mp_cmd_t* | |
775 mp_input_get_queued_cmd(void) { | |
776 mp_cmd_t* ret; | |
777 | |
778 if(cmd_queue_length == 0) | |
779 return NULL; | |
780 | |
781 ret = cmd_queue[cmd_queue_start]; | |
782 | |
783 cmd_queue_length--; | |
784 cmd_queue_start = (cmd_queue_start + 1) % CMD_QUEUE_SIZE; | |
785 | |
786 return ret; | |
787 } | |
788 | |
760 mp_cmd_t* | 789 mp_cmd_t* |
761 mp_input_get_cmd(int time, int paused) { | 790 mp_input_get_cmd(int time, int paused) { |
762 mp_cmd_t* ret; | 791 mp_cmd_t* ret; |
792 | |
793 ret = mp_input_get_queued_cmd(); | |
794 if(ret) | |
795 return ret; | |
763 | 796 |
764 ret = mp_input_read_keys(time,paused); | 797 ret = mp_input_read_keys(time,paused); |
765 if(ret) | 798 if(ret) |
766 return ret; | 799 return ret; |
767 | 800 |
809 | 842 |
810 static char* | 843 static char* |
811 mp_input_get_key_name(int key) { | 844 mp_input_get_key_name(int key) { |
812 int i; | 845 int i; |
813 | 846 |
814 if(key == ' ') | 847 for(i = 0; key_names[i].name != NULL; i++) { |
815 return "SPACE"; | 848 if(key_names[i].key == key) |
816 | 849 return key_names[i].name; |
850 } | |
851 | |
817 if(key >> 8 == 0) { | 852 if(key >> 8 == 0) { |
818 snprintf(key_str,2,"%c",(char)key); | 853 snprintf(key_str,2,"%c",(char)key); |
819 return key_str; | 854 return key_str; |
820 } | 855 } |
821 | 856 |
822 for(i = 0; key_names[i].name != NULL; i++) { | |
823 if(key_names[i].key == key) | |
824 return key_names[i].name; | |
825 } | |
826 | |
827 return NULL; | 857 return NULL; |
828 } | 858 } |
829 | 859 |
830 static int | 860 static int |
831 mp_input_get_key_from_name(char* name) { | 861 mp_input_get_key_from_name(char* name) { |
922 bs += r+1; | 952 bs += r+1; |
923 buffer[bs-1] = '\0'; | 953 buffer[bs-1] = '\0'; |
924 } | 954 } |
925 } | 955 } |
926 // Empty buffer : return | 956 // Empty buffer : return |
927 if(bs <= 1) { | 957 if(bs <= 0) { |
928 printf("Input config file %s parsed : %d binds\n",file,n_binds); | 958 printf("Input config file %s parsed : %d binds\n",file,n_binds); |
929 if(binds) | 959 if(binds) |
930 cmd_binds = binds; | 960 cmd_binds = binds; |
931 return 1; | 961 return 1; |
932 } | 962 } |
933 | 963 |
934 iter = buffer; | 964 iter = buffer; |
935 | 965 |
936 if(comments) { | 966 if(comments) { |
937 for( ; iter[0] != '\0' && iter[0] != '\n' ; iter++) | 967 for( ; iter[0] != '\0' && iter[0] != '\n' ; iter++) |
938 /* NOTHING */; | 968 /* NOTHING */; |
1009 } | 1039 } |
1010 continue; | 1040 continue; |
1011 } | 1041 } |
1012 for(end = iter ; end[0] != '\n' && end[0] != '\r' && end[0] != '\0' ; end++) | 1042 for(end = iter ; end[0] != '\n' && end[0] != '\r' && end[0] != '\0' ; end++) |
1013 /* NOTHING */; | 1043 /* NOTHING */; |
1014 if(end[0] == '\0' && ! (eof && (end - buffer) == bs)) { | 1044 if(end[0] == '\0' && ! (eof && ((end+1) - buffer) == bs)) { |
1015 if(iter == buffer) { | 1045 if(iter == buffer) { |
1016 printf("Buffer is too small for command %s\n",buffer); | 1046 printf("Buffer is too small for command %s\n",buffer); |
1017 mp_input_free_binds(binds); | 1047 mp_input_free_binds(binds); |
1018 return 0; | 1048 return 0; |
1019 } | 1049 } |
1031 binds[n_binds].cmd = strdup(cmd); | 1061 binds[n_binds].cmd = strdup(cmd); |
1032 n_binds++; | 1062 n_binds++; |
1033 memset(&binds[n_binds],0,sizeof(mp_cmd_bind_t)); | 1063 memset(&binds[n_binds],0,sizeof(mp_cmd_bind_t)); |
1034 } | 1064 } |
1035 keys[0] = 0; | 1065 keys[0] = 0; |
1066 end++; | |
1036 if(bs > (end-buffer)) | 1067 if(bs > (end-buffer)) |
1037 memmove(buffer,end,bs-(end-buffer)); | 1068 memmove(buffer,end,bs-(end-buffer)); |
1038 bs -= (end-buffer); | 1069 bs -= (end-buffer); |
1070 buffer[bs-1] = '\0'; | |
1039 continue; | 1071 continue; |
1040 } | 1072 } |
1041 } | 1073 } |
1042 printf("What are we doing here ?\n"); | 1074 printf("What are we doing here ?\n"); |
1043 return 0; | 1075 return 0; |