reading config files 
Author Message
 reading config files

Where is the best place to find a common piece of source
for reading config files? There are hundreds of programs that
need to read config files of this type:

#comment

 option arg
option   arg  #comment
# comment
...

So I think it will not be necessary to do something new.

thanks
Robert



Tue, 24 Jun 2003 06:38:53 GMT  
 reading config files

Quote:

> Where is the best place to find a common piece of source
> for reading config files? There are hundreds of programs that
> need to read config files of this type:

> #comment

>  option arg
> option   arg  #comment
> # comment
> ...

> So I think it will not be necessary to do something new.

It will probably take you less time to write this code than to find it. Give it a try.

        david

--
fortran was the language of choice for the same reason that three-legged races are popular.
        -- Ken Thompson, "Reflections on Trusting Trust"



Tue, 24 Jun 2003 18:44:40 GMT  
 reading config files
Quote:
> It will probably take you less time to write this code than to find it.

Give it a try.
Thanks, I've done so.
Just wanted to be sure that there's nothing like getopt to fetch options
from
the command line, but just for this other purpose.

Robert

PS: Hope that mention 'getopt' was not off topic.
Better get some copy of this standard that I can look it up before.



Wed, 25 Jun 2003 06:24:20 GMT  
 reading config files


Quote:

> > Where is the best place to find a common piece of source
[...]
> > So I think it will not be necessary to do something new.
> It will probably take you less time to write this code than to
> find it. Give it a try.

Really?  It took me about five minutes to find "Functions to
read configuration files" on www.snippets.org.  :)

Not attempting to reinvent the wheel is a virtue that deserves
more encouragement, I think.

Sent via Deja.com
http://www.deja.com/



Wed, 25 Jun 2003 07:03:42 GMT  
 reading config files

Quote:



> > It will probably take you less time to write this code than to
> > find it. Give it a try.

> Really?  It took me about five minutes to find "Functions to
> read configuration files" on www.snippets.org.  :)

> Not attempting to reinvent the wheel is a virtue that deserves
> more encouragement, I think.

The problem with this philosophy comes up when the existing
"wheels" are shaped like triangles.  A couple of years ago I was
looking for a CGI library in C that fit a few, not-too-stringent
requirements:

        * Supported POST and GET queries and file uploads.

        * 100% pure ANSI C[1].

        * Reasonably usable library programming interface.

        * Well-written, with no arbitrary limits or security
          holes that I could spot.

        * Freely redistributable source license.

I found *lots* of CGI libraries in C, but not one of them met
these requirements.  So I wrote my own.  I still like it the best
of the ones I've seen for C, but that might be the Not Invented
Here syndrome at work.

(There are probably others that meet these requirements now, but
I couldn't find one then.)

[1] Believe it or not you can do a significant amount of
CGI-based web programming without straying outside the C
standard.
--
"You call this a *C* question? What the hell are you smoking?" --Kaz



Wed, 25 Jun 2003 07:52:21 GMT  
 reading config files

Quote:


[...]
> > Not attempting to reinvent the wheel is a virtue that deserves
> > more encouragement, I think.
> The problem with this philosophy comes up when the existing
> "wheels" are shaped like triangles.

[...]

Oh, no, I don't doubt that at all.  However, I still think a
sensible strategy would be to spend some time (perhaps up to a
third of the amount of time required to do it yourself) looking
for something you can just borrow, and not just always do it
over.

In this case, for example, while a config file of the form:

  # comment
  <string1>=<string2>

might be fairly simple, something that supports numbers or
enumerated strings (as <string2>) with error checking might be
more involved.

Sent via Deja.com
http://www.deja.com/



Wed, 25 Jun 2003 08:58:10 GMT  
 reading config files

Quote:

> Where is the best place to find a common piece of source
> for reading config files? There are hundreds of programs that
> need to read config files of this type:

> #comment

>  option arg
> option   arg  #comment
> # comment
> ...

Not exactly what you mentioned, but you might want to
have a look at the following ini file parser:

http://www.eso.org/~ndevilla/iniparser/

An ini file has the following syntax (roughly):

# comment

[Section]
key1 = value ; comment
key2 = value # comment
key3 = value

Your values might be whatever you want, the parser
understands them all as strings, up to you to do a
conversion to whatever type you were expecting.

Sorting your key/value pairs by section might
be a good idea when you have lots of them.

Hope it helps,
--
Nicolas

Sent via Deja.com
http://www.deja.com/



Tue, 01 Jul 2003 02:19:19 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. read Config-file module for C?

2. are there better ways to read config file?

3. looking for function to read config file

4. Library for reading config files?

5. read config file

6. How to read config file with repeting elements. Help Please.

7. Config files: best to use struct when reading in data

8. basic config file read

9. How to read a config file in C

10. Updating the security.config file in the CONFIG directory

11. Can't read app.config....

12. cannot read web.config

 

 
Powered by phpBB® Forum Software