Discussion:
How to parse sections in INI-file? (existing tool?)
(too old to reply)
Rudi Effe
2004-05-28 11:20:09 UTC
Permalink
Hi there,

I plan to interpret / convert an ini-file like this:

[SECTION 1]
property 1 = value 1
property 2 = value 2
property 3 = value 3

[SECTION 2]
property 1 = value 4
...

As can be seen, the names of the sections, properties, values may contain
spaces. Seperators are new line, [ ] for section heads, '=' for
property/value. As this format is not only default for ini-files in windows,
but also for many *rc config files, there should be ready made routines in c
or c++ or even qt to handle such files.

Any hints welcome
regards

Rudi.

P.S.: Being used to C and Java, what would be the best option for developing X
apps? c++/qt? v c++ gui? gtk? java? ... ? thanks!
--
To UNSUBSCRIBE, email to debian-devel-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Richard Atterer
2004-05-28 12:10:13 UTC
Permalink
Post by Rudi Effe
[SECTION 1]
property 1 = value 1
If your app is a Gnome or KDE program, you might be able to use those
systems' facilities for ini-style files. I've also implemented something
like this myself in C++, see
<http://cvs.berlios.de/cgi-bin/viewcvs.cgi/jigdo/jigdo/src/util/configfile.hh?rev=HEAD&content-type=text/vnd.viewcvs-markup>

Cheers,

Richard
--
__ _
|_) /| Richard Atterer | GnuPG key:
| \/¯| http://atterer.net | 0x888354F7
¯ '` ¯
--
To UNSUBSCRIBE, email to debian-devel-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Simon Law
2004-05-28 13:00:25 UTC
Permalink
Post by Rudi Effe
P.S.: Being used to C and Java, what would be the best option for
developing X apps? c++/qt? v c++ gui? gtk? java? ... ? thanks!
You can try using WvStreams, a library that happens to have
WvConf inside it. WvConf is made for parsing INI-style configuration
files.

Simon
--
To UNSUBSCRIBE, email to debian-devel-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Petter Reinholdtsen
2004-05-28 16:30:17 UTC
Permalink
[Rudi Effe]
Post by Rudi Effe
P.S.: Being used to C and Java, what would be the best option for
developing X apps? c++/qt? v c++ gui? gtk? java? ... ? thanks!
There is a perl module Config::IniFiles to do it as well.
--
To UNSUBSCRIBE, email to debian-devel-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Rudi Effe
2004-05-28 18:10:14 UTC
Permalink
hej petter :)
Post by Petter Reinholdtsen
There is a perl module Config::IniFiles to do it as well.
Thanks for the hint - and @Adrian: sorry, could you please state a more
appropriate list?

I tried using sed like below to convert the ini file to XML - the section
entry, alas, does not work (fields do):

cat .kde/share/config/kmailrc |sed -e 's/"/\\"/g' |
sed -e 's/\[\([^\]]*\)\]/<\/section><section name="\1">/g;
s/ *\([^=]*\)=\(.*\)/<field name="\1" value="\2">/g'

(single line)
--
To UNSUBSCRIBE, email to debian-devel-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Adrian 'Dagurashibanipal' von Bidder
2004-06-01 06:50:10 UTC
Permalink
Post by Rudi Effe
@Adrian: sorry, could you please state a
more appropriate list?
The comp.unix.programmer newsgroup comes to mind. Or
comp.os.linux.development.apps. Ok, newsgroups and mailing lists are
not the same, but I just feel the volume here is too high, so
non-Debian specific things do not belong here, really.

cheers
-- vbi
--
I suggest a new strategy, Artoo: let the Wookie win.
-- C3P0
Matt Zimmerman
2004-05-28 17:30:12 UTC
Permalink
Post by Rudi Effe
[SECTION 1]
property 1 = value 1
property 2 = value 2
property 3 = value 3
[SECTION 2]
property 1 = value 4
...
Python's ConfigParser module reads a format which is close enough that it
should be compatible.
--
- mdz
--
To UNSUBSCRIBE, email to debian-devel-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Bob Proulx
2004-05-31 23:30:13 UTC
Permalink
Post by Rudi Effe
[SECTION 1]
property 1 = value 1
property 2 = value 2
property 3 = value 3
[SECTION 2]
property 1 = value 4
...
[...]
Any hints welcome
You said any hints. Not suggesting this is the best way. But for
single items it is not bad.

Using /bin/sh you can extract individual properties this way.

PROPERTY1=$(sed -n '/^\[SECTION 1\]/,/^$/{/property 1 = */s///p;}' cnffile)

Bob
Ondřej Surý
2004-06-01 12:30:11 UTC
Permalink
Post by Rudi Effe
[SECTION 1]
property 1 = value 1
property 2 = value 2
property 3 = value 3
[SECTION 2]
property 1 = value 4
...
[...]
Any hints welcome
Using python ConfigParser would be probably fastest... But I didn't
see original mail requirements on what lang it should use.

O.
--
Ondřej SurÜ <***@sury.org>
Martin Olsson
2004-06-01 08:30:21 UTC
Permalink
Post by Adrian 'Dagurashibanipal' von Bidder
Post by Rudi Effe
@Adrian: sorry, could you please state a
more appropriate list?
The comp.unix.programmer newsgroup comes to mind. Or
comp.os.linux.development.apps. Ok, newsgroups and mailing lists are
not the same, but I just feel the volume here is too high, so
non-Debian specific things do not belong here, really.
If you want a real mailing list try the "Linux C Programming" list
hosted by linux.org it has a homepage here:

http://www.linux.org/docs/lists.html

On a side note; I've just GPLed a .ini file library, its pure ANSI-C so
it should compile on just about any platform. Its very robust in the
sense that it allows very strange .ini files with keys written using
extra spaces/TABs and weird capitalization.

http://mnemo.nu/cs/software/mini_lib/


mvh.
/m
Post by Adrian 'Dagurashibanipal' von Bidder
Hi there,
[SECTION 1]
property 1 = value 1
property 2 = value 2
property 3 = value 3
[SECTION 2]
property 1 = value 4
...
As can be seen, the names of the sections, properties, values may contain
spaces. Seperators are new line, [ ] for section heads, '=' for
property/value. As this format is not only default for ini-files in windows,
but also for many *rc config files, there should be ready made routines in c
or c++ or even qt to handle such files.
Any hints welcome
regards
Rudi.
P.S.: Being used to C and Java, what would be the best option for developing X
apps? c++/qt? v c++ gui? gtk? java? ... ? thanks!
--
To UNSUBSCRIBE, email to debian-devel-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
martin f krafft
2004-06-01 09:10:09 UTC
Permalink
Post by Martin Olsson
On a side note; I've just GPLed a .ini file library, its pure ANSI-C so
it should compile on just about any platform. Its very robust in the
sense that it allows very strange .ini files with keys written using
extra spaces/TABs and weird capitalization.
http://mnemo.nu/cs/software/mini_lib/
Also, there are

libconfig
libdotconfig
libconfuse
--
Please do not CC me when replying to lists; I read them!

.''`. martin f. krafft <***@debian.org>
: :' : proud Debian developer, admin, and user
`. `'`
`- Debian - when you have better things to do than fixing a system

Invalid/expired PGP subkeys? Use subkeys.pgp.net as keyserver!
Loading...