| 1774 | } |
| 1775 | |
| 1776 | bool CRGUIAcceleratorTableList::openFromFile( const char * defFile, const char * mapFile ) |
| 1777 | { |
| 1778 | _table.clear(); |
| 1779 | LVHashTable<lString16, int> defs( 256 ); |
| 1780 | LVStreamRef defStream = LVOpenFileStream( defFile, LVOM_READ ); |
| 1781 | if ( defStream.isNull() ) { |
| 1782 | CRLog::error( "cannot open keymap def file %s", defFile ); |
| 1783 | return false; |
| 1784 | } |
| 1785 | LVStreamRef mapStream = LVOpenFileStream( mapFile, LVOM_READ ); |
| 1786 | if ( mapStream.isNull() ) { |
| 1787 | CRLog::error( "cannot open keymap file %s", defFile ); |
| 1788 | return false; |
| 1789 | } |
| 1790 | lString16 line; |
| 1791 | CRPropRef props = LVCreatePropsContainer(); |
| 1792 | while ( readNextLine(defStream, line) ) { |
| 1793 | lString16 name; |
| 1794 | lString16 value; |
| 1795 | if ( splitLine( line, lString16(L"="), name, value ) ) { |
| 1796 | int key = decodeKey( value ); |
| 1797 | if ( key!=0 ) |
| 1798 | defs.set( name, key ); |
| 1799 | else |
| 1800 | CRLog::error("Unknown key definition in line %s", UnicodeToUtf8(line).c_str() ); |
| 1801 | } else if ( !line.empty() ) |
| 1802 | CRLog::error("Invalid definition in line %s", UnicodeToUtf8(line).c_str() ); |
| 1803 | } |
| 1804 | if ( !defs.length() ) { |
| 1805 | CRLog::error("No definitions read from %s", defFile); |
| 1806 | return false; |
| 1807 | |
| 1808 | } |
| 1809 | lString16 section; |
| 1810 | CRGUIAcceleratorTableRef table( new CRGUIAcceleratorTable() ); |
| 1811 | bool eof = false; |
| 1812 | do { |
| 1813 | eof = !readNextLine(mapStream, line); |
| 1814 | if ( eof || (!line.empty() && line[0]=='[') ) { |
| 1815 | // eof or [section] found |
| 1816 | // save old section |
| 1817 | if ( !section.empty() ) { |
| 1818 | if ( table->length() ) { |
| 1819 | _table.set( section, table ); |
| 1820 | } |
| 1821 | section.clear(); |
| 1822 | } |
| 1823 | // begin new section |
| 1824 | if ( !eof ) { |
| 1825 | table = CRGUIAcceleratorTableRef( new CRGUIAcceleratorTable() ); |
| 1826 | int endbracket = line.pos( lString16(L"]") ); |
| 1827 | if ( endbracket<=0 ) |
| 1828 | endbracket = line.length(); |
| 1829 | if ( endbracket >= 2 ) |
| 1830 | section = line.substr( 1, endbracket - 1 ); |
| 1831 | else |
| 1832 | section.clear(); // wrong sectino |
| 1833 | } |
no test coverage detected