comparison input/input.c @ 36153:affa86541a51

Avoid dead code and a memleak.
author reimar
date Tue, 07 May 2013 20:39:18 +0000
parents c3b4a1b48c7d
children 0caa0bf428b9
comparison
equal deleted inserted replaced
36152:c3b4a1b48c7d 36153:affa86541a51
1585 memmove(dst, src, strlen(src) + 1); 1585 memmove(dst, src, strlen(src) + 1);
1586 } 1586 }
1587 1587
1588 static int 1588 static int
1589 mp_input_parse_config(char *file) { 1589 mp_input_parse_config(char *file) {
1590 int res = 0;
1590 int fd; 1591 int fd;
1591 int eof = 0,comments = 0; 1592 int eof = 0,comments = 0;
1592 char *iter,*end; 1593 char *iter,*end;
1593 char buffer[BS_MAX]; 1594 char buffer[BS_MAX];
1594 int n_binds = 0, keys[MP_MAX_KEY_DOWN+1] = { 0 }; 1595 int n_binds = 0, keys[MP_MAX_KEY_DOWN+1] = { 0 };
1612 buffer[bs] = 0; 1613 buffer[bs] = 0;
1613 if(r < 0) { 1614 if(r < 0) {
1614 if(errno == EINTR) 1615 if(errno == EINTR)
1615 continue; 1616 continue;
1616 mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrReadingInputConfig,file,strerror(errno)); 1617 mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrReadingInputConfig,file,strerror(errno));
1617 close(fd); 1618 break;
1618 return 0;
1619 } 1619 }
1620 eof = r == 0; 1620 eof = r == 0;
1621 } 1621 }
1622 // Empty buffer : return 1622 // Empty buffer : return
1623 if(!buffer[0]) { 1623 if(!buffer[0]) {
1624 mp_msg(MSGT_INPUT,MSGL_V,"Input config file %s parsed: %d binds\n",file,n_binds); 1624 mp_msg(MSGT_INPUT,MSGL_V,"Input config file %s parsed: %d binds\n",file,n_binds);
1625 close(fd); 1625 res = 1;
1626 return 1; 1626 break;
1627 } 1627 }
1628 1628
1629 iter = buffer; 1629 iter = buffer;
1630 1630
1631 if(comments) { 1631 if(comments) {
1658 for(end = iter; end[0] && strchr(SPACE_CHAR,end[0]) == NULL ; end++) 1658 for(end = iter; end[0] && strchr(SPACE_CHAR,end[0]) == NULL ; end++)
1659 /*NOTHING */; 1659 /*NOTHING */;
1660 if(!end[0]) { // Key name doesn't fit in the buffer 1660 if(!end[0]) { // Key name doesn't fit in the buffer
1661 if(buffer == iter) { 1661 if(buffer == iter) {
1662 mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrBuffer2SmallForKeyName,iter); 1662 mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrBuffer2SmallForKeyName,iter);
1663 return 0; 1663 break;
1664 } 1664 }
1665 strmove(buffer,iter); 1665 strmove(buffer,iter);
1666 continue; 1666 continue;
1667 } 1667 }
1668 end[0] = 0; 1668 end[0] = 0;
1669 if(! mp_input_get_input_from_name(iter,keys)) { 1669 if(! mp_input_get_input_from_name(iter,keys)) {
1670 mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrUnknownKey,iter); 1670 mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrUnknownKey,iter);
1671 close(fd); 1671 break;
1672 return 0;
1673 } 1672 }
1674 strmove(buffer,end+1); 1673 strmove(buffer,end+1);
1675 continue; 1674 continue;
1676 } else { // Get the command 1675 } else { // Get the command
1677 while(iter[0] == ' ' || iter[0] == '\t') iter++; 1676 while(iter[0] == ' ' || iter[0] == '\t') iter++;
1689 for(end = iter ; end[0] != '\n' && end[0] != '\r' && end[0] ; end++) 1688 for(end = iter ; end[0] != '\n' && end[0] != '\r' && end[0] ; end++)
1690 /* NOTHING */; 1689 /* NOTHING */;
1691 if(!end[0]) { 1690 if(!end[0]) {
1692 if(iter == buffer) { 1691 if(iter == buffer) {
1693 mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrBuffer2SmallForCmd,buffer); 1692 mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrBuffer2SmallForCmd,buffer);
1694 close(fd); 1693 break;
1695 return 0;
1696 } 1694 }
1697 strmove(buffer,iter); 1695 strmove(buffer,iter);
1698 continue; 1696 continue;
1699 } 1697 }
1700 end[0] = 0; 1698 end[0] = 0;
1703 keys[0] = 0; 1701 keys[0] = 0;
1704 strmove(buffer,end+1); 1702 strmove(buffer,end+1);
1705 continue; 1703 continue;
1706 } 1704 }
1707 } 1705 }
1708 mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrWhyHere);
1709 close(fd); 1706 close(fd);
1710 mp_input_set_section(NULL); 1707 return res;
1711 return 0;
1712 } 1708 }
1713 1709
1714 void 1710 void
1715 mp_input_set_section(char *name) { 1711 mp_input_set_section(char *name) {
1716 mp_cmd_bind_section_t* bind_section = NULL; 1712 mp_cmd_bind_section_t* bind_section = NULL;