MCPcopy Create free account
hub / github.com/DaedalusX64/daedalus / Open

Method Open

Source/Utility/IniFile.cpp:314–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312//
313//*****************************************************************************
314bool IIniFile::Open( const char * filename )
315{
316 const u32 BUFFER_LEN = 1024;
317 char readinfo[BUFFER_LEN+1];
318 const char trim_chars[]="{}[]"; //remove first and last character
319
320 FILE * fh( fopen( filename, "r" ) );
321 if (fh == NULL)
322 {
323 return false;
324 }
325
326 //
327 // By default start with the default section
328 //
329 mpDefaultSection = new IIniFileSection( "" );
330 IIniFileSection * p_current_section( mpDefaultSection );
331 readinfo[BUFFER_LEN] = '\0';
332
333 // XXXX Using fgets needs reworking...
334 while (fgets( readinfo, BUFFER_LEN, fh ) != NULL)
335 {
336 Tidy(readinfo); // Strip spaces from end of lines
337
338 // Handle comments
339 if (readinfo[0] == '/')
340 continue;
341
342 // Check that the line isn't empty
343 if (*readinfo != 0)
344 {
345 // Check for a section heading
346 if (readinfo[0] == '{' || readinfo[0] == '[')
347 {
348 trim(readinfo,trim_chars);
349
350 p_current_section = new IIniFileSection( readinfo );
351
352 mSections.push_back( p_current_section );
353 }
354 else
355 {
356 char *key, *value;
357
358 char * equals_idx = strchr(readinfo, '=');
359 if( equals_idx != NULL)
360 {
361 *equals_idx = '\0';
362 key = &readinfo[0];
363 value = equals_idx+1;
364 }
365 else
366 {
367 key = &readinfo[0];
368 value = NULL;
369 }
370
371 Tidy( key );

Callers 1

CreateMethod · 0.45

Calls 3

TidyFunction · 0.85
AddPropertyMethod · 0.80
trimFunction · 0.70

Tested by

no test coverage detected