ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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?
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.
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.
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.
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).
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.
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.
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.
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.
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.