Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-31-2004, 10:38 PM
|
#1
|
|
Member
Registered: Jul 2004
Posts: 96
Rep:
|
configuration files
What is the best and most effective way to parse configuration files (standard Linux text files, # is a comment)? Is there a standard library that does that or do I have to implement my own parser (or lex for that matter)? Is it a good idea to use xml for configuration files, do you believe user would prefer that over usual text files? How would you go about parsing xml?
Thank you!
Max
|
|
|
|
09-01-2004, 01:17 AM
|
#2
|
|
Member
Registered: Apr 2002
Posts: 549
Rep:
|
I think XML is a good idea, since it takes care of all the mundane text processing. It's a little awkward if your user is used to regular files. But I'd go for it anyway because it really handles a lot of the work for you.
edit: you don't have to manually parse xml yourself. There are libraries for that (expat and libxml2 for eg). You just provide a DTD. That's the reason why I recommended xml.
Last edited by ugenn; 09-01-2004 at 01:19 AM.
|
|
|
|
09-24-2004, 09:04 AM
|
#3
|
|
Senior Member
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251
Rep:
|
max_sipos, are you going to take the XML route? I was considering creating a library that would parse an apache like conf file (name/value pairs with sections contained within <></> pairs). Actually I was hoping Apache would have a separate library for this posted but it does not appear so... the search continues.
jpbarto
|
|
|
|
09-24-2004, 10:18 AM
|
#4
|
|
Member
Registered: Jul 2004
Posts: 96
Original Poster
Rep:
|
Actually, I thought that, for the purposes of my application, a custom built, tiny parser is good enough. It would be probably a good idea if something like that would already exist, but the little I have spent analyzing sources of popular programs, I have noticed that all of them use integrated parsers.
|
|
|
|
09-24-2004, 11:17 AM
|
#5
|
|
Senior Member
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251
Rep:
|
Well I think I'm going to try my hand at writing one. It won't be XML but will follow coding standards such as httpd.conf (name value pairs and <></> sections). It doesn't make sense not to have one common one (like getopt).
|
|
|
|
09-24-2004, 12:41 PM
|
#6
|
|
Member
Registered: Jul 2004
Posts: 96
Original Poster
Rep:
|
True, if there is a way I could help, don't hesitate pm-ing me 
Best,
|
|
|
|
09-24-2004, 02:24 PM
|
#7
|
|
Senior Member
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251
Rep:
|
uhm ... max ... uhm ... you have private messages turn off ... hehe.
Anyway, I've just started creating a couple of structs for holding config data and I should have something a little more testable here in a few days. Once I do I'll let you know as I'd appreciate a tester and a second pair of eyes to make sure the code isn't completely nuts.
|
|
|
|
09-24-2004, 02:40 PM
|
#8
|
|
Member
Registered: Jul 2004
Posts: 96
Original Poster
Rep:
|
Oops  I see you're supposed to be a contributing member to use PM  . I'll have to contribute some time
Anyways, I'd be very happy test the code, be sure to post it here when you're ready!
|
|
|
|
09-28-2004, 12:05 AM
|
#9
|
|
Senior Member
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251
Rep:
|
Max, I've completed some initial tests on an alpha release for a library of sorts. I'll be posting it along with a README on Tuesday. Please download it and give it a try. It's not too well tested yet but its operable (at least on NetBSD). Please take a look and make any recommendations you'd like.
jpbarto
|
|
|
|
09-28-2004, 10:14 AM
|
#10
|
|
Senior Member
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251
Rep:
|
Ok a first alpha release has been made available. You can download it from:
http://jpbarto.freeshell.org/?id=code#conf4c
It still needs a few things like better error handling, proper configuration and makefiles, and portability testing but its operational so I thought I'd make it available for testing.
jpbarto
|
|
|
|
09-28-2004, 11:45 AM
|
#11
|
|
Senior Member
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251
Rep:
|
Ok ... you remember that whole 'download it and try it' thing ... yeah ... well uhm ... unless you're going to run it on NetBSD you might have some problems. I just got a chance to try it out on a Gentoo box and the thing just segfaults right out. Some of the tests complete successfully but the big 'test-everything' test fails immediately ... so back to the coding board I go.
|
|
|
|
09-29-2004, 12:42 PM
|
#12
|
|
Senior Member
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251
Rep:
|
A better C4C has been posted and is ready for general tester consumption. A couple of detailed readmes are included with the download. To get it up and running just download the tarball, unpack, configure, make.
You can then cd to the test directory and run make. But before you execute any of the test binaries you will have to define LD_LIBRARY_PATH (unless you installed the C4C library). I also included txt files which dictate what the output from these binaries *should* look like so you can just run a diff on the actual vs predicted to see if something went wrong.
Enjoy:
http://jpbarto.freeshell.org/dl.php?id=C4C.tar.gz
|
|
|
|
09-29-2004, 09:20 PM
|
#13
|
|
Member
Registered: Jul 2004
Posts: 96
Original Poster
Rep:
|
Results of the testing
OK, I've did a short test of the code. I had no problems making. BTW I'm running slackware 10.
****************** System info:
cat /proc/cpuinfo:
processor : 0
vendor_id : AuthenticAMD
cpu family : 6
model : 6
model name : AMD Athlon(tm) XP 1900+
stepping : 2
cpu MHz : 1595.492
cache size : 256 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 mmx fxsr sse syscall mp mmxext 3dno
wext 3dnow
bogomips : 3185.04
cat /proc/meminfo:
total: used: free: shared: buffers: cached:
Mem: 527814656 522891264 4923392 0 38309888 336007168
Swap: 509923328 16453632 493469696
MemTotal: 515444 kB
MemFree: 4808 kB
MemShared: 0 kB
Buffers: 37412 kB
Cached: 326556 kB
SwapCached: 1576 kB
Active: 223372 kB
Inactive: 218632 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 515444 kB
LowFree: 4808 kB
SwapTotal: 497972 kB
SwapFree: 481904 kB
cat /proc/version:
Linux version 2.4.26 (root@tree) (gcc version 3.3.4) #6 Mon Jun 14 19:07:27 PDT 2004
******************
I've executed the test programs one by one and compared the differences to .output files.
testc4c: OK
testc4cf: OK
testconffile: OK
testconfsection: diff output:
11c11
< stor 1- 3
---
> stor 1- 3
17c17
< stor 2- 3
---
> stor 2- 3
testconfstor: OK
testconfvalue: OK
Besides the diff at testconfsection, all programs worked properly without anything like segfault
Hope this helps, I will continue testing when I find time!
|
|
|
|
09-30-2004, 01:44 PM
|
#14
|
|
Senior Member
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251
Rep:
|
It does help, there seem to be some differences or disparities in how strings are handled between BSD and Linux. I have a couple of functions which trim non-printables and whitespace, so I'll be looking closely at those to see where improvements can be made. Also I'm going to be constructing a Conf4CReader object and functions which will allow a conf file to be easily traversed via line-by-line. After that its on to being able to easily create a configuration file and then write it to disk, instead of just reading from disk. Other improvements and suggestions are greatly appreciated of course.
Thanks,
jpbarto
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:15 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|