[AD] Config files issues

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> Maybe a mix can be a good thing after all: whenever a config 
> file is loaded, it's kept in memory as strings. Now, when the 
> program requests some variable, the function name (get_int, 
> get_float, etc) will tell the config routines how to convert 
> the string. The converted value can be catched and returned 
> in subsequent calls, as long as the function used to retrieve 
> the value is equal to the cached value type.

Hum, if I get it correctly, this way a variable will always be stored
with the type with which it was last read; this is not that good in
certain situations, as a clueless user may change an int to bool,
loosing informations.

> Anyway, since C is strong typed, and programs are going to 
> request variables in a specific type, maybe it would be good 
> to "strong type" the variables in the .cfg files too so that 
> clever users know what kind of value does the program expect. 
> [...]

That could be useful, even if personally I don't like it that much. I'd
prefer autodetection, with the possibility to give the file parser some
clues on each variable types; something like this:

My_var = 1		# bool

In this view theoretically the file loading routine should be able to
look for clues about the type in comments surrounding the variable
entry; if no comments (or bad ones without meanings) are found, it'll
just guess the type.
We could make the routine to look for comments before the entry and on
the same line of its definition for example.

> One thing I've never figured out how to do properly, both for 
> the program and the user, is how to support multiline strings 
> in variables in such a way that it's difficult for the user 
> to screw the validity of the file. Any ideas on that?

What about surrounding valid strings with double quotes, allowing escape
sequences inside the string like in C? This way we could have in a
config file:

My_string = "This is a multiline string,
             using the new \"filesystem-like\"
             configure routines for Allegro 5!\n
             Isn't this cool?"

Another completely different approach to config files I was thinking
sometime ago was to use XML. Imagine config loading/saving routines
handling XML files as config files... This could be cool, but the
disadvantage would be 1) to loose compatibility with the old config
files structure and 2) the users could have problems manually editing
the files.

--
Angelo Mottola
a.mottola@xxxxxxxxxx
http://www.ecplusplus.com



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/