Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4597 in orxonox.OLD for orxonox/trunk/src/lib/util/ini_parser.cc


Ignore:
Timestamp:
Jun 11, 2005, 12:55:48 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: setClassID implemented in all files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/util/ini_parser.cc

    r4381 r4597  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    2828IniParser::IniParser (const char* filename)
    2929{
     30  this->setClassID(CL_INI_PARSER, "IniParser");
     31
    3032  stream = NULL;
    3133  bInSection = false;
     
    5052  char* tmpName = ResourceManager::homeDirCheck(filename);
    5153  if( filename == NULL) return -1;
    52   if( stream != NULL)   fclose (stream);
     54  if( stream != NULL)   fclose (stream);
    5355  if( (stream = fopen (tmpName, "r")) == NULL)
    5456    {
     
    7173  bInSection = false;
    7274  if( stream == NULL) return -1;
    73  
     75
    7476  char linebuffer[PARSELINELENGHT];
    7577  char secbuffer[PARSELINELENGHT];
    7678  char* ptr;
    77  
     79
    7880  rewind (stream);
    7981  while( !feof( stream))
     
    8587      // check for section identifyer
    8688      if( sscanf (linebuffer, "[%s", secbuffer) == 1)
    87         {
    88           if( (ptr = strchr( secbuffer, ']')) != NULL)
    89             {
    90               *ptr = 0;
    91               if( !strcmp( secbuffer, section))
    92                 {
    93                   bInSection = true;
    94                   return 0;
    95                 }
    96             }
    97         }
     89        {
     90          if( (ptr = strchr( secbuffer, ']')) != NULL)
     91            {
     92              *ptr = 0;
     93              if( !strcmp( secbuffer, section))
     94                {
     95                  bInSection = true;
     96                  return 0;
     97                }
     98            }
     99        }
    98100    }
    99101  return -1;
     
    114116    }
    115117  if( !bInSection) return -1;
    116  
     118
    117119  char linebuffer[PARSELINELENGHT];
    118120  char* ptr;
    119  
     121
    120122  while( !feof( stream))
    121123    {
     
    125127      if( (ptr = strchr( linebuffer, '\n')) != NULL) *ptr = 0;
    126128      if( linebuffer[0] == '[')
    127         {
    128           bInSection = false;
    129           return -1;
    130         }
     129        {
     130          bInSection = false;
     131          return -1;
     132        }
    131133      sscanf(linebuffer, "%s = %s", name, value);
    132134      return 0;
    133135      /*
    134         if( (ptr = strchr( tmpBuffer, '=')) != NULL)
    135         {
    136         if( ptr == linebuffer) continue;
    137         strcpy (value, &ptr[1]);
    138         strncpy (name, linebuffer, strlen (linebuffer) - strlen (value) - 1);
    139         printf ("%s, %s\n", value, name);
    140         return 0;
    141         }
     136        if( (ptr = strchr( tmpBuffer, '=')) != NULL)
     137        {
     138        if( ptr == linebuffer) continue;
     139        strcpy (value, &ptr[1]);
     140        strncpy (name, linebuffer, strlen (linebuffer) - strlen (value) - 1);
     141        printf ("%s, %s\n", value, name);
     142        return 0;
     143        }
    142144      */
    143145    }
    144   return -1;   
     146  return -1;
    145147}
    146148
     
    151153   \param defvalue: what should be returned in case the entry cannot be found
    152154   \return a pointer to a buffer conatining the value of the specified entry. This buffer will contain the data specified in defvalue in case the entry wasn't found
    153    
     155
    154156   The returned pointer points to an internal buffer, so do not free it on your own. Do not give a NULL pointer to defvalue, this will certainly
    155157   lead to unwanted behaviour.
     
    159161  strcpy (internbuf, defvalue);
    160162  if( getSection (section) == -1) return internbuf;
    161  
     163
    162164  char namebuf[PARSELINELENGHT];
    163165  char valuebuf[PARSELINELENGHT];
    164  
     166
    165167  while( nextVar (namebuf, valuebuf) != -1)
    166168    {
    167169      if( !strcmp (name, namebuf))
    168         {
    169           strcpy (internbuf, valuebuf);
    170           return internbuf;
    171         }
     170        {
     171          strcpy (internbuf, valuebuf);
     172          return internbuf;
     173        }
    172174    }
    173175  return internbuf;
Note: See TracChangeset for help on using the changeset viewer.