LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Standard way to read config files? (https://www.linuxquestions.org/questions/programming-9/standard-way-to-read-config-files-135844/)

nmoog 01-17-2004 06:25 PM

Standard way to read config files?
 
Newbie C (and/or C++) programming question!

Since many configuration options are set up in plain text config files, is there are standard way to read and parse them?

I could write my own version, but it would probably not be the most efficient way, and wound just be reinventing the wheel...

Thanks

jtshaw 01-17-2004 06:36 PM

The answer is..... no:(

There really isn't a default standard way linux configuration files are layed out.

Sometimes the option labes are one word, sometimes they are multiple. Sometimes the option value is one word/value, sometimes it is multiple. Sometimes there are " or some other character around values, sometimes not. It really is inconsistant.

synna 01-17-2004 07:32 PM

It depend on what do you need to store. For short info use something like :
info as string separated by a special char (say 29 so user never use it).

But it as some big disadvantage : it can be really hard to extend. If your project grow it can be a whole part to rewrite.

I would suggest you to write it as xml files. There's a lot of parser for xml files like libxml or QT. Some of the job is already done but you have to learn some basis of xml....

I think this is the best way since it's extensible and a very powerfull way of storing things...
And more it can be edited...

Hope this help...

nmoog 01-17-2004 09:46 PM

Yeah thanks. I really have no need for it at the moment, but I am pretty new to linux and having edited a million linux config files that essentially looked the same I was just wondering why it was that way!

LogicG8 01-19-2004 11:17 AM

Config files are the same mostly out of convention.
There are no rules or convenient libraries it's just
that people do it the same way b/c it is easy and
there isn't really a need to do it differently.


All times are GMT -5. The time now is 07:21 PM.