#166597 - hacker013 - Wed Feb 11, 2009 8:39 am
hey everybody,
I'm looking for an Library for reading from and writing to ini files. I already found the one made by dragonminded but that one only support reading. Does someone from you guys one with reading and writing support?
gr,
newbie013
_________________
Website / Blog
Let the nds be with you.
#166600 - kusma - Wed Feb 11, 2009 1:37 pm
Uhh, this is a very simple matter of fscanf and fprintf... Sure you can't handle this by yourself?
#166606 - hacker013 - Wed Feb 11, 2009 4:33 pm
i think ini files are more complicated then you think :)
_________________
Website / Blog
Let the nds be with you.
#166607 - elhobbs - Wed Feb 11, 2009 4:45 pm
I think ini files are less complicated then you think...
Code: |
;comment
[section]
key=value |
#166608 - hacker013 - Wed Feb 11, 2009 6:12 pm
with fscanf and fprintf i haven't parsed it yet.
_________________
Website / Blog
Let the nds be with you.
#166615 - silent_code - Wed Feb 11, 2009 11:36 pm
Maybe XML will prove a better choise for the future?
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#166617 - Lazy1 - Thu Feb 12, 2009 12:05 am
It's fairly easy to parse, not sure about writing it since I haven't needed to.
1) For each line in the file
2) Get a pointer to the key/value seperator using strstr()
3) Set the key/value seperator to a null terminator
4) Add 1 to the pointer returned by strstr
There you go, your line buffer now is the key and your character pointer points to the value.
You'll probably need to handle whitespace though but that's pretty much what I did.
#166623 - gauauu - Thu Feb 12, 2009 4:58 am
silent_code wrote: |
Maybe XML will prove a better choise for the future? |
Except that XML is much slower and harder to parse. Which is no big deal on fast machines, but on something slim and slow like the DS, a more compact and simple format can sometimes be desirable.
#166624 - elwing - Thu Feb 12, 2009 7:14 am
that said the ol expat is prolly faster than a badly written user ini parser, no? as long as you do not care about schema and such it's quite easy and fast... the dificulty is not the parsing itself it is the datastructure... for simple ini file a simple map would be sufficient but for more complex ini file (ini file with path in [sections]) or for xml you will need a tree...
#166627 - timkins - Thu Feb 12, 2009 10:07 am
JSON is a nice simple format. Of the parsers listed on the official site YAJL seemed to be a good fit for the DS.[/url]
#166628 - nanou - Thu Feb 12, 2009 11:14 am
JSON is nice, I only have a couple of minor complaints about it. But I really think that if an .ini file can handle the situation anything more complex is an insane choice, unless you expect to need that complexity later on.
EDIT: I forgot to mention I agree that YAJL is probably a good fit for the DS. In the meantime I checked and it has no deps and compiles without complaint after fixing paths. I haven't tested it in that state, though, but it looks promising.
_________________
- nanou
Last edited by nanou on Thu Feb 12, 2009 12:59 pm; edited 1 time in total
#166629 - kusma - Thu Feb 12, 2009 12:58 pm
hacker13: can't you use dragonminded's lib for reading the ini-files, and write them using a simple series for fwritef()-calls?
FWIW, I tried implementing an ini-parser, and it took me about 15 minutes to get it working properly, including all special cases I could think of. I didn't end up using fscanf, since it was easier to just read a line at the time, strip it, classify it, and "manually" parse by using strchr() etc.
#166634 - hacker013 - Thu Feb 12, 2009 4:31 pm
the writing is what i think more difficult because i want no dubbel keys, and support for writing commetary :) but if it is so easy, why nobody written a completely library for it in c/c++?
_________________
Website / Blog
Let the nds be with you.
#166635 - kusma - Thu Feb 12, 2009 4:36 pm
Someone has: Microsoft. There's INI support in winapi.
Anyway: why do you think double keys and comments are issues here? A comment is just a semicolon plus some text. It can perfectly fine be fprintf-ed. Double keys is similarly easy; don't write your keys multiple times...
Last edited by kusma on Thu Feb 12, 2009 4:45 pm; edited 2 times in total
#166636 - hacker013 - Thu Feb 12, 2009 4:39 pm
but if i wanna rewrite a key :( how do i check if it exists and and if not how do i add then the key to the end of the section.
_________________
Website / Blog
Let the nds be with you.
#166638 - kusma - Thu Feb 12, 2009 4:45 pm
You parse it all in, and modify. What needs modifying. Or you can just read all the stuff in the ini-file on init, and dump the entire config-database on exit. Or something else.
#166639 - kusma - Thu Feb 12, 2009 4:46 pm
kusma wrote: |
Someone has: Microsoft. There's INI support in winapi. |
And someone at sourceforge has too. And someone else. And someone else... etc. Did you even try google?
#166642 - hacker013 - Thu Feb 12, 2009 6:14 pm
yes i tryed but the most librarys i found were platform dependent
_________________
Website / Blog
Let the nds be with you.
#166644 - Lazy1 - Thu Feb 12, 2009 6:43 pm
Is the data you are trying to read/write complicated enough to need more than a simple key=value format?
Something like that would be very easy to write since it's not very complicated.
If you want to rewrite a key=value pair just read them all in, modify the entry and write them all out again.
#166645 - kusma - Thu Feb 12, 2009 8:03 pm
hacker013 wrote: |
yes i tryed but the most librarys i found were platform dependent |
Weird, I thought I remembered you say "but if it is so easy, why nobody written a completely library for it in c/c++?"...
#166646 - Tommmie - Thu Feb 12, 2009 8:57 pm
minIni works well for me