LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   read options from config file (https://www.linuxquestions.org/questions/programming-9/read-options-from-config-file-320021/)

biiiep 05-04-2005 08:32 AM

read options from config file
 
halo,

i want to read options from my c-program which are written in an config file in the normal way like most config file

for example

[foo]

bar = xxx

are there any functions to do this?

thanks in advance

oblivious69 05-04-2005 08:42 AM

I don't know about functions that can handle this, but look into string tokenizers.

biiiep 05-04-2005 09:17 AM

aren't there any other useful functions, because it is used often and in many programs?

Hko 05-04-2005 11:33 AM

AFAIK there are none. And think it's a bit strange as well. getopt() exists for a long time, but general config file parser do not exist apparently...

You could copy some functions for it from a free software source.

One option that comes close may be to use XML config files and use a XML-parser library. But if your program is simple, this may be an overkill.

gnashley 05-05-2005 03:30 AM

Check out mkxf86config from knoppix.net/sources. It contains two short functions: checkbootparam and getbootparam that are for parsing options from /proc/cmdline.
You can use those or modify to suit.


All times are GMT -5. The time now is 10:45 PM.