mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-25 11:26:37 +00:00 
			
		
		
		
	ignore syntax errors and empty lines; fixed merge function
This commit is contained in:
		
							parent
							
								
									6eb3281c4c
								
							
						
					
					
						commit
						e35670c6cb
					
				
					 2 changed files with 24 additions and 27 deletions
				
			
		|  | @ -25,19 +25,16 @@ strmap MwIniImporter::loadIniFile(std::string filename) { | ||||||
|         if(line[0] == '[') { |         if(line[0] == '[') { | ||||||
|             if(line.length() > 2) { |             if(line.length() > 2) { | ||||||
|                 section = line.substr(1, line.length()-3); |                 section = line.substr(1, line.length()-3); | ||||||
|                 continue; |  | ||||||
|             } |             } | ||||||
|             throw IniParseException(); |             continue; | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         int pos = line.find("="); |         int pos = line.find("="); | ||||||
|         if(pos < 1) { |         if(pos < 1) { | ||||||
|             throw IniParseException(); |             continue; | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         map.insert(std::pair<std::string,std::string>( |         map.insert(STRPAIR(section + ":" + line.substr(0,pos), line.substr(pos+1))); | ||||||
|             section + " " + line.substr(0,pos), line.substr(pos+1) |  | ||||||
|         )); |  | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     return map; |     return map; | ||||||
|  | @ -68,30 +65,30 @@ strmap MwIniImporter::loadCfgFile(std::string filename) { | ||||||
|          |          | ||||||
|         int pos = line.find("="); |         int pos = line.find("="); | ||||||
|         if(pos < 1) { |         if(pos < 1) { | ||||||
|             throw IniParseException(); |             continue; | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         map.insert(std::pair<std::string,std::string>( |         map.insert(STRPAIR(line.substr(0,pos), line.substr(pos+1))); | ||||||
|             line.substr(0,pos), line.substr(pos+1) |  | ||||||
|         )); |  | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     return map; |     return map; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MwIniImporter::merge(strmap &cfg, strmap &ini) { | void MwIniImporter::merge(strmap &cfg, strmap &ini) { | ||||||
|     strmap::iterator ini_it; |     strmap::iterator cfgIt; | ||||||
|     for(strmap::iterator it=cfg.begin(); it != cfg.end(); it++) { |     strmap::iterator iniIt; | ||||||
|         ini_it = ini.find(it->first); |     for(strmap::iterator it=mMergeMap.begin(); it!=mMergeMap.end(); it++) { | ||||||
|  |         if((iniIt = ini.find(it->second)) != ini.end()) { | ||||||
|  |             cfg.erase(it->first); | ||||||
|  |             if(!this->specialMerge(it->first, it->second, cfg, ini)) { | ||||||
|  |                 cfg.insert(STRPAIR(it->first, iniIt->second)); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
|         // found a key in both files
 | bool MwIniImporter::specialMerge(std::string cfgKey, std::string iniKey, strmap cfg, strmap ini) { | ||||||
|         if(ini_it != ini.end()) { |     return false; | ||||||
|             cfg.erase(it); |  | ||||||
|             cfg.insert(std::pair<std::string,std::string>( |  | ||||||
|                 ini_it->first, ini_it->second |  | ||||||
|             )); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MwIniImporter::writeToFile(std::string file, strmap &cfg) { | void MwIniImporter::writeToFile(std::string file, strmap &cfg) { | ||||||
|  |  | ||||||
|  | @ -5,17 +5,16 @@ | ||||||
| #include <map> | #include <map> | ||||||
| #include <exception> | #include <exception> | ||||||
| 
 | 
 | ||||||
| typedef std::map<std::string, std::string> strmap; |  | ||||||
| 
 | 
 | ||||||
| class IniParseException : public std::exception { | typedef std::map<std::string, std::string> strmap; | ||||||
|     virtual const char* what() const throw() { | #define STRPAIR std::make_pair<std::string, std::string> | ||||||
|         return "unexpected end of line"; |  | ||||||
|     } |  | ||||||
| }; |  | ||||||
| 
 | 
 | ||||||
| class MwIniImporter { | class MwIniImporter { | ||||||
| 
 | 
 | ||||||
|   public: |   public: | ||||||
|  |     MwIniImporter() { | ||||||
|  |         mMergeMap.insert(STRPAIR("fps", "General:Show FPS")); | ||||||
|  |     }; | ||||||
|     void    setVerbose(bool verbose); |     void    setVerbose(bool verbose); | ||||||
|     strmap  loadIniFile(std::string filename); |     strmap  loadIniFile(std::string filename); | ||||||
|     strmap  loadCfgFile(std::string filename); |     strmap  loadCfgFile(std::string filename); | ||||||
|  | @ -23,8 +22,9 @@ class MwIniImporter { | ||||||
|     void    writeToFile(std::string file, strmap &cfg); |     void    writeToFile(std::string file, strmap &cfg); | ||||||
|      |      | ||||||
|   private: |   private: | ||||||
|  |     bool   specialMerge(std::string cfgKey, std::string iniKey, strmap cfg, strmap ini); | ||||||
|     bool mVerbose; |     bool mVerbose; | ||||||
| 
 |     strmap mMergeMap; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue