comparison input/input.c @ 5198:a528f6c891b5

A bug fix in the auto-repeat stuff + moved all printf to mp_msg
author albeu
date Tue, 19 Mar 2002 13:30:16 +0000
parents 74e0ebe59cab
children 022c957633a3
comparison
equal deleted inserted replaced
5197:f0e3dcefb7af 5198:a528f6c891b5
26 26
27 #ifdef HAVE_LIRC 27 #ifdef HAVE_LIRC
28 #include "lirc.h" 28 #include "lirc.h"
29 #endif 29 #endif
30 30
31 // If the args field is not NULL, the command will only be passed if 31 /// This array defines all know commands.
32 // an argument exist. 32 /// The first field is an id used to recognize the command without too many strcmp
33 /// The second is abviously the command name
34 /// The third is the minimum number of argument this command need
35 /// Then come the definition of each argument, terminated with and arg of type -1
36 /// A command can take maximum MP_CMD_MAX_ARGS-1 arguments (-1 because of
37 /// the terminal one) wich is actually 9
38
39 /// For the args, the first field is the type (actually int, float or string), the second
40 /// is the default value wich is used for optional arguments
33 41
34 static mp_cmd_t mp_cmds[] = { 42 static mp_cmd_t mp_cmds[] = {
35 { MP_CMD_SEEK, "seek", 1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } }, 43 { MP_CMD_SEEK, "seek", 1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
36 { MP_CMD_AUDIO_DELAY, "audio_delay", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } }, 44 { MP_CMD_AUDIO_DELAY, "audio_delay", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
37 { MP_CMD_QUIT, "quit", 0, { {-1,{0}} } }, 45 { MP_CMD_QUIT, "quit", 0, { {-1,{0}} } },
68 { MP_CMD_GUI_SKINBROWSER, "gui_skinbrowser", 0, { {-1,{0}} } }, 76 { MP_CMD_GUI_SKINBROWSER, "gui_skinbrowser", 0, { {-1,{0}} } },
69 #endif 77 #endif
70 78
71 { 0, NULL, 0, {} } 79 { 0, NULL, 0, {} }
72 }; 80 };
81
82 /// The names of the key for input.conf
83 /// If you add some new keys, you also need to add them here
73 84
74 static mp_key_name_t key_names[] = { 85 static mp_key_name_t key_names[] = {
75 { ' ', "SPACE" }, 86 { ' ', "SPACE" },
76 { KEY_ENTER, "ENTER" }, 87 { KEY_ENTER, "ENTER" },
77 { KEY_TAB, "TAB" }, 88 { KEY_TAB, "TAB" },
135 { JOY_BTN8, "JOY_BTN8" }, 146 { JOY_BTN8, "JOY_BTN8" },
136 { JOY_BTN9, "JOY_BTN9" }, 147 { JOY_BTN9, "JOY_BTN9" },
137 { 0, NULL } 148 { 0, NULL }
138 }; 149 };
139 150
140 // This is the default binding we use when no config file is here 151 // This is the default binding. The content of input.conf override these ones.
152 // The first args is a null terminated array of key codes.
153 // The second is the command
141 154
142 static mp_cmd_bind_t def_cmd_binds[] = { 155 static mp_cmd_bind_t def_cmd_binds[] = {
143 156
144 { { MOUSE_BTN3, 0 }, "seek 10" }, 157 { { MOUSE_BTN3, 0 }, "seek 10" },
145 { { MOUSE_BTN4, 0 }, "seek -10" }, 158 { { MOUSE_BTN4, 0 }, "seek -10" },
241 // This fields are for the cmd fds 254 // This fields are for the cmd fds
242 char* buffer; 255 char* buffer;
243 int pos,size; 256 int pos,size;
244 } mp_input_fd_t; 257 } mp_input_fd_t;
245 258
246 259 // These are the user defined binds
247 static mp_cmd_bind_t* cmd_binds = NULL; 260 static mp_cmd_bind_t* cmd_binds = NULL;
248 261
249 static mp_input_fd_t key_fds[MP_MAX_KEY_FD]; 262 static mp_input_fd_t key_fds[MP_MAX_KEY_FD];
250 static unsigned int num_key_fd = 0; 263 static unsigned int num_key_fd = 0;
251 static mp_input_fd_t cmd_fds[MP_MAX_CMD_FD]; 264 static mp_input_fd_t cmd_fds[MP_MAX_CMD_FD];
263 static unsigned int ar_delay = 100, ar_rate = 8, last_ar = 0; 276 static unsigned int ar_delay = 100, ar_rate = 8, last_ar = 0;
264 277
265 static int use_joystick = 1, use_lirc = 1; 278 static int use_joystick = 1, use_lirc = 1;
266 static char* config_file = "input.conf"; 279 static char* config_file = "input.conf";
267 280
281 // Our command line options
268 static config_t input_conf[] = { 282 static config_t input_conf[] = {
269 { "conf", &config_file, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL }, 283 { "conf", &config_file, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL },
270 { "ar-delay", &ar_delay, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL }, 284 { "ar-delay", &ar_delay, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL },
271 { "ar-rate", &ar_rate, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL }, 285 { "ar-rate", &ar_rate, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL },
272 { NULL, NULL, 0, 0, 0, 0, NULL} 286 { NULL, NULL, 0, 0, 0, 0, NULL}
289 303
290 304
291 int 305 int
292 mp_input_add_cmd_fd(int fd, int select, mp_cmd_func_t read_func, mp_close_func_t close_func) { 306 mp_input_add_cmd_fd(int fd, int select, mp_cmd_func_t read_func, mp_close_func_t close_func) {
293 if(num_cmd_fd == MP_MAX_CMD_FD) { 307 if(num_cmd_fd == MP_MAX_CMD_FD) {
294 printf("Too much command fd, unable to register fd %d\n",fd); 308 mp_msg(MSGT_INPUT,MSGL_ERR,"Too much command fd, unable to register fd %d\n",fd);
295 return 0; 309 return 0;
296 } 310 }
297 311
298 memset(&cmd_fds[num_cmd_fd],0,sizeof(mp_input_fd_t)); 312 memset(&cmd_fds[num_cmd_fd],0,sizeof(mp_input_fd_t));
299 cmd_fds[num_cmd_fd].fd = fd; 313 cmd_fds[num_cmd_fd].fd = fd;
343 } 357 }
344 358
345 int 359 int
346 mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t close_func) { 360 mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t close_func) {
347 if(num_key_fd == MP_MAX_KEY_FD) { 361 if(num_key_fd == MP_MAX_KEY_FD) {
348 printf("Too much key fd, unable to register fd %d\n",fd); 362 mp_msg(MSGT_INPUT,MSGL_ERR,"Too much key fd, unable to register fd %d\n",fd);
349 return 0; 363 return 0;
350 } 364 }
351 365
352 memset(&key_fds[num_key_fd],0,sizeof(mp_input_fd_t)); 366 memset(&key_fds[num_key_fd],0,sizeof(mp_input_fd_t));
353 key_fds[num_key_fd].fd = fd; 367 key_fds[num_key_fd].fd = fd;
406 switch(cmd_def->args[i].type) { 420 switch(cmd_def->args[i].type) {
407 case MP_CMD_ARG_INT: 421 case MP_CMD_ARG_INT:
408 errno = 0; 422 errno = 0;
409 cmd->args[i].v.i = atoi(ptr); 423 cmd->args[i].v.i = atoi(ptr);
410 if(errno != 0) { 424 if(errno != 0) {
411 printf("Command %s : argument %d isn't an integer\n",cmd_def->name,i+1); 425 mp_msg(MSGT_INPUT,MSGL_ERR,"Command %s : argument %d isn't an integer\n",cmd_def->name,i+1);
412 ptr = NULL; 426 ptr = NULL;
413 } 427 }
414 break; 428 break;
415 case MP_CMD_ARG_FLOAT: 429 case MP_CMD_ARG_FLOAT:
416 errno = 0; 430 errno = 0;
417 cmd->args[i].v.f = atof(ptr); 431 cmd->args[i].v.f = atof(ptr);
418 if(errno != 0) { 432 if(errno != 0) {
419 printf("Command %s : argument %d isn't a float\n",cmd_def->name,i+1); 433 mp_msg(MSGT_INPUT,MSGL_ERR,"Command %s : argument %d isn't a float\n",cmd_def->name,i+1);
420 ptr = NULL; 434 ptr = NULL;
421 } 435 }
422 break; 436 break;
423 case MP_CMD_ARG_STRING: 437 case MP_CMD_ARG_STRING:
424 e = strchr(ptr,' '); 438 e = strchr(ptr,' ');
429 cmd->args[i].v.s[l] = '\0'; 443 cmd->args[i].v.s[l] = '\0';
430 break; 444 break;
431 case -1: 445 case -1:
432 ptr = NULL; 446 ptr = NULL;
433 default : 447 default :
434 printf("Unknown argument %d\n",i); 448 mp_msg(MSGT_INPUT,MSGL_ERR,"Unknown argument %d\n",i);
435 } 449 }
436 } 450 }
437 cmd->nargs = i; 451 cmd->nargs = i;
438 452
439 if(cmd_def->nargs > cmd->nargs) { 453 if(cmd_def->nargs > cmd->nargs) {
440 printf("Got [%s] but\n",str); 454 mp_msg(MSGT_INPUT,MSGL_ERR,"Got command '%s' but\n",str);
441 printf("Command %s require at least %d arguments, we found only %d so far\n",cmd_def->name,cmd_def->nargs,cmd->nargs); 455 mp_msg(MSGT_INPUT,MSGL_ERR,"command %s require at least %d arguments, we found only %d so far\n",cmd_def->name,cmd_def->nargs,cmd->nargs);
442 mp_cmd_free(cmd); 456 mp_cmd_free(cmd);
443 return NULL; 457 return NULL;
444 } 458 }
445 459
446 for( ; i < MP_CMD_MAX_ARGS && cmd_def->args[i].type != -1 ; i++) { 460 for( ; i < MP_CMD_MAX_ARGS && cmd_def->args[i].type != -1 ; i++) {
478 mp_fd->pos = 0; 492 mp_fd->pos = 0;
479 mp_fd->size = MP_CMD_MAX_SIZE; 493 mp_fd->size = MP_CMD_MAX_SIZE;
480 } 494 }
481 495
482 if(mp_fd->size - mp_fd->pos == 0) { 496 if(mp_fd->size - mp_fd->pos == 0) {
483 printf("Cmd buffer of fd %d is full : dropping content\n",mp_fd->fd); 497 mp_msg(MSGT_INPUT,MSGL_ERR,"Cmd buffer of fd %d is full : dropping content\n",mp_fd->fd);
484 mp_fd->pos = 0; 498 mp_fd->pos = 0;
485 mp_fd->flags |= MP_FD_DROP; 499 mp_fd->flags |= MP_FD_DROP;
486 } 500 }
487 501
488 while( !(mp_fd->flags & MP_FD_EOF) && (mp_fd->size - mp_fd->pos > 1) ) { 502 while( !(mp_fd->flags & MP_FD_EOF) && (mp_fd->size - mp_fd->pos > 1) ) {
490 if(r < 0) { 504 if(r < 0) {
491 if(errno == EINTR) 505 if(errno == EINTR)
492 continue; 506 continue;
493 else if(errno == EAGAIN) 507 else if(errno == EAGAIN)
494 break; 508 break;
495 printf("Error while reading cmd fd %d : %s\n",mp_fd->fd,strerror(errno)); 509 mp_msg(MSGT_INPUT,MSGL_ERR,"Error while reading cmd fd %d : %s\n",mp_fd->fd,strerror(errno));
496 return MP_INPUT_ERROR; 510 return MP_INPUT_ERROR;
497 } else if(r == 0) { 511 } else if(r == 0) {
498 mp_fd->flags |= MP_FD_EOF; 512 mp_fd->flags |= MP_FD_EOF;
499 break; 513 break;
500 } 514 }
571 cmd = mp_input_find_bind_for_key(cmd_binds,n,keys); 585 cmd = mp_input_find_bind_for_key(cmd_binds,n,keys);
572 if(cmd == NULL) 586 if(cmd == NULL)
573 cmd = mp_input_find_bind_for_key(def_cmd_binds,n,keys); 587 cmd = mp_input_find_bind_for_key(def_cmd_binds,n,keys);
574 588
575 if(cmd == NULL) { 589 if(cmd == NULL) {
576 printf("No bind found for key %s",mp_input_get_key_name(keys[0])); 590 mp_msg(MSGT_INPUT,MSGL_ERR,"No bind found for key %s",mp_input_get_key_name(keys[0]));
577 if(n > 1) { 591 if(n > 1) {
578 int s; 592 int s;
579 for(s=1; s < n; s++) 593 for(s=1; s < n; s++)
580 printf("-%s",mp_input_get_key_name(keys[s])); 594 mp_msg(MSGT_INPUT,MSGL_ERR,"-%s",mp_input_get_key_name(keys[s]));
581 } 595 }
582 printf(" \n"); 596 mp_msg(MSGT_INPUT,MSGL_ERR," \n");
583 return NULL; 597 return NULL;
584 } 598 }
585 ret = mp_input_parse_cmd(cmd); 599 ret = mp_input_parse_cmd(cmd);
586 if(!ret) { 600 if(!ret) {
587 printf("Invalid command for binded key %s",mp_input_get_key_name(key_down[0])); 601 mp_msg(MSGT_INPUT,MSGL_ERR,"Invalid command for binded key %s",mp_input_get_key_name(key_down[0]));
588 if( num_key_down > 1) { 602 if( num_key_down > 1) {
589 unsigned int s; 603 unsigned int s;
590 for(s=1; s < num_key_down; s++) 604 for(s=1; s < num_key_down; s++)
591 printf("-%s",mp_input_get_key_name(key_down[s])); 605 mp_msg(MSGT_INPUT,MSGL_ERR,"-%s",mp_input_get_key_name(key_down[s]));
592 } 606 }
593 printf(" : %s \n",cmd); 607 mp_msg(MSGT_INPUT,MSGL_ERR," : %s \n",cmd);
594 } 608 }
595 return ret; 609 return ret;
596 } 610 }
597 611
598 static mp_cmd_t* 612 static mp_cmd_t*
633 647
634 while(n > 0) { 648 while(n > 0) {
635 if(select(max_fd+1,&fds,NULL,NULL,time_val) < 0) { 649 if(select(max_fd+1,&fds,NULL,NULL,time_val) < 0) {
636 if(errno == EINTR) 650 if(errno == EINTR)
637 continue; 651 continue;
638 printf("Select error : %s\n",strerror(errno)); 652 mp_msg(MSGT_INPUT,MSGL_ERR,"Select error : %s\n",strerror(errno));
639 } 653 }
640 break; 654 break;
641 } 655 }
642 656
643 for(i = last_loop + 1 ; i != last_loop ; i++) { 657 for(i = last_loop + 1 ; i != last_loop ; i++) {
660 } 674 }
661 else 675 else
662 code = ((mp_key_func_t)key_fds[i].read_func)(key_fds[i].fd); 676 code = ((mp_key_func_t)key_fds[i].read_func)(key_fds[i].fd);
663 if(code < 0) { 677 if(code < 0) {
664 if(code == MP_INPUT_ERROR) 678 if(code == MP_INPUT_ERROR)
665 printf("Error on key input fd %d\n",key_fds[i].fd); 679 mp_msg(MSGT_INPUT,MSGL_ERR,"Error on key input fd %d\n",key_fds[i].fd);
666 else if(code == MP_INPUT_DEAD) { 680 else if(code == MP_INPUT_DEAD) {
667 printf("Dead key input on fd %d\n",key_fds[i].fd); 681 mp_msg(MSGT_INPUT,MSGL_ERR,"Dead key input on fd %d\n",key_fds[i].fd);
668 key_fds[i].flags |= MP_FD_DEAD; 682 key_fds[i].flags |= MP_FD_DEAD;
669 } 683 }
670 continue; 684 continue;
671 } 685 }
672 // key pushed 686 // key pushed
673 if(code & MP_KEY_DOWN) { 687 if(code & MP_KEY_DOWN) {
674 if(num_key_down > MP_MAX_KEY_DOWN) { 688 if(num_key_down > MP_MAX_KEY_DOWN) {
675 printf("Too much key down at the same time\n"); 689 mp_msg(MSGT_INPUT,MSGL_ERR,"Too much key down at the same time\n");
676 continue; 690 continue;
677 } 691 }
678 code &= ~MP_KEY_DOWN; 692 code &= ~MP_KEY_DOWN;
679 // Check if we don't already have this key as pushed 693 // Check if we don't already have this key as pushed
680 for(j = 0; j < num_key_down; j++) { 694 for(j = 0; j < num_key_down; j++) {
696 if(key_down[j] == code) 710 if(key_down[j] == code)
697 break; 711 break;
698 } 712 }
699 if(j == num_key_down) { // key was not in the down keys : add it 713 if(j == num_key_down) { // key was not in the down keys : add it
700 if(num_key_down > MP_MAX_KEY_DOWN) { 714 if(num_key_down > MP_MAX_KEY_DOWN) {
701 printf("Too much key down at the same time\n"); 715 mp_msg(MSGT_INPUT,MSGL_ERR,"Too much key down at the same time\n");
702 continue; 716 continue;
703 } 717 }
704 key_down[num_key_down] = code; 718 key_down[num_key_down] = code;
705 num_key_down++; 719 num_key_down++;
706 last_key_down = 1; 720 last_key_down = 1;
727 if(ar_rate > 0 && ar_state >=0 && num_key_down > 0 && ! (key_down[num_key_down-1] & MP_NO_REPEAT_KEY)) { 741 if(ar_rate > 0 && ar_state >=0 && num_key_down > 0 && ! (key_down[num_key_down-1] & MP_NO_REPEAT_KEY)) {
728 unsigned int t = GetTimer(); 742 unsigned int t = GetTimer();
729 // First time : wait delay 743 // First time : wait delay
730 if(ar_state == 0 && (t - last_key_down) >= ar_delay*1000) { 744 if(ar_state == 0 && (t - last_key_down) >= ar_delay*1000) {
731 ar_cmd = mp_input_get_cmd_from_keys(num_key_down,key_down,paused); 745 ar_cmd = mp_input_get_cmd_from_keys(num_key_down,key_down,paused);
732 if(!ar_cmd) 746 if(!ar_cmd) {
733 ar_state = -1; 747 ar_state = -1;
734 else { 748 return NULL;
735 ar_state = 1; 749 }
736 last_ar = t; 750 ar_state = 1;
737 } 751 last_ar = t;
738 return mp_cmd_clone(ar_cmd); 752 return mp_cmd_clone(ar_cmd);
739 // Then send rate / sec event 753 // Then send rate / sec event
740 } else if(ar_state == 1 && (t -last_ar) >= 1000000/ar_rate) { 754 } else if(ar_state == 1 && (t -last_ar) >= 1000000/ar_rate) {
741 last_ar = t; 755 last_ar = t;
742 return mp_cmd_clone(ar_cmd); 756 return mp_cmd_clone(ar_cmd);
784 while(n > 0) { 798 while(n > 0) {
785 if((i = select(max_fd+1,&fds,NULL,NULL,time_val)) <= 0) { 799 if((i = select(max_fd+1,&fds,NULL,NULL,time_val)) <= 0) {
786 if(i < 0) { 800 if(i < 0) {
787 if(errno == EINTR) 801 if(errno == EINTR)
788 continue; 802 continue;
789 printf("Select error : %s\n",strerror(errno)); 803 mp_msg(MSGT_INPUT,MSGL_ERR,"Select error : %s\n",strerror(errno));
790 } 804 }
791 return NULL; 805 return NULL;
792 } 806 }
793 break; 807 break;
794 } 808 }
806 continue; 820 continue;
807 821
808 r = mp_input_read_cmd(&cmd_fds[i],&cmd); 822 r = mp_input_read_cmd(&cmd_fds[i],&cmd);
809 if(r < 0) { 823 if(r < 0) {
810 if(r == MP_INPUT_ERROR) 824 if(r == MP_INPUT_ERROR)
811 printf("Error on cmd fd %d\n",cmd_fds[i].fd); 825 mp_msg(MSGT_INPUT,MSGL_ERR,"Error on cmd fd %d\n",cmd_fds[i].fd);
812 else if(r == MP_INPUT_DEAD) 826 else if(r == MP_INPUT_DEAD)
813 cmd_fds[i].flags |= MP_FD_DEAD; 827 cmd_fds[i].flags |= MP_FD_DEAD;
814 continue; 828 continue;
815 } 829 }
816 ret = mp_input_parse_cmd(cmd); 830 ret = mp_input_parse_cmd(cmd);
1026 mp_cmd_bind_t* binds = NULL; 1040 mp_cmd_bind_t* binds = NULL;
1027 1041
1028 fd = open(file,O_RDONLY); 1042 fd = open(file,O_RDONLY);
1029 1043
1030 if(fd < 0) { 1044 if(fd < 0) {
1031 printf("Can't open input config file %s : %s\n",file,strerror(errno)); 1045 mp_msg(MSGT_INPUT,MSGL_ERR,"Can't open input config file %s : %s\n",file,strerror(errno));
1032 return 0; 1046 return 0;
1033 } 1047 }
1034 1048
1035 printf("Parsing input config file %s\n",file); 1049 mp_msg(MSGT_INPUT,MSGL_V,"Parsing input config file %s\n",file);
1036 1050
1037 while(1) { 1051 while(1) {
1038 if(! eof && bs < BS_MAX-1) { 1052 if(! eof && bs < BS_MAX-1) {
1039 if(bs > 0) bs--; 1053 if(bs > 0) bs--;
1040 r = read(fd,buffer+bs,BS_MAX-1-bs); 1054 r = read(fd,buffer+bs,BS_MAX-1-bs);
1041 if(r < 0) { 1055 if(r < 0) {
1042 if(errno == EINTR) 1056 if(errno == EINTR)
1043 continue; 1057 continue;
1044 printf("Error while reading input config file %s : %s\n",file,strerror(errno)); 1058 mp_msg(MSGT_INPUT,MSGL_ERR,"Error while reading input config file %s : %s\n",file,strerror(errno));
1045 mp_input_free_binds(binds); 1059 mp_input_free_binds(binds);
1046 return 0; 1060 return 0;
1047 } else if(r == 0) 1061 } else if(r == 0)
1048 eof = 1; 1062 eof = 1;
1049 else { 1063 else {
1051 buffer[bs-1] = '\0'; 1065 buffer[bs-1] = '\0';
1052 } 1066 }
1053 } 1067 }
1054 // Empty buffer : return 1068 // Empty buffer : return
1055 if(bs <= 0) { 1069 if(bs <= 0) {
1056 printf("Input config file %s parsed : %d binds\n",file,n_binds); 1070 mp_msg(MSGT_INPUT,MSGL_INFO,"Input config file %s parsed : %d binds\n",file,n_binds);
1057 if(binds) 1071 if(binds)
1058 cmd_binds = binds; 1072 cmd_binds = binds;
1059 return 1; 1073 return 1;
1060 } 1074 }
1061 1075
1095 for(end = iter; end[0] != '\0' && strchr(SPACE_CHAR,end[0]) == NULL ; end++) 1109 for(end = iter; end[0] != '\0' && strchr(SPACE_CHAR,end[0]) == NULL ; end++)
1096 /*NOTHING */; 1110 /*NOTHING */;
1097 if(end[0] == '\0') { // Key name don't fit in the buffer 1111 if(end[0] == '\0') { // Key name don't fit in the buffer
1098 if(buffer == iter) { 1112 if(buffer == iter) {
1099 if(eof && (buffer-iter) == bs) 1113 if(eof && (buffer-iter) == bs)
1100 printf("Unfinished binding %s\n",iter); 1114 mp_msg(MSGT_INPUT,MSGL_ERR,"Unfinished binding %s\n",iter);
1101 else 1115 else
1102 printf("Buffer is too small for this key name : %s\n",iter); 1116 mp_msg(MSGT_INPUT,MSGL_ERR,"Buffer is too small for this key name : %s\n",iter);
1103 mp_input_free_binds(binds); 1117 mp_input_free_binds(binds);
1104 return 0; 1118 return 0;
1105 } 1119 }
1106 memmove(buffer,iter,end-iter); 1120 memmove(buffer,iter,end-iter);
1107 bs = end-iter; 1121 bs = end-iter;
1110 { 1124 {
1111 char name[end-iter+1]; 1125 char name[end-iter+1];
1112 strncpy(name,iter,end-iter); 1126 strncpy(name,iter,end-iter);
1113 name[end-iter] = '\0'; 1127 name[end-iter] = '\0';
1114 if(! mp_input_get_input_from_name(name,keys)) { 1128 if(! mp_input_get_input_from_name(name,keys)) {
1115 printf("Unknown key '%s'\n",name); 1129 mp_msg(MSGT_INPUT,MSGL_ERR,"Unknown key '%s'\n",name);
1116 mp_input_free_binds(binds); 1130 mp_input_free_binds(binds);
1117 return 0; 1131 return 0;
1118 } 1132 }
1119 } 1133 }
1120 if( bs > (end-buffer)) 1134 if( bs > (end-buffer))
1124 } else { // Get the command 1138 } else { // Get the command
1125 while(iter[0] == ' ' || iter[0] == '\t') iter++; 1139 while(iter[0] == ' ' || iter[0] == '\t') iter++;
1126 // Found new line 1140 // Found new line
1127 if(iter[0] == '\n' || iter[0] == '\r') { 1141 if(iter[0] == '\n' || iter[0] == '\r') {
1128 int i; 1142 int i;
1129 printf("No command found for key %s" ,mp_input_get_key_name(keys[0])); 1143 mp_msg(MSGT_INPUT,MSGL_ERR,"No command found for key %s" ,mp_input_get_key_name(keys[0]));
1130 for(i = 1; keys[i] != 0 ; i++) 1144 for(i = 1; keys[i] != 0 ; i++)
1131 printf("-%s",mp_input_get_key_name(keys[i])); 1145 mp_msg(MSGT_INPUT,MSGL_ERR,"-%s",mp_input_get_key_name(keys[i]));
1132 printf("\n"); 1146 mp_msg(MSGT_INPUT,MSGL_ERR,"\n");
1133 keys[0] = 0; 1147 keys[0] = 0;
1134 if(iter > buffer) { 1148 if(iter > buffer) {
1135 memmove(buffer,iter,bs- (iter-buffer)); 1149 memmove(buffer,iter,bs- (iter-buffer));
1136 bs -= (iter-buffer); 1150 bs -= (iter-buffer);
1137 } 1151 }
1139 } 1153 }
1140 for(end = iter ; end[0] != '\n' && end[0] != '\r' && end[0] != '\0' ; end++) 1154 for(end = iter ; end[0] != '\n' && end[0] != '\r' && end[0] != '\0' ; end++)
1141 /* NOTHING */; 1155 /* NOTHING */;
1142 if(end[0] == '\0' && ! (eof && ((end+1) - buffer) == bs)) { 1156 if(end[0] == '\0' && ! (eof && ((end+1) - buffer) == bs)) {
1143 if(iter == buffer) { 1157 if(iter == buffer) {
1144 printf("Buffer is too small for command %s\n",buffer); 1158 mp_msg(MSGT_INPUT,MSGL_ERR,"Buffer is too small for command %s\n",buffer);
1145 mp_input_free_binds(binds); 1159 mp_input_free_binds(binds);
1146 return 0; 1160 return 0;
1147 } 1161 }
1148 memmove(buffer,iter,end - iter); 1162 memmove(buffer,iter,end - iter);
1149 bs = end - iter; 1163 bs = end - iter;
1164 bs -= (end-buffer); 1178 bs -= (end-buffer);
1165 buffer[bs-1] = '\0'; 1179 buffer[bs-1] = '\0';
1166 continue; 1180 continue;
1167 } 1181 }
1168 } 1182 }
1169 printf("What are we doing here ?\n"); 1183 mp_msg(MSGT_INPUT,MSGL_ERR,"What are we doing here ?\n");
1170 return 0; 1184 return 0;
1171 } 1185 }
1172 1186
1173 extern char *get_path(char *filename); 1187 extern char *get_path(char *filename);
1174 1188
1179 file = config_file[0] != '/' ? get_path(config_file) : config_file; 1193 file = config_file[0] != '/' ? get_path(config_file) : config_file;
1180 if(!file) 1194 if(!file)
1181 return; 1195 return;
1182 1196
1183 if(! mp_input_parse_config(file)) 1197 if(! mp_input_parse_config(file))
1184 printf("Falling back on default (hardcoded) config\n"); 1198 mp_msg(MSGT_INPUT,MSGL_WARN,"Falling back on default (hardcoded) config\n");
1185 1199
1186 #ifdef HAVE_JOYSTICK 1200 #ifdef HAVE_JOYSTICK
1187 if(use_joystick) { 1201 if(use_joystick) {
1188 int fd = mp_input_joystick_init(NULL); 1202 int fd = mp_input_joystick_init(NULL);
1189 if(fd < 0) 1203 if(fd < 0)
1190 printf("Can't init input joystick\n"); 1204 mp_msg(MSGT_INPUT,MSGL_ERR,"Can't init input joystick\n");
1191 else 1205 else
1192 mp_input_add_key_fd(fd,1,mp_input_joystick_read,(mp_close_func_t)close); 1206 mp_input_add_key_fd(fd,1,mp_input_joystick_read,(mp_close_func_t)close);
1193 } 1207 }
1194 #endif 1208 #endif
1195 1209