.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Programming
General Programming Help others and get yourself helped here!

Reply
 
Thread Tools
a simple .ini parser
Old
  (#1)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default a simple .ini parser - 02-01-2005

its code isn't very "clever"... but it's enough to be used with bots:
http://cvs.sourceforge.net/viewcvs.p...pp?view=markup
http://cvs.sourceforge.net/viewcvs.p....h?view=markup

(I'm licensing this code under GNU GPL with the special exception to link against the HLSDK)

using is very simple:

PHP Code:
#include "ini.h" // at the top of your source file

CIniFile ini("test.ini"); // load an ini file
printf("%s\n"ini.Get("SECTION""Item")); // read a item from the file
ini.Set("SECTION""Item""Value"); // write a value to the ini
ini.Save("filename.ini"); // save the ini file 

Last edited by Whistler; 02-01-2005 at 09:12..
  
Reply With Quote
Re: a simple .ini parser
Old
  (#2)
Rifleman
This user broke our rules and has been BANNED
 
Status: Offline
Posts: 128
Join Date: Sep 2004
Location: Mars
Default Re: a simple .ini parser - 02-01-2005

well done man !
  
Reply With Quote
Re: a simple .ini parser
Old
  (#3)
koraX
Member
 
koraX's Avatar
 
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
Default Re: a simple .ini parser - 02-01-2005

Some notes :
  • Get rid of pragma once, you already have .h guard defined before it
  • I recommend using C++ constructs, if you are already using classes (malloc -> new, FILE* -> std::fstream, char* -> std::string
  • Wrap your parser in some napespace, so people can use it in their programs without potential conflicts
  • you should trim section name after you remove [ ], example
    Code:
      [   foo]
    will be loaded as " FOO" instead of "FOO"
  • implement removing items
  • realoc is too often, will fragment memory and slow things down. I recommend allocating in blocks, like I'll allocate 10 units at start and if eleventh unit will come, I'll allocate another 10 units, allocating everytime unit comes is IMO slow and ineffective
  • overall it is small good simple program


kXBot
koraX's utils
- see my homepage for other projects (OpenGL CSG Editor, FAT16 Sim, NNetwork Sim, ...)

Last edited by koraX; 02-01-2005 at 13:40..
  
Reply With Quote
Re: a simple .ini parser
Old
  (#4)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: a simple .ini parser - 02-01-2005

maybe use the STL, especially the vector<..> class, to get rid of all those explicit memory handling stuff, makes a lot of stuff a lot more simpler.

and depending on how you wanna use that ini class, if it's called often and needs to be fast, a hashtable might be useful


  
Reply With Quote
Re: a simple .ini parser
Old
  (#5)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: a simple .ini parser - 08-01-2005

updating CVS to fix a memory leak and allocate memory in blocks (thanks Jozef Wagner)

P.S, I found the memory leak with this handy tool:
http://filebase.bots-united.com/inde...on=file&id=254
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com